/* Awaken - "System window" UI. Dark holographic panels, cyan glow, mobile-first. */
:root {
  --bg: #04060d;
  --bg2: #07101f;
  --panel: rgba(8, 18, 38, 0.86);
  --panel2: rgba(14, 30, 60, 0.7);
  --line: rgba(76, 201, 255, 0.45);
  --line-soft: rgba(76, 201, 255, 0.18);
  --glow: #4cc9ff;
  --glow2: #8fe3ff;
  --text: #dcefff;
  --muted: #7f97b6;
  --gold: #ffc14d;
  --danger: #ff4d6d;
  --ok: #5ef2b4;
  --radius: 6px;
  --nav-h: 64px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Roboto Mono', Consolas, monospace;
  /* Capacitor 8 injects --safe-area-inset-* on Android; browsers use env(). */
  --sat: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --sab: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(40, 110, 200, 0.22), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, rgba(120, 60, 220, 0.14), transparent 60%),
    linear-gradient(transparent 0 calc(100% - 1px), rgba(76, 201, 255, 0.04) 0) 0 0 / 100% 32px,
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--panel); padding: 8px; }

/* ---------- shell */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 10px) 16px 10px;
  background: linear-gradient(var(--bg), rgba(4, 6, 13, 0.85));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { font-weight: 800; letter-spacing: 0.3em; color: var(--glow2); text-shadow: 0 0 12px rgba(76, 201, 255, 0.6); }
.brand-mark { color: var(--glow); }
.sys-chip { font: 600 11px var(--mono); letter-spacing: 0.2em; color: var(--muted); }

main { max-width: 560px; margin: 0 auto; padding: 14px 16px calc(var(--nav-h) + var(--sab) + 24px); outline: none; }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + var(--sab));
  padding-bottom: var(--sab);
  background: rgba(4, 8, 18, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line-soft);
}
#tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; letter-spacing: 0.06em;
}
#tabs a span { font-size: 18px; line-height: 1; }
#tabs a[aria-current='page'] { color: var(--glow2); text-shadow: 0 0 10px rgba(76, 201, 255, 0.7); }
body.fullscreen #tabs, body.fullscreen .topbar { display: none; }
body.fullscreen main { padding-top: calc(var(--sat) + 14px); padding-bottom: calc(var(--sab) + 24px); }

