:root {
  --blue: #0C447C;
  --blue-deep: #08305a;
  --coral: #D85A30;
  --coral-soft: #fbe6dc;
  --tint: #E6F1FB;
  --ink: #2C2C2A;
  --muted: #6b6b66;
  --line: #d9e3ee;
  --bg: #f6f9fc;
  --card: #ffffff;
  --ok: #2f7d4f;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eef2f6;
    --muted: #a7b0ba;
    --line: #2a3a4d;
    --bg: #0d1722;
    --card: #15222f;
    --tint: #1b2e42;
    --coral-soft: #3a2219;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
body.has-player main { padding-bottom: 210px; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
svg text { font: 700 7px var(--font); fill: currentColor; stroke: none; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--blue); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center; background: var(--coral);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-text strong { font-size: 17px; }
.brand-text span { font-size: 13px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.net-pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: rgba(255,255,255,.18); }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent;
  display: grid; place-items: center; flex: none;
}
.icon-btn:active { background: rgba(127,127,127,.18); }
.topbar .back { margin-left: -8px; color: #fff; }

main { max-width: 720px; margin: 0 auto; padding: 20px 16px 40px; outline: none; }

/* Lock screen */
.lock { text-align: center; padding-top: 6vh; }
.lock h1 { font-size: 26px; margin: 18px 0 6px; }
.lock p { color: var(--muted); margin: 0 auto 24px; max-width: 340px; line-height: 1.45; }
.lock-art {
  width: 84px; height: 84px; margin: 0 auto; border-radius: 24px;
  display: grid; place-items: center; background: var(--tint); color: var(--blue);
}
@media (prefers-color-scheme: dark) { .lock-art { color: #9cc6f0; } }
.lock-art svg { width: 44px; height: 44px; }
.code-form { display: flex; flex-direction: column; gap: 12px; max-width: 340px; margin: 0 auto; }
.code-input {
  font: 700 22px/1 var(--font); letter-spacing: .12em; text-align: center; text-transform: uppercase;
  padding: 16px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); color: var(--ink); width: 100%;
}
.code-input:focus { outline: none; border-color: var(--blue); }
.btn {
  border: 0; border-radius: 14px; padding: 15px 18px; font-weight: 700; font-size: 16px;
  background: var(--coral); color: #fff;
}
.btn:active { filter: brightness(.92); }
.btn.secondary { background: var(--tint); color: var(--blue); }
@media (prefers-color-scheme: dark) { .btn.secondary { color: #cfe3f7; } }
.btn:disabled { opacity: .55; }
.form-msg { min-height: 20px; font-size: 14px; color: var(--coral); margin: 0; }
.hint-es { font-size: 13px; color: var(--muted); margin-top: 26px !important; }

/* Home */
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 4px 2px 14px; }
.section-head h1 { font-size: 22px; margin: 0; }
.section-head span { color: var(--muted); font-size: 14px; }
.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .levels { grid-template-columns: repeat(3, 1fr); } }
.level-card {
  position: relative; text-align: left; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); padding: 16px 14px 14px; min-height: 140px;
  display: flex; flex-direction: column; gap: 4px; overflow: hidden;
}
.level-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: var(--blue);
}
.level-card:nth-child(even)::before { background: var(--coral); }
.level-card .num { font-size: 40px; font-weight: 800; color: var(--blue); line-height: 1; margin-top: 4px; }
@media (prefers-color-scheme: dark) { .level-card .num { color: #9cc6f0; } }
.level-card .t { font-weight: 700; font-size: 16px; margin-top: 6px; }
.level-card .s { color: var(--muted); font-size: 13px; }
.level-card .meta { margin-top: auto; padding-top: 10px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.level-card.locked { opacity: .55; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.badge svg { width: 14px; height: 14px; }
.badge.ok { color: var(--ok); }
@media (prefers-color-scheme: dark) { .badge.ok { color: #7dd3a0; } }

.install-card, .note-card {
  margin-top: 20px; padding: 16px; border-radius: var(--radius);
  background: var(--tint); display: flex; gap: 12px; align-items: center;
}
.install-card p, .note-card p { margin: 0; font-size: 14px; line-height: 1.4; flex: 1; }
.install-card .btn { padding: 10px 14px; font-size: 14px; }
.foot-actions { margin-top: 22px; text-align: center; }
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 14px; padding: 8px; }

/* Level page */
.level-hero { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.level-hero .big {
  width: 64px; height: 64px; border-radius: 18px; flex: none; display: grid; place-items: center;
  background: var(--blue); color: #fff; font-size: 30px; font-weight: 800;
}
.level-hero h1 { margin: 0; font-size: 22px; }
.level-hero p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.offline-box {
  border: 1px solid var(--line); background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 10px;
}
.offline-row { display: flex; align-items: center; gap: 12px; }
.offline-row p { margin: 0; flex: 1; font-size: 14px; line-height: 1.35; }
.offline-row .btn { padding: 10px 14px; font-size: 14px; white-space: nowrap; }
.progress { height: 8px; border-radius: 99px; background: var(--tint); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--coral); transition: width .2s; }

.tracks { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); overflow: hidden; }
.track { border-top: 1px solid var(--line); }
.track:first-child { border-top: 0; }
.track button {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  border: 0; background: transparent; padding: 14px; min-height: 60px;
}
.track .n {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--tint); color: var(--blue); font-weight: 700; font-size: 14px;
}
@media (prefers-color-scheme: dark) { .track .n { color: #cfe3f7; } }
.track .tt { flex: 1; font-size: 15px; line-height: 1.3; }
.track .dl { color: var(--ok); }
.track .dl svg { width: 18px; height: 18px; }
@media (prefers-color-scheme: dark) { .track .dl { color: #7dd3a0; } }
.track.current button { background: var(--coral-soft); }
.track.current .n { background: var(--coral); color: #fff; }
.track.current .tt { font-weight: 700; }
.track.unavailable { opacity: .5; }

/* Player */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(12,68,124,.10);
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
}
.player > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.player-titles { display: flex; flex-direction: column; min-width: 0; }
.player-level { font-size: 12px; color: var(--coral); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.player-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seek { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 8px; }
.seek input { flex: 1; accent-color: var(--coral); height: 28px; }
.controls { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.controls .icon-btn { color: var(--ink); }
.play {
  width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--coral); color: #fff;
  display: grid; place-items: center; box-shadow: 0 6px 16px rgba(216,90,48,.35);
}
.play svg { width: 28px; height: 28px; }
.chip {
  min-width: 48px; height: 36px; border-radius: 99px; border: 1px solid var(--line); background: transparent;
  font-size: 14px; font-weight: 700; display: grid; place-items: center; padding: 0 10px;
}
.chip svg { width: 18px; height: 18px; }
.chip[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }

.toast {
  position: fixed; left: 50%; bottom: 230px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
body:not(.has-player) .toast { bottom: 24px; }
.level-card .num.word { font-size: 30px; padding-top: 6px; letter-spacing: -.01em; }
.level-hero .big.word { font-size: 17px; }
.unit-head {
  padding: 10px 14px 8px; font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: var(--coral); background: var(--bg); border-top: 1px solid var(--line);
}
.unit-head:first-child { border-top: 0; }
.unit-head + .track { border-top: 1px solid var(--line); }
