:root {
  --bg1: #f6efe6; --bg2: #ece3f6; --bg3: #e3f1ec;
  --ink: #2a2838; --ink2: #5f5b70; --ink3: #8f8aa0;
  --glass: rgba(255, 255, 255, 0.58); --glass-b: rgba(255, 255, 255, 0.75); --glass-shadow: 0 10px 30px rgba(60, 40, 90, 0.14), 0 1px 0 rgba(255, 255, 255, 0.8) inset;
  --accent: #ff6b5b; --accent2: #ffb648; --good: #2fbf78; --bad: #ef4b4b;
  --chip: rgba(255, 255, 255, 0.7);
  --font: "SF Pro Rounded", ui-rounded, "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --ad-h: 50px;
}
[data-theme='dark'] {
  --bg1: #15141c; --bg2: #1f1b2c; --bg3: #142021;
  --ink: #f3f0fa; --ink2: #b9b4c9; --ink3: #7d7890;
  --glass: rgba(34, 32, 46, 0.6); --glass-b: rgba(255, 255, 255, 0.1); --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 1px 0 rgba(255, 255, 255, 0.06) inset;
  --chip: rgba(255, 255, 255, 0.08);
}
@media (min-width: 768px) { :root { --ad-h: 90px; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font); color: var(--ink);
  background: radial-gradient(120% 80% at 20% 10%, var(--bg2), transparent 60%), radial-gradient(100% 70% at 90% 90%, var(--bg3), transparent 60%), var(--bg1);
  -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; touch-action: none;
}
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.glass {
  background: var(--glass); border: 1px solid var(--glass-b); box-shadow: var(--glass-shadow);
  backdrop-filter: blur(18px) saturate(1.5); -webkit-backdrop-filter: blur(18px) saturate(1.5);
}
.hidden { display: none !important; }

