/* ---------- design tokens ---------- */
:root, [data-theme="dark"] {
  --bg: #0f1117;
  --bg-grad: radial-gradient(1200px 800px at 20% -10%, #1a2236 0%, #0f1117 55%);
  --surface: #161a23;
  --surface-2: #1f2532;
  --surface-3: #262d3d;
  --border: #2a3142;
  --border-strong: #3a4258;
  --text: #e8eaf0;
  --text-dim: #8c93a6;
  --accent: #7aa2ff;
  --accent-2: #5ae0c1;
  --warn: #ffb347;
  --bad: #ff6b6b;
  --good: #5ad07e;
  --chain: #f78fb3;
  --weights: #ffd166;
  --decryp: #9b8cff;
  --syllab: #5ae0c1;
  --bullseye: #ff8a65;
  --letterbox: #ee6a73;
  --skein: #c779e0;
  --quartet: #c7a868;
  --hive: #e8a420;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.25);
  --modal-overlay: rgba(0, 0, 0, 0.6);
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-grad: radial-gradient(1200px 800px at 20% -10%, #e6ecfb 0%, #f4f6fb 55%);
  --surface: #ffffff;
  --surface-2: #f1f4fa;
  --surface-3: #e6ecf6;
  --border: #d8dee8;
  --border-strong: #b8c1d0;
  --text: #1c2230;
  --text-dim: #5b6478;
  --accent: #4a72d6;
  --accent-2: #1fa890;
  --warn: #d68a16;
  --bad: #d33b3b;
  --good: #2e9e54;
  --chain: #d96293;
  --weights: #c08300;
  --decryp: #6354c9;
  --syllab: #1fa890;
  --bullseye: #d65c30;
  --letterbox: #c44851;
  --skein: #92389e;
  --quartet: #8e6f30;
  --hive: #a06600;
  --shadow: 0 4px 18px rgba(40, 50, 80, 0.10);
  --shadow-sm: 0 2px 6px rgba(40, 50, 80, 0.08);
  --modal-overlay: rgba(20, 30, 50, 0.45);
}

:root {
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  color-scheme: dark light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-grad) fixed, var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

/* ---------- top header ---------- */
header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
header.top .brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
header.top .brand-mark {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-radius: 10px;
  font-weight: 800;
  letter-spacing: -0.04em;
  font-size: 20px;
  box-shadow: var(--shadow-sm);
}
header.top h1 {
  font-size: 24px;
  margin: 0;
  letter-spacing: -0.02em;
  font-weight: 700;
}
header.top .right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
header.top .date {
  color: var(--text-dim);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-controls { display: inline-flex; gap: 6px; }

.wg-iconbtn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.wg-iconbtn:hover { border-color: var(--border-strong); }
.wg-iconbtn:active { transform: scale(0.96); }

/* ---------- back link / nav ---------- */
.back {
  margin: -8px 0 18px;
  font-size: 14px;
  color: var(--text-dim);
}
.back a { color: var(--text-dim); }
.back a:hover { color: var(--accent); }

/* ---------- dashboard ---------- */
.greet {
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 8px 0 4px;
  font-weight: 700;
}
.greet-sub {
  color: var(--text-dim);
  margin: 0 0 26px;
}

.dash-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}
.dash-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
}
.dash-stat .v {
  font-size: 28px;
  font-weight: 800;
  font-family: var(--mono);
  letter-spacing: -0.02em;
}
.dash-stat .l {
  color: var(--text-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.dash-stat .icon {
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 18px;
  opacity: 0.5;
}

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin: 28px 0 12px;
  font-weight: 700;
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

/* Community play counter — small, centered, low-key */
.play-counts {
  text-align: center;
  font-size: 13px;
  margin: 18px 0 8px;
  min-height: 18px;
}
.community-counts {
  text-align: center;
  font-size: 13px;
  margin: 0 0 14px;
  min-height: 18px;
}

/* Banner shown on a game page when a past date is being played */
.past-play-banner {
  background: rgba(255, 179, 71, 0.12);
  border: 1px solid var(--warn);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  margin: 0 0 16px;
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.past-play-banner a {
  margin-left: auto;
  font-weight: 600;
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  text-decoration: none;
  color: inherit;
  position: relative;
  overflow: hidden;
}
.game-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--card-accent, var(--accent));
}
.game-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--card-accent, var(--accent));
  text-decoration: none;
}
.game-card .emoji { font-size: 28px; }
.game-card h3 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.game-card p { margin: 0; color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.game-card .tagline { color: var(--text); font-size: 13px; opacity: 0.85; }
.game-card .meta {
  display: flex;
  gap: 14px;
  margin-top: 6px;
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: 12px;
}
.game-card .meta .tag {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--mono);
}
.game-card .meta .tag.streak { color: var(--good); border-color: rgba(90, 208, 126, 0.3); }
.game-card .meta .tag.played-today { color: var(--good); }
.game-card .play {
  margin-top: auto;
  padding-top: 8px;
  font-weight: 600;
  color: var(--card-accent, var(--accent));
  font-size: 14px;
}
.game-card .card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
}
.game-card .card-actions .btn {
  padding: 8px 14px;
  font-size: 14px;
}

