:root {
  color-scheme: dark;
  --ink-950: #0c1215;
  --ink-900: #10191d;
  --ink-850: #152126;
  --ink-800: #1a2a30;
  --ink-700: #294047;
  --ink-500: #66818a;
  --ink-300: #a8bec1;
  --paper: #ead4a0;
  --paper-deep: #c69755;
  --paper-light: #f2dfb3;
  --vermilion: #d85643;
  --vermilion-soft: #ef8e6d;
  --jade: #78b6a7;
  --white: #f6f1e7;
  --muted: #91a7aa;
  --line: rgba(183, 211, 209, 0.14);
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--ink-950);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--white);
  background:
    radial-gradient(circle at 7% 0%, rgba(83, 143, 137, 0.16), transparent 31rem),
    radial-gradient(circle at 93% 24%, rgba(193, 104, 64, 0.12), transparent 26rem),
    linear-gradient(145deg, var(--ink-950) 0%, var(--ink-900) 50%, #0d161a 100%);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--jade);
  outline-offset: 3px;
}

.app-shell {
  width: min(1320px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 18px;
}

.topbar,
.board-heading,
.section-heading,
.action-row,
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar {
  min-height: 48px;
  margin-bottom: 44px;
}

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

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid rgba(239, 142, 109, 0.65);
  border-radius: 12px 12px 12px 3px;
  color: var(--vermilion-soft);
  background: rgba(216, 86, 67, 0.12);
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 21px;
  box-shadow: inset 0 0 0 4px rgba(216, 86, 67, 0.04);
}

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

.brand strong {
  font-family: "Noto Serif TC", "Songti TC", "Microsoft JhengHei", serif;
  font-size: 20px;
  letter-spacing: 0.14em;
  line-height: 1;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.18em;
}

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

.signal-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--jade);
  box-shadow: 0 0 0 5px rgba(120, 182, 167, 0.1);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 350px);
  gap: clamp(32px, 6vw, 86px);
  align-items: start;
}

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

.board-heading {
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--jade);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2em;
}

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

h1 {
  max-width: 600px;
  margin-bottom: 0;
  color: var(--white);
  font-family: "Noto Serif TC", "Songti TC", "Microsoft JhengHei", serif;
  font-size: clamp(26px, 3vw, 40px);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.24;
}

h2 {
  margin-bottom: 0;
  color: var(--white);
  font-family: "Noto Serif TC", "Songti TC", "Microsoft JhengHei", serif;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.3;
}

.turn-card {
  flex: 0 0 auto;
  padding: 11px 15px 12px;
  border-left: 2px solid var(--vermilion);
  background: rgba(255, 255, 255, 0.035);
}

.turn-label {
  display: block;
  margin-bottom: 1px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.14em;
}

.turn-card strong {
  color: var(--vermilion-soft);
  font-size: 15px;
  white-space: nowrap;
}

.board-shell {
  position: relative;
  width: min(100%, 700px);
  margin: 0 auto;
  padding: 12px;
  border: 1px solid rgba(234, 212, 160, 0.22);
  border-radius: 20px;
  background:
    linear-gradient(132deg, rgba(255, 255, 255, 0.08), transparent 30%),
    #77532f;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.board-shell::before {
  position: absolute;
  inset: 6px;
  z-index: 0;
  border: 1px solid rgba(255, 224, 168, 0.16);
  border-radius: 15px;
  content: "";
  pointer-events: none;
}

#boardCanvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 9 / 10;
  border-radius: 11px;
  touch-action: manipulation;
  cursor: pointer;
}

.board-overlay {
  position: absolute;
  inset: 12px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  color: var(--white);
  background: rgba(12, 18, 21, 0.7);
  backdrop-filter: blur(4px);
  text-align: center;
}

.board-overlay[hidden] {
  display: none;
}

.overlay-kicker {
  margin-bottom: 8px;
  color: var(--jade);
  font-size: 12px;
  letter-spacing: 0.2em;
}

.board-overlay strong {
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: clamp(30px, 5vw, 48px);
  font-weight: 600;
}

.board-overlay span:last-child {
  margin-top: 4px;
  color: var(--muted);
  font-size: 15px;
}

.board-hint {
  width: min(100%, 700px);
  margin: 16px auto 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.control-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(155deg, rgba(38, 59, 65, 0.7), rgba(19, 31, 36, 0.83));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
}

.panel-section {
  padding: 25px 25px 24px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 22px;
}

.section-heading.compact {
  align-items: center;
  margin-bottom: 17px;
}

.section-index {
  color: rgba(168, 190, 193, 0.46);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  letter-spacing: 0.12em;
}

.field {
  display: block;
  margin: 0 0 16px;
}

.field > span {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-300);
  font-size: 14px;
}

select {
  width: 100%;
  min-height: 46px;
  padding: 0 38px 0 13px;
  border: 1px solid rgba(183, 211, 209, 0.18);
  border-radius: 10px;
  color: var(--white);
  background-color: rgba(10, 20, 24, 0.52);
  font-size: 15px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) 20px,
    calc(100% - 12px) 20px;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
}

select option {
  color: #132025;
  background: #e8dcc0;
}

