/* ============================================================
   SPELLTOWER — style.css
   ============================================================ */


/* ── Global utility ─────────────────────────────────────── */
.hidden { display: none !important; }

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --bg:          #f7f6f3;
  --surface:     #ffffff;
  --border:      #e8e3dc;
  --accent:      #1a1a1a;
  --accent-fg:   #ffffff;
  --accent2:     #d0474a;
  --text:        #1a1a1a;
  --text-dim:    #9a9590;
  --text-muted:  #c5c0b8;
  --tile-bg:        #ffffff;
  --tile-border:    #e8e3dc;
  --tile-hover:     #f2efe9;
  --tile-sel:       #b3d2fa;
  --tile-sel-fg:    #1a1a1a;
  --tile-empty:     transparent;
  --tile-new-row:   #f0f6fd;
  --tile-new-row-b: #b8d4f0;
  --tile-penalty:   #fdf0f0;
  --tile-penalty-b: #f0b8b8;

  --tile-size: clamp(30px, 8vw, 48px);
  --gap: 0;
  --cols: 8;
  --rows: 12;

  --sk-shine: rgba(255, 255, 255, 0.55);

  /* derived layout */
  --board-w: calc(var(--cols) * var(--tile-size));
  --board-h: calc(var(--rows) * var(--tile-size));
  --words-w:  220px;
  --game-gap: 16px;
  --scorebar-h: 30px;
  /* total width of game content (board + gap + words panel) */
  --game-inner-w: calc(var(--board-w) + var(--game-gap) + var(--words-w));
}

/* ── Dark theme ─────────────────────────────────────────── */
body.dark {
  --bg:          #121212;
  --surface:     #1e1e1e;
  --border:      #2e2e2e;
  --accent:      #e8e3dc;
  --accent-fg:   #121212;
  --text:        #e8e3dc;
  --text-dim:    #808080;
  --text-muted:  #5c5c5c;
  --tile-bg:        #252525;
  --tile-border:    #2e2e2e;
  --tile-hover:     #333333;
  --tile-sel:       #b3d2fa;
  --tile-sel-fg:    #1a1a1a;
  --tile-empty:     transparent;
  --tile-new-row:   #1e2e3e;
  --tile-new-row-b: #2a4a6a;
  --tile-penalty:   #3e1e1e;
  --tile-penalty-b: #6a2a2a;

  --sk-shine: rgba(255, 255, 255, 0.12);
}
body.dark .modal,
body.dark #gameover-overlay {
  background: rgba(18,18,18,0.88);
}

/* ── High contrast ──────────────────────────────────────── */
body.high-contrast {
  --tile-sel:    #ffd600;
  --tile-sel-fg: #000000;
  --accent2:     #ff3b30;
}

/* ── No animations ──────────────────────────────────────── */
body.no-animations .tile.just-fell,
body.no-animations .tile.just-rose    { animation: none; }
body.no-animations .tile.new-row      { animation: none; }
body.no-animations .tile.penalty-tile { animation: none; }

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
*:focus:not(:focus-visible) { outline: none; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation; /* prevent double-tap zoom on iOS Safari */
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Top bar ────────────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  justify-content: center;        /* centre inner div */
  padding: 10px 20px 9px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

/* constrain topbar content to game container width */
#topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--game-inner-w);
  gap: 8px;
}

#topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#logo {
  display: flex;
  flex-direction: row;       /* desktop: one line */
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text);
  white-space: nowrap;
  line-height: 1;
}


/* ── Custom mode dropdown ───────────────────────────────── */
.mode-dropdown {
  position: relative;
}

.mode-dropdown-btn {
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 10px 5px 12px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s;
  white-space: nowrap;
}
.mode-dropdown-btn:hover { border-color: var(--text-dim); }
.mode-dropdown-btn[aria-expanded="true"] { border-color: var(--accent); }
.mode-dropdown-btn[aria-expanded="true"] .mode-chevron {
  transform: rotate(180deg);
}

.mode-chevron {
  color: var(--text-dim);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.mode-dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.10);
  list-style: none;
  margin: 0;
  padding: 5px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.mode-dropdown-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.mode-dropdown-opt {
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.1s;
  white-space: nowrap;
}
.mode-dropdown-opt:hover { background: var(--bg); }
.mode-dropdown-opt.active {
  background: var(--accent);
  color: var(--accent-fg);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.1s, border-color 0.1s;
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-dim); }


/* ── Feedback toast (flies from anchor point to top of screen) ─ */
@keyframes toastRise {
  0%   { transform: translate(-50%, 0);                           opacity: 1; }
  100% { transform: translate(-50%, var(--rise-dist, -50vh));     opacity: 0; }
}

