:root {
  color-scheme: light;
  --ink: #19392f;
  --ink-deep: #0e2a22;
  --ink-soft: #60736c;
  --paper: #f4f0e7;
  --paper-light: #fbf9f3;
  --line: rgba(25, 57, 47, 0.14);
  --gold: #bd8952;
  --wood: #d9af77;
  --wood-light: #e5c490;
  --coral: #b95f4d;
  --shadow: 0 24px 60px rgba(27, 47, 39, 0.12);
  --radius-lg: 24px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 5% 0%, rgba(189, 137, 82, 0.13), transparent 27rem),
    linear-gradient(180deg, #f8f5ed 0%, var(--paper) 100%);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(185, 95, 77, 0.28);
  outline-offset: 2px;
}

.page-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 0 42px 64px;
}

.topbar {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 8px);
  gap: 4px;
  width: 34px;
  height: 34px;
  align-content: center;
  justify-content: center;
  border: 1px solid var(--ink);
  border-radius: 50%;
}

.brand-mark i {
  width: 8px;
  height: 8px;
  display: block;
  border-radius: 50%;
  background: var(--ink);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  letter-spacing: 0.14em;
  font-family: "Songti TC", "Noto Serif TC", serif;
  font-size: 19px;
}

.brand small {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 8px;
  letter-spacing: 0.23em;
}

.topbar-note {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink-soft);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6c9a72;
  box-shadow: 0 0 0 5px rgba(108, 154, 114, 0.12);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: clamp(30px, 4vw, 66px);
  align-items: start;
  padding-top: 42px;
}

.game-column {
  min-width: 0;
}

.game-heading,
.section-heading,
.profile-title-row,
.panel-heading,
.game-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.23em;
}

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

h1,
h2 {
  font-family: "Songti TC", "Noto Serif TC", serif;
  font-weight: 700;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 4vw, 47px);
  letter-spacing: 0.04em;
}

h2 {
  margin-bottom: 0;
  font-size: 23px;
}

.game-metrics {
  display: flex;
  gap: 36px;
  text-align: right;
}

.game-metrics span,
.game-metrics strong {
  display: block;
}

