/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { background: #3B520C; }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: transparent;
  color: #f0ede6;
}

/* ── Full-page background canvas ── */
#bg-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: -1;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ── Puzzle grid — fixed over canvas, shown only during game ── */
#grid {
  display: none;
  position: fixed;
  gap: 0;
  z-index: 1;
}

/* ── App shell ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── Screens ── */
.screen { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.screen.active { display: flex; }

/* ─────────────────────────────────────────────
   HERO BANNER
───────────────────────────────────────────── */
#hero {
  display: grid;
  grid-template-columns: minmax(52px, 1fr) auto minmax(52px, 1fr);
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  position: relative;
  /* Layered glass: gradient + blur + inner highlight */
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.62) 0%,
    rgba(0, 0, 0, 0.44) 100%
  );
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  /* Top inner highlight + bottom border */
  box-shadow:
    inset 0 1px 0 #3B520C,
    0 1px 0 rgba(255, 255, 255, 0.07),
    0 4px 24px rgba(0, 0, 0, 0.35);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  z-index: 100;
  transition: padding 0.18s ease;
}

.hero-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.wordmark {
  font-family: 'Jersey 25', sans-serif;
  font-size: 2.6rem;
  color: #f0e4a8;
  letter-spacing: 0.08em;
  line-height: 1;
  /* Warm glow + depth shadow */
  text-shadow:
    0 0 30px rgba(240, 210, 80, 0.28),
    0 0 8px  rgba(240, 210, 80, 0.15),
    0 2px 6px rgba(0, 0, 0, 0.55);
  transition: font-size 0.18s ease;
  white-space: nowrap;
}

/* Compact hero when in game */
#hero.hero--compact { padding: 8px 14px; }
#hero.hero--compact .wordmark { font-size: 1.15rem; letter-spacing: 0.06em; }

#game-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
}
#game-title {
  color: #e8d9a0;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
#game-difficulty {
  color: rgba(255,255,255,0.4);
  text-transform: capitalize;
  font-size: 0.68rem;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 4px;
  padding: 1px 6px;
  letter-spacing: 0.1em;
}
#game-difficulty:empty {visibility:hidden;}

.hero-actions {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* Styled icon buttons */
.icon-btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  cursor: pointer;
  width: 32px;
  height: 32px;
  padding: 0;
  color: #e8d9a0;
  border-radius: 8px;
  line-height: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 1px 3px rgba(0, 0, 0, 0.3);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.24);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    0 2px 6px rgba(0, 0, 0, 0.35);
}
.icon-btn:active {
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Compact hero (game screen): row layout, bigger than the old stacked 20px buttons */
.hero--compact .hero-actions { flex-direction: row; gap: 6px; }
.hero--compact .icon-btn { width: 28px; height: 28px; }
.hero--compact .icon-btn svg { width: 16px; height: 16px; }

/* Game-only hero elements */
.hero-game-only { display: none; }
#app[data-screen="game"] .hero-game-only { display: inline-flex; align-items: center; }
#app[data-screen="game"] div.hero-game-only { display: flex; }

/* Back button always occupies the first grid column so the wordmark stays centred.
   Hidden on home screen via visibility (not display:none, which removes it from flow). */
#btn-back {
  justify-self: start;
  display: inline-flex !important;
  visibility: hidden;
  pointer-events: none;
}
#app[data-screen="game"] #btn-back {
  visibility: visible;
  pointer-events: auto;
}

/* ─────────────────────────────────────────────
   HOME SCREEN
───────────────────────────────────────────── */
#screen-home {
  padding: 0 16px calc(2 * 48px);
  gap: 10px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  justify-content: flex-end;
}

#home-date {
  font-size: 0.7rem;
  color: rgba(240, 217, 160, 0.65);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
#app[data-screen="game"] #home-date { display: none; }

#puzzle-tiles {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.puzzle-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 16px 20px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  cursor: pointer;
  background: rgba(10, 22, 6, 0.68);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  transition: background 0.15s, border-color 0.15s;
}
.puzzle-tile:hover { background: rgba(10, 22, 6, 0.92); }
/* Empty tiles: same opacity, just muted colours */
.puzzle-tile.puzzle-tile-empty { cursor: default; pointer-events: none; }
.puzzle-tile.puzzle-tile-empty .tile-word { opacity: 0.35; }
.puzzle-tile.puzzle-tile-empty .tile-hint { opacity: 0.4; }

