:root {
  --bg: #1c1c1e;
  --fg: #e7e7e7;
  --muted: #888;
  --accent: #ffb43a;
  --red: #d24343;
  --black: #2c2c2c;
  --cell: #3a2a18;
  --face-up: #f4dca6;
  --face-down: #8a5a3b;
  --grid-line: #1a0e07;
  --primary: #ffb43a;
  --primary-fg: #2a1502;
  --err-bg: #3b1c1c;
  --err-border: #d24343;
  --err-fg: #fbd0c5;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 system-ui, sans-serif;
}
.page { max-width: 960px; margin: 24px auto; padding: 0 16px; }
a { color: var(--accent); text-decoration: underline; }
a:hover { color: #ffc868; }
header h1 { margin: 0; font-size: 26px; }
header .brand { color: inherit; text-decoration: none; }
.subtitle { color: var(--muted); }
.muted { color: var(--muted); }
.muted.small { font-size: 12px; }
.err { color: var(--err-fg); }
.hidden { display: none; }

.panel {
  background: #232326;
  border-radius: 8px;
  padding: 16px 18px;
  margin-top: 16px;
  border: 1px solid #2f2f33;
}
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.sep { color: var(--muted); }

input[type=text], select {
  background: #1a1a1c;
  color: var(--fg);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 6px 10px;
  font-family: monospace;
}
button, a.primary {
  background: #2c2c30;
  color: var(--fg);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover:not([disabled]), a.primary:hover { background: #3a3a40; }
button[disabled] { opacity: 0.4; cursor: not-allowed; }
.primary, a.primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
  font-weight: 600;
}
.primary:hover, a.primary:hover { background: #ffc868; }
.big { padding: 10px 18px; font-size: 16px; }

.link-btn {
  background: transparent;
  color: var(--accent);
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  font: inherit;
  text-decoration: underline;
}
.link-btn:hover { background: transparent; color: #ffc868; }

/* ---- lobby ---- */
.lobby-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 12px;
}
.lobby-card {
  background: #1a1a1c;
  border: 1px solid #2f2f33;
  border-radius: 6px;
  padding: 14px 16px;
}
.lobby-card h2 { margin-top: 0; margin-bottom: 6px; font-size: 17px; color: var(--accent); }
@media (max-width: 900px) {
  .lobby-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
  .lobby-grid { grid-template-columns: 1fr; }
}
.me-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 12px; border-bottom: 1px solid #2f2f33; margin-bottom: 12px; }
.sign-in { padding: 6px 0 12px; border-bottom: 1px solid #2f2f33; margin-bottom: 12px; display: flex; gap: 10px; flex-wrap: wrap; }
.invite-signin h2 { margin: 0 0 6px; }
.invite-signin > p { margin: 0 0 12px; }
.invite-signin .sign-in { border-bottom: 0; padding: 0; margin: 0 0 8px; }
.advanced { margin-top: 14px; color: var(--muted); }
.advanced summary { cursor: pointer; font-size: 13px; }

/* ---- board ---- */
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(4, 1fr);
  background: var(--grid-line);
  border: 2px solid var(--grid-line);
  border-radius: 6px;
  aspect-ratio: 8 / 4;
  user-select: none;
  margin-top: 10px;
}
.cell {
  background: var(--cell);
  margin: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 600;
  font-family: "Noto Sans CJK TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  color: #2a1502;
}
.cell:hover.legal { transform: scale(1.03); }
.cell.empty { background: var(--cell); cursor: default; }
.cell.facedown { background: var(--face-down); color: #f4dca6; }
.cell.facedown::before { content: "?"; font-size: 22px; }
.cell.faceup { background: var(--face-up); }
.cell.faceup.red    { color: var(--red); }
.cell.faceup.black  { color: var(--black); }
.cell.selected { outline: 3px solid var(--accent); }
.cell.legal { outline: 2px dashed rgba(255, 180, 60, 0.6); }
.cell.legal-target { outline: 2px solid rgba(120, 220, 120, 0.7); }
.cell.replay-highlight { box-shadow: inset 0 0 0 3px rgba(120, 180, 255, 0.85); }
.board.replay-viewing { filter: saturate(0.85) brightness(0.95); cursor: default; }
.board.replay-viewing .cell { cursor: default; }
.board.replay-viewing .cell:hover { transform: none; }

/* ---- game view header ---- */
.meta { display: flex; flex-direction: column; gap: 6px; padding: 6px 0; }
.meta b { color: var(--muted); font-weight: 500; }

/* ---- OTB banner ---- */
.otb-banner {
  font-size: 22px;
  font-weight: 600;
  padding: 10px 14px;
  background: #1a1a1c;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  text-align: center;
}

/* ---- vs AI ---- */
.ai-header { display: flex; flex-direction: column; gap: 6px; }
.ai-meta { font-size: 13px; color: var(--muted); text-align: center; }
.ai-thinking {
  margin-top: 8px;
  padding: 6px 12px;
  background: #2a2416;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font-size: 13px;
  text-align: center;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

/* ---- dashboard list ---- */
.dashboard-list { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.game-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 12px;
  padding: 10px 12px;
  background: #1a1a1c;
  border: 1px solid #2f2f33;
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
}
.game-row:hover { border-color: var(--accent); }
.g-opp    { font-weight: 600; }
.g-status { color: var(--accent); font-size: 13px; }
.g-meta   { grid-column: 1 / -1; font-size: 12px; }

/* ---- tables (leaderboard / profile) ---- */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}
table th, table td { padding: 6px 8px; border-bottom: 1px solid #2f2f33; text-align: left; }
table th { color: var(--muted); font-weight: 500; }
table a { color: var(--accent); text-decoration: none; }
table a:hover { text-decoration: underline; }

/* ---- transcript panel (replay + notation) ---- */
.transcript-panel {
  margin-top: 14px;
  border: 1px solid #2f2f33;
  border-radius: 6px;
  background: #1a1a1c;
  padding: 8px 10px;
}
.transcript-panel:empty { display: none; }
.transcript-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 6px;
  border-bottom: 1px solid #2f2f33;
  margin-bottom: 6px;
}
.transcript-head h3 {
  margin: 0;
  font-size: 13px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.transcript-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.transcript-controls button {
  padding: 2px 8px;
  font-size: 13px;
  min-width: 28px;
}
.transcript-step {
  font-family: monospace;
  font-size: 12px;
  color: var(--muted);
  padding: 0 6px;
  min-width: 80px;
  text-align: center;
}
.transcript-list {
  display: flex;
  flex-direction: column;
  max-height: 280px;
  overflow-y: auto;
}
.transcript-row {
  display: grid;
  grid-template-columns: 30px 28px 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--fg);
  text-align: left;
  cursor: pointer;
  font: 13px/1.4 monospace, system-ui, sans-serif;
}
.transcript-row:hover { background: #2a2a30; }
.transcript-row.current { background: #3a2c10; outline: 1px solid var(--accent); }
.transcript-row.resign { color: var(--err-fg); font-style: italic; }
.transcript-row .t-num { color: var(--muted); }
.transcript-row .t-mover {
  font-weight: 600;
  font-size: 11px;
  text-align: center;
  border-radius: 3px;
  padding: 1px 4px;
  background: #2c2c30;
}
.transcript-row .t-mover.mover-p1 { background: rgba(210, 67, 67, 0.22); color: #f0a0a0; }
.transcript-row .t-mover.mover-p2 { background: rgba(220, 220, 220, 0.18); color: #e0e0e0; }
.transcript-row .t-piece {
  font-family: "Noto Sans CJK TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  font-size: 18px;
  text-align: center;
  color: var(--accent);
}
.transcript-row .t-notation { font-weight: 600; }
.transcript-row .t-detail { color: var(--muted); font-size: 12px; }
.transcript-row .badge.jump {
  font-size: 10px;
  background: rgba(120, 180, 255, 0.18);
  color: #9ec0ff;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.transcript-empty {
  padding: 10px;
  font-size: 13px;
}
.replay-banner {
  background: #2a2416;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 8px;
}
.replay-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--primary-fg);
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}

/* ---- crib sheet (reused from prior version) ---- */
.crib-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.crib-grid h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
table.crib {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}
table.crib th, table.crib td {
  padding: 4px 8px;
  border-bottom: 1px solid #2f2f33;
  text-align: left;
}
table.crib td.zh {
  font-family: "Noto Sans CJK TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  width: 1.7em;
}
table.crib td.zh.red    { color: var(--red); }
table.crib td.zh.black  { color: #d8d8d8; }
.crib-rules { margin: 0; padding-left: 20px; line-height: 1.6; }
.crib-rules li { margin-bottom: 4px; }
.crib-rules b { color: var(--accent); font-weight: 600; }
@media (max-width: 700px) {
  .crib-grid { grid-template-columns: 1fr; }
}