.game-metrics span {
  margin-bottom: 6px;
  color: var(--ink-soft);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.game-metrics strong {
  font-variant-numeric: tabular-nums;
  font-size: 18px;
}

.stone-label {
  display: flex !important;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.stone-label i {
  width: 16px;
  height: 16px;
  display: inline-block;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #53635e, #0b1714 63%);
}

.turn-banner {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 60px;
  margin: 28px 0 16px;
  padding: 10px 18px;
  border: 1px solid rgba(25, 57, 47, 0.13);
  border-radius: 14px;
  background: rgba(251, 249, 243, 0.72);
}

.turn-banner.ai-turn .turn-stone {
  background: radial-gradient(circle at 35% 28%, #fff, #d9d5cc 70%);
  border: 1px solid rgba(25, 57, 47, 0.22);
}

.turn-banner.ended .turn-stone {
  background: var(--gold);
}

.turn-stone {
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #53635e, #0b1714 63%);
  box-shadow: 0 5px 12px rgba(13, 32, 26, 0.22);
}

.turn-banner strong,
.turn-banner span {
  display: block;
}

.turn-banner strong {
  margin-bottom: 2px;
  font-size: 15px;
}

.turn-banner div span {
  color: var(--ink-soft);
  font-size: 12px;
}

.board-frame {
  position: relative;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 12px;
  border: 1px solid rgba(89, 64, 35, 0.22);
  border-radius: 8px;
  background: #b88651;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.24);
}

.board-frame::before {
  content: "";
  position: absolute;
  inset: 4px;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 5px;
}

.board-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(117, 73, 35, 0.045) 1px, transparent 1px) 0 0 / 28px 100%,
    radial-gradient(circle at 45% 32%, var(--wood-light), var(--wood));
}

#board-canvas,
.intersection-grid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.intersection-grid {
  z-index: 2;
}

.intersection {
  position: absolute;
  width: clamp(20px, 6.4%, 44px);
  aspect-ratio: 1;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.intersection:not(:disabled):hover {
  background: rgba(24, 53, 43, 0.14);
  box-shadow: inset 0 0 0 2px rgba(24, 53, 43, 0.3);
}

.intersection:focus-visible {
  outline-color: rgba(185, 95, 77, 0.72);
  outline-offset: -3px;
}

.result-card {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 6%;
  width: min(330px, 78%);
  padding: 17px 22px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  background: rgba(14, 42, 34, 0.94);
  color: #fffaf0;
  box-shadow: 0 18px 45px rgba(14, 42, 34, 0.25);
  text-align: center;
  backdrop-filter: blur(10px);
}

.result-card span,
.result-card strong {
  display: block;
}

.result-card span {
  margin-bottom: 5px;
  color: #d9b27c;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.result-card strong {
  font-family: "Songti TC", serif;
  font-size: 25px;
}

.result-card p {
  margin: 5px 0 0;
  color: rgba(255, 250, 240, 0.74);
  font-size: 12px;
}

.game-actions {
  gap: 12px;
  padding: 18px 0 30px;
}

.game-actions p {
  margin: 0 0 0 auto;
  color: var(--ink-soft);
  font-size: 12px;
}

.button {
  min-height: 46px;
  padding: 0 20px;
  border-radius: 10px;
  font-weight: 700;
}

.button-primary {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 30px;
  min-width: 174px;
  border: 1px solid var(--ink-deep);
  background: var(--ink-deep);
  color: #fff;
}

.button-primary:hover {
  background: #173d32;
}

.button-quiet {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.button-quiet:hover:not(:disabled) {
  background: rgba(25, 57, 47, 0.06);
}

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

.level-section {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.section-heading {
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 20px;
}

.section-heading > p {
  max-width: 270px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.7;
  text-align: right;
}

.level-track {
  display: grid;
  grid-template-columns: repeat(10, minmax(56px, 1fr));
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 8px;
}

.level-button {
  position: relative;
  min-height: 73px;
  padding: 9px 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(251, 249, 243, 0.62);
  color: var(--ink-soft);
}

.level-button strong,
.level-button small {
  display: block;
}

.level-button strong {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 18px;
}

.level-button small {
  font-size: 9px;
  white-space: nowrap;
}

.level-button.unlocked:hover {
  transform: translateY(-2px);
  border-color: rgba(25, 57, 47, 0.35);
}

.level-button.active {
  border-color: var(--ink-deep);
  background: var(--ink-deep);
  color: rgba(255, 255, 255, 0.67);
  box-shadow: 0 9px 22px rgba(14, 42, 34, 0.16);
}

.level-button.active strong {
  color: #fff;
}

.level-button.locked {
  cursor: not-allowed;
  opacity: 0.48;
}

.level-button.locked::after {
  content: "·";
  position: absolute;
  top: 5px;
  right: 8px;
  font-size: 17px;
}

.profile-column {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 22px;
}

.panel,
.score-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(251, 249, 243, 0.72);
  box-shadow: 0 10px 30px rgba(31, 53, 44, 0.035);
}

.profile-card,
.history-card,
.rules-card {
  padding: 22px;
}

.profile-title-row {
  justify-content: flex-start;
  gap: 13px;
  margin-bottom: 18px;
}

.avatar {
  width: 45px;
  height: 45px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--ink-deep);
  color: #fff;
  font-family: "Songti TC", serif;
  font-size: 19px;
}

.profile-title-row span,
.profile-title-row strong {
  display: block;
}

.profile-title-row span {
  margin-bottom: 2px;
  color: var(--ink-soft);
  font-size: 10px;
}

.profile-title-row strong {
  font-size: 17px;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-soft);
  font-size: 11px;
}

.select-control,
.new-player-row input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper-light);
  color: var(--ink);
}

.select-control {
  padding: 0 36px 0 12px;
}

.new-player-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px;
  margin-top: 9px;
}

.new-player-row input {
  min-width: 0;
  padding: 0 12px;
}

.new-player-row button {
  padding: 0 13px;
  border: 0;
  border-radius: 9px;
  background: var(--gold);
  color: #fff;
  font-weight: 700;
}