.puzzle-tile[data-diff="easy"]   { border-color: rgba(90,  200, 120, 0.45); }
.puzzle-tile[data-diff="medium"] { border-color: rgba(200, 180,  80, 0.45); }
.puzzle-tile[data-diff="hard"]   { border-color: rgba(220,  80,  80, 0.45); }

.tile-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}
.puzzle-tile[data-diff="easy"]   .tile-label { color: #7aca8a; }
.puzzle-tile[data-diff="medium"] .tile-label { color: #c8b870; }
.puzzle-tile[data-diff="hard"]   .tile-label { color: #f08a8a; }

.tile-word {
  font-family: 'Jersey 25', sans-serif;
  font-size: 2.2rem;
  color: #e8d9a0;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

.tile-hint {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.32);
  margin-top: 2px;
}

.tile-status {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}
.puzzle-tile[data-diff="easy"]   .tile-status--started { color: #7aca8a; }
.puzzle-tile[data-diff="medium"] .tile-status--started { color: #c8b870; }
.puzzle-tile[data-diff="hard"]   .tile-status--started { color: #f08a8a; }
.tile-status--won { color: #5aaa6a; font-size: 1.1rem; }

/* ─────────────────────────────────────────────
   GAME LAYOUT
───────────────────────────────────────────── */
#game-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

#game-area { flex: 1; }

/* ── Clue panel (mobile: bottom strip; desktop: floating card) ── */
#clue-panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.58) 0%,
    rgba(0, 0, 0, 0.44) 100%
  );
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

/* ── Clue panel header (theme word + difficulty) ── */
#clue-panel-header {
  display: none; /* shown on desktop via media query */
  align-items: baseline;
  gap: 10px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}
#panel-theme {
  font-family: 'Jersey 25', sans-serif;
  font-size: 1.4rem;
  color: #f0e4a8;
  letter-spacing: 0.06em;
  line-height: 1;
  text-shadow: 0 0 16px rgba(240, 210, 80, 0.2), 0 1px 4px rgba(0,0,0,0.5);
}
#panel-diff {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.38);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  padding: 2px 6px;
}

/* ── Active clue bar ── */
#clue-bar {
  /* Row layout: [number + arrow] left column | [clue text] fills the rest */
  padding: 10px 14px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  background: rgba(50, 110, 230, 0.13);
}
#clue-bar-meta {
  /* Badge container: number on top, arrow below — both inside one box */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
  background: rgba(200, 180, 80, 0.12);
  border: 1px solid rgba(200, 180, 80, 0.22);
  border-radius: 6px;
  padding: 5px 10px;
  min-width: 42px;
}
#clue-number {
  font-weight: 700;
  white-space: nowrap;
  color: #c8b870;
  font-size: 1.0rem;
  text-align: center;
  line-height: 1;
}
#clue-dir-bar {
  font-size: 1.45rem;
  font-weight: 700;
  flex-shrink: 0;
  line-height: 1;
}
#clue-dir-bar.dir-across { color: #5ab0e8; }
#clue-dir-bar.dir-down   { color: #6ad870; }
#clue-dir-bar.dir-up     { color: #e89850; }
#clue-dir-bar.dir-back   { color: #e870b0; }
#clue-text {
  flex: 1;
  font-size: 1.0rem;
  color: #dff0ff;
  line-height: 1.35;
}

/* ─────────────────────────────────────────────
   GRID CELLS
───────────────────────────────────────────── */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Blocked — fully transparent */
.cell.blocked {
  background: transparent;
  cursor: default;
}

/* Path cells — white frosted glass */
.cell:not(.blocked) {
  width: calc(var(--cell-size) - 6px);
  height: calc(var(--cell-size) - 6px);
  margin: 3px;
  background: rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(2px) saturate(1.1);
  -webkit-backdrop-filter: blur(2px) saturate(1.1);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.14),
    0 2px 6px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  cursor: pointer;
}

