:root {
  --bg: #071421;
  --bg-2: #0b1f33;
  --panel: #10263d;
  --panel-2: #143049;
  --line: rgba(140, 190, 230, 0.18);
  --text: #e8f3ff;
  --muted: #8fb0c9;
  --accent: #3ec7ff;
  --accent-2: #1fbf75;
  --warn: #ffb020;
  --danger: #ff5d6c;
  --found-1: #2dd4bf;
  --found-2: #60a5fa;
  --found-3: #a78bfa;
  --found-4: #f472b6;
  --found-5: #fbbf24;
  --found-6: #34d399;
  --found-7: #fb7185;
  --found-8: #38bdf8;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --font: "Fredoka", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 700px at 10% -10%, #143552 0%, transparent 55%),
              radial-gradient(900px 600px at 100% 0%, #0d3a4f 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  /* mobile feel */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* kill 300ms delay, allow pan/zoom where needed */
}

button {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  min-height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 16px 28px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(28px, env(safe-area-inset-bottom));
  padding-top: max(18px, env(safe-area-inset-top));
}

/* while dragging wordsearch, lock page scroll bounce */
body.dragging-ws {
  overflow: hidden;
  touch-action: none;
}
body.dragging-ws #app {
  touch-action: none;
}

.screen { display: none; }
.screen.active { display: block; animation: fade .18s ease; }

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* HOME */
.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 12%, rgba(62,199,255,.16), transparent 28%),
    radial-gradient(circle at 82% 18%, rgba(31,191,117,.12), transparent 24%),
    radial-gradient(circle at 50% 100%, rgba(62,199,255,.06), transparent 35%);
  z-index: 0;
}

.hero {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 18px 10px 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(62,199,255,.16), rgba(31,191,117,.1));
  color: var(--accent);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  border: 1px solid rgba(62,199,255,.22);
  box-shadow: 0 0 0 4px rgba(62,199,255,.05);
}

.logo {
  margin: 14px 0 8px;
  font-size: clamp(2.8rem, 9vw, 4.2rem);
  line-height: 1;
  letter-spacing: -0.04em;
  filter: drop-shadow(0 8px 24px rgba(62,199,255,.12));
}
.logo-teka { color: var(--text); }
.logo-met {
  background: linear-gradient(135deg, #5ed4ff 0%, #3ec7ff 40%, #1fbf75 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0 auto;
  max-width: 420px;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.5;
}

.stats-bar {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px auto 16px;
  max-width: 560px;
}

.stat {
  background: linear-gradient(180deg, rgba(20,48,73,.9), rgba(12,30,48,.85));
  border: 1px solid rgba(140,190,230,.14);
  border-radius: 16px;
  padding: 14px 8px 12px;
  text-align: center;
  backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.stat-val {
  display: block;
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.stat-label {
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}

.tahap-cards {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 14px;
  max-width: 640px;
  margin: 0 auto;
}

.tahap-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 18px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(20,48,73,.95), rgba(12,30,48,.95));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.tahap-card:hover {
  transform: translateY(-2px);
  border-color: rgba(62,199,255,.4);
}
.tahap-card.tahap-2 .tahap-num {
  background: linear-gradient(145deg, #1fbf75, #0d8f56);
}

.tahap-num {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(145deg, #3ec7ff, #1a7fa8);
  color: #042033;
  box-shadow: 0 8px 20px rgba(62,199,255,.25);
}

.tahap-body h2 {
  margin: 0 0 2px;
  font-size: 1.25rem;
}
.tahap-body p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: .92rem;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .35s ease;
}
.prog-text {
  display: inline-block;
  margin-top: 6px;
  font-size: .8rem;
  color: var(--muted);
}
.chev { color: var(--muted); }

.home-foot {
  position: relative;
  z-index: 1;
  text-align: center;
  margin-top: 22px;
}
.linkish {
  color: var(--muted);
  font-size: .9rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.linkish:hover { color: var(--text); }

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.topbar h2 {
  margin: 0;
  font-size: 1.2rem;
}
.spacer { flex: 1; }
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(16,38,61,.8);
  border: 1px solid var(--line);
  color: var(--text);
}
.icon-btn:hover { border-color: rgba(62,199,255,.45); }

/* LEVEL LIST */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.level-card {
  position: relative;
  padding: 16px 14px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: left;
  transition: transform .12s ease, border-color .12s ease;
}
.level-card:hover {
  transform: translateY(-2px);
  border-color: rgba(62,199,255,.4);
}
.level-card.done {
  border-color: rgba(31,191,117,.45);
  background: linear-gradient(160deg, rgba(31,191,117,.12), var(--panel));
}
.level-id {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
}
.level-card.done .level-id { color: var(--accent-2); }
.level-diff {
  margin-top: 6px;
}
.diff-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.diff-badge.diff-easy {
  color: #86efac;
  background: rgba(34,197,94,.14);
  border: 1px solid rgba(34,197,94,.28);
}
.diff-badge.diff-mid {
  color: #fde68a;
  background: rgba(245,158,11,.14);
  border: 1px solid rgba(245,158,11,.3);
}
.diff-badge.diff-hard {
  color: #fda4af;
  background: rgba(244,63,94,.14);
  border: 1px solid rgba(244,63,94,.3);
}
.level-card.diff-easy { border-color: rgba(34,197,94,.2); }
.level-card.diff-mid { border-color: rgba(245,158,11,.22); }
.level-card.diff-hard { border-color: rgba(244,63,94,.22); }
.level-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: .85rem;
}
.level-check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-2);
  color: #042016;
  display: none;
  place-items: center;
  font-size: .75rem;
  font-weight: 700;
}
.level-card.done .level-check { display: grid; }

