/* ==========================================================================
   五子棋 · 样式表
   移动端优先；桌面端居中卡片。深色 UI + 木色棋盘。
   ========================================================================== */

:root {
  --bg-0: #0c1015;
  --bg-1: #121821;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.075);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eaf0f8;
  --muted: #93a0b4;
  --muted-2: #7d8ba0;
  --accent: #e6b566;
  --accent-strong: #f3c97e;
  --accent-deep: #d9a353;
  --accent-ink: #2b1c06;
  --danger: #ef6b6b;
  --ok: #7ee2a8;
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-lg: 0 30px 70px -28px rgba(0, 0, 0, 0.85);
  --shadow-board: 0 20px 48px -20px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 255, 255, 0.07);
  --ease: cubic-bezier(0.22, 0.8, 0.28, 1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  color: var(--text);
  font-family: "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1100px 520px at 50% -12%, rgba(230, 181, 102, 0.14), transparent 62%),
    radial-gradient(760px 520px at 105% 108%, rgba(78, 122, 184, 0.12), transparent 60%),
    var(--bg-0);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

button {
  font-family: inherit;
}

body.no-scroll {
  overflow: hidden;
}

h1,
h2,
h3,
p {
  margin: 0;
}

/* ---------------------------------------------------------------- 布局骨架 */

.app {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: 16px 12px calc(26px + env(safe-area-inset-bottom));
}

.stage {
  margin-top: 2px;
}

/* ---------------------------------------------------------------- 顶部品牌 */

.topbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  display: block;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  filter: drop-shadow(0 6px 14px rgba(230, 181, 102, 0.28));
}

.brand-mark svg {
  display: block;
  width: 100%;
  height: 100%;
}

.brand-text {
  min-width: 0;
}

.brand-text h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2;
}

.brand-text p {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- 通用按钮 */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  padding: 11px 14px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.16s, border-color 0.16s, transform 0.12s, opacity 0.16s, box-shadow 0.16s;
}

.btn:hover {
  background: var(--panel-strong);
  border-color: var(--border-strong);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent-deep));
  border-color: rgba(255, 255, 255, 0.16);
  color: var(--accent-ink);
  font-weight: 700;
  box-shadow: 0 8px 20px -8px rgba(230, 181, 102, 0.65);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #f8d492, #dda85a);
  border-color: rgba(255, 255, 255, 0.28);
}

.btn-danger {
  background: linear-gradient(180deg, #f08787, #d95c58);
  border-color: rgba(255, 255, 255, 0.16);
  color: #2c0a0a;
  font-weight: 700;
}

.btn-danger:hover {
  background: linear-gradient(180deg, #f59a9a, #e06662);
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
}

.btn-sm {
  padding: 9px 12px;
  font-size: 12px;
  border-radius: 10px;
}

.btn:focus-visible,
.icon-btn:focus-visible,
.segmented button:focus-visible,
.history-main:focus-visible,
.history-del:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 图标按钮 */

.icon-btn {
  appearance: none;
  position: relative;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.16s, background 0.16s, border-color 0.16s, transform 0.12s;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--panel-strong);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn svg {
  display: block;
}

.icon-btn .icon-off {
  display: none;
}

.icon-btn[data-on="false"] {
  color: var(--muted-2);
}

.icon-btn[data-on="false"] .icon-on {
  display: none;
}

.icon-btn[data-on="false"] .icon-off {
  display: block;
}

/* ---------------------------------------------------------------- 控制区 */

.control-row {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border);
  border-radius: 13px;
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 0;
  border-radius: 9px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s, transform 0.12s;
}

.segmented button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.segmented button:active {
  transform: scale(0.98);
}

.segmented button.is-active {
  color: var(--accent-ink);
  font-weight: 700;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent-deep));
  box-shadow: 0 4px 14px -4px rgba(230, 181, 102, 0.6);
}

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

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

/* ---------------------------------------------------------------- 续局提示 */

.resume-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(230, 181, 102, 0.14), rgba(230, 181, 102, 0.06));
  border: 1px solid rgba(230, 181, 102, 0.32);
  animation: fadeUp 0.3s var(--ease) both;
}

.resume-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.resume-text strong {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.resume-text span {
  font-size: 11px;
  color: var(--muted);
}

.resume-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

/* ---------------------------------------------------------------- 状态栏 */

.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  min-height: 42px;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  font-size: 13px;
  transition: border-color 0.25s, background 0.25s;
}

.statusbar.is-thinking {
  border-color: rgba(230, 181, 102, 0.45);
  background: rgba(230, 181, 102, 0.07);
}

.turn-dot {
  width: 11px;
  height: 11px;
  flex: 0 0 11px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.turn-dot[data-color="black"] {
  background: radial-gradient(circle at 34% 28%, #5d6673, #0b0e13 72%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.turn-dot[data-color="white"] {
  background: radial-gradient(circle at 34% 28%, #ffffff, #c6cdd7 78%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7);
}

.turn-dot[data-color="none"] {
  display: none;
}

.status-text {
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-meta {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: -2px;
}

.dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotBounce 1.05s infinite ease-in-out;
}

.dots i:nth-child(2) {
  animation-delay: 0.14s;
}

.dots i:nth-child(3) {
  animation-delay: 0.28s;
}

/* ---------------------------------------------------------------- 棋盘 */

.board-wrap {
  position: relative;
  margin-top: 12px;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #e0aa5f;
  box-shadow: var(--shadow-board);
  isolation: isolate;
}

.board-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: crosshair;
  -webkit-tap-highlight-color: transparent;
}

.board-wrap canvas.is-locked {
  cursor: default;
}

/* 结果浮层 */

.result-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 12, 18, 0.52);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  animation: fadeIn 0.25s ease both;
}