/* Theme row — clear glass */
.cell.prefilled {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.45);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.1),
    0 1px 4px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* Selected word */
.cell.selected-word:not(.blocked) {
  background: rgba(160, 215, 255, 0.38);
  border-color: rgba(140, 200, 255, 0.7);
}
.cell.selected-word.prefilled {
  background: rgba(160, 215, 255, 0.28);
  border-color: rgba(140, 200, 255, 0.55);
}

/* Active cell */
.cell.active-cell {
  background: rgba(90, 170, 240, 0.52) !important;
  border-color: rgba(80, 160, 240, 0.85) !important;
  box-shadow:
    0 2px 10px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(200, 230, 255, 0.5) !important;
}

/* Direction arrow on the active (empty) cell */
.cell.active-cell::after {
  content: attr(data-dir);
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: calc(var(--cell-size) * 0.28);
  color: rgba(20, 60, 120, 0.5);
  pointer-events: none;
  line-height: 1;
}

/* Directional nudge animations */
@keyframes arrowDown  { 0%,100% { transform: translateY(0);    } 50% { transform: translateY(3px);  } }
@keyframes arrowUp    { 0%,100% { transform: translateY(0);    } 50% { transform: translateY(-3px); } }
@keyframes arrowRight { 0%,100% { transform: translateX(0);    } 50% { transform: translateX(3px);  } }
@keyframes arrowLeft  { 0%,100% { transform: translateX(0);    } 50% { transform: translateX(-3px); } }

.cell.active-cell[data-dir-name="down"]::after   { animation: arrowDown  0.9s ease-in-out infinite; }
.cell.active-cell[data-dir-name="up"]::after     { animation: arrowUp    0.9s ease-in-out infinite; }
.cell.active-cell[data-dir-name="across"]::after { animation: arrowRight 0.9s ease-in-out infinite; }
.cell.active-cell[data-dir-name="back"]::after   { animation: arrowLeft  0.9s ease-in-out infinite; }

/* Correct */
.cell.correct,
.cell.correct.selected-word,
.cell.correct.active-cell {
  background: rgba(90, 200, 120, 0.38) !important;
  border-color: rgba(70, 185, 100, 0.65) !important;
  box-shadow:
    0 1px 6px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(180, 255, 200, 0.4) !important;
}

/* ── Cell contents ── */
.cell-letter {
  font-size: calc(var(--cell-size) * 0.5);
  font-weight: 800;
  text-transform: uppercase;
  pointer-events: none;
  user-select: none;
  line-height: 1;
  color: #1a2e0a;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.4);
}

.cell.prefilled .cell-letter {
  color: #3a2800;
}

.cell-number {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: calc(var(--cell-size) * 0.22);
  line-height: 1;
  color: rgba(20, 40, 10, 0.65);
  pointer-events: none;
  font-weight: 700;
}

/* ─────────────────────────────────────────────
   CLUE LIST
───────────────────────────────────────────── */
#clue-list-wrap {
  display: none; /* mobile: only the active clue bar is shown */
}
/* Custom scrollbar */
#clue-list-wrap::-webkit-scrollbar { width: 4px; }
#clue-list-wrap::-webkit-scrollbar-track { background: transparent; }
#clue-list-wrap::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

#clue-list { display: flex; flex-direction: column; }

.clue-item {
  font-size: 0.9rem;
  padding: 8px 18px 8px 5px;
  cursor: pointer;
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: #b8ac68;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  transition: background 0.12s, color 0.12s;
}
.clue-item:last-child { border-bottom: none; }
.clue-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #d4c880;
}
.clue-item.active {
  background: rgba(50, 130, 240, 0.18);
  color: #e8f4ff;
  font-weight: 600;
}
.clue-item.solved {
  color: #3a4a3c;
  text-decoration: line-through;
}