.card-chain { --card-accent: var(--chain); }
.card-weights { --card-accent: var(--weights); }
.card-decryp { --card-accent: var(--decryp); }
.card-syllab { --card-accent: var(--syllab); }
.card-bullseye { --card-accent: var(--bullseye); }
.card-letterbox { --card-accent: var(--letterbox); }
.card-skein { --card-accent: var(--skein); }
.card-quartet { --card-accent: var(--quartet); }
.card-hive { --card-accent: var(--hive); }

/* Promoted card: a "NEW" pill ribbon plus an accent outline + soft glow so
   the featured game pops without breaking the grid's layout. */
.game-card[data-promoted="true"],
.game-card[data-updated="true"] {
  outline: 2px solid var(--card-accent, var(--accent));
  outline-offset: -2px;
  box-shadow: 0 8px 24px -8px var(--card-accent, var(--accent));
}
.game-card[data-updated="true"]::after,
.game-card[data-promoted="true"]::after {
  content: 'NEW';
  position: absolute;
  top: 12px;
  right: 14px;
  background: var(--card-accent, var(--accent));
  color: #0e1118;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 4px 10px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  text-transform: uppercase;
  pointer-events: none;
  z-index: 1;
}
.game-card[data-updated="true"]::after { content: 'UPDATED'; }

/* ---------- game shell ---------- */
.game-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.game-shell::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--game-accent, var(--accent));
}
.game-shell.game-chain { --game-accent: var(--chain); }
.game-shell.game-weights { --game-accent: var(--weights); }
.game-shell.game-decryp { --game-accent: var(--decryp); }
.game-shell.game-syllab { --game-accent: var(--syllab); }
.game-shell.game-bullseye { --game-accent: var(--bullseye); }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}
.game-header h2 {
  margin: 0;
  font-size: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.01em;
}

.rules {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 22px 0 14px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.55;
}
.rules strong { color: var(--text); }

.howto {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  /* 22px above so the panel never crowds the game's action buttons.
     Adjacent .howto panels (e.g. Rules + How to play) sit close together
     via the sibling rule below. */
  margin: 22px 0 4px;
  overflow: hidden;
}
.howto + .howto { margin-top: 4px; }
.howto > summary {
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 600;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
}
.howto > summary::-webkit-details-marker { display: none; }
.howto > summary::after {
  content: '\25BE';
  color: var(--text-dim);
  transition: transform .15s;
  margin-left: 12px;
}
.howto[open] > summary::after { transform: rotate(180deg); }
.howto-body {
  padding: 4px 22px 18px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.65;
}
.howto-body strong { color: var(--text); }
.howto-body h4 { margin: 16px 0 6px; color: var(--text); font-size: 14px; }
.howto-body ol, .howto-body ul { padding-left: 22px; margin: 6px 0; }
.howto-body li { margin: 3px 0; }
.howto-body code, .howto-body kbd {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
}
.howto-body .example {
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 12px 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  overflow-x: auto;
}

.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.row.center { justify-content: center; }
.row.between { justify-content: space-between; }
.row.tight { gap: 8px; }

.btn {
  background: var(--accent);
  color: #0a0d14;
  border: none;
  padding: 11px 18px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  transition: filter .15s, transform .1s;
  font-family: inherit;
  min-height: 42px;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--surface-3); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn.full { width: 100%; }

[data-theme="light"] .btn { color: #fff; }
[data-theme="light"] .btn.secondary { color: var(--text); }

input[type=text], input[type=number], input[type=email] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  min-height: 42px;
}
input[type=text]:focus, input[type=number]:focus, input[type=email]:focus { border-color: var(--accent); }

.tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 18px;
  padding: 10px 14px;
  min-width: 44px;
  min-height: 44px;
  text-transform: uppercase;
  user-select: none;
}
.tile.score-pill { position: relative; }
.tile .pip {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 10px;
  color: var(--text-dim);
  pointer-events: none;
}
.tile.used { opacity: 0.35; }
.tile.selected { background: var(--accent); color: #0a0d14; border-color: var(--accent); }
.tile.clickable { cursor: pointer; transition: transform .12s ease, border-color .12s ease, background .12s ease; }
.tile.clickable:hover { border-color: var(--border-strong); background: var(--surface-3); }
.tile.clickable:active { transform: scale(0.94); }
.tile.clickable.used { cursor: default; pointer-events: none; }

/* read-only word-building display, used by touch-only games */
.current-word {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 10px 16px;
  margin: 12px 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  word-break: break-all;
  text-align: center;
}
.current-word:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: normal;
  font-size: 14px;
  font-family: var(--sans);
  text-transform: none;
}

