:root {
  --bg: #0f1115;
  --card: #171a21;
  --card-2: #1e222b;
  --line: #262b36;
  --text: #e8e6e1;
  --muted: #8b90a0;
  --gold: #c9a96a;
  --gold-dim: #8f7a4f;
  --bad: #c0443f;
  --bad-deep: #5a1a18;
  --good: #3f9a63;
  --good-deep: #164a2b;
  --radius: 16px;
  --font: -apple-system, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.err { color: #e07070; font-size: 0.9rem; min-height: 1.2em; margin: 0.5rem 0 0; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0; letter-spacing: 0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; color: var(--muted); }
p { margin: 0.5rem 0 0; line-height: 1.45; }

.screen { min-height: 100vh; min-height: 100dvh; }

/* ---------- lock ---------- */
#lock { display: flex; align-items: center; justify-content: center; padding: 24px; }
.lock-card { width: 100%; max-width: 380px; }
.brand { text-align: center; margin-bottom: 1.5rem; }
.brand-ar { font-family: var(--serif); font-size: 3rem; color: var(--gold); line-height: 1; }
.brand h1 { font-size: 1.6rem; margin-top: 0.35rem; }
.lock-msg { text-align: center; color: var(--muted); font-size: 0.95rem; margin-bottom: 1rem; }
#lock-form { display: flex; flex-direction: column; gap: 0.6rem; }
#lock-note { text-align: center; margin-top: 1rem; }

/* ---------- inputs ---------- */
input[type="text"], input[type="password"], input[type="date"], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 0.7rem 0.85rem; outline: none; -webkit-appearance: none; appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold-dim); }
input[type="date"] { color-scheme: dark; width: auto; }
select { color-scheme: dark; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 2rem; }
textarea { resize: vertical; margin-top: 0.75rem; line-height: 1.4; }