.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.score-card {
  min-height: 105px;
  padding: 17px;
}

.score-card-featured {
  grid-column: 1 / -1;
  min-height: 119px;
  border-color: transparent;
  background: var(--ink-deep);
  color: #fff;
}

.score-card > span,
.score-card > strong,
.score-card > small {
  display: block;
}

.score-card > span {
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 10px;
}

.score-card-featured > span,
.score-card-featured > small {
  color: rgba(255, 255, 255, 0.57);
}

.score-card > strong {
  font-size: 25px;
  font-variant-numeric: tabular-nums;
}

.score-card-featured > strong {
  font-family: "Songti TC", serif;
  font-size: 38px;
}

.score-card > strong small {
  display: inline;
  margin-left: 4px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 500;
}

.score-card > small {
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: 9px;
}

.panel-heading {
  align-items: flex-start;
  margin-bottom: 16px;
}

.panel-heading h2,
.rules-card h2 {
  font-size: 19px;
}

.panel-heading > span {
  color: var(--ink-soft);
  font-size: 10px;
}

.history-list {
  display: grid;
  max-height: 302px;
  overflow-y: auto;
}

.history-empty {
  padding: 28px 10px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 11px;
  align-items: center;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}

.history-badge {
  min-width: 39px;
  padding: 5px 6px;
  border-radius: 7px;
  background: rgba(25, 57, 47, 0.09);
  color: var(--ink);
  font-size: 10px;
  font-weight: 800;
  text-align: center;
}

.history-badge.win {
  background: rgba(108, 154, 114, 0.16);
  color: #3e7047;
}

.history-badge.loss {
  background: rgba(185, 95, 77, 0.12);
  color: var(--coral);
}

.history-meta strong,
.history-meta span,
.history-score strong,
.history-score span {
  display: block;
}

.history-meta strong {
  margin-bottom: 3px;
  font-size: 12px;
}

.history-meta span,
.history-score span {
  color: var(--ink-soft);
  font-size: 9px;
}

.history-score {
  text-align: right;
}

.history-score strong {
  margin-bottom: 3px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.rules-card dl {
  margin: 12px 0 0;
}

.rules-card dl div {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 11px;
}

.rules-card dt {
  color: var(--ink-soft);
}

.rules-card dd {
  margin: 0;
  font-weight: 700;
}

.toast {
  position: fixed;
  z-index: 10;
  right: 24px;
  bottom: 24px;
  max-width: min(360px, calc(100vw - 48px));
  padding: 13px 18px;
  transform: translateY(25px);
  border-radius: 10px;
  background: var(--ink-deep);
  color: #fff;
  box-shadow: 0 16px 38px rgba(14, 42, 34, 0.28);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1080px) {
  .page-shell {
    padding-inline: 26px;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 28px;
  }

  .game-actions p {
    display: none;
  }
}

@media (max-width: 850px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .profile-column {
    position: static;
    grid-template-columns: 1fr 1fr;
  }

  .profile-card,
  .score-grid {
    align-self: stretch;
  }

  .history-card,
  .rules-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 600px) {
  .page-shell {
    padding: 0 14px 40px;
  }

  .topbar {
    min-height: 76px;
  }

  .topbar-note {
    width: 10px;
    overflow: hidden;
    white-space: nowrap;
  }

  .game-layout {
    padding-top: 26px;
  }

  .game-heading {
    align-items: flex-end;
  }

  h1 {
    font-size: 29px;
  }

  .game-metrics {
    gap: 15px;
  }

  .game-metrics > div:last-child {
    display: none;
  }

  .turn-banner {
    margin-top: 20px;
  }

  .board-frame {
    padding: 7px;
  }

  .game-actions {
    flex-wrap: wrap;
  }

  .button-primary {
    flex: 1;
  }

  .section-heading {
    align-items: flex-start;
  }

  .section-heading > p {
    display: none;
  }

  .profile-column {
    grid-template-columns: 1fr;
  }

  .history-card,
  .rules-card {
    grid-column: auto;
  }

  .result-card {
    bottom: 4%;
  }
}

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