.primary-button,
.secondary-button,
.icon-button,
.surrender-button {
  min-height: 45px;
  border-radius: 10px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, opacity 160ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover,
.surrender-button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.secondary-button:active,
.icon-button:active,
.surrender-button:active {
  transform: translateY(0);
}

.primary-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  border: 1px solid rgba(239, 142, 109, 0.5);
  color: #fff2ea;
  background: linear-gradient(120deg, #a83e35, #c95742);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.primary-button:hover {
  border-color: rgba(255, 219, 200, 0.8);
  background: linear-gradient(120deg, #b4473b, #d06049);
}

.field-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.status-pill {
  display: inline-flex;
  min-height: 27px;
  align-items: center;
  padding: 0 9px;
  border: 1px solid rgba(120, 182, 167, 0.35);
  border-radius: 99px;
  color: var(--jade);
  background: rgba(120, 182, 167, 0.08);
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.ai {
  border-color: rgba(239, 142, 109, 0.36);
  color: var(--vermilion-soft);
  background: rgba(216, 86, 67, 0.08);
}

.status-pill.over {
  border-color: rgba(234, 212, 160, 0.32);
  color: var(--paper-light);
  background: rgba(234, 212, 160, 0.08);
}

.status-message {
  min-height: 48px;
  margin: 0 0 17px;
  color: var(--ink-300);
  font-size: 15px;
  line-height: 1.6;
}

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

.stat {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid rgba(183, 211, 209, 0.09);
  border-radius: 9px;
  background: rgba(10, 20, 24, 0.28);
}

.stat span,
.stat strong {
  display: block;
}

.stat span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
}

.stat strong {
  overflow: hidden;
  color: var(--white);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.moves-section {
  padding-bottom: 17px;
}

.move-list {
  display: flex;
  max-height: 202px;
  flex-direction: column;
  gap: 3px;
  overflow: auto;
  margin: 0 -8px 0 0;
  padding: 0 8px 0 0;
  list-style: none;
}

.move-list::-webkit-scrollbar {
  width: 5px;
}

.move-list::-webkit-scrollbar-thumb {
  border-radius: 5px;
  background: rgba(168, 190, 193, 0.28);
}

.move-item {
  display: grid;
  grid-template-columns: 30px 1fr 1fr;
  gap: 7px;
  align-items: center;
  min-height: 31px;
  padding: 3px 8px;
  border-radius: 7px;
  color: var(--ink-300);
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 14px;
}

.move-item:nth-child(odd) {
  background: rgba(255, 255, 255, 0.025);
}

.move-number {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.move-side-r {
  color: var(--vermilion-soft);
}

.move-side-b {
  color: var(--ink-300);
}

.empty-moves {
  padding: 12px 0 10px;
  color: var(--muted);
  font-size: 14px;
}

.action-row {
  gap: 9px;
  padding: 17px 25px 0;
}

.secondary-button,
.icon-button {
  border: 1px solid rgba(183, 211, 209, 0.17);
  color: var(--ink-300);
  background: rgba(10, 20, 24, 0.28);
  font-size: 14px;
}

.secondary-button {
  flex: 1;
}

.secondary-button:hover,
.icon-button:hover {
  border-color: rgba(120, 182, 167, 0.55);
  color: var(--white);
  background: rgba(120, 182, 167, 0.08);
}

.icon-button {
  width: 45px;
  flex: 0 0 45px;
  color: var(--jade);
  font-size: 21px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none !important;
}

.surrender-button {
  display: block;
  width: calc(100% - 50px);
  margin: 12px 25px 0;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
}

.surrender-button:hover {
  border-color: rgba(216, 86, 67, 0.3);
  color: var(--vermilion-soft);
  background: rgba(216, 86, 67, 0.06);
}

.privacy-note {
  display: flex;
  gap: 8px;
  margin: 18px 25px 24px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.lock-mark {
  flex: 0 0 auto;
  color: var(--jade);
}

.site-footer {
  width: min(100%, 700px);
  margin: 27px auto 0;
  color: rgba(168, 190, 193, 0.58);
  font-size: 12px;
  letter-spacing: 0.05em;
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #fff;
  background: var(--ink-950);
  font-size: 18px;
  text-align: center;
}

@media (max-width: 920px) {
  .app-shell {
    width: min(720px, calc(100% - 32px));
  }

  .topbar {
    margin-bottom: 32px;
  }

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

  .control-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .setup-section,
  .status-section,
  .moves-section {
    min-width: 0;
  }

  .setup-section {
    grid-row: span 2;
    border-right: 1px solid var(--line);
  }

  .moves-section {
    border-bottom: 0;
  }

  .action-row,
  .surrender-button,
  .privacy-note {
    grid-column: 1 / -1;
  }

  .privacy-note {
    margin-bottom: 23px;
  }
}

@media (max-width: 600px) {
  .app-shell {
    width: min(100% - 20px, 480px);
    padding-top: 16px;
  }

  .topbar {
    margin-bottom: 27px;
  }

  .topbar-note {
    font-size: 11px;
  }

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

  h1 {
    font-size: 26px;
  }

  .turn-card {
    padding: 8px 10px 9px;
  }

  .turn-label {
    font-size: 10px;
  }

  .turn-card strong {
    font-size: 13px;
  }

  .board-shell {
    padding: 8px;
    border-radius: 15px;
  }

  .board-shell::before {
    inset: 4px;
    border-radius: 12px;
  }

  .board-overlay {
    inset: 8px;
  }

  .control-panel {
    display: block;
  }

  .setup-section {
    border-right: 0;
  }

  .status-section,
  .moves-section {
    border-bottom: 1px solid var(--line);
  }

  .site-footer {
    margin-top: 22px;
    font-size: 11px;
  }
}

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