.muted { color: var(--text-dim); font-size: 13px; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.divider { height: 1px; background: var(--border); margin: 18px 0; border: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 90;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }

/* Global plays-today line on dashboard game cards. */
.game-card .card-plays { font-size: 12px; margin: 0 0 8px; }

/* Catalogue game with no unplayed puzzle today (no-repeat rule). */
.game-card.card-unavailable { opacity: 0.55; }
.tag.unavail { color: var(--bad); border-color: var(--bad); }
.btn.btn-disabled { pointer-events: none; opacity: 0.6; }

/* Board replacement when the daily rotation lands on an already-solved puzzle. */
.wg-repeat-notice {
  text-align: center;
  padding: 28px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.wg-repeat-notice h3 { margin: 0 0 8px; }
.wg-repeat-notice p { color: var(--text-dim); margin: 8px 0 14px; }

/* Brief per-version update log in the profile/settings modal. */
.wg-changelog {
  max-height: 140px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}
.wg-changelog-row strong { color: var(--text); font-weight: 600; }

/* ---------- modals ---------- */
.wg-modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(4px);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.wg-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  animation: pop .2s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes pop { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.wg-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.wg-modal-head h3 { margin: 0; font-size: 18px; }
.wg-modal input[type=text] { width: 100%; margin-top: 12px; }
.wg-modal p { margin: 6px 0 12px; }
.wg-share-preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 12px 0;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-height: 220px;
  overflow-y: auto;
}
.wg-share-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.wg-share-actions .btn { flex: 1; min-width: 110px; }

/* ---------- profile modal prefs ---------- */
.wg-pref-label { display: block; font-size: 12px; font-weight: 600; color: var(--text); margin: 14px 0 6px; letter-spacing: 0.02em; text-transform: uppercase; }
.wg-pref-help { margin: 4px 0 0; font-size: 12px; color: var(--text-dim); }
.wg-pref-sep { border: none; border-top: 1px solid var(--border); margin: 18px 0 0; }
.wg-pref-toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; padding: 4px 0; }
.wg-pref-toggle input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.wg-backup-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 0; }
.wg-backup-actions .btn { min-width: 130px; }

/* ---------- decrypticon toolbar ---------- */
.cipher-toolbar { margin-top: 12px; }
.cipher-toolbar-info { color: var(--text-dim); font-size: 14px; margin-bottom: 8px; }
.cipher-toolbar-info strong { color: var(--accent); }

/* Full-width row: used by "View Frequency Distribution". */
.cipher-toolbar-wide {
  display: block;
  width: 100%;
  margin-bottom: 8px;
}

/* Row of equal-width action buttons. Each button flex-grows to the same size;
   on narrow screens they wrap and the next row stays equal-width too. */
.cipher-toolbar-equal {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cipher-toolbar-equal > .btn {
  flex: 1 1 0;
  min-width: 130px;
}

/* ---------- letterbox (wordle-style) ---------- */
.game-letterbox { /* placeholder for future per-game tweaks */ }

.lb-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  margin: 16px 0 18px;
}
.lb-row {
  display: flex;
  gap: 6px;
}
.lb-row.lb-shake {
  animation: lb-shake .35s cubic-bezier(.36, .07, .19, .97);
}
@keyframes lb-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.lb-cell {
  width: 54px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Empty cells use text-dim rather than the faint border colour so the
     guess grid stands out from the page in both themes. */
  border: 2px solid var(--text-dim);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 26px;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  user-select: none;
  transition: background .15s, border-color .15s, color .15s;
}
.lb-cell.lb-filled {
  border-color: var(--text);
}
/* Cells in the row being typed are tappable: tapping one moves the caret
   there so a single wrong letter can be replaced in place. */
.lb-cell.lb-editable { cursor: pointer; }
.lb-cell.lb-cursor {
  border-color: var(--accent);
  box-shadow: inset 0 -3px 0 0 var(--accent);
}
.lb-cell.lb-correct {
  background: var(--good);
  border-color: var(--good);
  color: #0e1118;
}
.lb-cell.lb-present {
  background: var(--warn);
  border-color: var(--warn);
  color: #1a140a;
}
.lb-cell.lb-absent {
  background: var(--surface-2);
  border-color: var(--surface-2);
  color: var(--text-dim);
}
@media (max-width: 420px) {
  .lb-cell { width: 46px; height: 46px; font-size: 22px; }
}

/* Local game-log table inside the "Your games" panel. */
.lb-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}
.lb-log-table th, .lb-log-table td {
  text-align: left;
  padding: 5px 10px 5px 0;
  border-bottom: 1px solid var(--border);
}
.lb-log-table th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* On-screen keyboard. Mirrors the per-letter state with the same colour
   semantics: green for confirmed-in-place, yellow for misplaced, dimmed for
   ruled-out. ENTER and BACK get a wider key. */
.lb-keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  margin: 10px 0 6px;
}
.lb-keyrow {
  display: flex;
  gap: 5px;
  justify-content: center;
  width: 100%;
  max-width: 540px;
}
.lb-key {
  flex: 1 1 0;
  min-width: 0;
  height: 48px;
  padding: 0 4px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, border-color .12s, color .12s, transform .06s;
}
.lb-key:active { transform: translateY(1px); }
.lb-key-wide { flex: 1.6 1 0; font-size: 13px; }
.lb-key.lb-correct {
  background: var(--good);
  border-color: var(--good);
  color: #0e1118;
}
.lb-key.lb-present {
  background: var(--warn);
  border-color: var(--warn);
  color: #1a140a;
}
.lb-key.lb-absent {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-dim);
  opacity: 0.55;
}
@media (max-width: 420px) {
  .lb-key { height: 42px; font-size: 14px; }
  .lb-key-wide { font-size: 12px; }
}

