:root {
  --bg: #0f1226;
  --bg2: #151a36;
  --surface: #1c2246;
  --surface2: #262d5a;
  --line: rgba(255, 255, 255, .08);
  --text: #f1f4ff;
  --muted: #9aa3c7;
  --gold: #ffcc33;
  --primary: #4f7cff;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabbar-h: 64px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, #24306b 0%, transparent 70%), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  touch-action: manipulation;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

#app { min-height: 100%; max-width: 640px; margin: 0 auto; }
#view { padding: calc(var(--safe-t) + 12px) 16px calc(var(--tabbar-h) + var(--safe-b) + 20px); }
body[data-view="play"] #view { padding: 0; }
body[data-view="play"] #tabbar { display: none; }

/* ---------- Tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 12px calc(6px + var(--safe-b));
  background: rgba(15, 18, 38, .88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
#tabbar a {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 14px; font-size: 12px; color: var(--muted); transition: color .15s, background .15s;
}
#tabbar a .ti { font-size: 22px; line-height: 1; filter: grayscale(.6); transition: transform .2s, filter .2s; }
#tabbar a.on { color: var(--text); background: var(--surface); }
#tabbar a.on .ti { filter: none; transform: translateY(-1px) scale(1.08); }

.page { animation: fadeUp .25s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.title { font-size: 24px; margin: 4px 0 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 14px;
  background: var(--primary); color: #fff; font-weight: 700;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25); transition: transform .08s, filter .15s, box-shadow .08s;
  user-select: none; -webkit-user-select: none;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .25); }
.btn.ghost { background: var(--surface2); box-shadow: none; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.big { min-height: 54px; font-size: 18px; width: 100%; background: var(--c, var(--primary)); }
.btn:disabled { opacity: .5; }
.icon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  font-size: 24px; background: var(--surface); flex: none; transition: transform .1s;
}
.icon:active { transform: scale(.92); }

/* ---------- Home ---------- */
.hero {
  background: linear-gradient(135deg, #3651d6, #7b3fe4); border-radius: 22px; padding: 16px;
  box-shadow: 0 10px 30px rgba(79, 124, 255, .25); margin-bottom: 14px;
}
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.logo { font-size: 28px; font-weight: 900; letter-spacing: -.5px; }
.logo span { color: var(--gold); }
.name-chip { background: rgba(255, 255, 255, .16); padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hero-stats { display: flex; align-items: flex-end; gap: 22px; margin-top: 14px; }
.hero-stats > div { display: flex; flex-direction: column; }
.hero-stats b { font-size: 26px; line-height: 1.1; }
.hero-stats small { opacity: .8; font-size: 12px; }
.hero-stats .btn { margin-left: auto; background: rgba(255, 255, 255, .18); }

.daily {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; margin-bottom: 12px;
  border-radius: var(--radius); background: linear-gradient(135deg, #0e7490, #06b6d4);
  box-shadow: 0 8px 22px rgba(6, 182, 212, .2); transition: transform .12s;
}
.daily:active { transform: scale(.98); }
.daily-emoji { font-size: 34px; width: 52px; height: 52px; display: grid; place-items: center; background: rgba(255, 255, 255, .18); border-radius: 14px; flex: none; }
.daily-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.daily-text small { text-transform: uppercase; letter-spacing: .08em; font-size: 11px; opacity: .85; font-weight: 700; }
.daily-text strong { font-size: 19px; }
.daily-text span { font-size: 13px; opacity: .9; }
.pill { background: #fff; color: #0e7490; font-weight: 800; padding: 8px 14px; border-radius: 999px; font-size: 14px; flex: none; }
.pill.done { background: rgba(255, 255, 255, .22); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.card {
  position: relative; display: flex; flex-direction: column; gap: 2px; min-height: 0; align-items: center; text-align: center; padding: 12px 6px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 30%, var(--surface)), var(--surface) 70%);
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  border-radius: var(--radius); overflow: hidden;
  animation: pop .35s cubic-bezier(.2, .9, .3, 1.3) backwards;
}
.card { transform: perspective(500px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transition: transform .18s ease-out; }
.card::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(255,255,255,.22), transparent 55%); }
.card:hover::before, .card:active::before { opacity: 1; }
.card:active { transform: perspective(500px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) scale(.96); }
.card .gi-wrap { margin-bottom: 8px; }
.gtitle { display: flex; align-items: center; gap: 8px; }
.gtitle > span { overflow: hidden; text-overflow: ellipsis; }
@keyframes pop { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: none; } }
.card-emoji { font-size: 34px; line-height: 1; margin-bottom: 6px; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .3)); }
.card strong { font-size: 14px; line-height: 1.2; }
.card-desc { display: none; }
.card-best { margin-top: auto; padding-top: 4px; font-size: 11px; font-weight: 700; color: var(--c); }