.feedback-toast {
  position: fixed;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(26, 26, 26, 0.82);
  color: #ffffff;
  padding: 7px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
  animation: toastRise 3.2s ease-in forwards;
}
.feedback-toast.error   { background: rgba(208, 71, 74, 0.88); }
.feedback-toast.success { background: rgba(52, 168, 83, 0.88); }
.feedback-toast-word  { text-transform: uppercase; }
.feedback-toast-pts   { opacity: 0.75; }

/* ── Game area ──────────────────────────────────────────── */
#game-area {
  display: flex;
  flex-direction: row;
  flex: none;
  gap: var(--game-gap);
  padding: 8px 20px 4px;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
}

/* ── Left column ────────────────────────────────────────── */
#game-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Score bar (score number only, no progress bar) ─────── */
#score-bar {
  width: var(--board-w);
  display: none;
}

#sb-row-top {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

#sb-score {
  font-size: 15px;
  font-weight: 900;
  color: var(--text);
}

#sb-max {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

/* ── Board wrapper ──────────────────────────────────────── */
#board-wrapper {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden;
  flex-shrink: 0;
  /* iOS WebView: same hit region as board — avoid horizontal pan / chrome gestures */
  touch-action: none;
}

/* ── Board container ────────────────────────────────────── */
#board-container {
  position: relative;
  width:  var(--board-w);
  height: var(--board-h);
  flex-shrink: 0;
  touch-action: none; /* prevent browser scroll/zoom from hijacking drag gestures */
  background: var(--tile-bg);
}

/* ── Board grid ─────────────────────────────────────────── */
#board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile-size));
  grid-template-rows:    repeat(var(--rows), var(--tile-size));
  gap: var(--gap);
}

/* ── Board skeleton loader ──────────────────────────────── */
#board-skeleton {
  display: none;
  position: absolute;
  inset: 0;
  grid-template-columns: repeat(var(--cols), var(--tile-size));
  grid-template-rows:    repeat(var(--rows), var(--tile-size));
  gap: var(--gap);
  z-index: 10;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.35s ease;
}

#board-skeleton.sk-hidden {
  opacity: 0;
}

.sk-cell {
  position: relative;
  overflow: hidden;
  background: var(--tile-bg);
}

.sk-cell::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--sk-shine) 50%,
    transparent 100%
  );
  animation: sk-sweep 2s linear infinite;
  animation-delay: var(--sk-delay, 0s);
  will-change: transform;
  transform: translateX(-100%);
}

@keyframes sk-sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(200%); }
}

/* ── Page loader overlay ───────────────────────────────── */
#page-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease;
}
#page-loader.hidden {
  opacity: 0;
  pointer-events: none;
}
.loader-grid {
  display: grid;
  grid-template-columns: repeat(5, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 6px;
}

/* Cell pulse (scale + brightness) + letter styling */
.loader-grid .sk-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Nunito', sans-serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  animation: loaderPulse 2s ease-in-out infinite;
  animation-delay: var(--sk-delay, 0s);
}
@keyframes loaderPulse {
  0%, 100% { transform: scale(1);    background: var(--tile-bg);  color: var(--text);        }
  50%       { transform: scale(1.08); background: var(--tile-sel); color: var(--tile-sel-fg); }
}

/* Desktop 5×3 diagonal delays — negative values keep stagger permanent across every cycle */
/* delay = -(2s − (row+col)×0.15s)  so the phase offset never resets */
#page-loader .sk-cell:nth-child(1)  { --sk-delay: 0s;     } /* (0,0) */
#page-loader .sk-cell:nth-child(2)  { --sk-delay: -1.85s; } /* (0,1) */
#page-loader .sk-cell:nth-child(3)  { --sk-delay: -1.7s;  } /* (0,2) */
#page-loader .sk-cell:nth-child(4)  { --sk-delay: -1.55s; } /* (0,3) */
#page-loader .sk-cell:nth-child(5)  { --sk-delay: -1.4s;  } /* (0,4) */
#page-loader .sk-cell:nth-child(6)  { --sk-delay: -1.85s; } /* (1,0) */
#page-loader .sk-cell:nth-child(7)  { --sk-delay: -1.7s;  } /* (1,1) */
#page-loader .sk-cell:nth-child(8)  { --sk-delay: -1.55s; } /* (1,2) */
#page-loader .sk-cell:nth-child(9)  { --sk-delay: -1.4s;  } /* (1,3) */
#page-loader .sk-cell:nth-child(10) { --sk-delay: -1.25s; } /* (1,4) */
#page-loader .sk-cell:nth-child(11) { --sk-delay: -1.7s;  } /* (2,0) */
#page-loader .sk-cell:nth-child(12) { --sk-delay: -1.55s; } /* (2,1) */
#page-loader .sk-cell:nth-child(13) { --sk-delay: -1.4s;  } /* (2,2) */
#page-loader .sk-cell:nth-child(14) { --sk-delay: -1.25s; } /* (2,3) */
#page-loader .sk-cell:nth-child(15) { --sk-delay: -1.1s;  } /* (2,4) */

