:root {
  --cell: min(92px, min(18vw, calc((84vh - 180px) / 5)));
  --bg: #ffffff;
  --ink: #121212;
  --subtle: #757575;
  --muted: #a0a0a0;
  --line: #dfdfdf;
  --yellow: #ffda00;
  --blue: #a7d8ff;
  --cross: #e8eef2;
  --cell-bg: #ffffff;
  --grid-line: #000000;
  --revealed: #1a5fd0;
  --menu-bg: #ffffff;
  --menu-border: #d5d5d5;
  --menu-hover: #f0f4f8;
  --button-bg: #ffffff;
  --button-border: #ccc;
  --button-hover: #f2f2f2;
  --solid-bg: #1a1a1a;
  --solid-text: #ffffff;
  --kb-bg: #e3e6e8;
  --kb-active: #cfd4d8;
  --modal-bg: #ffffff;
  --font: "Libre Franklin", "Franklin Gothic Medium", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #121214;
  --ink: #f0f2f5;
  --subtle: #9ba1a6;
  --muted: #6e7681;
  --line: #2d3139;
  --yellow: #685a00;
  --blue: #1c3b5e;
  --cross: #1e2630;
  --cell-bg: #1a1d24;
  --grid-line: #333842;
  --revealed: #58a6ff;
  --menu-bg: #1c2128;
  --menu-border: #30363d;
  --menu-hover: #262c36;
  --button-bg: #1c2128;
  --button-border: #363d47;
  --button-hover: #2d333b;
  --solid-bg: #388bfd;
  --solid-text: #ffffff;
  --kb-bg: #21262d;
  --kb-active: #30363d;
  --modal-bg: #1c2128;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ---------------- loading screen ---------------- */
.app-loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.app-loader.fade-out {
  opacity: 0;
  visibility: hidden;
}

.loader-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.loader-grid {
  display: grid;
  grid-template-columns: repeat(2, 40px);
  grid-template-rows: repeat(2, 40px);
  gap: 4px;
  background: var(--grid-line);
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.loader-cell {
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  border-radius: 3px;
  animation: pulseCell 1.2s infinite ease-in-out alternate;
}

.loader-cell.black {
  background: var(--grid-line);
  animation: none;
}

.loader-cell.letter-m { animation-delay: 0.1s; }
.loader-cell.letter-i { animation-delay: 0.3s; }
.loader-cell.letter-n { animation-delay: 0.5s; }
.loader-cell.letter-i2 { animation-delay: 0.7s; }

@keyframes pulseCell {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(0.94); opacity: 1; background: var(--yellow); }
}

.loader-title {
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 16px;
  letter-spacing: -0.5px;
}

.loader-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-status {
  font-size: 13px;
  font-weight: 500;
  color: var(--subtle);
}

/* ---------------- theme toggle button ---------------- */
.icon-btn {
  background: var(--button-bg);
  border: 1px solid var(--button-border);
  color: var(--ink);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--button-hover);
}

.sun-icon { display: block; }
.moon-icon { display: none; }

