:root {
  color-scheme: light;
  --ink: #17222b;
  --muted: #667481;
  --page: #f3f5f2;
  --paper: #ffffff;
  --line: #d8dfdc;
  --wood: #dfb86b;
  --wood-deep: #a86e2d;
  --teal: #176f68;
  --teal-dark: #0e514c;
  --blue: #286f9e;
  --gold: #d99d29;
  --danger: #c44b3a;
  --shadow: 0 18px 42px rgba(18, 31, 39, 0.13);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(23, 111, 104, 0.1), transparent 34%),
    linear-gradient(315deg, rgba(217, 157, 41, 0.14), transparent 36%),
    var(--page);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang HK", "PingFang TC",
    "Microsoft JhengHei", Arial, sans-serif;
  line-height: 1.5;
}

button,
select {
  font: inherit;
}

button,
select,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(217, 157, 41, 0.6);
  outline-offset: 2px;
}

.app-shell {
  width: min(1200px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 44px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(116px, auto) 1fr auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.back-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  padding: 9px 13px;
  text-decoration: none;
  font-weight: 800;
}

.eyebrow {
  margin: 0;
  color: var(--teal-dark);
  font-size: 0.84rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  letter-spacing: 0;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(2rem, 7vw, 4.2rem);
  line-height: 0.95;
}

h2 {
  margin: 0;
  font-size: 1.08rem;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 330px);
  gap: 16px;
  align-items: start;
}

.board-panel,
.side-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.board-panel {
  overflow: hidden;
}

.board-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.board-toolbar div:first-child {
  display: grid;
  gap: 1px;
}

.board-toolbar span,
.score-strip {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 760;
}

.board-toolbar strong {
  font-size: 1.24rem;
}

.score-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.score-strip b {
  color: var(--ink);
}

.board-wrap {
  display: grid;
  place-items: center;
  padding: clamp(10px, 2.8vw, 22px);
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.28), transparent 30%),
    linear-gradient(135deg, #e7c57f, #d49e4f 48%, #b87d34);
}

.board {
  --size: min(76vw, 680px);
  width: min(var(--size), 100%);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  padding: 2.5%;
  border: 2px solid rgba(83, 53, 24, 0.72);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 42%),
    var(--wood);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.3),
    0 18px 42px rgba(73, 45, 19, 0.25);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  cursor: pointer;
}

.cell::before,
.cell::after {
  content: "";
  position: absolute;
  z-index: 0;
  background: rgba(70, 45, 24, 0.64);
  pointer-events: none;
}

.cell::before {
  width: 1px;
  top: 0;
  bottom: 0;
  left: 50%;
}

.cell::after {
  height: 1px;
  left: 0;
  right: 0;
  top: 50%;
}

.cell:hover:not(:disabled) .ghost {
  opacity: 0.34;
}

.cell:disabled {
  cursor: default;
}

.star {
  position: absolute;
  z-index: 1;
  width: 14%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(70, 45, 24, 0.8);
}

.ghost,
.piece {
  position: relative;
  z-index: 2;
  width: 72%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 999px;
}

.ghost {
  opacity: 0;
  background: rgba(23, 34, 43, 0.7);
}

.piece.black {
  background:
    radial-gradient(circle at 34% 28%, #69707a, #131820 46%, #050608 100%);
  box-shadow: inset -6px -7px 13px rgba(0, 0, 0, 0.58), 0 4px 10px rgba(0, 0, 0, 0.28);
}

.piece.white {
  background:
    radial-gradient(circle at 35% 25%, #ffffff, #f1eee7 56%, #c8c0b1 100%);
  box-shadow: inset -5px -6px 12px rgba(150, 134, 112, 0.36), 0 4px 9px rgba(62, 38, 18, 0.2);
}

.move-index {
  color: #ffffff;
  font-size: clamp(0.55rem, 1.5vw, 0.82rem);
  font-weight: 900;
  line-height: 1;
}

.piece.white .move-index {
  color: #1d2934;
}

.last-move {
  outline: 4px solid #006bff;
  outline-offset: 3px;
  filter: drop-shadow(0 0 7px rgba(0, 107, 255, 0.9));
}

.status-line {
  min-height: 1.5em;
  margin: 0;
  padding: 13px 16px 15px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-weight: 760;
}

.side-panel {
  display: grid;
  gap: 1px;
  overflow: hidden;
}

.control-section {
  display: grid;
  gap: 13px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.84);
}

.control-section + .control-section {
  border-top: 1px solid var(--line);
}

.topbar-reward {
  width: min(330px, 34vw);
  min-width: 260px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(217, 157, 41, 0.16), rgba(23, 111, 104, 0.08)),
    rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 28px rgba(18, 31, 39, 0.1);
}

.topbar-reward[hidden] {
  display: none;
}

.topbar-reward h2 {
  margin-bottom: 2px;
  font-size: 0.92rem;
}

.topbar-reward p {
  margin: 0;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.35;
}

.topbar-reward a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--teal);
  border-radius: 8px;
  background: var(--teal);
  color: #ffffff;
  padding: 9px 12px;
  text-decoration: none;
  white-space: nowrap;
  font-weight: 850;
}

label {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-weight: 850;
}

label span {
  color: var(--muted);
  font-size: 0.88rem;
}

select,
button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  padding: 9px 12px;
  font-weight: 800;
}

select {
  width: 100%;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

button:disabled,
select:disabled {
  opacity: 0.52;
  cursor: default;
}

.move-list {
  display: grid;
  gap: 7px;
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.move-list li {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  padding: 4px 0;
  color: var(--muted);
  font-weight: 780;
}

.move-list .move-number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.move-list .move-detail {
  min-width: 0;
}

.move-list .move-list-empty {
  display: block;
}

.move-list strong {
  color: var(--ink);
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .topbar-brand {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .topbar-reward {
    width: min(100%, 330px);
    min-width: 0;
    grid-column: 2;
    justify-self: end;
  }

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

  .board-panel {
    order: 2;
  }

  .side-panel {
    display: contents;
  }

  .side-panel .control-section {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: var(--shadow);
  }

  .side-panel .control-section:first-child {
    order: 1;
  }

  .side-panel .control-section:last-child {
    order: 3;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 16px, 1200px);
    padding-top: 12px;
  }

  .topbar {
    gap: 10px;
  }

  .back-link {
    min-height: 38px;
    padding: 7px 10px;
    font-size: 0.9rem;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar-brand {
    grid-column: 1;
    grid-row: 1;
  }

  .back-link {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
  }

  .topbar-reward {
    width: 100%;
    grid-column: 1;
    grid-row: 3;
  }

  .board-toolbar {
    align-items: start;
    flex-direction: column;
  }

  .score-strip {
    justify-content: flex-start;
  }

  .board-wrap {
    padding: 8px;
  }

  .board {
    width: min(94vw, 680px);
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .move-index {
    display: none;
  }
}