.result-card {
  width: min(310px, 100%);
  padding: 22px 20px 20px;
  text-align: center;
  border-radius: 20px;
  background: linear-gradient(180deg, #1c2532, #141b25);
  border: 1px solid rgba(255, 255, 255, 0.11);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.9);
  animation: popIn 0.38s var(--ease) both;
}

.result-kicker {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.24em;
  color: var(--accent);
  text-transform: uppercase;
}

.result-title {
  margin-top: 7px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.result-title[data-result="win"] {
  color: var(--accent-strong);
  text-shadow: 0 0 26px rgba(243, 201, 126, 0.35);
}

.result-title[data-result="loss"] {
  color: #f08a8a;
}

.result-title[data-result="draw"] {
  color: #b9c6d8;
}

.result-sub {
  margin-top: 7px;
  font-size: 12px;
  color: var(--muted);
}

.result-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.result-actions .btn {
  flex: 1;
}

.hint {
  margin-top: 12px;
  text-align: center;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--muted-2);
}

/* ---------------------------------------------------------------- 历史抽屉 */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(3, 6, 10, 0.58);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.2s ease both;
}

.drawer {
  position: fixed;
  visibility: hidden;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(180deg, #151d27, #111820);
  border-left: 1px solid var(--border);
  box-shadow: -24px 0 60px -30px rgba(0, 0, 0, 0.9);
  transform: translateX(103%);
  transition: transform 0.34s var(--ease), visibility 0s linear 0.34s;
}

.drawer.open {
  visibility: visible;
  transform: translateX(0);
  transition: transform 0.34s var(--ease), visibility 0s;
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.drawer-head h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.drawer-head p {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
}

.history-item {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.history-main {
  appearance: none;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  padding: 11px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.16s, border-color 0.16s, transform 0.12s;
}

.history-main:hover {
  background: rgba(255, 255, 255, 0.075);
  border-color: var(--border-strong);
}

.history-main:active {
  transform: scale(0.99);
}

.history-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
}

.chip-easy {
  color: #86e0b0;
  background: rgba(110, 231, 168, 0.12);
}

.chip-normal {
  color: #8fc2f2;
  background: rgba(110, 170, 240, 0.13);
}

.chip-hard {
  color: #f2a08f;
  background: rgba(240, 130, 110, 0.13);
}

.history-date {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}

.history-result {
  font-size: 12px;
  font-weight: 600;
}

.history-result.is-win {
  color: var(--ok);
}

.history-result.is-loss {
  color: #f08a8a;
}

.history-result.is-draw {
  color: #b9c6d8;
}

.history-result.is-live {
  color: var(--accent);
}

.history-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}

.history-del {
  appearance: none;
  flex: 0 0 42px;
  width: 42px;
  display: grid;
  place-items: center;
  color: var(--muted-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.16s, background 0.16s, border-color 0.16s;
}

.history-del:hover {
  color: #f08a8a;
  background: rgba(240, 110, 110, 0.1);
  border-color: rgba(240, 110, 110, 0.25);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 52px 20px;
  text-align: center;
  color: var(--muted-2);
  font-size: 12.5px;
  line-height: 1.7;
}

.empty strong {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

/* ---------------------------------------------------------------- 确认弹窗 */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 6, 10, 0.62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fadeIn 0.2s ease both;
}

.modal-card {
  width: min(320px, 100%);
  padding: 20px;
  border-radius: 18px;
  background: linear-gradient(180deg, #1b2431, #151c26);
  border: 1px solid rgba(255, 255, 255, 0.11);
  box-shadow: var(--shadow-lg);
  animation: popIn 0.3s var(--ease) both;
}

.modal-card h3 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.modal-card p {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.modal-actions .btn {
  flex: 1;
}

/* ---------------------------------------------------------------- 轻提示 */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 90;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text);
  background: rgba(30, 40, 54, 0.96);
  border: 1px solid var(--border-strong);
  box-shadow: 0 14px 34px -14px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.24s ease, transform 0.24s var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------------------------------------------------------- 动画 */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes dotBounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

/* ---------------------------------------------------------------- 响应式 */

/* 窄屏（320px 起）进一步压缩间距 */
@media (max-width: 360px) {
  .app {
    padding: 12px 10px calc(22px + env(safe-area-inset-bottom));
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .brand-text h1 {
    font-size: 18px;
  }

  .brand-text p {
    font-size: 10px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }

  .action-row {
    gap: 6px;
  }

  .btn {
    padding: 10px 6px;
    font-size: 12px;
    border-radius: 10px;
  }

  .segmented button {
    font-size: 12px;
    padding: 7px 0;
  }

  .statusbar {
    gap: 6px;
    padding: 8px 12px;
    font-size: 12px;
  }

  .status-meta {
    font-size: 10px;
  }

  .result-card {
    padding: 20px 16px 18px;
  }

  .result-title {
    font-size: 23px;
  }
}

/* 桌面端：居中卡片 */
@media (min-width: 700px) {
  .app {
    margin-top: 34px;
    margin-bottom: 34px;
    padding: 22px 22px 26px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
  }

  .board-wrap {
    max-width: 540px;
    margin-left: auto;
    margin-right: auto;
  }

  .statusbar,
  .hint {
    max-width: 540px;
    margin-left: auto;
    margin-right: auto;
  }

  .statusbar {
    margin-top: 14px;
  }

  .hint {
    margin-top: 14px;
  }
}

/* 尊重系统的「减少动态效果」设置 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