.clue-num {
  font-weight: 700;
  min-width: 20px;
  color: #c8b870;
  flex-shrink: 0;
  font-size: 0.78rem;
  text-align: right;
}
.clue-item.active .clue-num { color: #e8d580; }

/* Hard-mode theme word entry — sits at the bottom, slightly set apart */
.clue-item-theme {
  margin-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 10px;
}
.clue-item-theme .clue-num { color: #d4a84b; }

.clue-dir {
  font-size: 0.8rem;
  flex-shrink: 0;
  font-weight: 700;
}
/* Colored direction arrows */
.clue-dir.dir-across { color: #5ab0e8; }
.clue-dir.dir-down   { color: #6ad870; }
.clue-dir.dir-up     { color: #e89850; }
.clue-dir.dir-back   { color: #e870b0; }

/* ─────────────────────────────────────────────
   CUSTOM KEYBOARD (mobile)
───────────────────────────────────────────── */
#keyboard {
  display: none;
  padding: 6px 4px 10px;
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  gap: 5px;
  flex-direction: column;
  flex-shrink: 0;
}
#keyboard.visible { display: flex; }

/* Hide the on-screen keyboard only on devices with a precise pointer that can
   hover (mouse/trackpad) — these have a physical keyboard. Gating on input
   capability instead of screen width keeps the keyboard available on large
   tablets (coarse pointer, no hover), which would otherwise be unplayable. */
@media (hover: hover) and (pointer: fine) {
  #keyboard { display: none !important; }
}

.kb-row { display: flex; justify-content: center; gap: 4px; }

.kb-key {
  height: 42px;
  min-width: 30px;
  padding: 0 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.09);
  color: #e8d9a0;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.08);
  flex: 1;
  max-width: 38px;
}
.kb-key.wide { max-width: 54px; }
.kb-key:active { background: rgba(255, 255, 255, 0.2); }

/* ─────────────────────────────────────────────
   WIN SCREEN
───────────────────────────────────────────── */
#screen-win {
  align-items: center;
  justify-content: center;
}
.win-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 48px 64px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.6));
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-radius: 24px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
}
.win-card h2 {
  font-family: 'Jersey 25', sans-serif;
  font-size: 3.5rem;
  color: #2a4a1f;
  letter-spacing: 0.05em;
  margin: 0;
}
.win-card p { color: #445533; font-size: 1rem; margin: 0; }
#btn-play-again {
  margin-top: 4px;
  padding: 10px 28px;
  background: transparent;
  border: 1.5px solid rgba(42, 74, 31, 0.45);
  border-radius: 100px;
  color: #2a4a1f;
  font-size: 0.95rem;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: background 0.15s, border-color 0.15s;
}
#btn-play-again:hover {
  background: rgba(42, 74, 31, 0.08);
  border-color: #2a4a1f;
}

/* ─────────────────────────────────────────────
   STATS SCREEN
───────────────────────────────────────────── */
#screen-stats {
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.stats-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 420px;
  padding: 28px 24px 24px;
  background: rgba(10, 16, 26, 0.86);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid rgba(110, 170, 230, 0.5);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
}
#btn-stats-close {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 1.1rem;
  font-weight: 700;
}
.stats-card h2 {
  font-family: 'Jersey 25', sans-serif;
  font-size: 2rem;
  color: #f0e4a8;
  letter-spacing: 0.05em;
  text-shadow: 0 0 16px rgba(240, 210, 80, 0.2), 0 1px 4px rgba(0,0,0,0.5);
}
#stats-date {
  font-size: 0.7rem;
  color: rgba(240, 217, 160, 0.65);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: -12px;
}
#stats-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stats-row {
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.04);
}
.stats-row[data-diff="easy"]   { border-color: rgba(90,  200, 120, 0.4); }
.stats-row[data-diff="medium"] { border-color: rgba(200, 180,  80, 0.4); }
.stats-row[data-diff="hard"]   { border-color: rgba(220,  80,  80, 0.4); }

