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

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;900&display=swap');

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --bg:          #f7f6f3;
  --surface:     #ffffff;
  --border:      #e8e3dc;
  --accent:      #1a1a1a;
  --accent2:     #d0474a;
  --text:        #1a1a1a;
  --text-dim:    #9a9590;
  --text-muted:  #c5c0b8;
  --tile-bg:     #ffffff;
  --tile-border: #e8e3dc;
  --tile-sel:    #1a1a1a;
  --tile-sel-fg: #ffffff;
  --tile-empty:  transparent;

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

  /* 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;
  --text:        #e8e3dc;
  --text-dim:    #808080;
  --text-muted:  #484848;
  --tile-bg:     #252525;
  --tile-border: #2e2e2e;
  --tile-sel:    #e8e3dc;
  --tile-sel-fg: #121212;
  --tile-empty:  transparent;
}
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; }

/* ── 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: clamp(15px, 3vw, 22px);
  font-weight: 900;
  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: #ffffff;
}

.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: 1 1 auto;
  gap: var(--game-gap);
  padding: 8px 20px 4px;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}

/* ── 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;
}

/* ── 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 */
}

/* ── 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);
}

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

/* ── Mobile floating action controls (over board) ───────── */
#mobile-float-controls {
  display: none; /* shown only on mobile when selection exists */
  position: absolute;
  z-index: 15;
  gap: 8px;
  padding: 6px;
  pointer-events: auto;
}

.mobile-float-btn {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.1s, transform 0.08s;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
}
.mobile-float-btn:active { transform: scale(0.90); }
.mobile-float-btn.primary { background: var(--accent); color: #fff; }
.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);
}

/* ── 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: #ffffff;
}

.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: space-between;
  align-items: center;
  padding: 10px 16px 9px;
  border-bottom: 1px solid var(--bg);
  flex-shrink: 0;
}

.wc-label {
  font-size: 13px;
  color: var(--text-dim);
}

#words-count-num {
  font-size: 15px;
  font-weight: 900;
  color: var(--text);
}

/* ── Words list ─────────────────────────────────────────── */
#words-list-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

#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); }


.tile.new-row {
  border-color: #b8d4f0;
  background: #f0f6fd;
}

@media (hover: hover) {
  .tile:not(.empty):not(.selected):hover {
    background: #f2efe9;
  }
}

.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 + controls wrapper ────────────────────────────── */
#word-and-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  width: var(--board-w);
}

/* ── Word display ───────────────────────────────────────── */
#word-display {
  order: -1; /* sits above controls on desktop (column layout) */
  text-align: center;
  padding: 0 12px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  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); }

/* ── Controls ───────────────────────────────────────────── */
#controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  flex-wrap: wrap;
  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: var(--accent); color: #ffffff; }
.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;
}

.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); }

/* ── 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;
}
.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: #ffffff;
  cursor: pointer;
}
.cal-day.has-game:hover { opacity: 0.85; }
.cal-day.today-day {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  color: var(--text);
}
.cal-day.has-game.today-day { color: #ffffff; }

#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: #34a853;
}

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

/* ── 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 icons hidden on mobile → burger instead */
  #btn-stats, #btn-archive { display: none; }
  #btn-burger { display: flex; }

  /* ── Game area: thin uniform padding, stretch children full width ── */
  #game-area {
    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;
  }

  /* 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: 54px;
    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; }

  /* ── Word + controls: moved to top of game-left ── */
  #word-and-controls {
    order: -1;
    flex-direction: row;
    align-items: center;
    width: 100%;
    padding: 2px 8px;
    gap: 6px;
  }

  /* Controls: hidden on mobile — replaced by floating overlay buttons */
  #controls { display: none; }

  /* Word display: fills full width */
  #word-display {
    flex: 1;
    text-align: center;
    padding: 0;
    min-height: auto;
  }

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

  /* 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: 340px;
  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 ── */
#tutorial-banner {
  background: #4e8b4e;
  color: #ffffff;
  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: #4e8b4e; }

/* ── 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 {
  width: 100%;
  padding: 0 16px;
}
#tutorial-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  touch-action: none;
}
.tut-tile {
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--tile-bg);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 6vw, 26px);
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: background 0.1s, border-color 0.1s, transform 0.1s, color 0.1s;
}
.tut-tile.tut-empty {
  background: var(--bg);
  border-color: transparent;
  cursor: default;
  pointer-events: none;
}
.tut-tile.tut-selected {
  background: var(--tile-sel);
  border-color: var(--tile-sel);
  color: var(--tile-sel-fg);
  transform: scale(1.07);
}
.tut-tile.tut-selected-first {
  opacity: 0.82;
}
.tut-tile.tut-flash {
  animation: tut-flash 0.55s ease forwards;
}
@keyframes tut-flash {
  0%   { background: #4e8b4e; border-color: #4e8b4e; color: #fff; transform: scale(1.12); }
  50%  { transform: scale(1.18); }
  100% { background: #4e8b4e; border-color: #4e8b4e; color: #fff; 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: #4e8b4e;
  color: #ffffff;
}
.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; }