/* Mobile ≤640px: flip to 3 cols × 5 rows, recalculate delays for new layout */
@media (max-width: 640px) {
  .loader-grid {
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(5, 52px);
  }
  #page-loader .sk-cell:nth-child(1)  { --sk-delay: 0s;     } /* (0,0) */
  #page-loader .sk-cell:nth-child(2)  { --sk-delay: -1.85s; } /* (0,1) */
  #page-loader .sk-cell:nth-child(3)  { --sk-delay: -1.7s;  } /* (0,2) */
  #page-loader .sk-cell:nth-child(4)  { --sk-delay: -1.85s; } /* (1,0) */
  #page-loader .sk-cell:nth-child(5)  { --sk-delay: -1.7s;  } /* (1,1) */
  #page-loader .sk-cell:nth-child(6)  { --sk-delay: -1.55s; } /* (1,2) */
  #page-loader .sk-cell:nth-child(7)  { --sk-delay: -1.7s;  } /* (2,0) */
  #page-loader .sk-cell:nth-child(8)  { --sk-delay: -1.55s; } /* (2,1) */
  #page-loader .sk-cell:nth-child(9)  { --sk-delay: -1.4s;  } /* (2,2) */
  #page-loader .sk-cell:nth-child(10) { --sk-delay: -1.55s; } /* (3,0) */
  #page-loader .sk-cell:nth-child(11) { --sk-delay: -1.4s;  } /* (3,1) */
  #page-loader .sk-cell:nth-child(12) { --sk-delay: -1.25s; } /* (3,2) */
  #page-loader .sk-cell:nth-child(13) { --sk-delay: -1.4s;  } /* (4,0) */
  #page-loader .sk-cell:nth-child(14) { --sk-delay: -1.25s; } /* (4,1) */
  #page-loader .sk-cell:nth-child(15) { --sk-delay: -1.1s;  } /* (4,2) */
}

/* ── Initial letter reveal — diagonal shimmer wave ──────── */
@keyframes tileShimmerSweep {
  0%   { transform: translateX(-150%) skewX(-20deg); }
  100% { transform: translateX(250%)  skewX(-20deg); }
}

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

.tile.letter-reveal {
  overflow: hidden;
}

.tile.letter-reveal::after {
  content: '';
  position: absolute;
  top: -10%; left: 0;
  width: 60%; height: 120%;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--sk-shine) 50%,
    transparent 100%
  );
  animation: tileShimmerSweep 0.5s ease-out both;
  animation-delay: var(--reveal-delay, 0s);
  pointer-events: none;
  z-index: 1;
}

.tile.letter-reveal .letter,
.tile.letter-reveal .pts {
  opacity: 0;
  animation: letterFadeIn 0.35s ease both;
  animation-delay: var(--reveal-delay, 0s);
}

body.no-animations .tile.letter-reveal::after { animation: none; }
body.no-animations .tile.letter-reveal .letter,
body.no-animations .tile.letter-reveal .pts   { animation: none; opacity: 1; }

/* ── Canvas overlay ─────────────────────────────────────── */
#line-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ── Mobile floating action controls (pinned in #word-display on mobile) ── */
#mobile-float-controls {
  display: none; /* shown only on mobile when selection exists */
  gap: 5px;
  pointer-events: auto;
  flex-shrink: 0;
}

.mobile-float-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.1s, transform 0.08s;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.18);
}
.mobile-float-btn svg { width: 16px; height: 16px; }
.mobile-float-btn:active { transform: scale(0.90); }
.mobile-float-btn.primary { background: #b3d2fa; color: #1a1a1a; }
.mobile-float-btn.secondary {
  background: var(--surface);
  color: var(--text-dim);
  border: 1.5px solid var(--border);
}

/* ── Words panel ─────────────────────────────────────────── */
#words-panel {
  width: var(--words-w);
  flex-shrink: 0;
  background: var(--surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: var(--board-h);
  margin-top: 40px; /* word-display (34px) + gap inside #game-left (6px) */
}

/* ── Words tabs ─────────────────────────────────────────── */
#words-tabs {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--bg);
  flex-shrink: 0;
}

.words-tab {
  flex: 1;
  font-family: 'Nunito', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 11px 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-transform: uppercase;
}

.words-tab.active {
  background: var(--accent);
  color: var(--accent-fg);
}

.words-tab:first-child { border-radius: 0; }

.words-toggle-btn {
  display: none; /* desktop: hidden */
  width: 32px;
  height: 32px;
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  flex-shrink: 0;
}