/* ---------- hive (honeycomb word builder) ----------
   Seven hexagonal letter cells (one centre, six outer). Player taps or types
   letters to build a word that must include the centre letter. */
.game-hive { /* placeholder */ }

.hive-status {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: stretch;
  margin: 6px 0 14px;
}
.hive-rank-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  min-width: 0;
}
.hive-rank-block .label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.hive-rank-name {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}
.hive-progress {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: visible;
}
.hive-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--good), var(--warn));
  border-radius: 999px;
  transition: width .3s ease;
}
.hive-progress-ticks { position: absolute; inset: 0; }
.hive-tick {
  position: absolute;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}
.hive-tick.hive-tick-passed { background: var(--warn); border-color: var(--warn); }

.score-card.hive-score-card, .score-card.hive-words-card {
  min-width: 70px;
}

/* The current word being built. Each letter gets its own colour so the
   player sees at a glance whether they've included the centre letter. */
.hive-current {
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 4px;
  min-height: 38px;
  padding: 4px 10px;
  margin: 4px 0 10px;
  text-transform: uppercase;
}
.hive-current:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0;
}
/* Placeholder carrying a teammate update rather than the "Type a word" hint. */
.hive-current.hive-current-notice:empty::before {
  color: var(--good);
  font-weight: 600;
}
.hive-current.hive-shake {
  animation: lb-shake .35s cubic-bezier(.36, .07, .19, .97);
}
.hive-letter-center  { color: var(--warn); }
.hive-letter-outer   { color: var(--text); }
.hive-letter-invalid { color: var(--bad); }

/* The hex board. Absolute positioning keeps the seven cells in a tight
   honeycomb regardless of viewport. --hex-w drives the scale. */
.hive-board {
  --hex-w: 84px;
  --hex-h: calc(var(--hex-w) * 1.1547);    /* hex aspect ratio sqrt(3)/2 */
  --row-y: calc(var(--hex-h) * 0.75);      /* hex rows overlap by 1/4 */
  position: relative;
  width: calc(var(--hex-w) * 3);
  height: calc(var(--row-y) * 2 + var(--hex-h));
  margin: 0 auto 12px;
}
@media (max-width: 480px) { .hive-board { --hex-w: 70px; } }
@media (max-width: 360px) { .hive-board { --hex-w: 60px; } }

.hive-cell {
  position: absolute;
  width: var(--hex-w);
  height: var(--hex-h);
  /* Pointed-top hexagon. */
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: var(--surface-2);
  color: var(--text);
  border: none;
  cursor: pointer;
  user-select: none;
  font-family: inherit;
  font-size: calc(var(--hex-w) * 0.42);
  font-weight: 800;
  text-transform: uppercase;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .08s;
}
.hive-cell:active { transform: scale(0.94); }
.hive-cell.hive-center {
  background: var(--warn);
  color: #1a140a;
}
.hive-cell.hive-pos-1 { left: calc(var(--hex-w) * 0.5);   top: 0; }
.hive-cell.hive-pos-2 { left: calc(var(--hex-w) * 1.5);   top: 0; }
.hive-cell.hive-pos-3 { left: 0;                          top: var(--row-y); }
.hive-cell.hive-pos-c { left: var(--hex-w);               top: var(--row-y); }
.hive-cell.hive-pos-4 { left: calc(var(--hex-w) * 2);     top: var(--row-y); }
.hive-cell.hive-pos-5 { left: calc(var(--hex-w) * 0.5);   top: calc(var(--row-y) * 2); }
.hive-cell.hive-pos-6 { left: calc(var(--hex-w) * 1.5);   top: calc(var(--row-y) * 2); }

/* Found words area: a wrapping list of small pills, alphabetised. Pangrams
   get a gold border highlight. */
.hive-found-section { margin-top: 16px; }
.hive-found-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
  list-style: none;              /* summary: our caret replaces the marker */
}
.hive-found-label::-webkit-details-marker { display: none; }
.hive-found-caret { transition: transform .15s ease; }
.hive-found-section[open] .hive-found-caret { transform: rotate(180deg); }
.hive-found-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 50px;
}
.hive-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
  font-weight: 600;
}
.hive-pill .pts {
  color: var(--text-dim);
  font-weight: 700;
  font-size: 11px;
}
.hive-pill.hive-pangram {
  border-color: var(--warn);
  background: rgba(255, 179, 71, 0.12);
}
.hive-pill.hive-pangram .pts { color: var(--warn); }
/* Confetti canvas: above the win modal (z-index 100), never intercepts taps. */
.wg-confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 120;
}