/* ---------- System window */
.stack { display: grid; gap: 14px; }
.win {
  position: relative;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 0 22px rgba(76, 201, 255, 0.16), inset 0 0 28px rgba(76, 201, 255, 0.06);
  animation: rise 0.28s ease-out both;
}
.win::before, .win::after {
  content: ''; position: absolute; width: 14px; height: 14px; pointer-events: none;
  border: 2px solid var(--glow2); filter: drop-shadow(0 0 4px var(--glow));
}
.win::before { top: -2px; left: -2px; border-right: 0; border-bottom: 0; }
.win::after { bottom: -2px; right: -2px; border-left: 0; border-top: 0; }
.win.gold { --line: rgba(255, 193, 77, 0.55); --glow2: #ffd98a; --glow: var(--gold); box-shadow: 0 0 24px rgba(255, 193, 77, 0.18), inset 0 0 28px rgba(255, 193, 77, 0.06); }
.win.danger { --line: rgba(255, 77, 109, 0.6); --glow2: #ff8fa3; --glow: var(--danger); box-shadow: 0 0 24px rgba(255, 77, 109, 0.22), inset 0 0 28px rgba(255, 77, 109, 0.07); }
.win-h {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line-soft);
}
.win-t { font: 700 13px var(--font); letter-spacing: 0.22em; color: var(--glow2); text-shadow: 0 0 10px rgba(76, 201, 255, 0.5); }
.win-tag { font: 600 11px var(--mono); color: var(--muted); letter-spacing: 0.1em; }
.win-b { padding: 14px; display: grid; gap: 10px; }
.win-b > * { margin: 0; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- type & utils */
h1 { font-size: 26px; letter-spacing: 0.08em; margin: 6px 0; line-height: 1.2; }
.glow { color: var(--glow2); text-shadow: 0 0 14px rgba(76, 201, 255, 0.75); }
.gold { color: var(--gold); }
.gold.glow { color: #ffd98a; text-shadow: 0 0 16px rgba(255, 193, 77, 0.7); }
.danger-t { color: var(--danger); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.block { display: block; }
.center { text-align: center; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.gap { gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.warn { color: #ffb4c1; border-left: 2px solid var(--danger); padding-left: 8px; }
.big-num { font-size: 34px; font-weight: 800; }
.big-t { font-size: 20px; font-weight: 800; }
a { color: var(--glow2); }
ol, ul { margin: 0; padding-left: 20px; }
ol li, .bullets li { margin: 3px 0; }
details summary { cursor: pointer; color: var(--glow2); font-weight: 600; padding: 4px 0; }
details[open] summary { margin-bottom: 6px; }
details > * + * { margin-top: 8px; }

/* ---------- controls */
.btn {
  appearance: none; border: 1px solid var(--line); background: rgba(76, 201, 255, 0.08); color: var(--text);
  border-radius: var(--radius); padding: 10px 14px; font: 600 14px var(--font); letter-spacing: 0.06em;
  cursor: pointer; min-height: 44px; transition: background 0.15s, box-shadow 0.15s, transform 0.05s;
}
.btn:hover { background: rgba(76, 201, 255, 0.16); }
.btn:active { transform: scale(0.98); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--glow2); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, rgba(76, 201, 255, 0.35), rgba(40, 120, 220, 0.3)); border-color: var(--glow); box-shadow: 0 0 16px rgba(76, 201, 255, 0.35); color: #fff; }
.btn.danger { border-color: var(--danger); background: rgba(255, 77, 109, 0.14); color: #ffd0d8; }
.btn.ghost { background: transparent; border-color: var(--line-soft); color: var(--muted); }
.btn.big { width: 100%; padding: 14px; font-size: 16px; letter-spacing: 0.18em; }
.btn.icon { min-width: 44px; padding: 8px; font-size: 18px; line-height: 1; }
.btn.icon.sm { min-width: 36px; min-height: 36px; font-size: 13px; }
.btn.icon.lg { min-width: 56px; min-height: 56px; font-size: 20px; border-radius: 50%; }
.btn.icon.xl { min-width: 76px; min-height: 76px; font-size: 26px; border-radius: 50%; }

.text-in, .select, .step-in, textarea {
  width: 100%; background: rgba(0, 0, 0, 0.35); color: var(--text); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 11px 12px; font: 16px var(--font); min-height: 44px;
}
.stepper { display: flex; align-items: stretch; gap: 6px; }
.step-in { width: 84px; text-align: center; font: 700 20px var(--mono); -moz-appearance: textfield; }
.step-in::-webkit-outer-spin-button, .step-in::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.seg { display: flex; gap: 4px; padding: 3px; border: 1px solid var(--line-soft); border-radius: var(--radius); background: rgba(0, 0, 0, 0.3); }
.seg-b { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px 6px; border-radius: 4px; font: 600 13px var(--font); cursor: pointer; min-height: 40px; white-space: nowrap; }
.seg-b.on { background: rgba(76, 201, 255, 0.2); color: #fff; box-shadow: inset 0 0 0 1px var(--glow); }
.tabs-scroll { overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.tabs-scroll::-webkit-scrollbar { display: none; }
.tabs-scroll .seg { width: max-content; min-width: 100%; }

.toggle { cursor: pointer; padding: 6px 0; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { width: 46px; height: 26px; border-radius: 13px; background: rgba(127, 151, 182, 0.3); position: relative; flex: none; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #cfe3f7; transition: transform 0.2s; }
.toggle input:checked + .switch { background: rgba(76, 201, 255, 0.7); box-shadow: 0 0 10px rgba(76, 201, 255, 0.5); }
.toggle input:checked + .switch::after { transform: translateX(20px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--glow2); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 600 11.5px var(--mono); letter-spacing: 0.05em; padding: 4px 8px; border: 1px solid var(--line-soft); border-radius: 999px; color: var(--glow2); background: rgba(76, 201, 255, 0.06); }

.bar { height: 8px; background: rgba(127, 151, 182, 0.18); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #2a8bff, var(--glow), #b8f1ff); box-shadow: 0 0 10px var(--glow); border-radius: 4px; transition: width 0.3s; }
.bar.thin { height: 4px; }

.banner { border: 1px solid; border-radius: var(--radius); padding: 10px 12px; }
.banner p { margin: 4px 0 8px; }
.banner.danger { border-color: var(--danger); background: rgba(255, 77, 109, 0.1); color: #ffd0d8; }
.banner.gold { border-color: var(--gold); background: rgba(255, 193, 77, 0.08); }

/* ---------- status */
.status-top { display: flex; align-items: center; gap: 14px; }
.lv { display: grid; text-align: center; min-width: 64px; }
.lv small { font: 700 10px var(--mono); letter-spacing: 0.2em; color: var(--muted); }
.lv strong { font-size: 44px; line-height: 1; font-weight: 800; }
.who { flex: 1; min-width: 0; }
.who .name { font-size: 20px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank {
  width: 54px; height: 54px; display: grid; place-items: center; flex: none;
  font: 900 28px var(--font); border: 2px solid currentColor; border-radius: 8px; transform: rotate(45deg);
  box-shadow: 0 0 16px currentColor, inset 0 0 12px currentColor;
}
.rank > * { transform: rotate(-45deg); }
.rank-E { color: #9aa9bd; } .rank-D { color: #5ef2b4; } .rank-C { color: #4cc9ff; }
.rank-B { color: #b18cff; } .rank-A { color: #ff6b8b; } .rank-S { color: #ffc14d; }
.xp-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 10px; border: 1px solid var(--line-soft); border-radius: 4px; background: rgba(0, 0, 0, 0.25); font-family: var(--mono); font-size: 12px; }
.stat strong { font-size: 16px; color: #fff; }

/* ---------- quest */
.q-goal { font-size: 14px; }
.q-list { list-style: none; padding: 0; display: grid; gap: 2px; }
.q-line { display: flex; align-items: center; gap: 10px; padding: 7px 2px; border-bottom: 1px dashed rgba(76, 201, 255, 0.12); font-size: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; box-shadow: 0 0 8px currentColor; }
.q-total { display: flex; justify-content: space-between; font-weight: 700; }
.cleared { text-align: center; font: 800 20px var(--font); letter-spacing: 0.3em; color: var(--ok); text-shadow: 0 0 14px rgba(94, 242, 180, 0.7); padding: 6px; border: 1px solid rgba(94, 242, 180, 0.5); border-radius: var(--radius); }

/* ---------- session */
.session { display: grid; gap: 12px; }
.ses-top { display: flex; align-items: center; gap: 10px; }
.ses-disc { font: 700 12px var(--mono); letter-spacing: 0.25em; text-align: center; margin-top: 4px; }
.ses-title { text-align: center; font-size: 22px; margin: 0; }
.ring { position: relative; width: min(64vw, 240px); aspect-ratio: 1; margin: 0 auto; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(127, 151, 182, 0.15); stroke-width: 6; }
.ring-arc { fill: none; stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset 0.2s linear; }
.ring::before { content: ''; position: absolute; inset: 5%; border-radius: 50%; box-shadow: 0 0 34px rgba(76, 201, 255, 0.28), inset 0 0 24px rgba(76, 201, 255, 0.12); pointer-events: none; }
.ring-time { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(40px, 13vw, 60px); font-weight: 700; text-shadow: 0 0 16px rgba(76, 201, 255, 0.6); }
.cue { text-align: center; font-size: clamp(24px, 8vw, 34px); font-weight: 800; letter-spacing: 0.04em; min-height: 1.4em; color: #fff; text-shadow: 0 0 16px rgba(76, 201, 255, 0.8); }
.cue.pop { animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: scale(1.18); opacity: 0.4; } to { transform: none; opacity: 1; } }
.reps-box { display: grid; justify-items: center; gap: 6px; }
.reps-target { font-size: 44px; font-weight: 800; line-height: 1; }
.controls { display: flex; align-items: center; justify-content: center; gap: 22px; }
.howto { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 8px 12px; }
.videos { display: grid; gap: 6px; }
.video { display: flex; gap: 10px; align-items: center; text-decoration: none; color: var(--text); padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: var(--radius); background: rgba(0, 0, 0, 0.25); font-size: 13.5px; }
.video:hover { border-color: var(--line); }
.play { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: 50%; background: rgba(255, 60, 60, 0.85); color: #fff; font-size: 12px; }
.reward { font-size: 30px; font-weight: 800; color: var(--gold); text-shadow: 0 0 16px rgba(255, 193, 77, 0.6); margin: 4px 0; }

/* ---------- log / chart */
.chart { width: 100%; height: auto; }
.bar-r { fill: rgba(76, 201, 255, 0.55); }
.bar-today { fill: var(--gold); }
.bar-v { fill: var(--text); font: 8px var(--mono); }
.bar-l { fill: var(--muted); font: 8px var(--mono); }
.axis { stroke: rgba(127, 151, 182, 0.35); }
.hist { list-style: none; padding: 0; }
.hist li { padding: 6px 0; border-bottom: 1px solid rgba(76, 201, 255, 0.08); }

/* ---------- calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-d {
  aspect-ratio: 1; display: grid; place-items: center; align-content: center; gap: 0;
  border: 1px solid var(--line-soft); border-radius: 4px; background: rgba(0, 0, 0, 0.25); color: var(--text);
  font: 600 13px var(--mono); cursor: pointer; padding: 0; min-height: 40px;
}
.cal-i { font-size: 9px; color: var(--muted); }
.cal-d.done { background: rgba(94, 242, 180, 0.18); border-color: var(--ok); box-shadow: 0 0 8px rgba(94, 242, 180, 0.35); }
.cal-d.miss { background: rgba(255, 77, 109, 0.12); border-color: rgba(255, 77, 109, 0.6); }
.cal-d.today { border: 2px solid var(--glow2); box-shadow: 0 0 12px var(--glow); }
.cal-d.future { opacity: 0.55; }
.cal-d.rest .cal-n { font-style: italic; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.lg { width: 12px; height: 12px; border-radius: 3px; border: 1px solid; display: inline-block; }
.lg.done { background: rgba(94, 242, 180, 0.3); border-color: var(--ok); }
.lg.miss { background: rgba(255, 77, 109, 0.2); border-color: var(--danger); }
.lg.today { border: 2px solid var(--glow2); }

/* ---------- onboarding */
.awaken { display: grid; gap: 14px; padding-top: 4vh; }
.awaken-win .win-b { gap: 14px; }
.brand-big { font-size: 40px; letter-spacing: 0.35em; margin: 8px 0 0; }
.dots { display: flex; justify-content: center; gap: 6px; }
.dots span { width: 22px; height: 3px; background: rgba(127, 151, 182, 0.3); border-radius: 2px; }
.dots span.on { background: var(--glow); box-shadow: 0 0 6px var(--glow); }
.typed p { margin: 6px 0; opacity: 0; animation: typein 0.5s ease-out forwards; }
@keyframes typein { from { opacity: 0; clip-path: inset(0 100% 0 0); } to { opacity: 1; clip-path: inset(0 0 0 0); } }
.assess { display: grid; gap: 6px; padding: 12px; border: 1px solid var(--line-soft); border-radius: var(--radius); background: rgba(0, 0, 0, 0.2); }
.agree { align-items: flex-start; }
.agree input { width: 22px; height: 22px; accent-color: var(--glow); flex: none; margin-top: 1px; }

/* ---------- modal + toast */
.sys-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0, 4, 12, 0.72); backdrop-filter: blur(3px); animation: fade 0.18s ease-out; }
.sys-overlay.out { animation: fade 0.16s ease-in reverse forwards; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sys-win {
  width: min(440px, 100%); max-height: 86dvh; overflow: auto;
  background: linear-gradient(180deg, rgba(14, 32, 64, 0.97), rgba(6, 14, 30, 0.98));
  border: 1px solid var(--glow); border-radius: var(--radius);
  box-shadow: 0 0 40px rgba(76, 201, 255, 0.35), inset 0 0 30px rgba(76, 201, 255, 0.1);
  animation: sysin 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes sysin { from { transform: scaleY(0.2); opacity: 0; } to { transform: none; opacity: 1; } }
.tone-gold .sys-win { border-color: var(--gold); box-shadow: 0 0 40px rgba(255, 193, 77, 0.35), inset 0 0 30px rgba(255, 193, 77, 0.08); }
.tone-danger .sys-win { border-color: var(--danger); box-shadow: 0 0 40px rgba(255, 77, 109, 0.4), inset 0 0 30px rgba(255, 77, 109, 0.1); }
.sys-head { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line-soft); font: 800 14px var(--font); letter-spacing: 0.25em; color: var(--glow2); }
.tone-gold .sys-head { color: #ffd98a; }
.tone-danger .sys-head { color: #ff8fa3; }
.sys-icon { width: 22px; height: 22px; border: 1.5px solid currentColor; border-radius: 4px; display: grid; place-items: center; font: 800 13px var(--mono); }
.sys-body { padding: 14px 16px; display: grid; gap: 8px; text-align: center; }
.sys-body p { margin: 0; }
.sys-body .q-list { text-align: left; }
.sys-actions { display: flex; gap: 8px; padding: 0 16px 16px; }
.sys-actions .btn { flex: 1; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--sab) + 14px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; transition: 0.25s;
  background: rgba(8, 22, 44, 0.96); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; max-width: calc(100% - 32px); box-shadow: 0 0 18px rgba(76, 201, 255, 0.3); font-size: 14px;
}
.toast.in { transform: translate(-50%, 0); opacity: 1; }

@media (min-width: 700px) {
  main { padding-top: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .typed p { opacity: 1; }
}