/* ── Words count row ─────────────────────────────────────── */
#words-count-row {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 16px 9px;
  border-bottom: 1px solid var(--bg);
  flex-shrink: 0;
}

#words-count-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
}

/* ── Words list ─────────────────────────────────────────── */
#words-list-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #c2b9ae transparent;
}
#words-list-wrap::-webkit-scrollbar {
  width: 4px;
}
#words-list-wrap::-webkit-scrollbar-button {
  display: none;
}
#words-list-wrap::-webkit-scrollbar-track {
  background: var(--surface);
}
#words-list-wrap::-webkit-scrollbar-thumb {
  background: #c2b9ae;
  border-radius: 4px;
}
body.dark #words-list-wrap {
  scrollbar-color: rgba(255,255,255,0.22) transparent;
}
body.dark #words-list-wrap::-webkit-scrollbar-track {
  background: transparent;
}
body.dark #words-list-wrap::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.22);
}


#words-list {
  list-style: none;
}

/* BY ORDER: simple rows */
#words-list .wl-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--bg);
  transition: background 0.08s;
}
#words-list .wl-item:last-child { border-bottom: none; }
#words-list .wl-item:hover { background: var(--bg); }

.wl-word {
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
}

.wl-pts {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* BY LENGTH: group headers */
#words-list .wl-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px 4px;
  background: var(--bg);
  border-bottom: 1px solid var(--bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

.wlg-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
}

.wlg-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
}

/* Words within a group */
#words-list .wl-group-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px 6px 20px;
  border-bottom: 1px solid var(--bg);
}
#words-list .wl-group-item:hover { background: var(--bg); }
#words-list .wl-group-item .wl-word { font-size: 12px; }

/* Empty state */
#words-list .wl-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Tile ───────────────────────────────────────────────── */
.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tile-bg);
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.08s, border-color 0.08s;
  position: relative;
  min-width: 30px;
  min-height: 30px;
  touch-action: none;
}

.tile .letter {
  font-family: 'Nunito', sans-serif;
  font-size: calc(var(--tile-size) * 0.52);
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  pointer-events: none;
}

.tile .pts { display: none; }

.tile.selected {
  background: var(--tile-sel);
}
.tile.selected .letter { color: var(--tile-sel-fg); }


@keyframes newRowFade {
  0%   { background: var(--tile-new-row); border-color: var(--tile-new-row-b); }
  66%  { background: var(--tile-new-row); border-color: var(--tile-new-row-b); }
  100% { background: var(--tile-bg);      border-color: var(--tile-border); }
}

.tile.new-row {
  animation: newRowFade 3s ease-out forwards;
}

/* When both new-row and just-rose are present, run both animations together */
.tile.new-row.just-rose {
  animation: riseUp 0.2s ease-out, newRowFade 3s ease-out forwards;
}

@keyframes penaltyFade {
  0%   { background: var(--tile-penalty); border-color: var(--tile-penalty-b); }
  66%  { background: var(--tile-penalty); border-color: var(--tile-penalty-b); }
  100% { background: var(--tile-bg);      border-color: var(--tile-border); }
}

.tile.penalty-tile {
  animation: penaltyFade 3s ease-out forwards;
}

@media (hover: hover) {
  .tile:not(.empty):not(.selected):hover {
    background: var(--tile-hover);
  }
}

.tile.empty {
  background: var(--tile-empty);
  cursor: default;
  pointer-events: none;
}

@keyframes fallDown {
  from { transform: translateY(-20px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
.tile.just-fell { animation: fallDown 0.18s ease-out; }

@keyframes riseUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.tile.just-rose { animation: riseUp 0.2s ease-out; }

/* ── Word display (inside #game-left, centred over the board) ── */
#word-display {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  width: var(--board-w);
  flex-shrink: 0;
}
#current-word {
  font-size: clamp(15px, 3.5vw, 22px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  transition: color 0.1s;
}
#current-word.has-word { color: var(--text); }
#current-word.invalid  { color: var(--accent2); }

/* ── Action bar (buttons, below game on desktop, hidden on mobile) ── */
#word-and-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--game-gap);
  padding: 6px 20px;
  flex-shrink: 0;
  background: var(--bg);
  width: 100%;
  box-sizing: border-box;
}

/* Main controls: centred over the board column */
#controls-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: var(--board-w);
  flex-shrink: 0;
}

/* Replay: centred over the words panel, visually separated */
#controls-replay {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--words-w);
  flex-shrink: 0;
}

/* Desktop: icons hidden, text visible */
.btn-icon { display: none; }
.btn-text { display: inline; }

.ctrl-btn {
  font-family: 'Nunito', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.10em;
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  min-width: 66px;
  min-height: 38px;
  transition: opacity 0.1s, transform 0.08s;
}
.ctrl-btn:active { transform: scale(0.96); }