[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

/* ---------------- top bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: 1.1;
}

.brand-date {
  font-size: 12px;
  font-weight: 500;
  color: var(--subtle);
  margin-top: 2px;
}

.brand-note {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  margin-top: 1px;
}

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

.timer {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  color: var(--subtle);
  padding: 6px 8px;
  font-variant-numeric: tabular-nums;
}
.timer:hover { color: var(--ink); }

.tool-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--button-bg);
  border: 1px solid var(--button-border);
  border-radius: 16px;
  padding: 7px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.tool-btn:hover { background: var(--button-hover); }
.tool-btn.solid { background: var(--solid-bg); border-color: var(--solid-bg); color: var(--solid-text); }
.tool-btn.solid:hover { opacity: 0.9; }

.caret {
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: .7;
}

.menu { position: relative; }
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--menu-bg);
  border: 1px solid var(--menu-border);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
  min-width: 145px;
  padding: 4px 0;
  display: none;
  z-index: 40;
}
.menu.open .menu-list { display: block; }
.menu-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 9px 14px;
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
}
.menu-list button:hover { background: var(--menu-hover); }

/* ---------------- layout ---------------- */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 36px;
  min-height: calc(100vh - 75px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.board {
  display: flex;
  gap: 48px;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.grid-column { display: flex; flex-direction: column; align-items: center; }

.grid-wrap { position: relative; }

.grid {
  display: grid;
  grid-template-columns: repeat(5, var(--cell));
  grid-template-rows: repeat(5, var(--cell));
  gap: 1px;
  background: var(--grid-line);
  border: 2px solid var(--grid-line);
  touch-action: manipulation;
}

.cell {
  position: relative;
  background: var(--cell-bg);
  cursor: pointer;
  user-select: none;
  overflow: hidden;
}
.cell.black { background: var(--grid-line); cursor: default; }
.cell.highlight { background: var(--blue); }
.cell.selected { background: var(--yellow); }

.cell .num {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: calc(var(--cell) * 0.165);
  font-weight: 500;
  line-height: 1.2;
  color: var(--ink);
  pointer-events: none;
}

.cell .letter {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: calc(var(--cell) * 0.08);
  font-size: calc(var(--cell) * 0.55);
  font-weight: 500;
  line-height: 1;
  color: var(--ink);
  pointer-events: none;
}

/* verified-correct square: small check in the upper-right corner */
.cell.correct::after {
  content: "";
  position: absolute;
  top: 12%;
  right: 14%;
  width: 13%;
  height: 26%;
  border: solid #1a9c4b;
  border-width: 0 2px 2px 0;
  transform: rotate(40deg);
}

.cell.revealed .letter { color: var(--revealed); }
.cell.revealed::after {
  content: "";
  position: absolute;
  top: 0; right: 0;
  border-top: 9px solid var(--revealed);
  border-left: 9px solid transparent;
}
.cell.wrong::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom left, transparent calc(50% - 1px), #d0021b calc(50% - 1px), #d0021b calc(50% + 1px), transparent calc(50% + 1px));
}

.grid.solved .cell:not(.black) { animation: pop .5s ease both; }
@keyframes pop {
  0% { background: var(--cell-bg); }
  40% { background: var(--yellow); }
  100% { background: var(--cell-bg); }
}

.pause-cover {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--grid-line);
  z-index: 5;
}
.pause-cover.on { display: flex; }
.pause-inner { text-align: center; }
.pause-inner p { font-size: 15px; font-weight: 600; margin: 0 0 14px; color: var(--ink); }

/* ---------------- clue bar (mobile) ---------------- */
.clue-bar {
  display: none;
  width: calc(var(--cell) * 5 + 6px);
  background: var(--blue);
  align-items: stretch;
  margin-bottom: 10px;
  min-height: 52px;
  height: auto;
  border-radius: 6px;
  overflow: hidden;
}
.cb-arrow {
  border: none;
  background: rgba(0,0,0,.06);
  width: 38px;
  cursor: pointer;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  align-self: stretch;
}
.cb-body {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink);
  overflow: visible;
  word-break: break-word;
}
.cb-num { font-weight: 700; flex: none; }