.stats-row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.stats-diff {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}
.stats-row[data-diff="easy"]   .stats-diff { color: #7aca8a; }
.stats-row[data-diff="medium"] .stats-diff { color: #c8b870; }
.stats-row[data-diff="hard"]   .stats-diff { color: #f08a8a; }

.stats-word {
  font-family: 'Jersey 25', sans-serif;
  font-size: 1.3rem;
  color: #e8d9a0;
  letter-spacing: 0.04em;
}

.stats-row-body {
  display: flex;
  gap: 18px;
}
.stats-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stats-stat-label {
  font-size: 0.62rem;
  color: rgba(255, 255, 255, 0.4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stats-stat-value {
  font-size: 0.95rem;
  color: #f0ede6;
  font-weight: 600;
}

/* ── Shared buttons ── */
.btn {
  padding: 11px 28px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.4);
  color: #e8d9a0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.15s;
}
.btn:hover { background: rgba(0, 0, 0, 0.58); }

/* ─────────────────────────────────────────────
   CLUE PANEL ENTRANCE ANIMATION
───────────────────────────────────────────── */
.panel-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

@keyframes panelReveal {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0);    }
}
.panel-reveal {
  animation: panelReveal 0.45s ease forwards;
}

/* ─────────────────────────────────────────────
   CELL LOAD ANIMATIONS
───────────────────────────────────────────── */

/* Initial hidden state — no transition so the cell is instantly invisible */
.cell.cell-enter {
  opacity: 0 !important;
  transform: translateY(8px) !important;
  transition: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Theme tile pop: spring in from below */
@keyframes cellPop {
  0%   { opacity: 0; transform: scale(0.4)  translateY(4px);  }
  60%  { opacity: 1; transform: scale(1.08) translateY(-1px); }
  100% { opacity: 1; transform: scale(1)    translateY(0);    }
}
.cell.cell-pop {
  animation: cellPop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
}

/* Glass tile reveal: keyframe so it always plays from opacity-0 regardless of prior state */
@keyframes cellReveal {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}
.cell.cell-reveal {
  animation: cellReveal 0.4s ease forwards !important;
}

/* ─────────────────────────────────────────────
   DESKTOP TWO-COLUMN LAYOUT  (≥ 800px, mouse + keyboard)
   Gated on a precise hovering pointer so touch tablets — wide but coarse-
   pointer — fall through to the mobile single-column layout instead.
───────────────────────────────────────────── */
@media (min-width: 800px) and (hover: hover) and (pointer: fine) {
  /* Home tiles go horizontal */
  #screen-home { max-width: 860px; padding: calc(3 * 48px) 32px 24px; justify-content: flex-start; }
  #puzzle-tiles { flex-direction: row; gap: 16px; }
  .puzzle-tile { flex: 1; }
  .tile-word { font-size: 2.6rem; }
  #home-date { font-size: 0.8rem; }

  /* Game layout: grid left, floating panel right */
  #game-layout { flex-direction: row; align-items: stretch; }
  #game-area { flex: 1; }

  /* Floating glass card — top/left/bottom set by positionPanel() in JS */
  #clue-panel {
    position: fixed;
    max-width: 420px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(18px) saturate(1.3);
    -webkit-backdrop-filter: blur(18px) saturate(1.3);
    box-shadow:
      0 4px 24px rgba(0, 0, 0, 0.38),
      inset 0 1px 0 rgba(255, 255, 255, 0.08);
    border-top: 1px solid rgba(255, 255, 255, 0.13);
  }

  /* Show panel header on desktop */
  #clue-panel-header {
    display: flex;
    padding: 16px 18px 14px;
  }

  /* Active clue bar not needed on desktop — the list shows which is selected */
  #clue-bar { display: none; }

  .clue-item.active .clue-num { color: #e8d580; }

  #clue-list-wrap {
    display: block; /* restore — was hidden for mobile */
    flex: 1;
    max-height: none;
    overflow-y: auto;
    padding: 6px 0 6px;
  }


  /* Larger wordmark on desktop */
  .wordmark { font-size: 2.4rem; }
  #hero.hero--compact .wordmark { font-size: 1.2rem; }

  /* Desktop: buttons side by side, more room on each side */
  .hero-actions { flex-direction: row; gap: 6px; }
  #hero { grid-template-columns: minmax(96px, 1fr) auto minmax(96px, 1fr); }
}

/* ── Touch devices: strip backdrop-filter from grid cells ─────────────────
   On iOS Safari (iPhone AND iPad), each cell's backdrop-filter creates a GPU
   compositing layer. With ~50+ cells on screen, these layers can sit above
   position:fixed elements in the compositor's tree regardless of CSS z-index,
   blocking paint and touch on the hero until a full compositor rebuild (e.g.
   screen rotation). At 48px a 2px blur is imperceptible — safe to remove.
   Gated on coarse pointer so it covers tablets too, not just narrow phones. */
@media (pointer: coarse) {
  .cell:not(.blocked) {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  body.puzzle-loaded .cell:not(.blocked) {
    backdrop-filter: blur(2px) saturate(1.1);
    -webkit-backdrop-filter: blur(2px) saturate(1.1);
  }
}

/* ─────────────────────────────────────────────
   TABLET PORTRAIT  (large touch device, no mouse/keyboard, held upright)
   Wider than a phone (≥600px) but coarse-pointer, so it uses the mobile
   single-column layout. The phone-sized keyboard + clue bar are tiny here,
   and there's ample vertical room, so scale the on-screen keyboard up ~1.5×,
   lift it off the bottom edge, and enlarge the clue bar to match. The play
   area (fixed grid) is sized in JS from the live DOM — it re-measures the
   taller keyboard/clue panel automatically, so no grid rule is needed here.
───────────────────────────────────────────── */
@media (orientation: portrait) and (pointer: coarse) and (min-width: 600px) {
  /* Home: phone layout bottom-anchors small tiles, leaving a huge empty field
     above on a tall tablet. Centre the stack and scale the tiles up so the
     three puzzles read as the main content, not a strip at the bottom. */
  #screen-home {
    max-width: 620px;
    justify-content: center;
    gap: 16px;
    padding: 0 24px 6vh;
  }
  #home-date { font-size: 0.95rem; }
  #puzzle-tiles { gap: 16px; }
  .puzzle-tile { padding: 26px 32px; border-radius: 18px; gap: 8px; }
  .tile-label { font-size: 0.78rem; }
  .tile-word { font-size: 3rem; }
  .tile-hint { font-size: 0.9rem; }
  .tile-status { top: 14px; right: 16px; font-size: 1.35rem; }
  .tile-status--won { font-size: 1.5rem; }

  /* Keyboard scaled ~1.5× + lifted off the bottom edge for thumb reach */
  #keyboard {
    gap: 8px;
    padding: 10px 8px 6vh;
  }
  .kb-row { gap: 6px; }
  .kb-key {
    height: 63px;
    min-width: 45px;
    padding: 0 6px;
    border-radius: 7px;
    font-size: 1.3rem;
    max-width: 57px;
  }
  .kb-key.wide { max-width: 81px; }

  /* Clue panel scaled to match: roomier bar, larger clue text */
  #clue-bar { padding: 15px 20px; gap: 16px; }
  #clue-bar-meta { padding: 7px 14px; min-width: 56px; gap: 2px; }
  #clue-number { font-size: 1.3rem; }
  #clue-dir-bar { font-size: 1.9rem; }
  #clue-text { font-size: 1.3rem; }
}

