:root {
  --bg: #04060c;
  --panel: rgba(8, 20, 40, 0.82);
  --line: #2f8fff;
  --line-dim: rgba(47, 143, 255, 0.35);
  --glow: rgba(47, 143, 255, 0.5);
  --text: #dceaff;
  --dim: #7d91b2;
  --accent: #5cc8ff;
  --gold: #ffd166;
  --red: #ff4d5e;
  --red-glow: rgba(255, 77, 94, 0.5);
  --green: #4dffb0;
  --font: 'Rajdhani', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Share Tech Mono', ui-monospace, 'SF Mono', Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  font-weight: 500;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 120% 60% at 50% -10%, #0d2448 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
  overscroll-behavior-y: none;
  -webkit-user-select: none;
  user-select: none;
}

input, select, textarea { -webkit-user-select: text; user-select: text; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- HUD ---------- */
.hud { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hud-l { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hud-lv {
  font-family: var(--mono);
  border: 1px solid var(--line);
  box-shadow: 0 0 12px var(--glow), inset 0 0 10px rgba(47, 143, 255, .2);
  padding: 6px 10px;
  font-size: 14px;
  color: var(--accent);
  white-space: nowrap;
}
.hud-lv b { font-size: 22px; color: #fff; margin-left: 2px; }
.hud-name { font-weight: 700; font-size: 19px; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-sub { font-size: 13px; color: var(--dim); letter-spacing: .08em; text-transform: uppercase; }
.hud-streak { text-align: right; font-family: var(--mono); font-size: 24px; color: var(--gold); text-shadow: 0 0 10px rgba(255, 209, 102, .5); line-height: 1; }
.hud-streak small { display: block; font-size: 10px; letter-spacing: .15em; color: var(--dim); text-shadow: none; margin-top: 4px; }

.xpbar { height: 6px; background: rgba(47, 143, 255, .12); border: 1px solid var(--line-dim); margin-top: 12px; overflow: hidden; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, #1c6dff, var(--accent)); box-shadow: 0 0 10px var(--accent); transition: width .5s ease; }
.xptext { font-family: var(--mono); font-size: 12px; color: var(--dim); text-align: right; margin-top: 4px; }

/* ---------- System window ---------- */
.win {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 0 18px var(--glow), inset 0 0 28px rgba(47, 143, 255, .12);
  padding: 20px 16px 18px;
  margin: 18px 0;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: winIn .35s ease both;
}
.win::before, .win::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border-color: var(--accent);
  border-style: solid;
  pointer-events: none;
}
.win::before { top: -3px; left: -3px; border-width: 3px 0 0 3px; }
.win::after { bottom: -3px; right: -3px; border-width: 0 3px 3px 0; }

@keyframes winIn {
  from { opacity: 0; transform: scaleY(.92); filter: brightness(2); }
  to { opacity: 1; transform: none; filter: none; }
}

.win-title {
  width: fit-content;
  margin: 0 auto 14px;
  padding: 4px 18px;
  border: 1px solid var(--line);
  font-weight: 700;
  letter-spacing: .25em;
  text-transform: uppercase;
  font-size: 15px;
  text-shadow: 0 0 8px var(--glow);
  box-shadow: inset 0 0 12px rgba(47, 143, 255, .2);
}

.sys-line { text-align: center; color: var(--accent); margin: 0 0 16px; font-size: 16px; letter-spacing: .03em; }
.sys-small { font-family: var(--mono); color: var(--accent); font-size: 13px; letter-spacing: .2em; text-align: center; }
.section-h { font-weight: 700; letter-spacing: .3em; font-size: 13px; color: var(--dim); text-align: center; margin: 4px 0 10px; }
.dim { color: var(--dim); }
.gold { color: var(--gold); }
.center { text-align: center; }
.small { font-size: 14px; }

/* ---------- Quests ---------- */
.quest { padding: 10px 0 8px; border-bottom: 1px solid rgba(47, 143, 255, .14); }
.quest:last-of-type { border-bottom: 0; }
.q-row { display: flex; align-items: center; gap: 10px; }
.q-main { flex: 1; min-width: 0; }
.q-name { font-weight: 600; font-size: 18px; line-height: 1.15; }
.q-meta { font-family: var(--mono); font-size: 11px; color: var(--dim); letter-spacing: .08em; margin-top: 2px; }
.quest.done .q-name { color: var(--accent); }
.quest.done .q-name::after { content: ' ✓'; color: var(--green); }

.q-ctrl { display: flex; align-items: center; gap: 6px; }
.btn-sm {
  min-width: 44px; height: 40px;
  padding: 0 8px;
  background: rgba(47, 143, 255, .1);
  border: 1px solid var(--line-dim);
  font-family: var(--mono);
  font-size: 15px;
}
.btn-sm:active { background: rgba(47, 143, 255, .35); }
.q-val {
  min-width: 64px; height: 40px;
  background: none; border: 0;
  font-family: var(--mono); font-size: 15px;
  text-align: center;
}
.q-val small { display: block; font-size: 10px; color: var(--dim); margin-top: -2px; }

.check {
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  background: rgba(47, 143, 255, .08);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.check svg { width: 22px; height: 22px; stroke: var(--green); stroke-width: 3; fill: none; opacity: 0; transform: scale(.4); transition: .2s; }
.quest.done .check { border-color: var(--green); box-shadow: 0 0 10px rgba(77, 255, 176, .35); }
.quest.done .check svg { opacity: 1; transform: none; }
.q-tap { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; padding: 0; text-align: left; }

.q-bar { height: 3px; background: rgba(47, 143, 255, .1); margin-top: 8px; }
.q-bar i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.quest.done .q-bar i { background: var(--green); }

.quest.penalty .q-name { color: var(--red); }
.quest.penalty .check { border-color: var(--red); }
.quest.penalty.done .q-name { color: var(--green); }

.warn { color: var(--red); text-align: center; font-size: 15px; margin: 16px 0 6px; line-height: 1.3; }
.warn b { text-shadow: 0 0 8px var(--red-glow); }
.reset { text-align: center; font-family: var(--mono); font-size: 13px; color: var(--dim); }

.complete-banner { text-align: center; padding: 10px 0 4px; }
.complete-banner .big {
  font-size: 28px; font-weight: 700; letter-spacing: .14em;
  color: var(--green); text-shadow: 0 0 14px rgba(77, 255, 176, .55);
}
.complete-banner p { margin: 8px 0 0; line-height: 1.35; }

/* ---------- Status ---------- */
.st-top { display: flex; gap: 16px; align-items: center; }
.lvl { text-align: center; min-width: 84px; }
.lvl-n { font-family: var(--mono); font-size: 60px; line-height: 1; color: #fff; text-shadow: 0 0 18px var(--glow); }
.lvl-l { letter-spacing: .3em; font-size: 12px; color: var(--dim); font-weight: 700; }
.st-info { flex: 1; min-width: 0; display: grid; gap: 4px; }
.kv { display: flex; gap: 8px; font-size: 16px; align-items: baseline; }
.kv span:first-child { color: var(--dim); font-size: 13px; letter-spacing: .12em; min-width: 52px; }
.kv span:last-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv select { flex: 1; min-width: 0; }

.hr { height: 1px; background: linear-gradient(90deg, transparent, var(--line), transparent); margin: 16px 0; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.stat { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-k { font-family: var(--mono); color: var(--accent); font-size: 15px; }
.stat-v { font-family: var(--mono); font-size: 22px; margin-left: auto; }
.stat .plus {
  width: 32px; height: 32px;
  background: rgba(255, 209, 102, .12);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-family: var(--mono);
  font-size: 18px;
  line-height: 1;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 12px rgba(255, 209, 102, .6); } }
.points { text-align: right; margin-top: 12px; font-size: 14px; letter-spacing: .1em; }
.points b { font-family: var(--mono); font-size: 18px; color: var(--gold); }

.titles { display: grid; gap: 8px; }
.title-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line-dim); }
.title-row.locked { opacity: .45; border-style: dashed; }
.title-row .t-n { font-weight: 700; }
.title-row .t-d { font-size: 14px; color: var(--dim); }
.title-row .t-i { font-family: var(--mono); color: var(--gold); width: 18px; flex-shrink: 0; }

/* ---------- Log ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { border: 1px solid var(--line-dim); padding: 10px; text-align: center; }
.tile b { display: block; font-family: var(--mono); font-size: 26px; color: #fff; font-weight: 400; }
.tile span { font-size: 12px; letter-spacing: .15em; color: var(--dim); text-transform: uppercase; }

.heat { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; gap: 3px; }
.heat i { aspect-ratio: 1; background: rgba(47, 143, 255, .06); border: 1px solid rgba(47, 143, 255, .1); }
.heat i.c { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 6px var(--glow); }
.heat i.p { background: rgba(92, 200, 255, .3); }
.heat i.m { background: rgba(255, 77, 94, .35); border-color: rgba(255, 77, 94, .5); }
.heat i.r { background: rgba(125, 145, 178, .18); }
.heat i.t { border-color: var(--gold); }
.heat i.n { opacity: .45; }
.legend { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--dim); }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }
.spark { width: 100%; height: 90px; display: block; margin: 12px 0 4px; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 2; filter: drop-shadow(0 0 4px var(--glow)); }
.spark path.area { fill: rgba(92, 200, 255, .08); }
.wlist { display: grid; gap: 2px; margin-top: 8px; }
.wrow { display: flex; justify-content: space-between; align-items: center; font-family: var(--mono); font-size: 14px; padding: 4px 0; border-bottom: 1px solid rgba(47, 143, 255, .1); }
.wrow button { background: none; border: 0; color: var(--dim); font-size: 18px; padding: 0 6px; }

/* ---------- System / settings ---------- */
.qlist { display: grid; gap: 6px; }
.qitem { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line-dim); background: rgba(47, 143, 255, .04); width: 100%; text-align: left; }
.qitem .q-main { flex: 1; }
.qitem .days-mini { font-family: var(--mono); font-size: 11px; color: var(--dim); letter-spacing: .1em; }
.qitem .days-mini b { color: var(--accent); font-weight: 400; }

label { display: block; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); margin: 12px 0 0; }
label > input, label > select { margin-top: 5px; }
input, select {
  width: 100%;
  background: rgba(4, 10, 22, .9);
  border: 1px solid var(--line-dim);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 12px) 55%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 10px var(--glow); }
.kv select { padding: 4px 28px 4px 8px; font-size: 15px; }

.btn {
  display: inline-block;
  padding: 11px 18px;
  background: rgba(47, 143, 255, .16);
  border: 1px solid var(--line);
  color: #fff;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
  font-size: 15px;
  box-shadow: 0 0 10px rgba(47, 143, 255, .25);
}
.btn:active { background: rgba(47, 143, 255, .4); }
.btn.ghost { background: transparent; border-color: var(--line-dim); box-shadow: none; color: var(--dim); }
.btn.danger { border-color: var(--red); color: var(--red); background: rgba(255, 77, 94, .08); box-shadow: none; }
.btn.wide { width: 100%; margin-top: 12px; }
.row { display: flex; gap: 10px; margin-top: 16px; }
.row .btn { flex: 1; }

.seg { display: flex; margin-top: 5px; }
.seg button { flex: 1; padding: 9px; background: transparent; border: 1px solid var(--line-dim); color: var(--dim); font-weight: 700; letter-spacing: .1em; }
.seg button + button { border-left: 0; }
.seg button.on { background: rgba(47, 143, 255, .22); color: #fff; border-color: var(--line); }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 5px; }
.days button { padding: 9px 0; background: transparent; border: 1px solid var(--line-dim); color: var(--dim); font-family: var(--mono); }
.days button.on { background: rgba(47, 143, 255, .22); color: #fff; border-color: var(--line); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.about p { margin: 0 0 10px; line-height: 1.4; color: var(--dim); }
.about p b { color: var(--text); }

/* ---------- Onboarding ---------- */
.onboard { min-height: calc(100dvh - 140px); display: flex; flex-direction: column; justify-content: center; }
.onboard .win { text-align: center; }
.onboard p { font-size: 19px; line-height: 1.4; margin: 6px 0 18px; }
.onboard .btn { min-width: 140px; }
.onboard input { text-align: center; margin-bottom: 4px; }

/* ---------- Tabs ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  background: rgba(4, 8, 18, .92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line-dim);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
#tabs[hidden] { display: none; }
#tabs button {
  flex: 1; max-width: 140px;
  background: none; border: 0;
  padding: 9px 0 8px;
  color: var(--dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; letter-spacing: .14em; text-transform: uppercase; font-weight: 700;
}
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs button.on { color: var(--accent); text-shadow: 0 0 8px var(--glow); }
#tabs button.on svg { filter: drop-shadow(0 0 4px var(--glow)); }

/* ---------- Overlay & modal ---------- */
#overlay, #modal { position: fixed; inset: 0; z-index: 50; display: none; }
#overlay.show, #modal.show { display: block; }
.ov-back, .modal-back {
  position: absolute; inset: 0;
  background: rgba(1, 3, 8, .82);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade .25s ease;
  overflow-y: auto;
}
@keyframes fade { from { opacity: 0; } }
.ov-back .win, .modal-back .win { width: 100%; max-width: 440px; margin: auto; }
.ov-h { text-align: center; font-size: 26px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; margin: 6px 0 12px; text-shadow: 0 0 12px var(--glow); }
.ov-back p { text-align: center; line-height: 1.4; }
.rewards { list-style: none; padding: 0; margin: 0 0 8px; font-family: var(--mono); font-size: 15px; }
.rewards li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(47, 143, 255, .14); }
.rewards li b { color: var(--gold); font-weight: 400; }

.win.red { border-color: var(--red); box-shadow: 0 0 22px var(--red-glow), inset 0 0 28px rgba(255, 77, 94, .14); }
.win.red::before, .win.red::after { border-color: var(--red); }
.win.red .win-title, .win.red .ov-h { color: var(--red); border-color: var(--red); text-shadow: 0 0 10px var(--red-glow); }
.win.red .btn { border-color: var(--red); background: rgba(255, 77, 94, .14); box-shadow: none; }
.pen-name { text-align: center; font-size: 22px; font-weight: 700; color: #fff; border: 1px dashed var(--red); padding: 12px; margin: 8px 0; }

.lu-big {
  text-align: center; font-size: 46px; font-weight: 700; letter-spacing: .1em;
  color: #fff; text-shadow: 0 0 20px var(--accent), 0 0 40px var(--line);
  animation: luIn .7s cubic-bezier(.2, 1.6, .4, 1) both;
}
@keyframes luIn { from { transform: scale(.3); opacity: 0; letter-spacing: .6em; } }
.lu-lv { text-align: center; font-family: var(--mono); font-size: 20px; color: var(--accent); margin: 4px 0 8px; }
.lu-lv b { color: #fff; font-size: 28px; }

/* ---------- Side quests, check-in, tests ---------- */
.directive {
  border-left: 2px solid var(--gold);
  background: rgba(255, 209, 102, .06);
  color: var(--gold);
  padding: 8px 10px;
  margin: -4px 0 14px;
  font-size: 15px;
  line-height: 1.35;
}
.ci-row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 8px; margin: 8px 0; }
.ci-row > span { font-size: 13px; letter-spacing: .12em; color: var(--dim); text-transform: uppercase; font-weight: 700; }
.seg.sm { margin-top: 0; }
.seg.sm button { padding: 8px 0; font-size: 15px; }
.link { display: block; margin: 10px auto 0; background: none; border: 0; color: var(--dim); text-decoration: underline; font-size: 14px; }

.win.em { border-color: var(--gold); box-shadow: 0 0 22px rgba(255, 209, 102, .4), inset 0 0 28px rgba(255, 209, 102, .1); }
.win.em::before, .win.em::after { border-color: var(--gold); }
.win.em .win-title, .win.em .ov-h { color: var(--gold); border-color: var(--gold); text-shadow: 0 0 10px rgba(255, 209, 102, .5); }
.win.em .pen-name { border-color: var(--gold); }
.win.em .btn:not(.ghost) { border-color: var(--gold); background: rgba(255, 209, 102, .12); box-shadow: none; }
.ov-btns .btn + .btn { margin-top: 8px; }

.quest.emergency .q-name { color: var(--gold); }
.quest.emergency .check { border-color: var(--gold); }
.quest.emergency.done .q-name { color: var(--green); }
.q-meta .due { color: var(--gold); }

.test { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(47, 143, 255, .14); }
.test:last-child { border-bottom: 0; }
.t-stat { font-size: 11px; letter-spacing: .18em; color: var(--accent); font-weight: 700; }
.test-go { color: var(--gold); border-color: var(--gold); background: rgba(255, 209, 102, .08); font-size: 13px; }
.cool { font-family: var(--mono); color: var(--dim); font-size: 13px; min-width: 44px; text-align: center; }

/* ---------- Weekly evaluation ---------- */
.banner .btn { margin-top: 0; }
.step { display: flex; gap: 10px; align-items: flex-start; margin: 20px 0 8px; line-height: 1.35; }
.step b:first-child {
  width: 26px; height: 26px; flex-shrink: 0;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  font-family: var(--mono); font-weight: 400;
  color: var(--accent);
}
textarea {
  width: 100%; min-height: 130px;
  margin-top: 8px;
  background: rgba(4, 10, 22, .9);
  border: 1px solid var(--line-dim);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 10px;
  border-radius: 0;
  outline: none;
  resize: vertical;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 10px var(--glow); }
details { margin-top: 10px; }
summary { color: var(--dim); font-size: 14px; letter-spacing: .08em; cursor: pointer; }
a.btn { text-align: center; text-decoration: none; }
.sys-msg { border: 1px dashed var(--line); padding: 12px; margin: 0 0 14px; color: #fff; line-height: 1.4; text-align: left; }
.dossier { white-space: pre-wrap; color: var(--dim); font-size: 14px; line-height: 1.4; margin: 8px 0 0; }

.chg {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 0; margin: 0;
  border-bottom: 1px solid rgba(47, 143, 255, .14);
  text-transform: none; letter-spacing: 0;
  color: var(--text); font-size: 16px;
}
.chg input { width: 22px; height: 22px; margin: 1px 0 0; padding: 0; flex-shrink: 0; -webkit-appearance: auto; appearance: auto; accent-color: var(--accent); box-shadow: none; }
.chg small { display: block; color: var(--dim); font-size: 14px; margin-top: 2px; }
.chg em { display: block; color: var(--gold); font-style: normal; font-size: 13px; margin-top: 2px; }
.chg.blocked { opacity: .6; }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 76px);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; z-index: 60;
}
.toast {
  background: rgba(8, 20, 40, .95);
  border: 1px solid var(--line);
  box-shadow: 0 0 14px var(--glow);
  padding: 7px 16px;
  font-family: var(--mono);
  font-size: 15px;
  color: var(--accent);
  animation: toastIn .25s ease, toastOut .3s ease 1.9s forwards;
}
.toast.gold { color: var(--gold); border-color: var(--gold); }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-8px); opacity: 0; } }

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