:root {
  --bg: #07080c;
  --bg2: #0d0f15;
  --card: #11141c;
  --card2: #171b25;
  --line: #242833;
  --text: #eef1f7;
  --muted: #8b92a5;
  --accent: #19e3ff;
  --accent2: #a259ff;
  --gold: #ffd60a;
  --danger: #ff4d5e;
  --radius: 18px;
  --col: 640px;              /* width of the centred content column */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(162, 89, 255, .10), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, rgba(25, 227, 255, .08), transparent 60%),
    var(--bg);
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
#app { height: 100%; position: relative; }
[hidden] { display: none !important; }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0; display: none; flex-direction: column;
  padding: calc(12px + var(--safe-t)) 16px calc(12px + var(--safe-b));
}
.screen.active { display: flex; animation: screenIn .28s ease both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.scroll { overflow-y: auto; flex: 1; padding-bottom: 24px; scrollbar-width: thin; scrollbar-color: #2a2f3b transparent; }
.scroll > * + * { margin-top: 14px; }
/* Screens and their scroll areas span the window so scrollbars sit at its edge rather
   than mid-page; what's inside them stays in a centred column. */
.screen > *:not(.scroll) { width: 100%; max-width: var(--col); margin-inline: auto; }
.screen > .scroll { width: auto; margin-inline: -16px; padding-inline: 16px; }
.scroll > * { max-width: var(--col); margin-inline: auto; }

.topbar { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; min-height: 48px; margin-bottom: 10px; }
.topbar h2 { margin: 0; font-size: 20px; font-weight: 750; letter-spacing: .3px; text-align: center; }
.topbar-right { min-width: 44px; display: flex; justify-content: flex-end; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; font-size: 26px; line-height: 1; cursor: pointer; transition: transform .12s, background .2s;
}
.icon-btn:hover { background: var(--card2); }
.icon-btn:active { transform: scale(.94); }
.sound-toggle::before { content: "🔊"; font-size: 18px; }
.sound-toggle.off::before { content: "🔇"; }

.card { background: linear-gradient(180deg, var(--card), var(--bg2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; border: 0; cursor: pointer;
  border-radius: 16px; padding: 13px 18px; font-weight: 700; font-size: 16px; transition: transform .12s, filter .2s, background .2s;
  user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible, .ctrl:focus-visible, .icon-btn:focus-visible, .lvl:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: linear-gradient(135deg, #19e3ff, #2d7dff 55%, #a259ff); color: #04060a; box-shadow: 0 8px 28px rgba(45, 125, 255, .35); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--card2); border: 1px solid var(--line); }
.btn-secondary:hover { background: #1e2330; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-danger { background: rgba(255, 77, 94, .12); color: #ff8a96; border: 1px solid rgba(255, 77, 94, .35); }
.btn-lg { padding: 16px 20px; font-size: 18px; width: 100%; }
.btn-lg small { display: block; font-size: 12px; font-weight: 600; opacity: .75; }
.btn-icon { font-size: 18px; }

/* ---------- home ---------- */
#screen-home { gap: 16px; overflow-y: auto; }
.home-top { display: flex; justify-content: space-between; align-items: center; }
.all-games-link { color: var(--muted); text-decoration: none; font-weight: 600; padding: 8px; }
.all-games-link:hover { color: var(--text); }
.home-hero { text-align: center; margin-top: -8px; }
.logo { width: 112px; height: 112px; filter: drop-shadow(0 10px 30px rgba(25, 227, 255, .18)); }
.logo-path { stroke-dasharray: 200; stroke-dashoffset: 200; animation: draw 1.4s cubic-bezier(.6, 0, .2, 1) forwards; }
.logo-path.p2 { animation-delay: .25s; }
.logo-path.p3 { animation-delay: .5s; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.title { font-size: 44px; margin: 6px 0 2px; font-weight: 850; letter-spacing: .5px; }
.title span { background: linear-gradient(90deg, #19e3ff, #a259ff, #ff5fb7); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { margin: 0; color: var(--muted); }
.home-progress .hp-row { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.hp-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }
.hp-value { font-size: 26px; font-weight: 800; margin-top: 2px; }
.hp-value small { font-size: 14px; color: var(--muted); font-weight: 600; }
.bar { height: 8px; background: #1a1e28; border-radius: 99px; margin-top: 14px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, #20d65a, #19e3ff, #a259ff); border-radius: inherit; transition: width .6s ease; }
.home-menu { display: flex; flex-direction: column; gap: 12px; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn-tile { flex-direction: column; gap: 8px; padding: 18px 10px; background: var(--card); border: 1px solid var(--line); position: relative; font-size: 15px; }
.btn-tile:hover { background: var(--card2); }
.badge { position: absolute; top: 10px; right: 10px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 800; padding: 3px 7px; border-radius: 99px; letter-spacing: .5px; }
.tile-ico { width: 30px; height: 30px; display: block; background-size: contain; background-repeat: no-repeat; background-position: center; }
.tile-ico.sm { width: 18px; height: 18px; }
.ico-grid { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2319e3ff' stroke-width='2' stroke-linecap='round'%3E%3Crect x='3' y='3' width='7' height='7' rx='2'/%3E%3Crect x='14' y='3' width='7' height='7' rx='2'/%3E%3Crect x='3' y='14' width='7' height='7' rx='2'/%3E%3Crect x='14' y='14' width='7' height='7' rx='2'/%3E%3C/svg%3E"); }
.ico-cal { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffd60a' stroke-width='2' stroke-linecap='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='3'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4'/%3E%3Ccircle cx='12' cy='15' r='2' fill='%23ffd60a'/%3E%3C/svg%3E"); }
.ico-help { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2320d65a' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M9.5 9.5a2.5 2.5 0 1 1 3.5 2.3c-.7.3-1 .9-1 1.7'/%3E%3Ccircle cx='12' cy='17' r='.6' fill='%2320d65a'/%3E%3C/svg%3E"); }
.ico-stats { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ff5fb7' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 20V10M10 20V4M16 20v-7M22 20H2'/%3E%3C/svg%3E"); }
.ico-gear { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b92a5' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M4.9 19.1 7 17M17 7l2.1-2.1'/%3E%3C/svg%3E"); }

/* ---------- level select ---------- */
.star-pill { background: rgba(255, 214, 10, .12); color: var(--gold); border: 1px solid rgba(255, 214, 10, .3); padding: 6px 12px; border-radius: 99px; font-weight: 800; font-size: 14px; white-space: nowrap; }
.tier { margin-bottom: 18px; }
.tier-head { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 4px 10px; }
.tier-head h3 { margin: 0; font-size: 15px; letter-spacing: 1.2px; text-transform: uppercase; }
.tier-head span { color: var(--muted); font-size: 13px; }
.tier-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.lvl {
  aspect-ratio: 1; border-radius: 16px; border: 1px solid var(--line); background: var(--card); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative;
  transition: transform .12s, border-color .2s; padding: 0;
}
.lvl:hover:not(.locked) { transform: translateY(-2px); border-color: #3a4152; }
.lvl .n { font-size: 20px; font-weight: 800; }
.lvl .s { font-size: 11px; letter-spacing: 1px; color: #3a3f4c; }
.lvl .s b { color: var(--gold); font-weight: 400; }
.lvl.done { background: linear-gradient(160deg, color-mix(in srgb, var(--tc) 22%, var(--card)), var(--card)); border-color: color-mix(in srgb, var(--tc) 45%, var(--line)); }
.lvl.current { border-color: var(--tc); box-shadow: 0 0 0 2px color-mix(in srgb, var(--tc) 35%, transparent), 0 0 22px color-mix(in srgb, var(--tc) 30%, transparent); }
.lvl.locked { cursor: not-allowed; opacity: .55; }
.lvl.locked .n { display: none; }
.lvl.locked::before { content: ""; width: 20px; height: 22px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 26' fill='none' stroke='%236b7285' stroke-width='2.4' stroke-linecap='round'%3E%3Crect x='3' y='11' width='18' height='13' rx='3'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E") center/contain no-repeat; }
.lvl.locked .s { display: none; }
.lvl .rodmark { position: absolute; top: 6px; right: 7px; width: 8px; height: 8px; border-radius: 2px; background: #9aa6b8; opacity: .6; }

/* ---------- game ---------- */
#screen-game { padding-bottom: calc(10px + var(--safe-b)); }
.game-title { text-align: center; min-width: 0; }
.game-title h2 { margin: 0; font-size: 19px; }
.game-sub { display: flex; gap: 8px; justify-content: center; align-items: center; color: var(--muted); font-size: 12.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; }
.game-sub #game-feature { overflow: hidden; text-overflow: ellipsis; }
.tier-chip { font-size: 10.5px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; color: var(--tc, #19e3ff); background: color-mix(in srgb, var(--tc, #19e3ff) 14%, transparent); }
.hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.hud-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 7px 4px; text-align: center; }
.hud-label { display: block; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }
.hud-val { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-val small { color: var(--muted); font-weight: 600; font-size: 13px; }
.hud-val.good { color: #20d65a; }
.board-wrap { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; }
#board { display: block; touch-action: none; border-radius: 14px; outline: none; cursor: pointer;
  box-shadow: 0 0 0 1px #1c2029, 0 20px 60px rgba(0, 0, 0, .6); }
#board:focus-visible { box-shadow: 0 0 0 2px var(--accent), 0 20px 60px rgba(0, 0, 0, .6); }
.shake { animation: shake .3s; }
@keyframes shake { 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
.toast {
  position: fixed; left: 50%; top: calc(70px + var(--safe-t)); transform: translate(-50%, -6px); opacity: 0; pointer-events: none;
  background: rgba(17, 20, 28, .94); border: 1px solid var(--line); padding: 8px 14px; border-radius: 99px; font-size: 13.5px; font-weight: 600;
  transition: opacity .2s, transform .2s; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.rule-line { text-align: center; color: var(--muted); font-size: 12.5px; min-height: 18px; margin: 8px 0 6px; }
.rule-line b { color: var(--text); }
.controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.ctrl {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 9px 4px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; font-weight: 700; color: #c9cfdc; position: relative;
  transition: transform .12s, background .2s;
}
.ctrl:hover { background: var(--card2); }
.ctrl:active { transform: scale(.95); }
.ctrl:disabled { opacity: .4; cursor: default; }
.ctrl-ico { font-size: 20px; line-height: 1.1; }
.ctrl-badge { position: absolute; top: 5px; right: 10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--gold); color: #000; font-size: 11px; font-weight: 800; display: grid; place-items: center; }

/* ---------- daily ---------- */
.daily-card { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.daily-date { font-size: 13px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--gold); font-weight: 800; }
.daily-preview canvas { display: block; border-radius: 12px; box-shadow: 0 0 0 1px #1c2029; }
.daily-meta { color: var(--muted); font-size: 14px; }
.daily-status { font-weight: 700; }
.daily-status.done { color: #20d65a; }

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.stat-val { font-size: 24px; font-weight: 850; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.tier-row { display: grid; grid-template-columns: 110px 1fr 70px; gap: 10px; align-items: center; padding: 7px 0; font-size: 14px; }
.tier-row .bar { margin: 0; }
.tier-row span:last-child { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- how to ---------- */
.prose p { margin: 0 0 10px; }
.rules { margin: 0; padding-left: 20px; line-height: 1.55; }
.rules li + li { margin-top: 4px; }
.kv { list-style: none; margin: 0; padding: 0; }
.kv li { display: grid; grid-template-columns: 130px 1fr; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.kv li:first-child { border-top: 0; }
.kv span { color: #c3c9d6; }
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.legend-item { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; gap: 10px; align-items: center; }
.legend-item canvas { flex: none; border-radius: 8px; }
.legend-item b { display: block; font-size: 13.5px; }
.legend-item small { display: block; color: var(--muted); font-size: 12px; line-height: 1.35; margin-top: 2px; }
@media (max-width: 480px) { .legend { grid-template-columns: 1fr; } }

/* ---------- settings ---------- */
.settings { padding: 4px 16px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); cursor: pointer; }
.setting:first-child { border-top: 0; }
.setting b { display: block; font-size: 15px; }
.setting small { color: var(--muted); font-size: 12.5px; }
.setting input { position: absolute; opacity: 0; pointer-events: none; }
.switch { flex: none; width: 48px; height: 28px; border-radius: 99px; background: #2a2f3b; position: relative; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.setting input:checked + .switch { background: linear-gradient(135deg, #19e3ff, #2d7dff); }
.setting input:checked + .switch::after { transform: translateX(20px); }
.setting input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(3, 4, 7, .72); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 20px; animation: fade .25s ease both; }
@keyframes fade { from { opacity: 0; } }
.modal-card { width: min(380px, 100%); background: linear-gradient(180deg, #151925, #0d0f15); border: 1px solid #2a2f3b; border-radius: 24px; padding: 24px; text-align: center; position: relative; overflow: hidden; animation: pop .35s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.modal-card h2 { margin: 6px 0 4px; font-size: 26px; }
.modal-card .mc-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.burst { position: absolute; inset: -40%; background: conic-gradient(from 0deg, transparent, rgba(25, 227, 255, .08), transparent 20%, rgba(162, 89, 255, .08), transparent 40%, rgba(255, 214, 10, .08), transparent 60%, rgba(32, 214, 90, .08), transparent 80%); animation: spin 12s linear infinite; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.complete > *:not(.burst) { position: relative; }
.mc-stars { display: flex; justify-content: center; gap: 8px; margin-top: 4px; }
.mstar { font-size: 52px; color: #2a2f3b; transform: scale(.4); opacity: 0; transition: none; }
.mstar:nth-child(2) { font-size: 64px; margin-top: -10px; }
.mstar.on { color: var(--gold); text-shadow: 0 0 22px rgba(255, 214, 10, .7); }
.mstar.show { animation: starIn .45s cubic-bezier(.2, 1.6, .4, 1) forwards; }
@keyframes starIn { to { transform: scale(1); opacity: 1; } }
.mc-sub { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.mc-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.mc-stats div { background: rgba(255, 255, 255, .03); border: 1px solid var(--line); border-radius: 14px; padding: 10px 4px; }
.mc-stats span { display: block; font-size: 20px; font-weight: 850; font-variant-numeric: tabular-nums; }
.mc-stats small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; }
.mc-note { min-height: 18px; font-size: 13px; color: var(--gold); margin-bottom: 12px; }

@media (max-height: 700px) {
  .hud { margin-bottom: 6px; }
  .hud-item { padding: 4px; }
  .hud-val { font-size: 15px; }
  .ctrl { padding: 6px 4px; }
  .logo { width: 84px; height: 84px; }
  .title { font-size: 36px; }
}
@media (min-width: 900px) {
  :root { --col: 720px; }
  .tier-grid { grid-template-columns: repeat(10, 1fr); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