/* ─────────────────────────────────────────────
   TABLET LANDSCAPE  (large touch device, no mouse/keyboard, held sideways)
   Coarse-pointer, so it falls through to the mobile single-column layout.
   Gated on the short side (min-height ≥600px) to catch tablets but not phones
   held sideways. Vertical room is tighter than portrait, so the base keyboard
   size is kept (per feedback) — it's only lifted off the bottom edge. The wide
   viewport suits a horizontal tile row for the home screen.
───────────────────────────────────────────── */
@media (orientation: landscape) and (pointer: coarse) and (min-height: 600px) {
  /* Home: use the roomy horizontal tile row (like desktop) and centre it,
     instead of the narrow bottom-anchored column the phone layout gives. */
  #screen-home {
    max-width: 900px;
    justify-content: center;
    gap: 16px;
    padding: 0 32px 5vh;
  }
  #home-date { font-size: 0.9rem; }
  #puzzle-tiles { flex-direction: row; gap: 16px; }
  .puzzle-tile { flex: 1; padding: 22px; border-radius: 16px; }
  .tile-word { font-size: 2.6rem; }
  .tile-hint { font-size: 0.82rem; }

  /* Keyboard: base size is fine here — just lift it off the bottom edge so it
     isn't jammed against the screen bottom. */
  #keyboard { padding: 8px 8px 4vh; }
}
