:root {
  --bg: #eef2ff;
  --bg2: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --cell: #ffffff;
  --cell-border: #cbd5e1;
  --cell-shadow: rgba(15, 23, 42, .06);
  --sel: #fbbf24;
  --sel-glow: rgba(251, 191, 36, .45);
  --word: #dbeafe;
  --wrong: #ef4444;
  --ok: #16a34a;
  --revealed: #7c3aed;
  --accent: #2563eb;
  --accent2: #7c3aed;
  --accent-text: #ffffff;
  --key: #f1f5f9;
  --key-shadow: #cbd5e1;
  --key-special: #e0e7ff;
  --grad1: #2563eb;
  --grad2: #7c3aed;
  --logo1: #2563eb;
  --logo2: #7c3aed;
  --done-bg: linear-gradient(135deg, #dcfce7, #d1fae5);
  --done-text: #166534;
  --n: 9;
  --gap: 3px;
  --size: min(calc((100vw - 40px - (var(--n) - 1) * var(--gap)) / var(--n)), 46px);
  --radius: 20px;
  --shadow: 0 10px 30px rgba(30, 41, 59, .08), 0 1px 2px rgba(30, 41, 59, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --bg2: #111a2e;
    --card: #151f33;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --line: #253049;
    --cell: #1c2842;
    --cell-border: #34435f;
    --cell-shadow: rgba(0, 0, 0, .3);
    --sel: #f59e0b;
    --sel-glow: rgba(245, 158, 11, .4);
    --word: #1e3a8a;
    --accent: #60a5fa;
    --accent2: #a78bfa;
    --accent-text: #0b1120;
    --key: #223150;
    --key-shadow: #0b1120;
    --key-special: #1e3a8a;
    --grad1: #2563eb;
    --grad2: #6d28d9;
    --logo1: #93c5fd;
    --logo2: #c4b5fd;
    --done-bg: linear-gradient(135deg, #14532d, #064e3b);
    --done-text: #bbf7d0;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, var(--bg), var(--bg2) 70%);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.45 "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  touch-action: manipulation;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- sarlavha ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 6px; max-width: 580px; margin: 0 auto;
}
.brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.logo {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 24px; letter-spacing: -0.5px; line-height: 1.1;
}
.logo .txt {
  background: linear-gradient(90deg, var(--logo1), var(--logo2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo .mark { width: 24px; height: 24px; display: inline-grid; grid-template-columns: repeat(2, 1fr); gap: 3px; }
.logo .mark i { display: block; border-radius: 4px; background: var(--accent); }
.logo .mark i:nth-child(2) { background: var(--sel); }
.logo .mark i:nth-child(3) { background: var(--accent2); }
.tagline { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
.date { font-size: 12px; color: var(--muted); font-weight: 600; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); display: grid; place-items: center; box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- oʻyin kartasi ---------- */
.game {
  max-width: 580px; margin: 6px auto 30px; padding: 14px 12px 18px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}
@media (max-width: 600px) { .game { margin: 6px 8px 24px; } }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 12px; }
.timer {
  display: inline-flex; align-items: center; gap: 6px;
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 17px;
  padding: 7px 12px; border-radius: 999px; background: var(--bg); color: var(--text);
}
.timer::before { content: "⏱"; font-size: 14px; }
.actions { display: flex; gap: 8px; }
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 9px 14px; font-size: 14px; font-weight: 700; box-shadow: 0 1px 2px rgba(0,0,0,.04);
  transition: transform .12s, box-shadow .12s, opacity .12s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary {
  background: linear-gradient(135deg, var(--grad1), var(--grad2)); color: #fff; border-color: transparent;
  box-shadow: 0 6px 18px rgba(37, 99, 235, .3);
}
.btn.wide { width: 100%; margin-top: 8px; padding: 13px; font-size: 16px; }

/* ---------- jadval ---------- */
.grid-wrap { display: flex; justify-content: center; position: relative; }
.hidden-input {
  position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0.01; border: 0; padding: 0; margin: 0;
  font-size: 16px; /* iOS zoom qilmasligi uchun */ color: transparent; background: transparent; caret-color: transparent;
  pointer-events: none; z-index: 0;
}
.grid {
  display: grid;
  grid-template-columns: repeat(var(--n), var(--size));
  grid-auto-rows: var(--size);
  gap: var(--gap);
  user-select: none;
}
.cell {
  position: relative; background: var(--cell); border: 1.5px solid var(--cell-border);
  border-radius: 8px; display: grid; place-items: center;
  font-weight: 800; font-size: calc(var(--size) * 0.5); cursor: pointer;
  box-shadow: 0 1px 2px var(--cell-shadow);
  transition: background .12s, transform .12s, box-shadow .12s, border-color .12s;
}
.cell.black { background: transparent; border-color: transparent; box-shadow: none; cursor: default; }
.cell.word { background: var(--word); border-color: transparent; }
.cell.sel {
  background: var(--sel); color: #1f2937; border-color: transparent;
  box-shadow: 0 0 0 3px var(--sel-glow); transform: scale(1.06); z-index: 1;
}
.cell .num {
  position: absolute; top: 2px; left: 4px;
  font-size: calc(var(--size) * 0.24); font-weight: 700; line-height: 1; color: var(--muted);
}
.cell.sel .num { color: #374151; }
.cell .ltr { line-height: 1; padding-top: 3px; }
.cell .ltr.two { font-size: calc(var(--size) * 0.36); letter-spacing: -0.5px; }
.cell.wrong .ltr { color: var(--wrong); }
.cell.wrong::after {
  content: ""; position: absolute; left: 12%; right: 12%; top: 50%;
  border-top: 2.5px solid var(--wrong); transform: rotate(-35deg); opacity: .85; border-radius: 2px;
}
.cell.ok .ltr { color: var(--ok); }
.cell.revealed .ltr { color: var(--revealed); }
.cell.done { animation: pop .45s cubic-bezier(.2,.9,.3,1.3); }
@keyframes pop { 40% { transform: scale(1.18); } }

/* ---------- savol paneli ---------- */
.cluebar {
  margin-top: 14px; display: flex; align-items: stretch; gap: 4px;
  background: linear-gradient(135deg, var(--grad1), var(--grad2)); color: #fff;
  border-radius: 16px; overflow: hidden; min-height: 56px; box-shadow: 0 8px 22px rgba(37, 99, 235, .25);
}
.cluebar .nav { border: 0; background: rgba(255,255,255,.12); width: 46px; font-size: 26px; font-weight: 800; color: #fff; }
.cluebar .nav:active { background: rgba(255,255,255,.25); }
.cluetext { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; padding: 8px 6px; font-size: 15.5px; font-weight: 700; cursor: pointer; }
.cluetext .tag { background: rgba(255,255,255,.22); padding: 2px 8px; border-radius: 999px; margin-right: 8px; white-space: nowrap; font-size: 13px; }
.cluetext .muted { color: rgba(255,255,255,.75); margin-left: 4px; }

/* ---------- klaviatura ---------- */
.keyboard { margin-top: 12px; display: flex; flex-direction: column; gap: 7px; }
.krow { display: flex; justify-content: center; gap: 5px; }
.key {
  flex: 1; max-width: 46px; height: 48px; border: 0; border-radius: 10px;
  background: var(--key); box-shadow: 0 3px 0 var(--key-shadow);
  font-weight: 800; font-size: 17px; padding: 0; color: var(--text);
  transition: transform .06s, box-shadow .06s;
}
.key.wide { flex: 1.6; max-width: 78px; font-size: 20px; }
.key.special { background: var(--key-special); color: var(--accent); }
.key:active { box-shadow: 0 0 0 var(--key-shadow); transform: translateY(3px); }
.krow:last-child .key { max-width: 70px; }
.keyboard.compact { flex-direction: column; align-items: center; }
.keyboard.compact .key { max-width: 66px; min-width: 58px; flex: 0 0 auto; }
.kbhint { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 2px; }

/* ---------- savollar roʻyxati ---------- */
.clues { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 22px; }
@media (max-width: 440px) { .clues { grid-template-columns: 1fr; } }
.cluelist h3 {
  margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.cluelist ol { list-style: none; margin: 0; padding: 0; }
.cluelist li {
  padding: 8px 10px; border-radius: 10px; font-size: 14px; cursor: pointer;
  display: flex; gap: 10px; align-items: flex-start; transition: background .12s;
}
.cluelist li:hover { background: var(--bg); }
.cluelist li b {
  min-width: 24px; height: 24px; border-radius: 8px; background: var(--bg); color: var(--muted);
  display: inline-grid; place-items: center; font-size: 12px; flex-shrink: 0;
}
.cluelist li.active { background: var(--word); }
.cluelist li.active b { background: var(--accent); color: #fff; }
.cluelist li.solved { color: var(--muted); text-decoration: line-through; }
.cluelist li.solved b { background: #dcfce7; color: var(--ok); }
@media (prefers-color-scheme: dark) { .cluelist li.solved b { background: #14532d; } }

.foot { margin-top: 24px; font-size: 13px; color: var(--muted); text-align: center; line-height: 1.5; }

/* ---------- yechildi paneli ---------- */
.donebar {
  background: var(--done-bg); color: var(--done-text); border-radius: 16px; padding: 12px 14px; margin-bottom: 12px;
  display: flex; flex-direction: column; gap: 6px; align-items: center; text-align: center;
}
.donetext { font-weight: 800; }
.donetext::before { content: "🎉 "; }
.donenext { font-size: 14px; opacity: .9; font-variant-numeric: tabular-nums; }
.donenext b { font-size: 17px; }
.donebar .btn { background: rgba(255,255,255,.7); border-color: transparent; color: #14532d; }
@media (prefers-color-scheme: dark) { .donebar .btn { background: rgba(255,255,255,.12); color: #fff; } }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(2, 6, 23, .55); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px; z-index: 50;
}
.card {
  position: relative; background: var(--card); border-radius: 24px; padding: 26px 22px 22px;
  width: 100%; max-width: 390px; box-shadow: 0 24px 70px rgba(0,0,0,.35); text-align: center;
  max-height: 90vh; overflow: auto; animation: rise .25s ease;
}
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
.card h2 { margin: 6px 0 8px; font-size: 24px; letter-spacing: -0.3px; }
.close { position: absolute; top: 10px; right: 12px; border: 0; background: var(--bg); width: 32px; height: 32px; border-radius: 999px; font-size: 20px; color: var(--muted); }
.win-emoji { font-size: 48px; }
.win-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 10px; margin: 16px 0; }
.win-stats div { background: var(--bg); border-radius: 14px; padding: 12px 6px; }
.win-stats b { display: block; font-size: 24px; font-weight: 800; }
.win-stats span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.row .btn { flex: 1; }
.countdown { font-variant-numeric: tabular-nums; }

.archive { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; text-align: left; }
.archive a {
  display: block; padding: 10px; border-radius: 12px; background: var(--bg); text-decoration: none; color: var(--text);
  font-size: 14px; font-weight: 700; border: 1.5px solid transparent;
}
.archive a.today { border-color: var(--accent); }
.archive a small { display: block; font-weight: 600; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.copybox {
  width: 100%; box-sizing: border-box; font: 15px/1.45 inherit; font-family: inherit;
  padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  resize: none; text-align: left;
}

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 60;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); max-width: 90vw; text-align: center; animation: rise .2s ease;
}

/* ---------- reyting ---------- */
.top-right { display: flex; gap: 8px; }
.icon-btn { position: relative; }
.avatar-dot { position: absolute; top: -3px; right: -3px; width: 12px; height: 12px; border-radius: 999px; background: var(--ok); border: 2px solid var(--card); }
.board-card { max-width: 420px; text-align: left; }
.board-card h2 { text-align: center; }
.tabs { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; margin: 6px 0 12px; }
.tab { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.board { list-style: none; margin: 0; padding: 0; max-height: 46vh; overflow: auto; }
.board li { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
.board li:last-child { border-bottom: 0; }
.board .rank { width: 26px; text-align: center; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.board li:nth-child(1) .rank { color: #d97706; } .board li:nth-child(2) .rank { color: #6b7280; } .board li:nth-child(3) .rank { color: #b45309; }
.board .name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .name small { display: block; font-weight: 600; color: var(--muted); font-size: 11.5px; }
.board .pts { font-weight: 800; font-variant-numeric: tabular-nums; }
.board li.me, .board-me { background: var(--word); border-radius: 10px; }
.board-me { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 8px; font-size: 14px; }
.avatar { width: 32px; height: 32px; border-radius: 999px; background: linear-gradient(135deg, var(--grad1), var(--grad2)); color: #fff; display: inline-grid; place-items: center; font-weight: 800; font-size: 14px; flex-shrink: 0; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.loginbox { margin-top: 14px; padding: 12px; border-radius: 14px; background: var(--bg); text-align: center; }
.loginbox p { margin: 0 0 10px; }
.profilebox { margin-top: 14px; padding: 12px; border-radius: 14px; background: var(--bg); }
.profile-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.profile-head .avatar { width: 40px; height: 40px; }
.profile-name { display: flex; flex-direction: column; }
.field { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 8px; }
.field input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-top: 10px; }
.linkbtn { border: 0; background: transparent; color: var(--muted); font-size: 12.5px; margin-top: 10px; text-decoration: underline; width: 100%; }
.board-note { margin: 12px 0 0; text-align: center; }
.winrank { margin: 4px 0 10px; font-weight: 700; color: var(--accent); }
.winrank a { font-weight: 600; }
