:root {
  --bg: #14171a;
  --bg2: #1a1e22;
  --panel: #20252a;
  --panel2: #2a3036;
  --line: #343c43;
  --text: #f3ead6;
  --muted: #a9a190;
  --lime: #a4e23a;
  --lime-dim: #5d8a22;
  --red: #e8553d;
  --amber: #f0b840;
  --brown: #8a5a36;
  --radius: 16px;
  --tap: 48px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 16px 0 8px; }
p { margin: 0 0 10px; }
small, .small { font-size: 0.82rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}

/* ---- top bar ---- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  background: var(--bg);
}
.lvl { flex: 1; min-width: 0; }
.lvl-line { display: flex; gap: 8px; align-items: baseline; }
#lvl-num { color: var(--lime); font-size: 1.05rem; display: inline-block; }
#lvl-title { color: var(--text); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lvl-num.pop { animation: pop 0.7s ease; }
.xpbar { height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; margin: 5px 0 2px; }
.xpbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--lime-dim), var(--lime)); transition: width 0.5s ease; }
.xpbar.big { height: 10px; border-radius: 5px; }
.streak { font-weight: 700; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; white-space: nowrap; }

/* ---- main + tabs ---- */
#view { flex: 1; overflow-y: auto; padding: 8px 16px 24px; -webkit-overflow-scrolling: touch; outline: none; }
#tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg2);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; min-height: 56px;
  color: var(--muted); text-decoration: none; font-size: 0.74rem;
}
#tabs a .ico { font-size: 1.3rem; line-height: 1; filter: grayscale(0.7); }
#tabs a.on { color: var(--lime); }
#tabs a.on .ico { filter: none; }

