:root {
  --bg: #03060c;
  --panel-top: rgba(14, 30, 58, 0.92);
  --panel-bottom: rgba(6, 13, 27, 0.95);
  --line: rgba(86, 170, 255, 0.32);
  --line-soft: rgba(86, 170, 255, 0.14);
  --line-strong: rgba(120, 195, 255, 0.75);
  --tint: rgba(42, 134, 245, 0.08);
  --text: #e4eeff;
  --muted: #93a8c9;
  --dim: #6a7f9e;
  --accent: #62bcff;
  --accent-strong: #2a86f5;
  --ok: #55e3a6;
  --warn: #ffc163;
  --bad: #ff6b7b;
  --violet: #b592ff;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Roboto Mono", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg) radial-gradient(120% 55% at 50% -10%, #0c2147 0%, rgba(3, 6, 12, 0) 65%) fixed;
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Icons */
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Shell */
.topbar { position: sticky; top: 0; z-index: 5; background: rgba(3, 6, 12, 0.86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line-soft); padding-top: env(safe-area-inset-top); }
.topbar .in { max-width: 480px; margin: 0 auto; padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; }
.brand { font-size: 12px; font-weight: 600; letter-spacing: 0.28em; text-transform: uppercase; color: var(--accent); }
.lv { font-size: 12px; color: var(--muted); }
.wrap { max-width: 480px; margin: 0 auto; padding: 14px 16px calc(96px + env(safe-area-inset-bottom)); }
.banner { max-width: 480px; margin: 10px auto 0; padding: 10px 14px; border: 1px solid rgba(255, 107, 123, 0.5); border-radius: 6px; color: var(--bad); font-size: 13px; }

/* System window */
.win {
  position: relative;
  margin: 0 0 12px;
  padding: 14px;
  background: linear-gradient(180deg, var(--panel-top), var(--panel-bottom));
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(98, 188, 255, 0.06), 0 0 22px rgba(30, 120, 255, 0.14);
}
.win::before, .win::after { content: ""; position: absolute; width: 14px; height: 14px; border: 2px solid var(--accent); pointer-events: none; }
.win::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; border-top-left-radius: 6px; }
.win::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; border-bottom-right-radius: 6px; }
.win.cleared { border-color: rgba(85, 227, 166, 0.5); box-shadow: inset 0 0 0 1px rgba(85, 227, 166, 0.08), 0 0 22px rgba(85, 227, 166, 0.12); }
.win.cleared::before, .win.cleared::after { border-color: var(--ok); }
.win.locked { opacity: 0.65; }
.notices { padding: 10px 14px; }