button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card-2); color: var(--text); border-radius: 12px; padding: 0.65rem 1rem; }
button:active { transform: translateY(1px); }
button.primary { background: var(--gold); color: #1a1507; border-color: var(--gold); font-weight: 600; }
button.link { background: none; border: none; padding: 0.25rem 0; color: var(--gold); }
button.link.danger { color: #b56a6a; }
button.danger-outline { border-color: #6a3a3a; color: #d08a8a; }
button:disabled { opacity: 0.45; cursor: default; }
button.tiny { padding: 0.35rem 0.65rem; font-size: 0.8rem; border-radius: 9px; }

/* ---------- app frame ---------- */
#app { display: flex; flex-direction: column; }
header.top { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top)) 18px 8px; }
.brand-row { display: flex; align-items: baseline; gap: 0.5rem; }
.small-ar { font-size: 1.5rem; }
.brand-name { font-family: var(--serif); font-size: 1.15rem; }
main { flex: 1; padding: 6px 14px calc(84px + env(safe-area-inset-bottom)); max-width: 560px; width: 100%; margin: 0 auto; }
.tab { display: flex; flex-direction: column; gap: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap { gap: 0.6rem; margin-top: 0.6rem; }
.row.wrap { flex-wrap: wrap; }
.row.gap > * { flex: 1; }
form.card > button { margin-top: 0.75rem; width: 100%; }
form.card input { margin-top: 0.6rem; }
form.card .row.gap input, form.card .row.gap select { margin-top: 0; }
#pass-form input { margin-top: 0.6rem; }

.pill { font-size: 0.75rem; padding: 0.15rem 0.6rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pill.bad { border-color: #5a2a2a; color: #d08a8a; }
.pill.good { border-color: #244a33; color: #7fc49a; }
.end-bad { color: #c47a76; }
.end-good { color: #7fc49a; }

/* ---------- big scale ---------- */
.scale-card { padding-top: 18px; }
.scale-title { font-family: var(--serif); font-size: 1.35rem; text-align: center; color: var(--gold); margin-bottom: 14px; }
.scale-ends { display: flex; justify-content: space-between; font-size: 0.8rem; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 6px; }
.scale-bar { position: relative; height: 14px; border-radius: 999px; background: linear-gradient(90deg, var(--bad-deep) 0%, var(--bad) 20%, #3a3d46 50%, var(--good) 80%, var(--good-deep) 100%); box-shadow: inset 0 1px 3px rgba(0,0,0,0.6); }
.scale-mid { position: absolute; left: 50%; top: -4px; width: 2px; height: 22px; background: rgba(255,255,255,0.25); transform: translateX(-50%); }
.scale-marker { position: absolute; top: 50%; width: 26px; height: 26px; border-radius: 50%; background: var(--gold); border: 3px solid var(--bg); box-shadow: 0 0 0 2px var(--gold-dim), 0 4px 10px rgba(0,0,0,0.5); transform: translate(-50%, -50%); left: 50%; transition: left 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.scale-word { text-align: center; font-family: var(--serif); font-size: 1.15rem; margin-top: 16px; }
.scale-sub { text-align: center; margin-top: 4px; }
.footnote { text-align: center; font-size: 0.75rem; margin-top: 14px; font-style: italic; }

/* ---------- day slider ---------- */
.slider-wrap { margin-top: 14px; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 36px; background: transparent; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 12px; border-radius: 999px; background: linear-gradient(90deg, var(--bad-deep) 0%, var(--bad) 20%, #3a3d46 50%, var(--good) 80%, var(--good-deep) 100%); box-shadow: inset 0 1px 3px rgba(0,0,0,0.6); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; border-radius: 50%; background: var(--text); border: 3px solid var(--bg); box-shadow: 0 0 0 2px var(--line), 0 3px 8px rgba(0,0,0,0.5); margin-top: -9px; }
input[type="range"]::-moz-range-track { height: 12px; border-radius: 999px; background: linear-gradient(90deg, var(--bad-deep) 0%, var(--bad) 20%, #3a3d46 50%, var(--good) 80%, var(--good-deep) 100%); }
input[type="range"]::-moz-range-thumb { width: 30px; height: 30px; border-radius: 50%; background: var(--text); border: 3px solid var(--bg); }
.slider-labels { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.slider-value { text-align: center; font-family: var(--serif); font-size: 1.2rem; margin-top: 10px; min-height: 1.5em; }
.slider-value.pos { color: #8fd1a8; }
.slider-value.neg { color: #d08a86; }
#day-status { min-height: 1.2em; }
#day-title { font-size: 1.2rem; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.list li { padding: 0.7rem 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: none; }
.list:empty + p { display: block; }
.day-row { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.day-row .d { width: 108px; flex: none; font-size: 0.9rem; }
.day-row .bar { flex: 1; position: relative; height: 8px; border-radius: 999px; background: #262a33; overflow: hidden; }
.day-row .bar::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,0.18); }
.day-row .fill { position: absolute; top: 0; bottom: 0; }
.day-row .fill.pos { left: 50%; background: var(--good); border-radius: 0 999px 999px 0; }
.day-row .fill.neg { right: 50%; background: var(--bad); border-radius: 999px 0 0 999px; }
.day-row .v { width: 34px; text-align: right; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.day-row .v.pos { color: #8fd1a8; } .day-row .v.neg { color: #d08a86; }
.day-row .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--bad); flex: none; }
.day-row .dot.none { background: transparent; }

.sin { display: flex; flex-direction: column; gap: 0.45rem; }
.sin .head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.sin .label { font-size: 1rem; line-height: 1.35; word-break: break-word; }
.sin .meta { font-size: 0.78rem; color: var(--muted); }
.sin.done .label { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(127,196,154,0.6); }
.sin.done .label::before { content: "✓ "; color: #7fc49a; text-decoration: none; }
.sin .checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem 0.75rem; }
.sin .checks label { display: flex; align-items: center; gap: 0.45rem; font-size: 0.82rem; color: var(--muted); }
.sin .checks input { accent-color: var(--gold); width: 16px; height: 16px; margin: 0; }
.sin .actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.sin .actions .link { padding: 0.25rem 0.4rem; }
.sev { font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; }
.sev.major { color: #d08a86; }
@media (max-width: 380px) { .sin .checks { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.stats .n { font-family: var(--serif); font-size: 1.5rem; }
.stats .l { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

/* ---------- bottom tabs ---------- */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: rgba(15,17,21,0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs button { flex: 1; background: none; border: none; border-radius: 0; color: var(--muted); padding: 10px 0 8px; font-size: 0.72rem; display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav.tabs button .ico { font-size: 1.2rem; line-height: 1; }
nav.tabs button.active { color: var(--gold); }

.toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--card-2); border: 1px solid var(--line); color: var(--text); padding: 0.5rem 0.9rem; border-radius: 999px; font-size: 0.85rem; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.toast.show { opacity: 1; }