/* ---------- Leaderboard ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 10px; margin: 0 -16px; scrollbar-width: none; scroll-snap-type: x proximity; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; background: var(--surface); color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap; scroll-snap-align: center; transition: background .15s, color .15s; }
.chip.on { background: var(--text); color: var(--bg); }
.lb { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lb li, .mine {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--surface);
  animation: fadeUp .25s ease both;
}
.lb li:nth-child(1) { background: linear-gradient(90deg, rgba(255, 204, 51, .22), var(--surface)); }
.lb li:nth-child(2) { background: linear-gradient(90deg, rgba(200, 210, 230, .16), var(--surface)); }
.lb li:nth-child(3) { background: linear-gradient(90deg, rgba(205, 127, 50, .2), var(--surface)); }
.lb li.me, .mine { outline: 2px solid var(--primary); }
.mine { position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); margin-top: 10px; background: var(--surface2); box-shadow: 0 6px 20px rgba(0, 0, 0, .4); }
.rank { width: 32px; text-align: center; font-weight: 800; color: var(--muted); font-size: 15px; flex: none; }
.lb li:nth-child(-n+3) .rank { font-size: 22px; }
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.sub { color: var(--muted); font-size: 12px; flex: none; }
.pscore { font-weight: 800; font-variant-numeric: tabular-nums; }
.note { background: rgba(245, 158, 11, .15); color: #fcd34d; padding: 10px 12px; border-radius: 12px; font-size: 13px; margin: 0 0 10px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.empty > div { font-size: 48px; }
.skeleton { display: flex; flex-direction: column; gap: 6px; }
.skeleton div { height: 48px; border-radius: 14px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Me ---------- */
.panel { background: var(--surface); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.panel h2 { font-size: 16px; margin: 0 0 8px; }
.lbl { font-size: 13px; color: var(--muted); }
.name-row { display: flex; gap: 8px; margin: 6px 0 8px; }
.name-row input { flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); font-size: 16px; }
.name-row input:focus { outline: 2px solid var(--primary); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; }
.row + .row { border-top: 1px solid var(--line); }
.row.total { font-size: 17px; }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--surface2); position: relative; cursor: pointer; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch:checked { background: var(--good); }
.switch:checked::after { transform: translateX(20px); }
.stats { list-style: none; padding: 0; margin: 0; }
.stats li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.stats li span:first-child { flex: 1; }
#view > .page > .btn.ghost { width: 100%; margin-bottom: 12px; }