.ctrl-btn.primary   { background: #b3d2fa; color: #1a1a1a; }
.ctrl-btn.primary:hover { opacity: 0.85; }

.ctrl-btn.secondary {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.ctrl-btn.secondary:hover { color: var(--text); border-color: var(--text-dim); }

/* ── Game Over overlay ──────────────────────────────────── */
#gameover-overlay {
  position: fixed;
  inset: 0;
  background: rgba(247,246,243,0.90);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#gameover-overlay.hidden { display: none; }

#gameover-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.10);
  padding: 40px 48px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
#gameover-title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--text);
}
#gameover-score-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  text-transform: uppercase;
}
#gameover-score {
  font-size: 56px;
  font-weight: 900;
  color: var(--text);
  line-height: 1;
}

/* ── Modals ─────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(247,246,243,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.10);
  padding: 24px;
  max-width: 480px;
  width: 100%;
  max-height: 85dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: #c2b9ae transparent;
}
.modal-box::-webkit-scrollbar {
  width: 4px;
}
.modal-box::-webkit-scrollbar-button {
  display: none;
}
.modal-box::-webkit-scrollbar-track {
  background: transparent;
}
.modal-box::-webkit-scrollbar-thumb {
  background: #c2b9ae;
  border-radius: 4px;
}
body.dark .modal-box {
  scrollbar-color: rgba(255,255,255,0.22) transparent;
}
body.dark .modal-box::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.22);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.04em;
}
.modal-close {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { color: var(--text); }

/* ── Confirm dialog ─────────────────────────────────────── */
.confirm-box {
  max-width: 320px;
  gap: 20px;
  text-align: center;
}
.confirm-message {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
  color: var(--text);
  margin: 0;
}
.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.confirm-actions .ctrl-btn {
  flex: 1;
}

/* ── Stats modal tabs ───────────────────────────────────── */
.modal-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
}
.tab-btn {
  flex: 1;
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 7px 4px;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  background: transparent;
  color: var(--text-dim);
  transition: background 0.1s, color 0.1s;
}
.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ── Stats content ──────────────────────────────────────── */
#stats-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
#stats-content.daily-mode {
  grid-template-columns: repeat(6, 1fr);
}
#stats-content.daily-mode .stat-card {
  grid-column: span 2;
}
#stats-content.daily-mode .stat-card:nth-child(4) {
  grid-column: 2 / span 2;
}
#stats-content.daily-mode .stat-card:nth-child(5) {
  grid-column: 4 / span 2;
}
.stat-card {
  background: var(--bg);
  border-radius: 12px;
  padding: 16px 12px;
  text-align: center;
}
.stat-value {
  font-size: 30px;
  font-weight: 900;
  color: var(--text);
  line-height: 1;
}
.stat-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-top: 5px;
}

/* ── Archive modal ──────────────────────────────────────── */
#archive-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#arch-month-label {
  font-weight: 700;
  font-size: 15px;
  flex: 1;
  text-align: center;
}
#arch-prev, #arch-next {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
}
#arch-prev:hover, #arch-next:hover { color: var(--text); border-color: var(--text-dim); }

#archive-calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-weekday {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 4px 0;
}
.cal-day {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  background: transparent;
  cursor: default;
}
.cal-day.empty-day { visibility: hidden; }
.cal-day.has-game {
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}
.cal-day.has-game:hover { opacity: 0.85; }
.cal-day.missed-day {
  cursor: pointer;
  border: 1.5px dashed var(--border);
  color: var(--text-dim);
}
.cal-day.missed-day:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.cal-day.today-day {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  color: var(--text);
}
.cal-day.has-game.today-day { color: var(--accent-fg); }

#archive-detail-play {
  margin-top: 4px;
  align-self: flex-start;
}
#gameover-archive-note {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 4px 0;
}

#archive-detail {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#archive-detail.hidden { display: none; }
#archive-detail-date { font-weight: 700; font-size: 14px; }
#archive-detail-score { font-size: 12px; color: var(--text-dim); }
#archive-detail-words {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 120px;
  overflow-y: auto;
}
#archive-detail-words li {
  background: var(--bg);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ── Settings modal ─────────────────────────────────────── */
.settings-list {
  display: flex;
  flex-direction: column;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 4px;
  border-bottom: 1px solid var(--border);
  background: transparent;
  border-left: none;
  border-right: none;
  border-top: none;
  font-family: 'Nunito', sans-serif;
  cursor: default;
  width: 100%;
  text-align: left;
}
.settings-row:last-child { border-bottom: none; }

.settings-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  flex-shrink: 0;
  width: 22px;
}

.settings-label-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.settings-sublabel {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
}

/* Link rows (Feedback, Privacy Policy) */
.settings-row-link {
  cursor: pointer;
}
.settings-row-link:hover { background: var(--bg); }