/* ---------------- clue lists ---------------- */
.clue-panel {
  display: flex;
  gap: 32px;
  flex: 1;
  min-width: 0;
  max-width: 560px;
}
.clue-panel section { flex: 1; min-width: 0; }
.clue-panel h3 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}
.clue-panel ol {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 500px;
  overflow-y: auto;
}
.clue-panel li {
  display: flex;
  gap: 10px;
  padding: 8px 10px 8px 8px;
  font-size: 15px;
  line-height: 1.35;
  cursor: pointer;
  border-left: 4px solid transparent;
  color: var(--ink);
  border-radius: 4px;
}
.clue-panel li:hover { background: var(--menu-hover); }
.clue-panel li .num { font-weight: 700; min-width: 16px; text-align: right; }
.clue-panel li.cross { background: var(--cross); }
.clue-panel li.active { background: var(--blue); border-left-color: #58a6ff; }
.clue-panel li.done .text { color: var(--muted); }

/* ---------------- keyboard ---------------- */
.keyboard {
  display: none;
  margin: 18px auto 0;
  max-width: 520px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.kb-row { display: flex; justify-content: center; gap: 5px; margin-bottom: 6px; }
.kb-key {
  flex: 1;
  min-width: 0;
  height: 46px;
  border: none;
  border-radius: 5px;
  background: var(--kb-bg);
  font-family: var(--font);
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.kb-key:active { background: var(--kb-active); }
.kb-key.wide { flex: 1.6; font-size: 14px; font-weight: 600; }

/* ---------------- modal ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}
.modal-backdrop.on { display: flex; }
.modal-card {
  background: var(--modal-bg);
  border-radius: 8px;
  padding: 34px 30px 26px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
  border: 1px solid var(--line);
}
.modal-mark { font-size: 40px; line-height: 1; color: #f5c518; margin-bottom: 8px; }
.modal-card h2 { margin: 0 0 8px; font-size: 24px; font-weight: 700; color: var(--ink); }
.modal-card p { margin: 0 0 22px; font-size: 15px; color: var(--subtle); line-height: 1.4; }
.modal-actions { display: flex; flex-direction: column; gap: 9px; }

.btn-primary {
  background: var(--solid-bg);
  color: var(--solid-text);
  border: none;
  border-radius: 20px;
  padding: 11px 22px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { opacity: 0.9; }
.btn-ghost {
  background: none;
  border: 1px solid var(--button-border);
  border-radius: 20px;
  padding: 11px 22px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
}
.btn-ghost:hover { background: var(--button-hover); }

/* ---------------- difficulty menu ---------------- */
.menu-list button.checked { font-weight: 700; }
.menu-list button.checked::after { content: " ✓"; color: #1a9c4b; }

/* ---------------- versus race strip ---------------- */
.race-strip {
  display: none;
  border-bottom: 1px solid var(--line);
  background: var(--cross);
  padding: 10px 20px 12px;
}
.race-strip.on { display: block; }

.race-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.race-code { font-size: 13px; font-weight: 500; color: var(--subtle); }
.race-code b { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 15px; letter-spacing: 2px; color: var(--ink); }
.race-status { font-size: 13px; font-weight: 700; color: var(--revealed); }
.race-leave {
  margin-left: auto;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--ink);
  border-radius: 14px;
  padding: 5px 12px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.race-leave:hover { background: var(--button-hover); }

.race-players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 6px 20px;
  max-width: 900px;
}
.race-player { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.race-player.me .rp-name { font-weight: 700; }
.rp-name { min-width: 92px; max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-bar { flex: 1; height: 8px; background: #e3e6e8; border-radius: 4px; overflow: hidden; }
.rp-bar i { display: block; height: 100%; background: #0a63c9; transition: width .25s ease; }
.race-player.done .rp-bar i { background: #1a9c4b; }
.rp-meta { min-width: 74px; text-align: right; font-variant-numeric: tabular-nums; color: #555; font-size: 12px; }
.race-player.done .rp-meta { color: #1a9c4b; font-weight: 700; }

/* During a race, disable New Puzzle button so players don't abort by accident */
body.racing #newBtn { opacity: .4; pointer-events: none; }

/* ---------------- countdown ---------------- */
.countdown {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.82);
  z-index: 70;
  pointer-events: none;
}
.countdown.on { display: flex; }
.countdown span {
  font-size: 128px;
  font-weight: 800;
  color: #111;
  animation: tick 1s ease-in-out infinite;
}
@keyframes tick {
  0% { transform: scale(.7); opacity: .35; }
  40% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.08); opacity: .5; }
}

/* ---------------- versus modal ---------------- */
.versus-card { max-width: 380px; text-align: left; position: relative; }
.versus-card h2 { text-align: center; }
.vs-close-corner { position: absolute; top: 16px; right: 16px; }

.field { display: block; margin-bottom: 14px; }
.field span {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--subtle);
  margin-bottom: 5px;
}
.field input, .field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 15px;
  background: var(--cell-bg);
  color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--revealed); outline-offset: -1px; }
#vsCode { text-transform: uppercase; letter-spacing: 6px; font-weight: 700; text-align: center; }

.vs-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.vs-tab {
  flex: 1;
  padding: 9px 8px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  border-radius: 16px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--subtle);
}
.vs-tab.active { background: var(--solid-bg); border-color: var(--solid-bg); color: var(--solid-text); }

.vs-pane .btn-primary { width: 100%; }
.vs-hint { font-size: 12.5px; color: var(--subtle); margin: 10px 0 14px; line-height: 1.4; text-align: center; }
.vs-error { font-size: 13px; color: #d0021b; text-align: center; margin: 12px 0 0; min-height: 18px; }

.vs-code-display { text-align: center; font-size: 12px; color: var(--subtle); margin: 0 0 4px; }
.vs-code-display b {
  display: block;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 38px;
  letter-spacing: 10px;
  color: var(--ink);
  margin-top: 4px;
  text-indent: 10px;
}
.vs-roster { list-style: none; margin: 14px 0; padding: 0; }
.vs-roster li {
  padding: 8px 12px;
  background: var(--cross);
  border-radius: 6px;
  margin-bottom: 5px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease;
}
.vs-roster li:hover { background: var(--menu-hover); }

#versusLobby .btn-primary { width: 100%; margin-bottom: 8px; }
#versusLobby .btn-primary:disabled { background: #999; cursor: default; }
#versusLobby .btn-ghost { width: 100%; }

/* ---------------- streak badge & monochrome flame ---------------- */
.streak-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: var(--button-bg);
  border: 1px solid var(--button-border);
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
}
.streak-badge:hover { background: var(--button-hover); }

.flame-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
}

.flame-svg {
  width: 26px;
  height: 26px;
  color: var(--ink);
  opacity: 1;
}

.streak-num-overlay {
  position: absolute;
  top: 61%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 10.5px;
  font-weight: 900;
  color: var(--bg);
  pointer-events: none;
  line-height: 1;
  letter-spacing: -0.5px;
}

/* ---------------- leaderboard modal ---------------- */
.leaderboard-card { max-width: 480px; text-align: left; position: relative; }

.lb-controls-wrap {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-period-tabs {
  display: flex;
  gap: 6px;
  background: var(--cross);
  padding: 3px;
  border-radius: 20px;
}

.lb-tab {
  flex: 1;
  padding: 6px 12px;
  border: none;
  background: transparent;
  border-radius: 16px;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  color: var(--subtle);
  text-align: center;
  transition: all 0.15s ease;
}
.lb-tab.active {
  background: var(--button-bg);
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.lb-diff-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.lb-diff-tab {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  border-radius: 12px;
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--subtle);
  white-space: nowrap;
  text-align: center;
}
.lb-diff-tab.active {
  background: var(--solid-bg);
  border-color: var(--solid-bg);
  color: var(--solid-text);
}

.lb-table-header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--subtle);
  border-bottom: 1px solid var(--line);
}

.lb-col-rank { width: 36px; text-align: center; }
.lb-col-name { flex: 1; padding-left: 8px; }
.lb-col-streak { width: 70px; text-align: center; }
.lb-col-time { width: 80px; text-align: right; }

.lb-list {
  max-height: 260px;
  overflow-y: auto;
  margin: 6px 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.lb-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  color: var(--ink);
}
.lb-item:last-child { border-bottom: none; }
.lb-item.me { background: var(--cross); font-weight: 700; }
.lb-rank { width: 36px; text-align: center; font-weight: 800; font-size: 15px; }
.lb-name { flex: 1; padding-left: 8px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-streak { width: 70px; text-align: center; font-weight: 700; color: var(--subtle); }
.lb-time { width: 80px; text-align: right; font-weight: 700; color: var(--revealed); font-variant-numeric: tabular-nums; }

/* ---------------- welcome & stats modals ---------------- */
.welcome-card { max-width: 380px; text-align: center; }
.welcome-icon { font-size: 48px; margin-bottom: 8px; }
.welcome-card h2 { margin: 0 0 8px; font-size: 24px; font-weight: 800; color: var(--ink); }
.welcome-card p { margin: 0 0 20px; font-size: 14px; color: var(--subtle); line-height: 1.4; }
.full-width { width: 100%; }

.stats-card { max-width: 440px; text-align: left; position: relative; }
.stats-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.stats-header h2 { margin: 0; font-size: 22px; font-weight: 800; color: var(--ink); }
.modal-close-icon {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--subtle);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.modal-close-icon:hover { color: var(--ink); }

.profile-name-edit { display: flex; gap: 8px; margin-bottom: 20px; }
.profile-name-edit input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  background: var(--cell-bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
}
.btn-ghost.sm { padding: 8px 14px; font-size: 13px; border-radius: 6px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}
.stat-box {
  background: var(--cross);
  border-radius: 8px;
  padding: 12px 8px;
  text-align: center;
  border: 1px solid var(--line);
}
.stat-num { display: block; font-size: 24px; font-weight: 800; color: var(--ink); line-height: 1.1; }
.stat-label { display: block; font-size: 11px; font-weight: 600; color: var(--subtle); margin-top: 4px; }

.stats-card h3 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin: 0 0 10px;
  color: var(--subtle);
}

.history-list {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 20px;
  background: var(--cell-bg);
}
.empty-history { font-size: 13px; color: var(--subtle); text-align: center; margin: 20px 0; }
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.history-item:last-child { border-bottom: none; }
.history-date { font-weight: 600; color: var(--ink); }
.history-meta { display: flex; align-items: center; gap: 8px; }
.history-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--cross);
  color: var(--ink);
  text-transform: capitalize;
}
.history-time { font-weight: 700; color: var(--revealed); font-variant-numeric: tabular-nums; }

