:root {
  color-scheme: dark;
  --ink: #f6edda;
  --muted: #a9b6ad;
  --deep: #101a16;
  --panel: #17251f;
  --panel-2: #1d3028;
  --line: rgba(242, 221, 174, 0.14);
  --red: #df654e;
  --red-dark: #a9362e;
  --jade: #6ba58b;
  --gold: #e6bd6c;
  --board: #d8b16d;
  --board-deep: #bb8b4e;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.28);
  font-family: "Segoe UI Variable Text", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 12%, rgba(107, 165, 139, 0.12), transparent 26rem),
    radial-gradient(circle at 92% 82%, rgba(223, 101, 78, 0.09), transparent 28rem),
    var(--deep);
}

html,
body {
  min-height: 100%;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px clamp(16px, 3vw, 42px) 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(230, 189, 108, 0.5);
  border-radius: 50%;
  color: var(--gold);
  background: rgba(230, 189, 108, 0.08);
  font-family: "Noto Serif CJK SC", "Microsoft YaHei", "SimSun", serif;
  font-size: 1.35rem;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--jade);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: "Segoe UI Variable Display", "Segoe UI", Arial, sans-serif;
  font-size: clamp(1.35rem, 3vw, 2.05rem);
  font-weight: 760;
  letter-spacing: -0.025em;
}

.game-result {
  min-width: 70px;
  padding: 9px 14px;
  border: 1px solid rgba(223, 101, 78, 0.42);
  border-radius: 999px;
  color: #ffd8d1;
  background: rgba(223, 101, 78, 0.1);
  font-weight: 800;
  text-align: center;
}

.view-mode-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.view-mode-button:hover {
  border-color: rgba(230, 189, 108, 0.55);
  background: var(--panel-2);
  transform: translateY(-1px);
}

.view-mode-button:focus-visible {
  outline: 3px solid rgba(230, 189, 108, 0.4);
  outline-offset: 2px;
}

.view-mode-button[aria-pressed="true"] {
  color: #fff7e8;
  border-color: rgba(223, 101, 78, 0.6);
  background: var(--red-dark);
}

.library-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(23, 37, 31, 0.72);
}

.library-toolbar label {
  color: var(--jade);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.library-toolbar select {
  min-width: min(420px, 55vw);
  min-height: 36px;
  padding: 6px 34px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-2);
  font: inherit;
}

.library-toolbar > span {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.8rem;
}

.media-toggles {
  display: flex;
  gap: 7px;
}

.media-toggles button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel);
  cursor: pointer;
}

.media-toggles button[aria-pressed="true"] {
  color: #fff7e8;
  border-color: rgba(230, 189, 108, 0.58);
  background: rgba(166, 107, 18, 0.35);
}

.media-toggles button:focus-visible {
  outline: 3px solid rgba(230, 189, 108, 0.4);
  outline-offset: 2px;
}

.media-toggles button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.media-toggles span {
  margin-left: 0;
  color: inherit;
  font-size: 0.8rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 0.9fr) minmax(430px, 1.1fr);
  gap: clamp(22px, 4vw, 52px);
  align-items: start;
}

.board-column {
  position: sticky;
  top: 18px;
  width: min(100%, max(300px, calc((100dvh - 390px) * 0.9)));
  justify-self: center;
}

.player-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border: 1px solid var(--line);
  background: rgba(23, 37, 31, 0.88);
}

.player-black {
  border-radius: 16px 16px 6px 6px;
}

.player-red {
  border-radius: 6px 6px 16px 16px;
}

.player-card strong {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
}

.side-label {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.piece-dot {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: #f1dbab;
  font-family: "Noto Serif CJK SC", "Microsoft YaHei", "SimSun", serif;
  font-size: 1rem;
  font-weight: 700;
}

.red-dot {
  color: var(--red-dark);
  border: 2px solid var(--red-dark);
}

.black-dot {
  color: #27342d;
  border: 2px solid #27342d;
}

.board-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  margin: 7px 0;
  border: 1px solid rgba(230, 189, 108, 0.25);
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: var(--board);
}

#board {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 9 / 10;
}

.board-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #47351f;
  background: var(--board);
  font-weight: 700;
}

.board-loading.hidden {
  display: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.controls button {
  min-height: 44px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.controls button:hover:not(:disabled) {
  border-color: rgba(230, 189, 108, 0.55);
  background: var(--panel-2);
  transform: translateY(-1px);
}

.controls button:focus-visible,
.move-cell:focus-visible {
  outline: 3px solid rgba(230, 189, 108, 0.4);
  outline-offset: 2px;
}

.controls button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.icon-button {
  width: 46px;
  border-radius: 12px;
  font-size: 1.2rem;
}

.play-button {
  min-width: 112px;
  border-radius: 12px;
  color: #fff7e8 !important;
  background: var(--red-dark) !important;
}

.speed-control {
  display: flex;
  flex: 0 0 100%;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.speed-control select {
  min-height: 34px;
  padding: 5px 30px 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-2);
  font: inherit;
}

.speed-control select:focus-visible {
  outline: 3px solid rgba(230, 189, 108, 0.4);
  outline-offset: 2px;
}

.speed-control select:disabled {
  opacity: 0.45;
}

.analysis-column {
  display: grid;
  gap: 16px;
}

.game-meta {
  display: grid;
  grid-template-columns: 1.5fr 0.8fr 0.65fr;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--line);
}

.game-meta > div {
  min-width: 0;
  padding: 13px 15px;
  background: var(--panel);
}

.game-meta span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.75rem;
}