.settings-chevron {
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Toggle switch (iOS-style pill) ─────────────────────── */
.toggle-switch {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  width: 50px;
  height: 28px;
  cursor: pointer;
}

.toggle-input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  border-radius: 28px;
  background: var(--border);
  transition: background 0.2s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.20);
  transition: transform 0.2s ease;
}

.toggle-input:checked + .toggle-slider {
  background: #b3d2fa;
}

.toggle-input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* ── Help modal ─────────────────────────────────────────── */
.help-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-section-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  font-weight: 800;
  color: var(--text-dim);
  text-transform: uppercase;
}

.help-mode-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-self: flex-start;
}

.help-mode-badge-btn {
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.10em;
  font-weight: 800;
  border-radius: 7px;
  padding: 3px 10px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.help-mode-badge-btn:hover {
  border-color: var(--text-muted);
}

.help-mode-badge-btn.active {
  border-color: transparent;
  background: var(--tile-sel);
  color: var(--tile-sel-fg);
}

.help-mode-badge-btn:focus-visible {
  outline: 2px solid var(--tile-sel);
  outline-offset: 2px;
}

.help-goal-text {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
}

.help-rule-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.help-rule-item {
  display: flex;
  gap: 8px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.help-rule-dash {
  color: var(--text-dim);
  flex-shrink: 0;
}

.faq-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.faq-item:last-child { border-bottom: none; }

.faq-question {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 5px;
}

.faq-answer {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.55;
}

#help-how-content,
#help-faq-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#help-faq-content.hidden,
#help-how-content.hidden { display: none; }

/* ── Burger button (desktop: hidden) ────────────────────── */
#btn-burger { display: none; }

/* ── Burger dropdown menu ───────────────────────────────── */
#burger-menu {
  position: fixed;
  top: 54px;
  right: 16px;
  z-index: 150;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.12);
  padding: 6px 0;
  min-width: 180px;
  display: flex;
  flex-direction: column;
}
#burger-menu.hidden { display: none; }

.burger-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
}
.burger-item:hover { background: var(--bg); }
.burger-item svg { color: var(--text-dim); flex-shrink: 0; }

/* ── Words panel summary (mobile-only row) ──────────────── */
#words-panel-summary {
  display: none; /* shown only on mobile */
}

/* ── Words panel body ───────────────────────────────────── */
#words-panel-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}


/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root {
    --gap: 0;
    /* word display sits above board → subtract its height (~28px) + topbar + padding */
    --tile-size: min(
      calc((100vw - 4px) / 8),
      calc((100dvh - 85px) / 12)
    );
  }

  /* ── Topbar ── */
  #topbar { padding: 8px 12px; }
  #topbar-inner { max-width: 100%; }

  /* Logo hidden on mobile */
  #logo { display: none; }

  /* Stats/archive/settings/help icons hidden on mobile → burger instead */
  #btn-stats, #btn-archive, #btn-settings, #btn-help { display: none; }
  #btn-burger { display: flex; }

  /* ── Game area: thin uniform padding, stretch children full width ── */
  #game-area {
    flex: 1;
    flex-direction: column;
    padding: 2px;
    gap: 0;
    align-items: stretch;
  }

  /* game-left fills all remaining height so we can pin board to bottom */
  #game-left {
    flex: 1;
    width: 100%;
    align-items: center;
    gap: 0;
    display: flex;
    flex-direction: column;
  }

  #score-bar { width: var(--board-w); }

  /* Board pinned to the bottom of game-left */
  #board-wrapper { overflow: hidden; margin-top: auto; }

  /* ── Words panel: summary moved to topbar; body uses fixed overlay ── */
  #words-panel {
    height: 0;
    overflow: visible;
    border: none;
    padding: 0;
    order: 0;
    margin-top: 0;
  }

  /* Summary row: shown in topbar on mobile */
  #words-panel-summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0 10px;
    cursor: pointer;
    flex: 1;
  }

  #words-summary-text {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
  }

  #words-chevron {
    color: var(--text-dim);
    transition: transform 0.2s ease;
    flex-shrink: 0;
  }

  /* Body hidden by default, visible when .open */
  #words-panel-body {
    display: none;
    border-top: 1px solid var(--border);
  }
  #words-panel-body.open {
    display: flex;
    position: fixed;
    top: 0; /* overridden dynamically by JS to match actual topbar height */
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  }

  /* Limit list height on mobile */
  #words-list-wrap { max-height: 200px; }

  /* Hide desktop tabs toggle button */
  .words-toggle-btn { display: none; }

  /* Action bar (buttons) hidden on mobile — floating buttons handle submit/clear */
  #word-and-controls { display: none; }

  /* Word display: inside game-left on mobile, shown as compact strip at top */
  #word-display {
    width: 100%;
    height: 36px;
    order: -1; /* pin to top of game-left column */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0 8px;
    box-sizing: border-box;
  }

  #current-word {
    font-size: clamp(14px, 5vw, 20px);
    letter-spacing: 0.10em;
  }

  /* Controls fixed on left side of the word-display strip */
  #mobile-float-controls {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    flex-direction: row;
  }

  /* Floating action controls: shown when selection exists */
  #mobile-float-controls.visible { display: flex; }

}