/* ---------------- toast notice ---------------- */
.toast-notice {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: var(--solid-bg);
  color: var(--solid-text);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast-notice.on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------- responsive ---------------- */
@media (min-width: 1200px) {
  :root { --cell: min(104px, calc((86vh - 200px) / 5)); }
  .page { max-width: 1340px; padding: 32px 24px 44px; }
  .topbar { max-width: 1340px; margin: 0 auto; }
  .clue-panel { max-width: 600px; }
}

@media (max-width: 900px) {
  :root { --cell: min(17.5vw, 72px); }
  .page { padding: 16px 12px 28px; min-height: auto; }
  .board { flex-direction: column; align-items: center; gap: 16px; }
  .clue-bar { display: flex; }
  .clue-panel { display: none; }
  .keyboard { display: block; width: 100%; max-width: 520px; }
  .brand-title { font-size: 17px; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .tool-btn { padding: 6px 11px; font-size: 12px; }
}

@media (max-width: 600px) {
  :root { --cell: min(18.5vw, 68px); }

  .topbar {
    padding: 10px 12px 8px;
    gap: 10px;
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }

  .brand {
    display: flex;
    flex-direction: column;
  }

  .brand-title { font-size: 16px; font-weight: 800; }
  .brand-date, .brand-note { display: none; }

  .header-controls {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .tools {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    width: 100%;
    overflow: visible;
  }

  .tools .menu { width: 100%; }
  .tool-btn {
    width: 100%;
    justify-content: center;
    padding: 7px 6px;
    font-size: 12px;
    border-radius: 8px;
  }
  .timer { padding: 4px 6px; font-size: 13.5px; }

  .page {
    padding: 10px 6px 20px;
    min-height: auto;
  }

  .board {
    gap: 8px;
    width: 100%;
  }

  .clue-bar {
    width: calc(var(--cell) * 5 + 6px);
    border-radius: 6px;
    margin-bottom: 6px;
    min-height: 48px;
    height: auto;
  }

  .cb-body {
    font-size: 13.5px;
    line-height: 1.3;
    padding: 8px 10px;
    word-break: break-word;
  }

  .keyboard {
    display: block;
    width: 100%;
    max-width: 480px;
    margin-top: 12px;
    padding: 0 2px;
  }

  .kb-row { gap: 3.5px; margin-bottom: 4.5px; }

  .kb-key {
    height: 46px;
    font-size: 16px;
    border-radius: 5px;
  }

  .kb-key.wide { font-size: 12.5px; }
}