/* ---- cards and buttons ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; margin: 12px 0; }
.row > * { flex: 1; }

button { cursor: pointer; border: 0; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.primary, .secondary, .danger, .ghost {
  min-height: var(--tap); padding: 10px 16px; border-radius: 12px; font-weight: 600;
}
.primary { background: var(--lime); color: #11150a; }
.primary:active:not(:disabled) { filter: brightness(0.9); }
.secondary { background: var(--panel2); border: 1px solid var(--line); color: var(--text); }
.secondary.on { background: var(--lime); color: #11150a; border-color: var(--lime); }
.danger { background: transparent; border: 1px solid var(--red); color: var(--red); margin-top: 10px; }
.ghost { background: transparent; color: var(--muted); }
.wide { width: 100%; margin-top: 12px; display: block; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 8px 14px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); }
.chip small { color: var(--muted); margin-left: 2px; }
.chip.on { background: var(--lime); color: #11150a; border-color: var(--lime); font-weight: 600; }
.chip.on small { color: #3a4a14; }

.choices { display: grid; gap: 8px; }
.choice { text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 2px; position: relative; }
.choice span { color: var(--muted); font-size: 0.85rem; }
.choice em { position: absolute; right: 12px; top: 12px; font-style: normal; font-size: 0.78rem; color: var(--lime); }
.choice.on { border-color: var(--lime); box-shadow: inset 0 0 0 1px var(--lime); }

.seg { display: flex; background: var(--panel2); border-radius: 12px; padding: 3px; margin: 10px 0; }
.seg button { flex: 1; min-height: 40px; background: transparent; border-radius: 9px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--bg); color: var(--lime); }

.filebox { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.filebox span { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--muted); }

.field { display: block; margin-bottom: 12px; }
.field input { width: 100%; margin-top: 8px; }
.switch { display: flex; gap: 10px; align-items: center; margin: 14px 0 8px; min-height: 40px; }
.switch input { width: 22px; height: 22px; accent-color: var(--lime); }

input[type="range"] { width: 100%; accent-color: var(--lime); height: 36px; }

.callout { background: rgba(232, 85, 61, 0.12); border: 1px solid rgba(232, 85, 61, 0.45); padding: 10px 12px; border-radius: 12px; }
.callout.good { background: rgba(164, 226, 58, 0.1); border-color: rgba(164, 226, 58, 0.4); }
.banner { text-align: center; font-weight: 700; padding: 8px 12px; border-radius: 12px; background: rgba(240, 184, 64, 0.14); border: 1px solid rgba(240, 184, 64, 0.5); }
.banner.level { background: rgba(164, 226, 58, 0.14); border-color: rgba(164, 226, 58, 0.5); animation: pop 0.7s ease; }

/* ---- home ---- */
.hero { display: flex; gap: 16px; align-items: center; }
.hero p { margin: 0 0 4px; }
.ring { width: 84px; height: 84px; flex: none; }
.ring .track { fill: none; stroke: var(--panel2); stroke-width: 8; }
.ring .fill { fill: none; stroke: var(--lime); stroke-width: 8; stroke-linecap: round; transition: stroke-dasharray 0.6s ease; }
.ring text { fill: var(--text); font-size: 15px; font-weight: 700; }
.daily { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.daily .done { grid-column: 1 / -1; color: var(--lime); font-weight: 600; }

/* ---- play ---- */
.runbar { display: flex; align-items: center; gap: 10px; }
.runbar .ghost { min-height: 40px; min-width: 40px; padding: 4px 10px; }
.progress { flex: 1; height: 8px; border-radius: 4px; background: var(--panel2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--lime); transition: width 0.3s ease; }
.runbar .count { font-variant-numeric: tabular-nums; color: var(--muted); }
.combo { font-weight: 700; color: var(--amber); min-width: 44px; text-align: right; }
.combo.dim { color: var(--muted); font-weight: 400; }
.modeline { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 6px 0 12px; }

.bigplay {
  display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%;
  min-height: 84px; border-radius: 18px; background: var(--panel2); border: 2px solid var(--line);
  font-size: 1.1rem; font-weight: 700;
}
.bigplay .icon { font-size: 1.6rem; color: var(--lime); }
.bigplay.on { border-color: var(--lime); background: rgba(164, 226, 58, 0.12); animation: pulse 1.6s ease-in-out infinite; }

.band-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 14px 0; }
.band { min-height: 58px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); font-weight: 700; font-size: 1.05rem; }
.band.on { background: var(--lime); color: #11150a; border-color: var(--lime); }

.tuner { margin: 14px 0 6px; text-align: center; }
.readout { display: block; font-size: 2rem; font-weight: 800; color: var(--lime); font-variant-numeric: tabular-nums; }
.scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.72rem; padding: 0 4px; }
.nudge { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.nudge button { min-height: 46px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); font-size: 1.3rem; }

.hint-text { min-height: 1.4em; color: var(--amber); text-align: center; font-size: 0.9rem; margin: 0; }

.result .tier { text-align: center; margin: 4px 0 8px; }
.result .tier .emoji { font-size: 2.2rem; display: block; animation: pop 0.5s ease; }
.result .tier b { font-size: 1.5rem; }
.result.perfect .tier b { color: var(--lime); }
.result.close .tier b { color: var(--amber); }
.result.miss .tier b { color: var(--red); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 6px; text-align: center; }
.facts dt { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }
.facts dd { margin: 2px 0 0; font-size: 1.2rem; font-weight: 700; }
.facts .good { color: var(--lime); }
.facts .you { color: var(--red); }
.result.perfect .facts .you, .result.close .facts .you { color: var(--text); }
.err { text-align: center; margin: 0 0 12px; color: var(--muted); }
.strip { position: relative; height: 14px; border-radius: 7px; background: linear-gradient(90deg, var(--panel2), var(--line), var(--panel2)); margin: 6px 4px 2px; }
.mark { position: absolute; top: 50%; width: 18px; height: 18px; border-radius: 50%; transform: translate(-50%, -50%); border: 3px solid var(--bg); }
.mark.target { background: var(--lime); z-index: 2; }
.mark.guess { background: var(--red); }
.xp-line { text-align: center; margin: 12px 0 0; }