/* ---------- HUD ---------- */
.hud { position: fixed; left: 0; right: 0; top: 0; padding: calc(10px + var(--safe-t)) 10px 0; z-index: 5; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hud-row { pointer-events: auto; width: min(640px, 100%); display: flex; align-items: center; gap: 8px; padding: 7px 6px 7px 12px; border-radius: 20px; }
.brand { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.brand-name { font-weight: 900; letter-spacing: 0.06em; font-size: 15px; }
.brand-day { font-weight: 800; font-size: 13px; color: var(--ink3); }
.timer {
  margin-left: auto; font: 800 20px/1 var(--mono); letter-spacing: 0.02em; padding: 7px 12px; border-radius: 12px;
  background: #16151d; color: #ff6b6b; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), 0 0 18px rgba(255, 80, 80, 0.15); min-width: 70px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.timer.urgent { animation: pulse 0.5s steps(2) infinite; }
.timer.won { color: #5bf0a8; box-shadow: 0 0 18px rgba(80, 255, 160, 0.2); }
@keyframes pulse { 50% { color: #ffb0b0; } }
.strikes { display: flex; gap: 4px; }
.strikes i { width: 11px; height: 11px; border-radius: 50%; background: rgba(120, 110, 140, 0.25); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2); transition: background 0.2s, transform 0.2s; }
.strikes i.on { background: var(--bad); box-shadow: 0 0 10px rgba(239, 75, 75, 0.7); transform: scale(1.15); }
.hud-btns { display: flex; gap: 2px; }
.icon { width: 33px; height: 34px; border-radius: 12px; display: grid; place-items: center; font-weight: 900; font-size: 17px; color: var(--ink2); }
.icon:active { background: var(--chip); }
.icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

.facts { pointer-events: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; width: min(640px, 100%); }
.fact {
  display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 999px; font-weight: 800; font-size: 12.5px;
  background: var(--glass); border: 1px solid var(--glass-b); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 4px 14px rgba(60, 40, 90, 0.1);
}
.fact small { font-size: 10px; letter-spacing: 0.08em; color: var(--ink3); font-weight: 900; }
.fact.unknown { opacity: 0.55; font-style: normal; }
.fact .mono { font-family: var(--mono); letter-spacing: 0.04em; }
.fact .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: #77718a; }
.fact .dot.lit { background: #ffc43d; box-shadow: 0 0 8px #ffc43d; }
.fact.pop { animation: pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes pop { 0% { transform: scale(0.6); } 100% { transform: scale(1); } }

/* ---------- bottom panels ---------- */
.bottom { position: fixed; left: 0; right: 0; bottom: calc(var(--ad-h) + var(--safe-b) + 8px); z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 10px; pointer-events: none; }
.panel { pointer-events: auto; width: min(640px, 100%); border-radius: 22px; padding: 10px; }
.hint { display: flex; align-items: center; gap: 8px; }
.hint-text { flex: 1; text-align: center; font-weight: 700; font-size: 14px; color: var(--ink2); line-height: 1.3; }
.turn { width: 52px; height: 52px; border-radius: 16px; font-size: 26px; font-weight: 900; background: var(--chip); color: var(--ink); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.05); }
.turn:active, .pill:active, .key:active, .cta:active, .ghost:active { transform: translateY(1px) scale(0.97); }

.rule { padding: 10px 10px 12px; }
.rule-top { display: flex; align-items: center; gap: 8px; }
.rule-title { flex: 1; min-width: 0; text-align: center; font-weight: 900; font-size: 11.5px; letter-spacing: 0.08em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-transform: uppercase; color: var(--ink3); }
.pill { padding: 9px 12px; border-radius: 12px; background: var(--chip); font-weight: 800; font-size: 14px; min-width: 76px; }
.rule-text { margin-top: 8px; padding: 12px 14px; border-radius: 14px; background: #24222f; color: #fffaf0; font-weight: 800; font-size: 17px; line-height: 1.35; text-align: center; }
.rule-text .arrow { color: var(--accent2); margin: 0 2px; }
.rule-text .else { color: #a9a3bd; font-weight: 700; }
.rule-text .sep { color: #6f6a82; margin: 0 4px; }
.rule-link { margin-top: 8px; text-align: center; font-weight: 800; font-size: 13px; color: var(--accent); }

.keyboard { padding: 8px 6px; display: flex; flex-direction: column; gap: 6px; }
.keyboard .krow { display: flex; gap: 5px; justify-content: center; }
.key { flex: 1; max-width: 44px; height: 46px; border-radius: 10px; background: var(--chip); font-weight: 800; font-size: 17px; text-transform: uppercase; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08); }
[data-theme='light'] .key { background: rgba(255, 255, 255, 0.85); }
.key.wide { max-width: 72px; flex: 1.6; font-size: 13px; }
.keyboard.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- ads ---------- */
.adbar { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--ad-h) + var(--safe-b)); padding-bottom: var(--safe-b); z-index: 6; display: flex; justify-content: center; align-items: center; background: var(--glass); border-top: 1px solid var(--glass-b); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.adbar ins, .adbox ins { display: block; }
.house { display: flex; align-items: center; justify-content: center; gap: 10px; width: 320px; height: 50px; font-weight: 800; font-size: 13px; color: var(--ink2); }
@media (min-width: 768px) { .house { width: 728px; height: 90px; font-size: 16px; } }
.house button { padding: 7px 12px; border-radius: 10px; background: var(--ink); color: var(--bg1); font-weight: 900; font-size: 12px; }
.adbox { width: 300px; height: 250px; margin: 14px auto 4px; display: flex; align-items: center; justify-content: center; border-radius: 14px; overflow: hidden; }
.adbox .house-box { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: var(--chip); border: 1px dashed var(--ink3); border-radius: 14px; text-align: center; padding: 18px; font-weight: 800; color: var(--ink2); }
.adbox .house-box .big { font-size: 40px; }
.adbox .house-box button { padding: 9px 14px; border-radius: 12px; background: var(--ink); color: var(--bg1); font-weight: 900; }

/* ---------- toast + flash ---------- */
.toast { position: fixed; left: 50%; top: calc(120px + var(--safe-t)); transform: translate(-50%, -10px); z-index: 20; padding: 10px 16px; border-radius: 14px; background: #24222f; color: #fff; font-weight: 800; font-size: 14px; opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; white-space: nowrap; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); }
.toast.good { background: var(--good); }
.flash { position: fixed; inset: 0; z-index: 4; pointer-events: none; background: radial-gradient(circle at 50% 50%, transparent 40%, rgba(255, 60, 60, 0.35)); opacity: 0; }
.flash.on { animation: flash 0.5s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px; padding-bottom: calc(var(--ad-h) + var(--safe-b) + 16px); background: rgba(30, 24, 44, 0.18); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade 0.25s; }
#intro { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
@keyframes fade { from { opacity: 0; } }
.card { position: relative; width: min(420px, 100%); border-radius: 28px; padding: 24px 20px 20px; text-align: center; animation: rise 0.35s cubic-bezier(0.2, 1.2, 0.4, 1); }
.card.scroll { max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
@keyframes rise { from { transform: translateY(24px) scale(0.98); opacity: 0; } }
.close { position: absolute; right: 10px; top: 10px; width: 36px; height: 36px; border-radius: 12px; font-size: 24px; color: var(--ink3); }
h1 { margin: 6px 0 2px; font-size: 34px; font-weight: 900; letter-spacing: 0.04em; }
h2 { margin: 4px 0 12px; font-size: 24px; font-weight: 900; }
h3 { margin: 18px 0 8px; font-size: 15px; font-weight: 900; text-align: left; }
.sub { margin: 0 0 16px; color: var(--ink2); font-weight: 700; }
.intro-badge { font-size: 40px; }
.intro-stats { display: flex; justify-content: center; gap: 10px; margin-bottom: 18px; }
.intro-stats div { flex: 1; padding: 10px 6px; border-radius: 16px; background: var(--chip); display: flex; flex-direction: column; }
.intro-stats b { font-size: 22px; font-weight: 900; font-variant-numeric: tabular-nums; }
.intro-stats span { font-size: 11px; color: var(--ink3); font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.cta { width: 100%; padding: 16px; border-radius: 18px; font-size: 18px; font-weight: 900; letter-spacing: 0.04em; color: #fff; background: linear-gradient(180deg, #ff7d6b, #f2544a); box-shadow: 0 8px 20px rgba(242, 84, 74, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
.row-btns { display: flex; gap: 8px; margin-top: 10px; }
.ghost { flex: 1; padding: 12px; border-radius: 14px; background: var(--chip); font-weight: 800; font-size: 14px; }
.fine { margin: 14px 0 0; font-size: 12px; color: var(--ink3); font-weight: 700; }
.steps { text-align: left; padding-left: 20px; margin: 0; line-height: 1.45; font-size: 15px; }
.steps li { margin-bottom: 8px; }
.mods { list-style: none; padding: 0; margin: 0; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.mods li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.4; padding: 8px 10px; border-radius: 14px; background: var(--chip); }
.mods li span { font-size: 20px; }
.mods b { display: block; }
.small { text-align: left; font-size: 13px; line-height: 1.45; color: var(--ink2); }

.res-head { margin-bottom: 12px; }
.res-emoji { font-size: 44px; }
.res-time { font: 900 54px/1 var(--mono); font-variant-numeric: tabular-nums; margin: 4px 0; }
.res-sub { color: var(--ink2); font-weight: 700; }
.share-preview { margin: 12px 0; padding: 12px; border-radius: 14px; background: var(--chip); font: 700 14px/1.5 var(--mono); white-space: pre-wrap; text-align: left; }
.statgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 14px; }
.statgrid div { padding: 8px 2px; border-radius: 14px; background: var(--chip); display: flex; flex-direction: column; align-items: center; }
.statgrid b { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.statgrid span { font-size: 9.5px; font-weight: 800; color: var(--ink3); text-transform: uppercase; letter-spacing: 0.04em; line-height: 1.2; }
.next { margin-top: 12px; font-weight: 700; color: var(--ink2); }
.next b { font-family: var(--mono); color: var(--ink); }
.toggle { display: flex; justify-content: space-between; align-items: center; padding: 14px 6px; font-weight: 800; border-bottom: 1px solid var(--glass-b); }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.links { margin-top: 16px; font-weight: 700; }
.links a { color: var(--ink2); }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-weight: 800; }

@media (max-height: 640px) {
  .rule-text { font-size: 15px; padding: 9px 12px; }
  .key { height: 40px; }
  .turn { width: 46px; height: 46px; }
}
