/* Tokens match Law of 100 (src/lib/theme.ts) and 2-2-2: papaya on near-black. */
:root {
  --bg: #0d0d0f;
  --surface: #18181c;
  --surface-2: #222228;
  --empty: #26262c;
  --line: #34343c;
  --text: #f5f5f7;
  --muted: #9a9aa2;
  --faint: #65656d;
  --accent: #ff8000;
  --accent-dim: #b35900;
  --good: #3ddc84;
  --bad: #ff5d5d;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h2 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
p { margin: 0 0 10px; line-height: 1.45; color: var(--muted); }
p b { color: var(--text); }

/* ---------- level header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(var(--safe-t) + 12px) 16px 12px;
  border-bottom: 1px solid var(--line);
}
.banner { font-size: 13px; text-align: center; color: var(--muted); background: var(--surface-2); border-radius: 8px; padding: 6px 10px; margin-bottom: 10px; }
.banner.bad { color: #fff; background: var(--bad); }
.lvl { display: flex; align-items: baseline; gap: 10px; }
.lvl-n { font-size: 30px; font-weight: 800; color: var(--accent); letter-spacing: -.02em; }
.lvl-t { font-size: 17px; font-weight: 600; }
.bar { height: 10px; background: var(--empty); border-radius: 999px; overflow: hidden; margin: 8px 0 6px; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .4s ease; }
.xp { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.view { padding: 14px 16px calc(var(--safe-b) + 84px); max-width: 560px; margin: 0 auto; }

/* ---------- date switcher ---------- */
.datebar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.nav-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 24px; }
.nav-btn:disabled { opacity: .3; cursor: default; }
.date { position: relative; font-size: 18px; font-weight: 700; padding: 8px 14px; }
.date input { position: absolute; inset: 0; opacity: 0; width: 100%; }

/* ---------- battery ---------- */
.battery { display: flex; align-items: center; gap: 4px; }
.cells { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; padding: 5px; border: 2px solid var(--line); border-radius: 12px; }
.cell { height: 46px; border-radius: 7px; background: var(--empty); display: grid; place-items: center; font-weight: 800; color: var(--faint); transition: background .2s, color .2s; }
.cell.on { background: var(--accent); color: #111; }
.cell.slip { background: var(--bad); color: #111; }
.nub { width: 7px; height: 22px; border-radius: 0 4px 4px 0; background: var(--line); }
.battery.full .cells { border-color: var(--accent); box-shadow: 0 0 18px rgba(255, 128, 0, .45); }
.battery.full .cell { animation: charge .6s ease both; }
.battery.full .nub { background: var(--accent); }
.battery.full .cell:nth-child(2) { animation-delay: .05s; }
.battery.full .cell:nth-child(3) { animation-delay: .1s; }
.battery.full .cell:nth-child(4) { animation-delay: .15s; }
.battery.full .cell:nth-child(5) { animation-delay: .2s; }
.battery.full .cell:nth-child(6) { animation-delay: .25s; }
.battery.full .cell:nth-child(7) { animation-delay: .3s; }
@keyframes charge { 50% { transform: scaleY(1.12); filter: brightness(1.3); } }

.dayxp { text-align: center; font-size: 15px; font-weight: 700; margin: 10px 0 14px; color: var(--accent); font-variant-numeric: tabular-nums; }
.dayxp.neg { color: var(--bad); }
.bonus { font-size: 12px; letter-spacing: .06em; background: var(--accent); color: #111; padding: 3px 8px; border-radius: 999px; margin-left: 6px; }

/* ---------- habit rows ---------- */
.habits { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.habit { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 4px 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.letter { grid-row: span 2; width: 40px; height: 40px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; font-size: 20px; color: var(--accent); }
.name { font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); }
.controls { grid-column: 2; display: flex; gap: 8px; margin-top: 6px; }
.chip { flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; font-size: 15px; position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #111; }
.chip.neg.on { background: var(--bad); border-color: var(--bad); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }
.up { color: var(--good); }
.down { color: var(--bad); }
.weak { color: var(--accent); font-size: 18px; margin-right: 4px; }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.badge { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 8px; text-align: center; }
.badge.earned { border: 1px solid var(--accent); background: rgba(255, 128, 0, .12); }
.b-label { font-weight: 700; font-size: 14px; }
.badge:not(.earned) .b-label { color: var(--faint); }
.b-sub { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- forms ---------- */
form { display: grid; gap: 10px; }
input[type=email], input[name=code] { width: 100%; min-height: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 12px; font-size: 17px; }
.btn { min-height: 48px; border: 0; border-radius: 12px; background: var(--accent); color: #111; font-weight: 700; padding: 0 18px; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px 0; }
.msg { color: var(--bad); }

/* ---------- tabs ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabs button { min-height: 58px; background: none; border: 0; color: var(--muted); font-weight: 600; }
.tabs button.on { color: var(--accent); }

/* ---------- level-up + toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .85); display: grid; place-items: center; animation: fade .25s ease; }
.levelup { text-align: center; padding: 24px; animation: pop .5s cubic-bezier(.2, 1.4, .4, 1); }
.lu-kicker { letter-spacing: .3em; font-weight: 800; color: var(--accent); }
.lu-num { font-size: 120px; font-weight: 900; line-height: 1; color: var(--accent); text-shadow: 0 0 40px rgba(255, 128, 0, .6); }
.lu-title { font-size: 26px; font-weight: 700; margin: 8px 0 24px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 80px); transform: translateX(-50%); z-index: 20; background: var(--accent); color: #111; font-weight: 800; padding: 12px 18px; border-radius: 999px; white-space: nowrap; animation: pop .4s ease; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.7); } }
.toast { animation-name: toastIn; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px); } }

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