/* ═══════════════════════════════════════════════════════════
   TUTORIAL OVERLAY
   ═══════════════════════════════════════════════════════════ */

#tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: 16px;
}
#tutorial-overlay.hidden { display: none; }

#tutorial-box {
  background: var(--surface);
  border-radius: 20px;
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.28);
  overflow: hidden;
  padding-bottom: 20px;
}

/* ── Banner ── (brand blue: same as letter selection) */
#tutorial-banner {
  background: var(--tile-sel);
  color: var(--tile-sel-fg);
  width: 100%;
  padding: 18px 20px 16px;
  text-align: center;
}
#tutorial-step-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 6px;
}
#tutorial-instruction {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
}

/* ── Step dots ── */
.tut-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.tut-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.25s;
}
.tut-dot.active { background: var(--tile-sel); }

/* ── Word display ── */
#tutorial-word-area {
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#tutorial-current-word {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text);
}

/* ── Tutorial board ── */
#tutorial-board-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 0 16px;
  touch-action: none;
}
#tutorial-board {
  --tut-tile: clamp(32px, 10vw, 44px);
  display: grid;
  grid-template-columns: repeat(5, var(--tut-tile));
  grid-template-rows:    repeat(8, var(--tut-tile));
  gap: 0;
  touch-action: none;
}
.tut-tile {
  border-radius: 0;
  background: var(--tile-bg);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(14px, 4.5vw, 20px);
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: background 0.08s, color 0.08s;
}
.tut-tile.tut-empty {
  background: var(--tile-empty);
  cursor: default;
  pointer-events: none;
}
.tut-tile.tut-selected {
  background: var(--tile-sel);
  color: var(--tile-sel-fg);
}
.tut-tile.tut-selected-first {
  opacity: 0.82;
}
.tut-tile.tut-flash {
  animation: tut-flash 0.55s ease forwards;
}
@keyframes tut-flash {
  0%   { background: var(--tile-sel); color: var(--tile-sel-fg); transform: scale(1.12); }
  50%  { transform: scale(1.18); }
  100% { background: var(--tile-sel); color: var(--tile-sel-fg); transform: scale(1); }
}
body.no-animations .tut-tile.tut-flash { animation: none; }

/* ── Footer ── */
#tutorial-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0 16px;
}
.tut-btn {
  font-family: 'Nunito', sans-serif;
  font-size: 15px;
  font-weight: 700;
  padding: 13px 24px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}
.tut-btn:active { transform: scale(0.97); }
.tut-btn.primary {
  background: var(--tile-sel);
  color: var(--tile-sel-fg);
}
.tut-btn.primary:hover { opacity: 0.88; }
.tut-btn.ghost {
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  width: auto;
}
.tut-btn.ghost:hover { opacity: 0.65; }
.tut-btn.hidden { display: none; }

/* ═══════════════════════════════════════════════════════════════
   LEADERBOARD + AUTH
   ═══════════════════════════════════════════════════════════════ */

/* ── Auth button in topbar ── */
.icon-btn--auth {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 8px;
}
#auth-username-label {
  font-size: 13px;
  font-weight: 700;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: none;
}


/* ── Gameover leaderboard section ── */
#gameover-leaderboard {
  margin: 8px 0 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}
#gameover-lb-rank {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
}
.lb-submit-btn {
  background: var(--tile-sel);
  color: var(--tile-sel-fg);
  border: none;
  width: 100%;
}
.lb-submit-btn:hover { opacity: 0.88; }
.lb-view-btn { width: 100%; }