.summary .stars { text-align: center; font-size: 2.2rem; color: var(--amber); letter-spacing: 6px; }
.bigscore { text-align: center; font-size: 3.2rem; font-weight: 800; line-height: 1.1; color: var(--lime); }
.bigscore small { color: var(--muted); font-size: 1rem; font-weight: 400; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; text-align: center; }
.stats3 b { display: block; font-size: 1.3rem; }
.stats3 small { color: var(--muted); }
.xp-list { list-style: none; padding: 0; margin: 0 0 8px; }
.xp-list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.xp-list li.total { border-bottom: 0; font-size: 1.1rem; color: var(--lime); }
.review { list-style: none; padding: 0; margin: 0; }
.review li { display: grid; grid-template-columns: 28px 1fr 1fr 28px; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); align-items: center; font-variant-numeric: tabular-nums; }
.review .n { color: var(--muted); }
.review .t { text-align: right; }

/* ---- lab ---- */
.list { padding: 6px; }
.labrow { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: transparent; padding: 12px 10px; border-radius: 12px; min-height: 64px; }
.labrow + .labrow { border-top: 1px solid var(--line); }
.labrow .hz { width: 84px; font-weight: 800; font-variant-numeric: tabular-nums; }
.labrow .txt { flex: 1; display: grid; }
.labrow small { color: var(--muted); }
.labrow .play { color: var(--lime); font-size: 1.2rem; width: 28px; text-align: center; }
.labrow.on { background: rgba(164, 226, 58, 0.12); }

/* ---- progress ---- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.tile { background: var(--panel2); border-radius: 12px; padding: 10px 6px; text-align: center; }
.tile b { display: block; font-size: 1.3rem; }
.tile small { color: var(--muted); }
.fmap { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; align-items: end; margin: 12px 0 8px; }
.fmap .col { display: grid; gap: 4px; text-align: center; }
.fmap .bar { position: relative; height: 110px; background: var(--panel2); border-radius: 6px; overflow: hidden; }
.fmap .bar.empty { background: repeating-linear-gradient(45deg, var(--panel2), var(--panel2) 4px, var(--bg2) 4px, var(--bg2) 8px); }
.fmap .bar i { position: absolute; bottom: 0; left: 0; right: 0; }
.fmap .hit { background: var(--lime-dim); }
.fmap .perf { background: var(--lime); }
.fmap small { color: var(--muted); font-size: 0.68rem; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { display: grid; grid-template-columns: 80px 1fr auto; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.plain li:last-child { border-bottom: 0; }

.badge-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.badge { background: var(--panel2); border-radius: 12px; padding: 10px; display: grid; gap: 2px; opacity: 0.5; }
.badge .ico { font-size: 1.6rem; }
.badge small { color: var(--muted); }
.badge.got { opacity: 1; border: 1px solid rgba(164, 226, 58, 0.45); }
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; }
.badge-row .badge { grid-template-columns: auto 1fr; align-items: center; gap: 8px; padding: 8px 12px; }

/* ---- toasts ---- */
#toasts { position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 64px); display: grid; gap: 8px; justify-items: center; pointer-events: none; z-index: 20; padding: 0 16px; }
.toast { background: var(--panel2); border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 999px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); max-width: 520px; animation: slide-in 0.25s ease; }
.toast.badge { border-color: var(--amber); }
.toast.level { border-color: var(--lime); }
.toast.error { border-color: var(--red); }
.toast.out { opacity: 0; transform: translateY(-8px); transition: all 0.3s ease; }

@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(164, 226, 58, 0.35); } 50% { box-shadow: 0 0 0 10px rgba(164, 226, 58, 0); } }
@keyframes slide-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 520px) {
  .band-grid { gap: 10px; }
  .badge-grid { grid-template-columns: repeat(3, 1fr); }
}