.tag { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; font-size: 11px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); background: rgba(42, 134, 245, 0.09); border: 1px solid var(--line); border-radius: 4px; }
.tag .ic { width: 14px; height: 14px; }
.h { margin: 10px 0 2px; font-size: 19px; font-weight: 600; letter-spacing: 0.01em; }
.sub { margin: 0; font-size: 13.5px; color: var(--muted); }
.label { font-size: 11px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--dim); }
.mono { font-family: var(--mono); }
.small { font-size: 12.5px; }
.dim { color: var(--dim); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.mt { margin-top: 14px; }
.mt-s { margin-top: 8px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap { gap: 10px; }
.grow { flex: 1; min-width: 0; }
.note { margin: 12px 0 0; padding-top: 10px; border-top: 1px dashed var(--line-soft); font-size: 12.5px; color: var(--dim); }
.sysline { margin: 4px 0; font-size: 13.5px; }
.sysline span { color: var(--accent); font-weight: 600; }
.sysline.warn { color: var(--warn); }

/* Day header */
.dayhead { display: flex; justify-content: space-between; align-items: flex-end; margin: 2px 0 12px; }
.date { font-size: 17px; font-weight: 600; }
.pills { display: flex; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; font-family: var(--mono); font-size: 13px; background: var(--tint); border: 1px solid var(--line); border-radius: 999px; }
.pill .ic { width: 15px; height: 15px; }
.pill.streak .ic { color: var(--warn); }
.pill.potion .ic { color: var(--violet); }
.seg { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { padding: 8px; border: 0; background: none; font-size: 13px; color: var(--muted); }
.seg button.on { background: rgba(42, 134, 245, 0.18); color: var(--text); }

/* Quest rows */
.q { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 0; border: 0; border-top: 1px solid var(--line-soft); background: none; text-align: left; }
.label + .q { border-top: 0; }
button.q:active { background: rgba(98, 188, 255, 0.05); }
.q .box { display: grid; place-items: center; flex: none; width: 22px; height: 22px; border: 1.5px solid var(--line-strong); border-radius: 4px; transition: background 0.2s, border-color 0.2s, box-shadow 0.2s; }
.q .box .ic { width: 15px; height: 15px; stroke-width: 2.6; color: #fff; }
.q.done .box { background: var(--accent-strong); border-color: var(--accent); box-shadow: 0 0 10px rgba(42, 134, 245, 0.55); }
.q .t { flex: 1; min-width: 0; }
.q .t b { display: flex; align-items: center; gap: 7px; font-weight: 500; }
.q .t small { display: block; margin-top: 1px; font-size: 12.5px; color: var(--muted); }
.q.done .t small { color: var(--dim); }
.q .qi { width: 16px; height: 16px; color: var(--accent); }
.q .xp { font-family: var(--mono); font-size: 12px; color: var(--accent); white-space: nowrap; }
.q.done .xp { color: var(--ok); }
.indent { padding: 0 0 10px 34px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; font-size: 13px; background: var(--tint); border: 1px solid var(--line); border-radius: 999px; }
.chip .ic { width: 16px; height: 16px; }
.chip.on { background: var(--accent-strong); border-color: var(--accent); color: #fff; }
.chip:disabled { opacity: 0.35; cursor: default; }
.moods { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.mchip { display: flex; flex-direction: column; align-items: center; padding: 7px 0 6px; background: var(--tint); border: 1px solid var(--line); border-radius: 6px; }
.mchip b { font-family: var(--mono); font-size: 15px; font-weight: 600; }
.mchip small { font-size: 10.5px; color: var(--muted); }
.mchip.on { background: var(--accent-strong); border-color: var(--accent); }
.mchip.on small { color: #dbeaff; }

/* Bars */
.bar { height: 8px; margin-top: 6px; background: rgba(98, 188, 255, 0.12); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-strong), var(--accent)); border-radius: inherit; box-shadow: 0 0 10px rgba(98, 188, 255, 0.6); transition: width 0.6s ease; }
.bar.boss { height: 10px; background: rgba(255, 107, 123, 0.14); }
.bar.boss > i { background: linear-gradient(90deg, #b8253d, var(--bad)); box-shadow: 0 0 10px rgba(255, 107, 123, 0.5); }

/* Status */
.profile { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; margin-top: 12px; }
.right { text-align: right; }
.big { font-size: 18px; font-weight: 600; }
.lvl { font-family: var(--mono); font-size: 34px; font-weight: 600; line-height: 1; color: var(--accent); text-shadow: 0 0 14px rgba(98, 188, 255, 0.6); }
.rankline { display: flex; align-items: center; gap: 12px; margin: 14px 0 4px; }
.rank { display: grid; place-items: center; width: 40px; height: 40px; font-family: var(--mono); font-size: 20px; font-weight: 700; color: var(--accent); border: 1px solid var(--line-strong); border-radius: 6px; }
.rankline b { display: block; font-weight: 500; }
.rankline small { font-size: 12.5px; color: var(--muted); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; margin-top: 12px; }
.stat { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-top: 1px solid var(--line-soft); }
.stat b { font-family: var(--mono); font-weight: 600; letter-spacing: 0.06em; }
.stat small { display: block; font-size: 11px; color: var(--dim); }
.stat .val { display: flex; align-items: baseline; gap: 4px; font-family: var(--mono); font-size: 18px; font-weight: 600; }
.stat .val span { font-size: 12px; }
.effect { display: flex; flex-direction: column; margin-top: 8px; padding: 8px 10px; font-size: 13px; border: 1px solid; border-radius: 6px; }
.effect b { font-weight: 600; }
.effect span { font-size: 12.5px; color: var(--muted); }
.effect.debuff { border-color: rgba(255, 193, 99, 0.4); background: rgba(255, 193, 99, 0.07); }
.effect.debuff b { color: var(--warn); }
.effect.buff { border-color: rgba(85, 227, 166, 0.4); background: rgba(85, 227, 166, 0.07); }
.effect.buff b { color: var(--ok); }
.effect.info { border-color: var(--line); background: var(--tint); }
.effect.info b { color: var(--accent); }
.arcs { margin: 14px 0 0; padding: 0; list-style: none; }
.arcs li { display: flex; align-items: center; gap: 8px; padding: 7px 0; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line-soft); }
.arcs li span:first-of-type { flex: 1; }
.arcs li.ok { color: var(--ok); }
.arcs li.dim { opacity: 0.5; }
.arcs .ic { width: 16px; height: 16px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 8px; margin: 12px 0 8px; }
.metrics div { padding: 8px 10px; background: var(--tint); border: 1px solid var(--line-soft); border-radius: 6px; }
.metrics small { display: block; font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.metrics b { font-family: var(--mono); font-size: 17px; font-weight: 600; }

/* Gate */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 12px; }
.wd { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; background: rgba(42, 134, 245, 0.04); border: 1px solid var(--line-soft); border-radius: 6px; }
.wd small { font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); }
.wd b { font-family: var(--mono); font-size: 15px; }
.wd i { display: grid; place-items: center; height: 16px; }
.wd i .ic { width: 15px; height: 15px; }
.wd.today { border-color: var(--line-strong); }
.wd.planned { background: rgba(42, 134, 245, 0.2); border-color: var(--accent); }
.wd.cleared i { color: var(--ok); }
.wd:disabled { opacity: 0.45; cursor: default; }
.big-btn { margin-bottom: 12px; padding: 16px; font-size: 16px; letter-spacing: 0.1em; text-transform: uppercase; }
.hist { margin: 10px 0 0; padding: 0; list-style: none; }
.hist li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line-soft); }
.hist li > div, .rowbtn > div { min-width: 0; }
.hist b { display: block; font-weight: 500; }
.hist small { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.rowbtn { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 0; border: 0; background: none; text-align: left; }
.rowbtn .ic { color: var(--dim); }
.chart { display: block; width: 100%; height: auto; margin-top: 6px; color: var(--accent); }
.chart circle { fill: var(--accent); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 16px; font-weight: 500; letter-spacing: 0.02em; background: rgba(42, 134, 245, 0.12); border: 1px solid var(--line-strong); border-radius: 6px; }
.btn.primary { background: var(--accent-strong); border-color: var(--accent); color: #fff; box-shadow: 0 0 18px rgba(42, 134, 245, 0.4); }
.btn.block { width: 100%; }
.btn.ghost { padding-left: 0; padding-right: 0; background: none; border-color: transparent; color: var(--accent); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.danger { background: rgba(255, 107, 123, 0.08); border-color: rgba(255, 107, 123, 0.5); color: var(--bad); }
.btn:active { transform: scale(0.98); }
.iconbtn { display: grid; place-items: center; flex: none; width: 36px; height: 36px; background: none; border: 1px solid transparent; border-radius: 6px; color: var(--muted); }
.iconbtn:active { background: rgba(98, 188, 255, 0.1); }

/* Tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); background: rgba(3, 6, 12, 0.94); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line-soft); }
.tabbar .in { display: flex; max-width: 480px; margin: 0 auto; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 0; font-size: 10.5px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); background: none; border: 0; }
.tab .ic { width: 22px; height: 22px; }
.tab.on { color: var(--accent); }
.tab.on .ic { filter: drop-shadow(0 0 6px rgba(98, 188, 255, 0.7)); }

/* Overlays */
.scrim { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; background: rgba(0, 3, 10, 0.74); animation: fade 0.18s ease-out; }
.scrim.center { align-items: center; padding: 20px; }
.sheet { display: flex; flex-direction: column; width: 100%; max-width: 480px; max-height: 90dvh; background: #06101f; border: 1px solid var(--line); border-bottom: 0; border-radius: 12px 12px 0 0; box-shadow: 0 -12px 40px rgba(20, 100, 255, 0.2); animation: rise 0.24s ease-out; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px 6px; }
.sheet-head .h { margin-top: 8px; }
.sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 6px 16px 16px; }
.sheet-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line-soft); }
.modal { width: 100%; max-width: 380px; margin: 0; transform-origin: center; animation: open 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.15); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
@keyframes open { from { transform: scaleY(0.15); opacity: 0; } }

/* Forms */
fieldset { margin: 14px 0 0; padding: 0; border: 0; }
legend { margin-bottom: 8px; padding: 0; font-size: 13px; color: var(--muted); }
.seg2, .seg3 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg3 { grid-template-columns: repeat(3, 1fr); }
.seg2 label, .seg3 label { position: relative; }
.seg2 input, .seg3 input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg2 span, .seg3 span { display: block; padding: 10px; text-align: center; background: rgba(42, 134, 245, 0.06); border: 1px solid var(--line); border-radius: 6px; }
.seg2 input:checked + span, .seg3 input:checked + span { background: var(--accent-strong); border-color: var(--accent); color: #fff; }
.seg2 input:focus-visible + span, .seg3 input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.drinks { display: none; margin-top: 12px; }
.rform.drank .drinks { display: block; }
.drink { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line-soft); }
.drink b { display: block; font-size: 14px; font-weight: 500; }
.drink small { font-size: 12px; color: var(--muted); }
.sub-drink { padding-top: 0; padding-left: 12px; border-top: 0; }
.stepper { display: flex; align-items: center; flex: none; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.stepper button { display: grid; place-items: center; width: 38px; height: 38px; background: rgba(42, 134, 245, 0.1); border: 0; }
.stepper input { width: 44px; height: 38px; font-family: var(--mono); font-size: 15px; text-align: center; background: none; border: 0; -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.wide .stepper { width: 100%; }
.wide .stepper input { flex: 1; }
.total { margin: 10px 0 0; padding: 10px; font-size: 13px; text-align: center; color: var(--warn); background: rgba(255, 193, 99, 0.07); border: 1px solid rgba(255, 193, 99, 0.3); border-radius: 6px; }
.field { display: block; margin-top: 14px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; padding: 11px 12px; background: rgba(3, 8, 18, 0.7); border: 1px solid var(--line); border-radius: 6px; }
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(42, 134, 245, 0.25); }
.err { margin: 12px 0 0; font-size: 13px; color: var(--bad); }

/* Onboarding */
.ob { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 24px 16px; }
.ob-win { width: 100%; max-width: 420px; padding: 20px; }
.ob-text { margin: 18px 0 6px; font-size: 18px; line-height: 1.45; }
.ob-text b { color: var(--accent); }
.ob-q { margin: 14px 0 12px; color: var(--muted); }
.ob-list { margin: 10px 0; padding-left: 18px; color: var(--muted); }
.ob-list li { margin: 4px 0; }

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