.game-meta strong {
  display: block;
  overflow: hidden;
  font-size: 0.92rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.current-move {
  min-height: 210px;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid rgba(230, 189, 108, 0.2);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(230, 189, 108, 0.08), transparent 48%),
    var(--panel);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.14);
}

.move-heading,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.phase-chip {
  padding: 6px 9px;
  border-radius: 7px;
  color: #d5f0e3;
  background: rgba(107, 165, 139, 0.18);
  font-size: 0.78rem;
  font-weight: 750;
}

.move-counter {
  color: var(--muted);
  font-size: 0.85rem;
}

.notation-line {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin: 22px 0 12px;
}

.notation-line strong {
  color: var(--gold);
  font-family: "Segoe UI Variable Display", "Segoe UI", Arial, sans-serif;
  font-size: clamp(1.7rem, 4vw, 2.65rem);
  font-weight: 760;
  letter-spacing: -0.025em;
}

.move-route {
  margin-bottom: 8px;
  color: #d6ded9;
  font-size: 0.95rem;
}

.move-note {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.65;
}

.score-list-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(23, 37, 31, 0.78);
}

.section-heading {
  padding: 18px 20px 14px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-family: "Segoe UI Variable Display", "Segoe UI", Arial, sans-serif;
  font-size: 1.3rem;
  font-weight: 760;
  letter-spacing: -0.015em;
}

.section-heading > span {
  color: var(--muted);
  font-size: 0.83rem;
}

.score-header,
.score-row {
  display: grid;
  grid-template-columns: 52px 1fr 1fr;
}

.score-header {
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.score-list {
  overflow-y: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  max-height: 470px;
  margin: 0;
  padding: 6px 8px 10px;
  list-style: none;
  scrollbar-color: var(--jade) transparent;
}

body.fit-screen {
  overflow: hidden;
  height: 100dvh;
}

body.fit-screen .app-shell {
  display: grid;
  width: min(1600px, 100%);
  height: 100dvh;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding-top: 12px;
  padding-bottom: 12px;
}

body.fit-screen .topbar {
  margin-bottom: 12px;
}

body.fit-screen .library-toolbar {
  margin-bottom: 8px;
  padding-block: 6px;
}

body.fit-screen .workspace {
  min-height: 0;
  align-items: stretch;
}

body.fit-screen .board-column {
  position: static;
  display: grid;
  width: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

body.fit-screen .board-wrap {
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 9 / 10;
  place-self: center;
}

body.fit-screen #board {
  width: 100%;
  height: 100%;
}

body.fit-screen .analysis-column {
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

body.fit-screen .score-list {
  max-height: none;
}

.score-row {
  align-items: center;
  border-bottom: 1px solid rgba(242, 221, 174, 0.07);
}

.turn-number {
  padding-left: 9px;
  color: var(--muted);
  font-size: 0.78rem;
}

.move-cell {
  min-height: 42px;
  padding: 9px 11px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  font-family: "Segoe UI Variable Text", "Segoe UI", Arial, sans-serif;
  font-size: 0.92rem;
  font-weight: 620;
  text-align: left;
  cursor: pointer;
}

.move-cell:hover:not(:disabled) {
  background: rgba(230, 189, 108, 0.08);
}

.move-cell.active {
  color: #fff9eb;
  background: var(--red-dark);
}

.move-cell:disabled {
  cursor: default;
}

@media (max-width: 940px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .board-column {
    position: static;
    width: min(650px, 100%);
    margin: 0 auto;
  }

  body.fit-screen .workspace {
    display: block;
    overflow-y: auto;
  }

  body.fit-screen .board-column {
    display: flex;
    flex-direction: column;
    width: min(100%, calc((100dvh - 345px) * 0.9));
    min-width: 290px;
    height: auto;
  }

  body.fit-screen .board-wrap {
    width: 100%;
    height: auto;
    max-height: none;
  }

  body.fit-screen .analysis-column {
    overflow: visible;
    margin-top: 18px;
    padding-right: 0;
  }

  body.fit-screen .score-list {
    overflow-y: auto;
    max-height: min(390px, 52dvh);
  }
}

@media (max-width: 580px) {
  .app-shell {
    padding: 16px 12px 28px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    align-items: flex-end;
    flex-direction: column;
    gap: 7px;
  }

  .view-mode-button {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  .library-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
  }

  .library-toolbar select {
    width: 100%;
    min-width: 0;
  }

  .library-toolbar > span {
    margin-left: 0;
  }

  .media-toggles {
    width: 100%;
  }

  .media-toggles button {
    flex: 1;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .game-result {
    min-width: 58px;
    padding-inline: 10px;
  }

  .game-meta {
    grid-template-columns: 1fr 1fr;
  }

  .game-meta > div:first-child {
    grid-column: 1 / -1;
  }

  .notation-line {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .score-header,
  .score-row {
    grid-template-columns: 40px 1fr 1fr;
  }

  .score-list {
    max-height: 390px;
  }

  body.fit-screen .app-shell {
    padding: 8px 10px;
  }

  body.fit-screen .topbar {
    margin-bottom: 8px;
  }

  body.fit-screen .board-column {
    width: min(100%, calc((100dvh - 190px) * 0.9));
    min-width: 270px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