/* ── Auth modal ── */
.modal-box--auth {
  max-width: 380px;
}
.auth-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 0 8px;
}
.auth-profile-icon {
  color: var(--text-muted);
  background: var(--tile-bg);
  border-radius: 50%;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-profile-name {
  font-size: 20px;
  font-weight: 800;
}
.auth-profile-email {
  font-size: 13px;
  color: var(--text-muted);
}
.auth-logout-btn {
  width: 100%;
  margin-top: 16px;
}
.auth-hint {
  font-size: 14px;
  color: var(--text-muted);
  margin: 8px 0 16px;
}
.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}
.auth-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}
.auth-sublabel {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.auth-input {
  font-family: 'Nunito', sans-serif;
  font-size: 16px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 8px;
  border: 2px solid var(--tile-bg);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  box-sizing: border-box;
}
.auth-input:focus {
  border-color: var(--tile-sel);
}
.auth-input--code {
  letter-spacing: 0.3em;
  font-size: 24px;
  text-align: center;
}
.auth-error {
  font-size: 13px;
  color: #c0392b;
  background: rgba(192, 57, 43, 0.08);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 10px;
}
.auth-submit-btn {
  width: 100%;
  margin-top: 4px;
}
.auth-resend-btn {
  width: 100%;
  margin-top: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  border: none;
  cursor: pointer;
  padding: 8px;
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
}
.auth-resend-btn:hover { opacity: 0.7; }
.auth-resend-btn:disabled { opacity: 0.4; cursor: default; }
.auth-spam-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin: 6px 0 0;
  line-height: 1.5;
}
.auth-success {
  text-align: center;
  padding: 28px 0 20px;
}
.auth-success-icon {
  font-size: 52px;
  line-height: 1;
  color: #27ae60;
  margin-bottom: 14px;
}
.auth-success-msg {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

/* ── Leaderboard modal ── */
.modal-box--lb {
  max-width: 480px;
}

/* ── Inline leaderboard inside stats modal (Daily tab) ── */
#stats-lb-section {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.stats-lb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.stats-lb-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  flex-shrink: 0;
}
.stats-lb-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
#stats-lb-section .lb-date-switch {
  margin: 0;
  gap: 4px;
}
.stats-lb-cal-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.stats-lb-cal-btn:hover {
  color: var(--text);
  background: var(--tile-bg);
}
.stats-lb-submit-btn {
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-dim);
  font-family: 'Nunito', sans-serif;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.stats-lb-submit-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
}
.stats-lb-submit-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
#stats-lb-date-picker {
  position: absolute;
  visibility: hidden;
  width: 0;
  height: 0;
  pointer-events: none;
}
.stats-lb-auth-hint {
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 8px;
  line-height: 1.5;
}
.stats-lb-auth-hint a {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.lb-date-switch {
  display: flex;
  gap: 0;
  background: var(--tile-bg);
  border-radius: 8px;
  padding: 3px;
  margin: 8px 0 12px;
}
.lb-date-btn {
  flex: 1;
  padding: 7px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: 'Nunito', sans-serif;
  font-size: 13px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.lb-date-btn.active {
  background: var(--bg);
  color: var(--text);
}
.lb-date-label {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 12px;
}
.lb-loading {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 0;
  font-size: 14px;
}
.lb-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 0;
  font-size: 14px;
}
.lb-scroll-area {
  max-height: 220px;
  overflow-y: auto;
}
.lb-table {
  width: 100%;
  border-collapse: collapse;
}
.lb-table th {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: left;
  padding: 0 8px 8px;
  border-bottom: 1px solid var(--tile-bg);
}
.lb-table th.lb-col-score,
.lb-table th.lb-col-words { text-align: right; }
.lb-table td {
  padding: 9px 8px;
  font-size: 14px;
  border-bottom: 1px solid var(--tile-bg);
}
.lb-col-rank {
  width: 36px;
  font-weight: 700;
  color: var(--text-muted);
}
.lb-col-score, .lb-col-words { text-align: right; font-weight: 700; }
.lb-col-words { color: var(--text-muted); font-size: 12px; font-weight: 600; }
.lb-row--me {
  background: rgba(78, 139, 78, 0.12);
}
.lb-row--me td { font-weight: 800; color: var(--text); }
.lb-rank-medal { font-size: 17px; }
.lb-total {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 10px 0 2px;
}
.lb-my-rank-banner {
  background: rgba(78, 139, 78, 0.1);
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 10px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}
.lb-signin-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 10px 0 4px;
}

/* ── Custom leaderboard date-picker calendar popup ──────── */
#stats-cal-popup {
  position: fixed;
  z-index: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.16);
  width: 238px;
  box-sizing: border-box;
}
#stats-cal-popup.hidden { display: none; }
.sc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sc-month-label {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.02em;
}
.sc-nav {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-dim);
  padding: 2px 7px;
  border-radius: 8px;
  transition: background 0.12s, color 0.12s;
}
.sc-nav:hover { background: var(--bg); color: var(--text); }
.sc-nav:disabled { opacity: 0.25; cursor: default; }
.sc-nav:disabled:hover { background: none; color: var(--text-dim); }
.sc-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.sc-weekday {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 2px 0 6px;
}
.sc-day {
  aspect-ratio: 1;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.sc-day.sc-selectable {
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.sc-day.sc-selectable:hover {
  background: var(--tile-sel);
  color: var(--tile-sel-fg);
}
.sc-day.sc-today {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.sc-day.sc-disabled {
  color: var(--text-muted);
  opacity: 0.35;
  cursor: default;
}
.sc-day.sc-empty { visibility: hidden; }

