:root {
  --ink: #1e1b4b;
  --muted: #5b5880;
  --card: #ffffff;
  --brand: #4338ca;
  --brand-2: #7c3aed;
  --soft: #eef2ff;
  --sel-border: #6366f1;
  --play: #16a34a;
  --play-dark: #15803d;
  --good: #16a34a;
  --bad: #dc2626;
  --bg-1: #6366f1;
  --bg-2: #8b5cf6;
  --radius: 22px;
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, sans-serif;
  --emoji: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, 'Courier New', monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%;
  font-family: var(--font); color: var(--ink);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2)) fixed;
  -webkit-tap-highlight-color: transparent;
}
body { overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--brand); }
code, kbd { font-family: var(--mono); font-size: .92em; background: var(--soft); border-radius: 6px; padding: 1px 5px; overflow-wrap: anywhere; }

#app { min-height: 100dvh; padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l)); }
.inner { max-width: 900px; margin: 0 auto; display: grid; gap: 16px; min-width: 0; }
.inner > * { min-width: 0; }
.back { color: #fff; font-weight: 600; text-decoration: none; justify-self: start; padding: 10px 2px; }
.brand { text-align: center; color: #fff; }
.brand .logo { font-size: clamp(40px, 10vw, 60px); line-height: 1.1; font-family: var(--emoji); }
.brand h1 { margin: 2px 0 0; font-size: clamp(32px, 8vw, 52px); text-shadow: 0 3px 0 rgba(30, 27, 75, .25); }
.brand p { margin: 4px 0 0; font-size: clamp(16px, 4vw, 20px); font-weight: 500; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 10px 30px rgba(30, 27, 75, .2); min-width: 0; }
.card h2 { margin: 0 0 10px; font-size: 21px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h3 { margin: 14px 0 6px; font-size: 17px; }
.card p { line-height: 1.45; margin: 0 0 10px; }
.card p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.step { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 16px; flex: none; }
.tip { font-size: 15px; color: var(--muted); }

/* Status bar */
.status { display: grid; gap: 8px; padding: 12px 16px; }
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 15px; line-height: 1.35; }
.status-line b { overflow-wrap: anywhere; }
.status-line .btn-small { min-height: 40px; padding: 4px 12px; font-size: 14px; }

/* Tabs */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 6px 0; }
@media (min-width: 700px) { .tabs { grid-template-columns: repeat(5, 1fr); position: sticky; top: 0; z-index: 3; } }
.tabs button {
  border: 0; border-radius: 16px; min-height: 64px; padding: 6px 4px; background: rgba(255, 255, 255, .85);
  display: grid; place-content: center; justify-items: center; gap: 2px; font-weight: 600; font-size: 14px; line-height: 1.15;
  box-shadow: 0 4px 12px rgba(30, 27, 75, .15);
}
.tabs button span { font-size: 24px; font-family: var(--emoji); line-height: 1.1; }
.tabs button[aria-selected="true"] { background: var(--brand); color: #fff; box-shadow: 0 4px 0 #312e81, 0 6px 16px rgba(30, 27, 75, .3); }
.panel-tab { display: grid; gap: 16px; min-width: 0; }

/* Buttons */
.btn { border: 0; border-radius: 999px; min-height: 50px; padding: 10px 22px; font-weight: 700; font-size: 18px; transition: transform .1s; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; text-align: center; }
.btn:active { transform: translateY(2px); }
.btn-main { background: var(--play); color: #fff; box-shadow: 0 5px 0 var(--play-dark); }
.btn-ghost { background: #fff; color: var(--brand); box-shadow: 0 5px 0 #c7d2fe; border: 2px solid #c7d2fe; }
.btn-small { border: 2px solid #c7d2fe; background: #fff; border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 15px; min-height: 44px; color: var(--brand); }
.btn-small.on { background: var(--soft); border-color: var(--brand); }
.btn-small.danger { border-color: #fecaca; color: var(--bad); }
.btn:disabled, .btn-small:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 6px; }

/* Forms */
.form { display: grid; gap: 6px; min-width: 0; }
.form label { font-weight: 600; font-size: 15px; margin-top: 6px; }
.form label small { font-weight: 400; color: var(--muted); }
.form input[type="text"], .form input[type="url"], .form select, .form textarea {
  width: 100%; min-width: 0; min-height: 46px; padding: 10px 12px; border: 2px solid #e0e7ff; border-radius: 14px; background: #fafaff; font-size: 17px;
}
.form textarea { font-family: var(--font); line-height: 1.45; resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--sel-border); box-shadow: 0 0 0 3px rgba(99, 102, 241, .2); background: #fff; }
.checkline { display: flex; align-items: center; gap: 10px; font-weight: 500 !important; min-height: 44px; }
.checkline input { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.two { display: grid; grid-template-columns: 1fr; gap: 6px 12px; }
@media (min-width: 560px) { .two { grid-template-columns: 2fr 1fr; } }
.two > div { display: grid; gap: 6px; min-width: 0; }
.check { margin: 2px 0 0 !important; font-size: 14px; min-height: 1em; }
.msg { margin: 4px 0 0 !important; font-weight: 600; min-height: 1.2em; line-height: 1.4; }
.ok-text { color: var(--good); }
.warn-text { color: #b45309; }
.bad-text { color: var(--bad); }

.help { background: var(--soft); border-radius: 12px; padding: 8px 12px; font-size: 15px; }
.help summary { cursor: pointer; font-weight: 600; color: var(--brand); min-height: 28px; }
.help ul { margin: 8px 0 2px; padding-left: 20px; display: grid; gap: 6px; line-height: 1.45; }

.preview { font-size: 14px; line-height: 1.45; color: var(--muted); display: grid; gap: 4px; }
.preview .sum { color: var(--ink); font-weight: 600; }
.preview .chips { display: flex; flex-wrap: wrap; gap: 4px; }
.preview .chip { background: var(--soft); border-radius: 999px; padding: 2px 9px; color: var(--ink); }
.preview .chip i { font-style: normal; color: var(--muted); font-size: 12px; }
.preview .prob { color: var(--bad); }
.preview .warn { color: #b45309; }

/* Steps */
.steps { margin: 0 0 12px; padding-left: 24px; display: grid; gap: 8px; line-height: 1.45; }

/* Code box */
.codebox { border: 2px solid #e0e7ff; border-radius: 16px; overflow: hidden; }
.codebar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 10px; background: var(--soft); }
.codebar .muted { font-size: 13px; flex: 1; }
.codebox pre {
  margin: 0; padding: 12px; max-height: 320px; overflow: auto; background: #1e1b4b; color: #e0e7ff;
  font: 13px/1.5 var(--mono); white-space: pre; tab-size: 2; user-select: text; -webkit-user-select: text;
}

.device-line { margin-top: 12px; padding: 10px 12px; border-radius: 14px; background: #f8fafc; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 15px; line-height: 1.35; }

/* Share box (link + QR) */
.share { display: grid; gap: 10px; margin-top: 12px; padding: 12px; border-radius: 16px; background: var(--soft); min-width: 0; }
.share .link { width: 100%; min-width: 0; font: 13px/1.4 var(--mono); padding: 10px; border: 2px solid #c7d2fe; border-radius: 12px; background: #fff; resize: none; overflow-wrap: anywhere; word-break: break-all; }
.share .qr { justify-self: center; width: min(100%, 340px); background: #fff; border-radius: 16px; padding: 8px; }
.share .qr svg { display: block; width: 100%; height: auto; }
.share .qr-note { text-align: center; font-size: 13px; color: var(--muted); margin: 0; }
.share .row { justify-content: center; }

.big-qr { border: 0; border-radius: 24px; padding: 18px; width: min(calc(100% - 24px), 760px); max-height: calc(100% - 24px); text-align: center; font-family: var(--font); color: var(--ink); }
.big-qr::backdrop { background: rgba(30, 27, 75, .7); }
.big-qr p { font-size: clamp(18px, 3vw, 28px); font-weight: 700; margin: 0 0 10px; }
.big-qr #bigQrCode svg { width: min(100%, 78vh); height: auto; display: block; margin: 0 auto 12px; }

/* Packs */
.pack-list { display: grid; gap: 10px; }
.pack { border: 2px solid #e0e7ff; border-radius: 18px; padding: 12px; display: grid; gap: 8px; min-width: 0; }
.pack.active { border-color: var(--play); background: #f0fdf4; }
.pack-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.pack-head h3 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.tag { font-size: 13px; font-weight: 600; border-radius: 999px; padding: 2px 9px; background: var(--soft); color: var(--brand); white-space: nowrap; }
.tag.on { background: var(--play); color: #fff; }
.counts { font-size: 14px; color: var(--muted); }
.emoji-row { font-family: var(--emoji); font-size: 22px; letter-spacing: 2px; overflow-wrap: anywhere; line-height: 1.3; }
.game-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.gchip { font-size: 13px; border-radius: 999px; padding: 3px 9px; background: #dcfce7; color: #166534; font-weight: 600; }
.gchip.no { background: #f1f5f9; color: #64748b; font-weight: 500; text-decoration: line-through; text-decoration-color: rgba(100, 116, 139, .5); }
.games-box { display: grid; gap: 6px; margin-top: 8px; padding: 10px 12px; border-radius: 14px; background: #f8fafc; font-size: 15px; }
.empty { color: var(--muted); text-align: center; padding: 12px; }

.pack details { font-size: 15px; }
.pack details summary { cursor: pointer; color: var(--brand); font-weight: 600; min-height: 28px; }
.pack details ul, .pack details ol { margin: 6px 0; padding-left: 22px; line-height: 1.45; }
.pack details h4 { margin: 10px 0 2px; font-size: 15px; }

/* Topic packs */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; min-height: 44px; padding: 6px 12px; border-radius: 14px; border: 2px solid #e0e7ff; background: #fafaff; font-weight: 600; }
.seg button[aria-pressed="true"] { border-color: var(--sel-border); background: var(--soft); color: var(--brand); }
.year-block { display: grid; gap: 10px; }
.year-block > h2 { color: #fff; margin: 8px 0 0; font-size: 24px; text-shadow: 0 2px 0 rgba(30, 27, 75, .25); }
.topic-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); }
.topic-grid .pack { background: #fff; border-color: transparent; box-shadow: 0 8px 22px rgba(30, 27, 75, .18); }
.topic-grid .pack.active { border-color: var(--play); background: #f0fdf4; }
.theme { font-size: 13px; color: var(--muted); }

/* Progress */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 10px; }
.stat { background: var(--soft); border-radius: 16px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 26px; color: var(--brand); }
.stat span { font-size: 13px; color: var(--muted); }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.badge { display: grid; justify-items: center; text-align: center; gap: 2px; padding: 10px 6px; border-radius: 16px; background: #f1f5f9; opacity: .5; filter: grayscale(1); }
.badge.earned { opacity: 1; filter: none; background: #fef9c3; box-shadow: inset 0 0 0 2px #facc15; }
.badge .icon { font-size: 32px; line-height: 1.1; font-family: var(--emoji); }
.badge b { font-size: 14px; }
.badge small { font-size: 12px; color: var(--muted); line-height: 1.25; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.res-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.res-table th, .res-table td { padding: 8px 6px; border-bottom: 1px solid #eef2ff; text-align: left; vertical-align: top; }
.res-table th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.res-table td.nowrap { white-space: nowrap; }
.res-table td.std { font-size: 13px; color: var(--muted); min-width: 140px; }
.res-table td small { display: block; color: var(--muted); }

/* Class Battle */
.battle { text-align: center; display: grid; justify-items: center; gap: 4px; }
.battle h2 { justify-content: center; font-size: 26px; }
.battle-icon { font-size: 56px; font-family: var(--emoji); line-height: 1.1; }

.install { display: grid; justify-items: center; gap: 6px; color: #fff; font-size: 14px; text-align: center; }
.install p { margin: 0; }

/* Phones: cards a bit tighter, rows of buttons full width */
@media (max-width: 480px) {
  .card { padding: 14px; border-radius: 18px; }
  .row .btn { flex: 1 1 100%; }
  .tabs button { font-size: 13px; min-height: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