.seg { display: inline-flex; background: var(--bg2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { padding: 7px 12px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; transition: background .15s, color .15s; }
.seg button.on { background: var(--surface2); color: var(--text); }

/* ---------- Game page ---------- */
.gamepage { display: flex; flex-direction: column; height: 100dvh; min-height: -webkit-fill-available; }
.gbar {
  display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-t) + 8px) 10px 8px;
  background: rgba(15, 18, 38, .6); border-bottom: 1px solid var(--line); flex: none;
}
.gbar .icon:first-child { font-size: 30px; padding-bottom: 3px; }
.gtitle { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; font-size: 16px; }
.hud { display: flex; gap: 6px; flex: none; }
.stat { display: flex; flex-direction: column; align-items: center; background: var(--surface); border-radius: 10px; padding: 3px 9px; min-width: 50px; }
.stat small { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; line-height: 1.2; }
.stat b { font-size: 15px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stage {
  flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; align-items: center;
  padding: 12px 12px calc(12px + var(--safe-b)); overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.loading { flex: 1; display: grid; place-items: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--surface2); border-top-color: var(--c, var(--primary)); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Shared game widgets */
.gopts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 10px; }
.gmsg { min-height: 24px; text-align: center; color: var(--muted); font-weight: 600; margin: 6px 0; }
.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(15, 18, 38, .72); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  text-align: center; padding: 20px; z-index: 5; animation: fadeIn .2s both; border-radius: inherit;
}
.overlay h3 { margin: 0; font-size: 22px; }
.overlay p { margin: 0; color: var(--muted); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.fit { width: 100%; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }

/* ---------- Sheets ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(5, 8, 20, 0); display: flex; align-items: flex-end; justify-content: center;
  transition: background .25s;
}
.backdrop.open { background: rgba(5, 8, 20, .6); }
.sheet {
  position: relative; width: 100%; max-width: 520px; max-height: 92dvh; overflow: auto;
  background: var(--bg2); border-radius: 24px 24px 0 0; padding: 8px 18px calc(18px + var(--safe-b));
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2, .9, .3, 1);
  border: 1px solid var(--line); border-bottom: 0;
}
.backdrop.open .sheet { transform: none; }
@media (min-width: 700px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 24px; border-bottom: 1px solid var(--line); transform: translateY(30px) scale(.96); opacity: 0; transition: transform .25s, opacity .2s; }
  .backdrop.open .sheet { opacity: 1; }
}
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--surface2); margin: 0 auto 10px; }
.result { text-align: center; }
.result-emoji { font-size: 54px; line-height: 1; animation: bounce .6s cubic-bezier(.2, .9, .3, 1.5) both; }
@keyframes bounce { from { transform: scale(.3); } to { transform: none; } }
.result h2 { margin: 6px 0 2px; font-size: 24px; }
.result-sub { color: var(--muted); margin: 0 0 8px; }
.result-score { display: flex; flex-direction: column; margin: 8px 0; }
.result-score small { color: var(--muted); text-transform: uppercase; font-size: 12px; letter-spacing: .08em; }
.result-score b { font-size: 46px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; background: var(--gold); color: #3a2a00; font-weight: 800; padding: 5px 12px; border-radius: 999px; animation: bounce .5s both; margin-bottom: 8px; }
.result-stats { display: flex; justify-content: center; gap: 10px; margin: 6px 0; }
.rstat { background: var(--surface); padding: 6px 14px; border-radius: 12px; display: flex; flex-direction: column; min-width: 80px; }
.rstat small { font-size: 11px; color: var(--muted); }
.rstat b { font-size: 18px; }
.result-status { min-height: 20px; font-size: 13px; color: var(--muted); }
.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.result-row { display: flex; gap: 10px; }
.result-row .btn { flex: 1; }

#toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 14px); z-index: 100;
  transform: translate(-50%, -150%); background: var(--text); color: var(--bg); font-weight: 700;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
  transition: transform .25s cubic-bezier(.2, .9, .3, 1.2), opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; opacity: 0;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall linear both; }
@keyframes fall { to { top: 110%; transform: translateX(30px) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- UI icon sizing ---------- */
#tabbar a .ti { display: grid; place-items: center; height: 24px; }
#tabbar a .ti .ui { width: 24px; height: 24px; }
.gbar .icon .ui { width: 24px; height: 24px; vertical-align: middle; }
.chip { display: inline-flex; align-items: center; gap: 6px; }
.chip .gi-wrap.sm { width: 20px; height: 20px; border-radius: 6px; }
.chip .ui { width: 18px; height: 18px; }
.stats .sname { display: flex; align-items: center; gap: 8px; }
.stats .gi-wrap.sm { width: 24px; height: 24px; }
.result-emoji .gi-wrap { margin: 0 auto; width: 64px; height: 64px; }
.rank .ui { width: 32px; height: 32px; vertical-align: middle; }
.stat small .ui { width: 14px; height: 14px; vertical-align: -3px; }
.pill .ui { width: 16px; height: 16px; vertical-align: -3px; }
.overlay .gi-wrap { margin: 0 auto; width: 64px; height: 64px; }
.gmsg .ui { width: 1.1em; height: 1.1em; }
.btn .ui, .seg .ui { width: 1.2em; height: 1.2em; }

/* ---------- durs.ai (this copy runs inside durs.ai's /games page) ---------- */
.hero-goal { font-size: 13px; font-weight: 700; line-height: 1.3; opacity: .95; }
.card-goal { font-size: 10.5px; font-weight: 800; color: var(--gold, #fbbf24); }
.goalbar { flex: none; padding: 5px 14px; font-size: 12px; font-weight: 700; text-align: center; color: var(--gold, #fbbf24);
  background: rgba(251, 191, 36, .08); border-bottom: 1px solid rgba(251, 191, 36, .18); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-goal { margin: 6px 0 2px; font-size: 13px; font-weight: 700; color: var(--gold, #fbbf24); }
.result-goal:empty { display: none; }
.me-name { font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.btn.gold { background: linear-gradient(180deg, #ffd76a, #f59e0b); color: #2a1a00; text-decoration: none; }
#toast.gold { background: linear-gradient(180deg, #ffd76a, #f59e0b); color: #2a1a00; font-size: 17px; }
.result-status .hint { margin: 0 0 8px; }

/* durs.ai: leaderboard tabs wrap instead of scrolling sideways — icons only, the chosen board with its name. */
.chips { flex-wrap: wrap; justify-content: center; overflow: visible; margin: 0; padding: 2px 0 12px; gap: 6px; }
.chip { scroll-snap-align: none; padding: 7px; gap: 0; }
.chip .chip-name { display: none; }
.chip.on, .chip.all { padding: 7px 14px 7px 8px; gap: 7px; }
.chip.on .chip-name, .chip.all .chip-name { display: inline; }
.chip:not(.on):hover { background: var(--surface-2, rgba(255,255,255,.12)); color: var(--text); transform: translateY(-1px); }
.chip .gi-wrap.sm, .chip .ui { width: 26px; height: 26px; }
.chip .gi-wrap.sm { border-radius: 8px; }

/* durs.ai: the full-screen toggle (phones; the page around the iframe does the full screen). Full: it turns into a
   clear "Гарах" pill in the game's colour. */
.fsbtn { color: var(--text); }
.fsbtn .ui { width: 20px; height: 20px; }
.durs-full .fsbtn { width: auto; padding: 0 12px 0 10px; gap: 5px; display: flex; align-items: center; background: var(--c, var(--primary)); color: #fff; font-size: 13px; font-weight: 800; border-radius: 999px; }
.durs-full .fsbtn span { white-space: nowrap; }
/* Wide screens don't need it — but a phone turned sideways while full screen keeps its way out. */
@media (min-width: 768px) { html:not(.durs-full) .fsbtn { display: none !important; } }
/* Phones: room for the toggle — the game's icon stands for its name, a little less space between buttons, and with
   three score boxes (memory, breakout) "Гарах" is the icon alone. */
@media (max-width: 440px) {
  .gbar:has(.fsbtn) { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .gbar:has(.fsbtn) .gtitle > span { display: none; }
  .gbar:has(.fsbtn) .icon { width: 38px; height: 38px; }
  .durs-full .gbar .fsbtn { width: auto; }
  .durs-full .gbar:has(.hud > .stat:nth-child(3)) .fsbtn { width: 38px; padding: 0; justify-content: center; }
  .durs-full .gbar:has(.hud > .stat:nth-child(3)) .fsbtn span { display: none; }
}