/* PLAY */
.play-top .play-title-wrap { flex: 1; min-width: 0; }
.play-title-wrap h2 {
  margin: 0;
  font-size: 1.1rem;
}
.play-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: .88rem;
  font-variant-numeric: tabular-nums;
}
.play-meta .dot { opacity: .5; }

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 18px;
  align-items: start;
}

.grid-wrap {
  position: relative;
  width: 100%;
  max-width: min(100%, 720px);
  margin: 0 auto;
  user-select: none;
  touch-action: none;
  /* softer board frame — less harsh navy */
  background: linear-gradient(180deg, #e8f1f8 0%, #dce8f2 100%);
  border: 1px solid rgba(140, 180, 210, 0.35);
  border-radius: 22px;
  padding: 14px;
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.letter-grid {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  gap: 5px;
  position: relative;
  z-index: 1;
}

.cell {
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(.78rem, 2.5vw, 1.12rem);
  letter-spacing: 0.02em;
  /* dark ink on soft light tile = easier on eyes */
  color: #1a3348;
  background: #f7fbfd;
  border: 1px solid rgba(26, 51, 72, 0.08);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
  /* avoid transform during drag — causes jank/layout thrash */
  transition: background .1s ease, color .1s ease, box-shadow .1s ease;
  will-change: background;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.cell.selected {
  background: #b8e6ff;
  color: #0a2a3d;
  border-color: rgba(30, 140, 200, 0.35);
  box-shadow: 0 0 0 2px rgba(62, 199, 255, 0.35);
}
.cell.found {
  color: #0b2a1c;
  font-weight: 800;
  border-color: transparent;
}
.cell.hint {
  outline: 2px solid #e0a21a;
  outline-offset: -2px;
  animation: pulse 1s ease infinite;
  background: #fff4d6;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 162, 26, .35); }
  50% { box-shadow: 0 0 0 5px rgba(224, 162, 26, 0); }
}

.line-layer {
  position: absolute;
  inset: 14px;
  width: calc(100% - 28px);
  height: calc(100% - 28px);
  pointer-events: none;
  z-index: 2;
}

.word-panel {
  background: linear-gradient(180deg, rgba(18, 42, 66, 0.95), rgba(12, 30, 48, 0.95));
  border: 1px solid rgba(140, 190, 230, 0.16);
  border-radius: 18px;
  padding: 16px;
  position: sticky;
  top: 12px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}
.word-panel h3 {
  margin: 0 0 6px;
  font-size: 1.02rem;
}
.word-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
}
.word-list li {
  padding: 9px 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(140, 190, 230, 0.1);
  font-family: var(--mono);
  font-size: .9rem;
  letter-spacing: .03em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: #e8f3ff;
}
.word-list li.found {
  text-decoration: line-through;
  opacity: .72;
  border-color: rgba(31, 191, 117, 0.28);
  background: rgba(31, 191, 117, 0.12);
  color: #b7f0d2;
}
.word-list li .mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  opacity: .4;
  flex-shrink: 0;
}
.word-list li.found .mark { opacity: 1; }

.play-actions {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.btn {
  padding: 11px 14px;
  border-radius: 12px;
  font-weight: 600;
  font-size: .95rem;
}
.btn.primary {
  background: linear-gradient(135deg, #3ec7ff, #1fbf75);
  color: #042033;
  box-shadow: 0 8px 20px rgba(62, 199, 255, .18);
}
.btn.ghost {
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(140, 190, 230, .16);
  color: var(--text);
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(3, 10, 18, .72);
  backdrop-filter: blur(6px);
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(100%, 380px);
  background: linear-gradient(180deg, #143049, #0d2135);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 26px 22px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop .28s ease;
}
@keyframes pop {
  from { opacity: 0; transform: scale(.94) translateY(8px); }
  to { opacity: 1; transform: none; }
}
.win-icon { margin-bottom: 8px; }
.modal-card h2 { margin: 4px 0 6px; font-size: 1.6rem; }
.modal-card p { margin: 0; color: var(--muted); }
.win-time { margin-top: 8px !important; }
.win-time strong { color: var(--text); }
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

/* FOUND COLOR VARIANTS — pastel, not neon */
.found-c0 { background: #7dd3c0 !important; color: #0b2a22 !important; }
.found-c1 { background: #8ec5f7 !important; color: #0b2440 !important; }
.found-c2 { background: #c4b5fd !important; color: #2e1065 !important; }
.found-c3 { background: #f9a8d4 !important; color: #500724 !important; }
.found-c4 { background: #fcd34d !important; color: #422006 !important; }
.found-c5 { background: #86efac !important; color: #052e16 !important; }
.found-c6 { background: #fda4af !important; color: #4c0519 !important; }
.found-c7 { background: #7dd3fc !important; color: #0c4a6e !important; }

@media (max-width: 820px) {
  .play-layout {
    grid-template-columns: 1fr;
  }
  .word-panel {
    position: static;
  }
  .word-list {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  .cell {
    font-size: clamp(.78rem, 3.6vw, 1.05rem);
    border-radius: 8px;
    min-height: 0;
  }
  .letter-grid { gap: 4px; }
  /* bigger touch targets on phone */
  .icon-btn {
    min-width: 44px;
    min-height: 44px;
  }
  .btn {
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  #app {
    padding: 12px 10px 20px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
  .grid-wrap { padding: 10px; border-radius: 16px; }
  .line-layer { inset: 10px; width: calc(100% - 20px); height: calc(100% - 20px); }
  .letter-grid { gap: 3px; }
  .cell {
    font-size: clamp(.74rem, 3.8vw, 1rem);
    border-radius: 7px;
  }
  .modal-actions { grid-template-columns: 1fr; }
  .cw-cell {
    width: clamp(34px, 8vw, 42px);
    height: clamp(34px, 8vw, 42px);
  }
  .cw-cell input { font-size: 16px; }
  .osk-key {
    min-width: 34px;
    height: 44px;
  }
}

/* GAME CARDS (home hub) */
.game-cards {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 12px;
  max-width: 640px;
  margin: 0 auto;
}
.game-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 18px;
  border-radius: 20px;
  background:
    linear-gradient(145deg, rgba(26,56,84,.96), rgba(12,30,48,.96));
  border: 1px solid rgba(140,190,230,.16);
  box-shadow:
    0 16px 40px rgba(0,0,0,.28),
    inset 0 1px 0 rgba(255,255,255,.05);
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.game-card:hover {
  transform: translateY(-3px);
  border-color: rgba(62,199,255,.45);
  box-shadow:
    0 20px 48px rgba(0,0,0,.34),
    0 0 0 1px rgba(62,199,255,.08),
    inset 0 1px 0 rgba(255,255,255,.06);
}
.game-card-cw {
  border-color: rgba(31,191,117,.22);
}
.game-card-cw:hover {
  border-color: rgba(31,191,117,.5);
  box-shadow:
    0 20px 48px rgba(0,0,0,.34),
    0 0 0 1px rgba(31,191,117,.1),
    inset 0 1px 0 rgba(255,255,255,.06);
}
.game-icon {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(62,199,255,.18), rgba(62,199,255,.06));
  color: var(--accent);
  border: 1px solid rgba(62,199,255,.18);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}
.game-card-cw .game-icon {
  background: linear-gradient(145deg, rgba(31,191,117,.2), rgba(31,191,117,.06));
  color: var(--accent-2);
  border-color: rgba(31,191,117,.2);
}
.game-body h2 {
  margin: 0 0 4px;
  font-size: 1.22rem;
  letter-spacing: -0.01em;
}
.game-body p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.4;
}
.game-card .chev {
  opacity: .7;
  transition: transform .15s ease, opacity .15s ease;
}
.game-card:hover .chev {
  opacity: 1;
  transform: translateX(2px);
  color: var(--accent);
}
.game-card-cw:hover .chev { color: var(--accent-2); }

/* CROSSWORD */
.cw-active-clue {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: baseline;
  padding: 12px 14px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: rgba(16,38,61,.9);
  border: 1px solid var(--line);
}
.cw-clue-num {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.1rem;
}
.cw-clue-dir {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  background: rgba(255,255,255,.06);
  padding: 2px 8px;
  border-radius: 999px;
}
.cw-clue-text {
  flex: 1 1 100%;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.35;
}

.cw-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(240px, .9fr);
  gap: 16px;
  align-items: start;
}

.cw-grid-wrap {
  background: linear-gradient(180deg, #0f2740, #0c2034);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  box-shadow: var(--shadow);
  overflow: auto;
}

.cw-grid {
  display: grid;
  gap: 2px;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
}

.cw-cell {
  position: relative;
  width: clamp(30px, 6vw, 42px);
  height: clamp(30px, 6vw, 42px);
  display: grid;
  place-items: center;
  border-radius: 5px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(.8rem, 2.3vw, 1.05rem);
  user-select: none;
  overflow: visible;
}
.cw-cell.block {
  background: transparent;
  pointer-events: none;
}
.cw-cell.letter {
  background: #f4f8fc;
  color: #0b1f33;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.1);
}
.cw-cell.letter:hover {
  background: #e8f3ff;
}
.cw-cell.selected {
  background: #ffe08a !important;
  outline: 2px solid #f0b429;
  outline-offset: -2px;
  z-index: 3;
}
.cw-cell.in-word {
  background: #cfefff;
}
.cw-cell.correct {
  background: #b8f0d2 !important;
  color: #064e3b;
}
.cw-cell.wrong {
  background: #ffd0d6 !important;
  color: #7f1d1d;
}
/* Locked = fully correct word letters (incl. shared intersections) */
.cw-cell.locked {
  background: #9be7c4 !important;
  color: #064e3b;
  box-shadow: inset 0 0 0 2px rgba(6, 78, 59, 0.25);
  cursor: default;
}
.cw-cell.locked input {
  cursor: default;
  caret-color: transparent;
  pointer-events: none;
}
.cw-cell.locked::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #059669;
  opacity: 0.85;
  pointer-events: none;
  z-index: 4;
}
/* Clue number badge — must stay above the input */
.cw-cell .cw-num {
  position: absolute;
  top: 1px;
  left: 2px;
  z-index: 5;
  min-width: 0.9em;
  padding: 0 1px;
  font-size: clamp(.58rem, 1.7vw, .78rem);
  font-weight: 700;
  color: #0f2740;
  font-family: var(--font);
  line-height: 1.1;
  pointer-events: none;
  background: transparent;
}
.cw-cell.has-num input {
  /* leave room so typed letter doesn't cover the number */
  padding-top: 8px;
  line-height: 1;
}
.cw-cell input {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  text-align: center;
  font: inherit;
  /* iOS zooms inputs under 16px — keep readable without zoom jump */
  font-size: max(16px, 1em);
  color: inherit;
  text-transform: uppercase;
  padding: 0;
  caret-color: #0b1f33;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0;
}
.cw-len {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255,255,255,.07);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cw-active-clue .cw-len {
  margin-left: 0;
  color: #9fd4ef;
  background: rgba(62,199,255,.14);
}

.cw-clues {
  background: rgba(16,38,61,.85);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  display: grid;
  gap: 12px;
}
.cw-clue-col h3 {
  margin: 0 0 8px;
  font-size: .95rem;
  color: var(--accent);
}
.cw-clue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
}
.cw-clue-list li {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: .9rem;
  line-height: 1.3;
  border: 1px solid transparent;
  color: var(--text);
}
.cw-clue-list li:hover {
  background: rgba(255,255,255,.05);
}
.cw-clue-list li.active {
  background: rgba(62,199,255,.14);
  border-color: rgba(62,199,255,.35);
}
.cw-clue-list li.solved {
  opacity: .55;
  text-decoration: line-through;
}
.cw-clue-list .n {
  display: inline-block;
  min-width: 1.4em;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 820px) {
  .cw-layout {
    grid-template-columns: 1fr;
  }
  .cw-clue-list {
    max-height: 160px;
  }
  .cw-clues {
    grid-template-columns: 1fr 1fr;
  }
  .cw-clues .play-actions {
    grid-column: 1 / -1;
  }
}
@media (max-width: 520px) {
  .cw-clues {
    grid-template-columns: 1fr;
  }
}


/* Active clue letter pattern */
.cw-pattern {
  flex: 1 1 100%;
  margin-top: 2px;
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #7dd3fc;
  font-size: 1.05rem;
}
.cw-cell.hinted input {
  color: #1d4ed8;
}


/* Player card */
.player-card {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  max-width: 560px;
  margin: 16px auto 12px;
  padding: 12px 12px 12px 14px;
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(24,52,78,.95), rgba(12,30,48,.92));
  border: 1px solid rgba(140,190,230,.16);
  box-shadow:
    0 12px 32px rgba(0,0,0,.22),
    inset 0 1px 0 rgba(255,255,255,.05);
  backdrop-filter: blur(10px);
}
.player-avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(62,199,255,.22), rgba(31,191,117,.12));
  color: var(--accent);
  border: 1px solid rgba(62,199,255,.2);
  box-shadow: 0 6px 16px rgba(62,199,255,.12);
}
.player-name {
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}
.player-class {
  color: var(--muted);
  font-size: .84rem;
  margin-top: 2px;
}
.btn-sm {
  padding: 8px 12px;
  font-size: .85rem;
  border-radius: 11px;
  border: 1px solid rgba(140,190,230,.16);
  background: rgba(255,255,255,.04);
}
.btn-sm:hover {
  border-color: rgba(62,199,255,.35);
  background: rgba(62,199,255,.08);
}
.dot-sep { color: var(--muted); margin: 0 6px; opacity: .7; }
.home-foot {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
  padding-top: 4px;
}
.home-foot .linkish {
  padding: 6px 4px;
}

/* Modal extras */
.modal-sub { color: var(--muted); margin: 0 0 14px; font-size: .95rem; }
.field { display: grid; gap: 6px; text-align: left; margin-bottom: 12px; color: var(--muted); font-size: .88rem; }
.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.25);
  color: var(--text);
  font: inherit;
  outline: none;
}
.field input:focus { border-color: rgba(62,199,255,.5); }
.modal-actions.col-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 520px) {
  .modal-actions.col-3 { grid-template-columns: 1fr; }
}

/* Tutorial */
.tutorial-card { text-align: left; }
.tut-step { display: none; }
.tut-step.active { display: block; animation: fade .25s ease; }
.tut-num {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #3ec7ff, #1fbf75);
  color: #042033; font-weight: 700; margin-bottom: 10px;
}
.tut-step h3 { margin: 0 0 6px; }
.tut-step p { margin: 0; color: var(--muted); line-height: 1.45; }
.tut-dots { display: flex; gap: 6px; justify-content: center; margin: 16px 0 4px; }
.tut-dots span { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.18); }
.tut-dots span.on { background: var(--accent); }

/* Meaning toast */
.meaning-toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(12px);
  z-index: 60;
  width: min(92vw, 420px);
  padding: 14px 16px;
  border-radius: 16px;
  background: linear-gradient(160deg, #143049, #0d2135);
  border: 1px solid rgba(62,199,255,.3);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.meaning-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.meaning-word { font-weight: 700; color: var(--accent); letter-spacing: .04em; margin-bottom: 4px; }
.meaning-text { color: var(--text); font-size: .95rem; line-height: 1.35; }
.meaning-example { margin-top: 6px; color: var(--muted); font-size: .82rem; line-height: 1.3; }

/* Shake */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.shake { animation: shake .4s ease; }

/* Confetti canvas inside win modal */
.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}
#win-modal .modal-card { position: relative; z-index: 2; }
#win-modal { position: fixed; }
.win-best { margin-top: 6px !important; color: var(--muted); }

/* Quiz */
.quiz-card {
  max-width: 640px;
  margin: 0 auto;
  padding: 18px;
  border-radius: 18px;
  background: rgba(16,38,61,.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.quiz-q { font-size: 1.15rem; font-weight: 600; margin: 0 0 14px; line-height: 1.4; }
.quiz-choices { display: grid; gap: 8px; }
.quiz-choice {
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  color: var(--text);
  font: inherit;
}
.quiz-choice:hover:not(:disabled) { border-color: rgba(62,199,255,.4); }
.quiz-choice.correct { background: rgba(31,191,117,.18); border-color: rgba(31,191,117,.45); }
.quiz-choice.wrong { background: rgba(255,93,108,.15); border-color: rgba(255,93,108,.4); }
.quiz-feedback { margin: 12px 0 0; font-size: .92rem; line-height: 1.35; }
.quiz-feedback.ok { color: #86efac; }
.quiz-feedback.bad { color: #fda4af; }
.quiz-score { font-size: 2rem; font-weight: 700; color: var(--accent); margin: 8px 0; }

/* Certificate */
.cert-wrap { max-width: 520px; }
.certificate {
  text-align: center;
  padding: 22px 18px;
  border-radius: 16px;
  border: 1px dashed rgba(62,199,255,.4);
  background:
    radial-gradient(circle at 20% 20%, rgba(62,199,255,.08), transparent 40%),
    radial-gradient(circle at 80% 0%, rgba(31,191,117,.08), transparent 35%),
    #0c2034;
  margin-bottom: 14px;
}
.cert-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(62,199,255,.12);
  color: var(--accent);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .06em;
}
.certificate h2 { margin: 10px 0 8px; }
.cert-line { color: var(--muted); margin: 0; font-size: .92rem; }
.cert-name {
  margin: 10px 0 2px;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}
.cert-class { margin: 0 0 10px; color: var(--accent-2); font-weight: 600; }
.cert-detail { margin: 8px 0 4px; font-weight: 600; }
.cert-stats { color: var(--muted); margin: 0; font-size: .9rem; }
.cert-date { margin: 14px 0 0; color: var(--muted); font-size: .85rem; }

@media print {
  body * { visibility: hidden !important; }
  body.printing-cert #cert-modal,
  body.printing-cert #cert-modal * { visibility: visible !important; }
  body.printing-cert #cert-modal {
    position: static !important;
    background: #fff !important;
    display: block !important;
  }
  body.printing-cert #cert-modal .modal-actions { display: none !important; }
  body.printing-cert .certificate {
    border: 2px solid #0b1f33;
    color: #0b1f33;
    background: #fff;
  }
  body.printing-cert .cert-name,
  body.printing-cert .certificate h2 { color: #0b1f33; }
}

/* Interactive UX extras */
.player-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.icon-btn.sm {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(140,190,230,.16);
  color: var(--text);
  transition: border-color .15s ease, background .15s ease, color .15s ease, transform .12s ease;
}
.icon-btn.sm:hover {
  border-color: rgba(62,199,255,.4);
  background: rgba(62,199,255,.1);
  color: var(--accent);
}
.icon-btn.sm[aria-pressed="true"] {
  color: #fda4af;
  border-color: rgba(251,113,133,.35);
  background: rgba(251,113,133,.1);
}
.icon-btn.sm:active { transform: scale(.96); }

.continue-card {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  max-width: 560px;
  margin: 0 auto 14px;
  padding: 14px 14px 14px 16px;
  border-radius: 18px;
  background:
    linear-gradient(120deg, rgba(62,199,255,.14), rgba(31,191,117,.1) 55%, rgba(16,38,61,.85));
  border: 1px solid rgba(62,199,255,.28);
  box-shadow:
    0 14px 36px rgba(0,0,0,.22),
    inset 0 1px 0 rgba(255,255,255,.06);
  overflow: hidden;
}
.continue-card[hidden] {
  display: none !important;
}
.continue-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, #3ec7ff, #1fbf75);
  border-radius: 4px 0 0 4px;
}
.continue-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  font-weight: 700;
}
.continue-title {
  font-weight: 700;
  margin-top: 3px;
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.continue-sub {
  color: var(--muted);
  font-size: .82rem;
  margin-top: 3px;
}
.continue-card .btn.primary {
  white-space: nowrap;
  box-shadow: 0 8px 18px rgba(31,191,117,.2);
}
.panel-help {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.35;
}
.encourage {
  min-height: 1.2em;
  margin: 10px 0 4px;
  color: #9fd4ef;
  font-size: .9rem;
  font-weight: 600;
}
.encourage.pop { animation: fade .25s ease; }
.word-list li { cursor: pointer; }
.word-list li:hover { border-color: rgba(62,199,255,.35); }

/* On-screen keyboard */
.osk {
  margin-top: 12px;
  display: grid;
  gap: 6px;
  user-select: none;
}
.osk-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
}
.osk-key {
  min-width: 30px;
  height: 40px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(16,38,61,.95);
  color: var(--text);
  font-family: var(--mono);
  font-weight: 700;
  font-size: .95rem;
}
.osk-key:hover { border-color: rgba(62,199,255,.45); background: rgba(62,199,255,.12); }
.osk-key:active { transform: scale(.96); }
.osk-wide { min-width: 52px; }
@media (min-width: 900px) {
  .osk { max-width: 520px; margin-left: auto; margin-right: auto; }
}
@media (max-width: 480px) {
  .player-card,
  .continue-card,
  .stats-bar { max-width: 100%; }
  .game-card { padding: 15px; gap: 12px; }
  .game-icon { width: 50px; height: 50px; border-radius: 14px; }
}

/* Leaderboard */
.lb-wrap {
  max-width: 640px;
  margin: 0 auto;
}
.lb-filters {
  display: grid;
  gap: 12px;
  margin-bottom: 4px;
}
.lb-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(140, 190, 230, 0.12);
}
.lb-tab {
  padding: 9px 8px;
  border-radius: 10px;
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid transparent;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.lb-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.lb-tab.active {
  color: #042033;
  background: linear-gradient(135deg, #3ec7ff, #1fbf75);
  border-color: transparent;
  box-shadow: 0 6px 14px rgba(62, 199, 255, 0.18);
}
.lb-filters .field { margin-bottom: 0; }
.lb-filters select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(140, 190, 230, 0.18);
  background: rgba(8, 20, 34, 0.9);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  outline: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #8fb0c9 50%),
    linear-gradient(135deg, #8fb0c9 50%, transparent 50%),
    linear-gradient(180deg, rgba(18,42,66,.95), rgba(10,24,40,.95));
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px),
    0 0;
  background-size: 6px 6px, 6px 6px, 100% 100%;
  background-repeat: no-repeat;
}
.lb-filters select:focus {
  border-color: rgba(62, 199, 255, 0.45);
  box-shadow: 0 0 0 3px rgba(62, 199, 255, 0.12);
}
.lb-filters select option,
.lb-filters select optgroup {
  background: #0d2135;
  color: #e8f3ff;
}
.lb-help {
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.4;
  margin: 12px 0;
}
.lb-status {
  color: var(--accent);
  font-size: .88rem;
  font-weight: 600;
  margin-bottom: 10px;
}
.lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.lb-item {
  display: grid;
  grid-template-columns: 48px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(20,48,73,.95), rgba(12,30,48,.95));
  border: 1px solid rgba(140,190,230,.14);
}
.lb-item.me {
  border-color: rgba(62,199,255,.45);
  box-shadow: 0 0 0 1px rgba(62,199,255,.12);
}
.lb-rank { font-weight: 700; color: var(--accent); }
.lb-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-set { color: var(--muted); font-size: .82rem; font-family: var(--mono); }
.lb-time {
  font-family: var(--mono);
  font-weight: 700;
  color: #86efac;
  min-width: 4.2em;
  text-align: right;
}
.lb-submit-status {
  margin: 12px 0 0;
  color: #9fd4ef;
  font-size: .88rem;
  font-weight: 600;
}
.btn.full-width { width: 100%; }
@media (max-width: 520px) {
  .lb-item { grid-template-columns: 40px 1fr auto; }
  .lb-set { display: none; }
  .lb-tab { font-size: .75rem; padding: 8px 4px; }
}

/* Auth modal */
.auth-card { text-align: left; }
.auth-card h2, .auth-card .modal-sub { text-align: center; }
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  margin: 0 0 14px;
  border-radius: 12px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(140,190,230,.12);
}
.auth-tab {
  padding: 9px 10px;
  border-radius: 9px;
  font-weight: 700;
  font-size: .9rem;
  color: var(--muted);
}
.auth-tab.active {
  color: #042033;
  background: linear-gradient(135deg, #3ec7ff, #1fbf75);
}
.auth-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.35;
}
.auth-error {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,93,108,.12);
  border: 1px solid rgba(255,93,108,.3);
  color: #fda4af;
  font-size: .88rem;
  font-weight: 600;
}
.auth-logout {
  display: block;
  width: 100%;
  margin-top: 12px;
  text-align: center;
  color: #fda4af !important;
}