/* A-Z / Newest toggle above found-word lists. */
.wg-sort-row { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.wg-sort-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.wg-sort-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  cursor: pointer;
}
.wg-sort-btn.is-on { background: var(--accent); color: #0a0d14; }
/* Discovery order only reads as an order if the list is linear, so the
   "Newest" view stacks one word per row instead of wrapping into a grid. */
.wg-found-stacked { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
.wg-found-stacked .pill,
.wg-found-stacked .hive-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  justify-content: flex-start;
  border-radius: var(--radius-sm);
}
/* Points (and the team-mate's name) sit at the right-hand end of the row. */
.wg-found-stacked .pill .pts,
.wg-found-stacked .hive-pill .pts { margin-left: auto; }
.wg-found-stacked .hive-pill .hive-by-name { order: 99; }
.hive-found-tools { display: flex; justify-content: flex-end; margin-bottom: 8px; }
/* Finder's name on a word pill in team play. */
.hive-by-name { color: var(--text-dim); font-size: 10px; font-weight: 600; text-transform: none; }

/* Rare (bonus) words: teal accent + a small sparkle marker. */
.hive-pill.hive-rare { border-color: var(--accent-2); }
.hive-rare-mark { color: var(--accent-2); font-size: 11px; }
.hive-rare-note { font-size: 12px; margin-top: 8px; }

/* Team play: room bar under the found list, plus per-player attribution
   badges on word pills. Badge colour = player join order (0-3 cycles). */
.hive-team { margin-top: 12px; }
.hive-team-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.hive-team-bar .btn { padding: 6px 12px; font-size: 13px; }
.hive-team-hint { font-size: 12px; }
.hive-team-spacer { flex: 1; }
.hive-team-code {
  font-weight: 800;
  letter-spacing: 0.15em;
  padding: 3px 9px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.hive-team-player {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
}
.hive-by {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  flex: 0 0 auto;
}
.hive-by-0 { background: var(--accent); }
.hive-by-1 { background: var(--accent-2); }
.hive-by-2 { background: var(--warn); }
.hive-by-3 { background: var(--bad); }
.hive-team-joinrow {
  display: flex;
  gap: 8px;
  align-items: center;
}
.hive-team-joinrow input[type=text] {
  flex: 1;
  margin-top: 0;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}
.hive-team-bigcode {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.25em;
  text-align: center;
  padding: 16px 0 6px;
  color: var(--accent);
}

/* ---------- quartet (connections-style) ----------
   4×4 grid of word tiles. As groups are guessed they stack up in the
   found-groups area in their difficulty colour. */
.game-quartet { /* placeholder for per-game tweaks */ }

/* Brand icon: a 2×2 grid of small coloured squares matching the difficulty
   tiers. Replaces a generic emoji and ties the icon to the game's mechanic.
   Default size sits in the header h1; `.qt-brand-icon-lg` is for the
   dashboard card. */
.qt-brand-icon {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  width: 22px;
  height: 22px;
  vertical-align: -4px;
  margin-right: 8px;
}
.qt-brand-icon-lg {
  width: 36px;
  height: 36px;
  gap: 3px;
  vertical-align: middle;
  margin-right: 0;
}
.qt-brand-sq {
  border-radius: 3px;
}
.qt-brand-icon .qt-brand-sq.qt-yellow { background: #f0c14b; }
.qt-brand-icon .qt-brand-sq.qt-green  { background: var(--good); }
.qt-brand-icon .qt-brand-sq.qt-blue   { background: var(--accent); }
.qt-brand-icon .qt-brand-sq.qt-purple { background: var(--decryp); }

.qt-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 8px 0 14px;
}
.qt-progress { color: var(--text); font-size: 14px; }
.qt-progress strong { color: var(--accent); }
.qt-mistakes { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.qt-dots { display: inline-flex; gap: 4px; }
.qt-dot { color: var(--bad); font-size: 14px; line-height: 1; }
.qt-dot.qt-dot-spent { color: var(--border); }

.qt-found-groups {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.qt-group-row {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: center;
  user-select: none;
  animation: qt-pop .25s ease;
}
@keyframes qt-pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.qt-group-name {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.qt-group-words {
  font-size: 13px;
  font-weight: 600;
  margin-top: 2px;
  opacity: 0.85;
}

.qt-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}
.qt-grid.qt-shake { animation: lb-shake .35s cubic-bezier(.36, .07, .19, .97); }

.qt-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 3px;
  /* Scales with viewport so 11-letter words like SCRUMPTIOUS fit at small
     widths without resorting to forced break-word for shorter labels. */
  font-size: clamp(11px, 2.6vw, 14px);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.15;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  text-transform: uppercase;
  min-height: 54px;
  /* Long words allowed to wrap onto a second line rather than overflow. */
  white-space: normal;
  word-break: break-word;
  hyphens: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  user-select: none;
  transition: background .12s, border-color .12s, color .12s, transform .06s;
}
.qt-tile:hover:not(:disabled) { border-color: var(--text-dim); }
.qt-tile:active:not(:disabled) { transform: translateY(1px); }
.qt-tile.qt-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #0e1118;
}
.qt-tile:disabled { cursor: default; opacity: 0.85; }
@media (max-width: 420px) {
  .qt-tile { padding: 8px 2px; min-height: 46px; }
}

/* Action row: explicit wrap so it never escapes the viewport. Buttons stay
   at their natural width but the row flows onto multiple lines on narrow
   screens. */
.qt-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 14px;
  width: 100%;
}
.qt-actions .btn {
  flex: 0 1 auto;
  min-width: 0;
}

/* Group difficulty colours — same palette across found-group bars and the
   small legend swatches inside the Rules panel. */
.qt-yellow { background: #f0c14b; color: #1a140a; }
.qt-green  { background: var(--good); color: #0e1118; }
.qt-blue   { background: var(--accent); color: #0e1118; }
.qt-purple { background: var(--decryp); color: #0e1118; }

.qt-legend {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------- skein (strands-style) ----------
   Reuses .lb-grid / .lb-row / .lb-cell from letterbox for layout, and adds
   four state classes for the cells: hinted (outlined), selected (current
   trail), found theme word (tinted accent), found spangram (gold). */
.sk-theme-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 0 0 14px;
}
.sk-theme-label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.sk-theme {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.sk-grid { user-select: none; }
.sk-cell { cursor: pointer; }
/* Three distinct cell states so the player can tell at a glance what's
   active, what's locked in as a theme word, and what's the spangram.
   Selected = accent blue, found theme = good green, spangram = warn gold.
   Letters stay at full opacity for legibility. */
.sk-cell.sk-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #0e1118;
}
.sk-cell.sk-last {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}
.sk-cell.sk-found-theme {
  /* Each found theme word picks its colour from FOUND_PALETTE in skein.php,
     written to this CSS variable per cell at render time. Falls back to
     green if the variable isn't set (e.g. legacy save with no foundOrder). */
  background: var(--sk-found-color, var(--good));
  border-color: var(--sk-found-color, var(--good));
  color: #0e1118;
  cursor: default;
}
.sk-cell.sk-found-spangram {
  background: var(--warn);
  border-color: var(--warn);
  color: #1a140a;
  cursor: default;
}
.sk-cell.sk-hinted {
  border-color: var(--warn);
  border-style: dashed;
  border-width: 2px;
}
.sk-current {
  min-height: 38px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 4px;
  text-align: center;
  color: var(--text);
  padding: 6px 12px;
  margin: 6px 0 10px;
}
.sk-current:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
}

/* Inline coloured swatches used inside the Rules panel to illustrate the
   green/yellow/grey legend. */
.lb-legend {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  color: #0e1118;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.lb-legend.lb-correct { background: var(--good); }
.lb-legend.lb-present { background: var(--warn); }
.lb-legend.lb-absent  { background: var(--surface-2); color: var(--text-dim); }

/* ---------- win / completion modal ---------- */
.wg-win-modal-box { text-align: center; }
.wg-win-modal-box .wg-modal-head { justify-content: center; position: relative; }
.wg-win-modal-box .wg-modal-head h3 { font-size: 22px; }
.wg-win-modal-box .wg-modal-head [data-x] { position: absolute; right: 0; top: 0; }
.wg-win-headline {
  font-size: 44px;
  font-weight: 800;
  line-height: 1;
  margin: 6px 0 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.wg-win-subhead {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 14px;
  letter-spacing: 0.02em;
}
.wg-win-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0 8px;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.wg-win-stat { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.wg-win-stat .label { color: var(--text-dim); }
.wg-win-stat .value { font-variant-numeric: tabular-nums; font-weight: 600; }
.wg-win-stat.tone-good .value { color: var(--good); }
.wg-win-stat.tone-bad .value { color: var(--bad); }
.wg-win-note { font-style: italic; font-size: 13px; color: var(--text-dim); margin: 6px 0 12px; }

/* ---------- chain reaction ---------- */
.chain-stack { display: flex; flex-direction: column; gap: 10px; }
.chain-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 18px;
  letter-spacing: 0.04em;
}
.chain-link .idx { color: var(--text-dim); width: 28px; }
.chain-link .arrow { color: var(--text-dim); margin-left: auto; }
.chain-link.start { border-color: var(--good); background: rgba(90, 208, 126, 0.08); }
.chain-link.end { border-color: var(--chain); background: rgba(247, 143, 179, 0.08); }

/* ---------- word weights ---------- */
.ww-stats-row {
  display: flex;
  gap: 28px;
  justify-content: center;
  align-items: flex-end;
  margin-bottom: 18px;
  text-align: center;
}
.ww-stat { text-align: center; min-width: 80px; }
.ww-stat .value {
  font-size: 30px;
  font-weight: 800;
  font-family: var(--mono);
  letter-spacing: -0.02em;
  line-height: 1;
}
.ww-stat .ww-target-num { font-size: 40px; color: var(--weights); }
.ww-stat .ww-score-num { font-size: 48px; }
.ww-stat .ww-time-num { font-size: 28px; font-weight: 700; }
.ww-start-row { margin: 6px 0 16px; justify-content: center; }

/* Rack: a 4-wide grid of large square tiles (the 8-letter rack fills two
   rows). Big targets matter — the whole game is tapping these at speed. */
.weights-letters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  max-width: 400px;
  margin: 18px auto;
}
.weights-letters .tile {
  width: 100%;
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  font-size: 30px;
}
.weights-letters .tile .pip { bottom: 4px; right: 6px; font-size: 12px; }
@media (max-width: 380px) {
  .weights-letters { gap: 8px; }
  .weights-letters .tile { font-size: 26px; }
}
.weights-target { text-align: center; margin: 10px 0; }
.weights-target .num { font-size: 36px; font-weight: 800; font-family: var(--mono); }
.weights-meter {
  position: relative;
  height: 14px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 16px 0;
  border: 1px solid var(--border);
}
.weights-meter .fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s ease; }
.weights-meter .target-mark { position: absolute; top: -2px; bottom: -2px; width: 3px; background: var(--weights); box-shadow: 0 0 8px var(--weights); }
.weights-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; max-height: 200px; overflow-y: auto; }
.weights-list .pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 14px;
  animation: slide-in .2s;
}
@keyframes slide-in { from { transform: translateY(6px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.weights-list .pill .pts { color: var(--weights); margin-left: 6px; font-weight: 700; }
.timer { font-family: var(--mono); font-size: 18px; font-weight: 700; }
.timer.warn { color: var(--warn); }
.timer.crit { color: var(--bad); animation: pulse .8s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------- decrypticon ---------- */
.cipher-paragraph {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  font-size: 18px;
  line-height: 2.4;
  margin: 16px 0;
  letter-spacing: 0.04em;
}
.cipher-letter {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin: 0 1px;
  font-family: var(--mono);
  position: relative;
}
/* Hyphen on the letter that sits at the end of a line within a word. The
   ::after is absolutely positioned so the marker doesn't push other letters
   around or change wrap points on next render. */
.cipher-letter.line-end::after {
  content: '-';
  position: absolute;
  right: -7px;
  top: 0;
  color: var(--text-dim);
  font-weight: 700;
  font-size: inherit;
  pointer-events: none;
}
.cipher-letter .top {
  font-size: 18px;
  font-weight: 700;
  color: var(--decryp);
  text-transform: uppercase;
  border-bottom: 2px solid var(--border);
  padding: 0 4px 1px;
  min-width: 16px;
  text-align: center;
  line-height: 1.1;
}
.cipher-letter .top.solved { color: var(--good); border-bottom-color: var(--good); }
.cipher-letter .top.wrong { color: var(--bad); border-bottom-color: var(--bad); }
.cipher-letter .bot {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  min-height: 14px;
  min-width: 14px;
  text-align: center;
  padding: 1px 2px 0;
}
/* Group of letters that make up a single word. Stays inline (default) so the
   browser may break it across lines if it's too long; line-break detection
   happens in JS to inject a trailing hyphen at the break point. */
.cipher-word { /* default inline */ }
/* Visible space between words. &nbsp; content keeps it from collapsing on Android. */
.cipher-space {
  display: inline-block;
  width: 24px;
  min-width: 24px;
  vertical-align: bottom;
  font-size: 18px;
  line-height: inherit;
}
.cipher-letter.punct .top { border: none; color: var(--text); font-weight: 400; }

/* ---------- decrypticon frequency panel ---------- */
.cipher-freq {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 12px 0;
}
.cipher-freq-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.freq-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: transform .08s, border-color .12s, background .12s;
}
.freq-pill:hover { border-color: var(--border-strong); background: var(--surface-3); }
.freq-pill:active { transform: scale(0.96); }
.freq-pill .freq-letter { font-weight: 700; color: var(--decryp); }
.freq-pill .freq-count { color: var(--text-dim); font-size: 12px; }
.freq-pill.sel { border-color: var(--accent); background: rgba(122, 162, 255, 0.10); }
.freq-pill.solved .freq-letter { color: var(--good); }
.freq-pill.revealed .freq-letter { color: var(--warn); }
.freq-pill.wrong .freq-letter { color: var(--bad); }
.freq-pill.wrong { border-color: var(--bad); }
.cipher-letter.punct .bot { display: none; }
.cipher-letter.sel .top { background: rgba(155, 140, 255, 0.18); border-radius: 4px 4px 0 0; }

.cipher-keyboard { display: grid; grid-template-columns: repeat(13, 1fr); gap: 6px; margin: 18px 0; }
.cipher-key {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 4px;
  text-align: center;
  font-family: var(--mono);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  min-height: 38px;
}
.cipher-key.active { background: var(--decryp); color: #fff; border-color: var(--decryp); }
.cipher-key.used { opacity: 0.35; }

/* ---------- syllable stack ---------- */
.syl-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
  min-height: 60px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}
.syl-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  user-select: none;
  text-transform: uppercase;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  transition: transform .1s;
}
.syl-tile:active { transform: scale(0.96); }
.syl-tile.in-build { background: var(--syllab); color: #082a23; border-color: var(--syllab); }
[data-theme="light"] .syl-tile.in-build { color: #fff; }

.syl-builder {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 60px;
}
.syl-builder .ph { color: var(--text-dim); font-style: italic; }

.syl-words { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.syl-word {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.syl-word .composed { font-family: var(--mono); font-weight: 700; flex: 1; }
.syl-word .frags { color: var(--text-dim); font-family: var(--mono); font-size: 13px; }

/* ---------- bullseye ---------- */
.bullseye-board {
  position: relative;
  width: 360px;
  height: 360px;
  margin: 12px auto 24px;
  max-width: 100%;
}
.bullseye-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid var(--border);
  pointer-events: none;
}
.bullseye-ring.outer { inset: 0; background: rgba(255, 138, 101, 0.08); }
.bullseye-ring.middle { inset: 16.66%; background: rgba(255, 138, 101, 0.18); }
.bullseye-ring.inner { inset: 33.33%; background: rgba(255, 138, 101, 0.34); }
[data-theme="light"] .bullseye-ring.outer { background: rgba(255, 138, 101, 0.10); }
[data-theme="light"] .bullseye-ring.middle { background: rgba(255, 138, 101, 0.20); }
[data-theme="light"] .bullseye-ring.inner { background: rgba(255, 138, 101, 0.30); }

.bullseye-letter {
  position: absolute;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  user-select: none;
  transform: translate(-50%, -50%);
  transition: transform .1s, box-shadow .1s;
}
.bullseye-letter:hover { box-shadow: var(--shadow-sm); }
.bullseye-letter:active { transform: translate(-50%, -50%) scale(0.92); }
/* color-coded by score multiplier */
.bullseye-letter.outer { color: var(--accent); border-color: rgba(122, 162, 255, 0.5); }
.bullseye-letter.middle { color: var(--weights); border-color: rgba(255, 209, 102, 0.5); }
.bullseye-letter.inner { color: var(--bullseye); border-color: var(--bullseye); }
.bullseye-letter.selected { background: var(--bullseye); color: #fff; border-color: var(--bullseye); }
/* score multiplier badge */
.bullseye-letter::after {
  position: absolute;
  bottom: -4px;
  right: -4px;
  font-size: 9px;
  font-weight: 700;
  background: var(--surface);
  color: var(--text-dim);
  padding: 1px 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  line-height: 1;
  pointer-events: none;
}
.bullseye-letter.outer::after { content: '1×'; }
.bullseye-letter.middle::after { content: '2×'; color: var(--weights); border-color: rgba(255, 209, 102, 0.5); }
.bullseye-letter.inner::after { content: '3×'; color: var(--bullseye); border-color: var(--bullseye); }

.attempts-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.attempt-pip { width: 12px; height: 12px; border-radius: 50%; background: var(--border); }
.attempt-pip.used { background: var(--bullseye); }

/* ---------- score cards ---------- */
.score-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}
.score-card .label { margin: 0; }
.score-card .value { font-size: 26px; font-weight: 800; font-family: var(--mono); letter-spacing: -0.02em; }

/* ---------- other-apps promo ---------- */
.other-apps {
  margin: 28px 0 0;
  padding: 14px 18px;
  background: linear-gradient(135deg, rgba(122,162,255,0.08), rgba(90,224,193,0.08));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}
.other-apps a {
  color: var(--accent);
  font-weight: 600;
  margin-left: 4px;
}

/* ---------- foot links ---------- */
.foot {
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  justify-content: space-between;
  align-items: center;
  color: var(--text-dim);
  font-size: 13px;
}
.foot a { color: var(--text-dim); }
.foot a:hover { color: var(--accent); text-decoration: none; }
.foot-links { display: flex; gap: 16px; flex-wrap: wrap; }

/* ---------- help / support pages ---------- */
.prose {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: var(--shadow);
}
.prose h2 { margin-top: 0; }
.prose h3 { margin-top: 28px; font-size: 17px; color: var(--text); }
.prose p, .prose li { color: var(--text-dim); line-height: 1.65; }
.prose strong { color: var(--text); }
.prose code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
}
.prose .callout {
  background: var(--surface-2);
  border-left: 3px solid var(--warn);
  padding: 12px 16px;
  border-radius: 6px;
  margin: 14px 0;
  color: var(--text);
  font-size: 14px;
}
.prose .callout.bad { border-left-color: var(--bad); }
.prose .callout.good { border-left-color: var(--good); }

.support-panel {
  background: linear-gradient(135deg, rgba(122,162,255,0.10), rgba(90,224,193,0.10));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin: 18px 0 26px;
}
.support-panel a.btn { text-decoration: none; }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  .container { padding: 18px 14px 60px; }
  header.top h1 { font-size: 20px; }
  .greet { font-size: 22px; }
  .game-shell { padding: 18px 16px; }
  .prose { padding: 22px 18px; }
  .cipher-paragraph { font-size: 16px; line-height: 2.2; padding: 14px; }
  .cipher-space { width: 18px; min-width: 18px; }
  .cipher-keyboard { grid-template-columns: repeat(7, 1fr); }
  .bullseye-board { width: 320px; height: 320px; }
  .bullseye-letter { width: 32px; height: 32px; font-size: 15px; }
  .score-card { min-width: 120px; padding: 12px 14px; }
  .score-card .value { font-size: 22px; }
  .weights-target .num { font-size: 30px; }
  .timer { font-size: 16px; }
  .row { gap: 8px; }
  .btn { padding: 10px 14px; }
  .ww-stat .value { font-size: 22px; }
  .ww-stat .ww-target-num { font-size: 32px; }
  .ww-stat .ww-score-num { font-size: 40px; }
  .ww-stat .ww-time-num { font-size: 22px; }
  .ww-stats-row { gap: 18px; }
  .current-word { font-size: 22px; min-height: 50px; }
}

@media (max-width: 420px) {
  .dash-summary { grid-template-columns: 1fr 1fr; }
  .hub-grid { grid-template-columns: 1fr; }
  .bullseye-board { width: 280px; height: 280px; }
  .bullseye-letter { width: 28px; height: 28px; font-size: 13px; }
  .cipher-paragraph { font-size: 15px; line-height: 2.1; }
  .syl-tile { font-size: 14px; padding: 9px 12px; }
}
