:root {
	color-scheme: light;
	--page: #f6f6f3;
	--surface: #ffffff;
	--surface-2: #efefea;
	--ink: #0b0b0b;
	--ink-2: #52514e;
	--muted: #898781;
	--grid: #e4e3dc;
	--border: rgba(11, 11, 11, 0.10);
	--accent: #2a78d6;
	--accent-ink: #ffffff;
	--good: #0a7a2f;
	--good-bg: #e3f3e7;
	--bad: #c03030;
	--bad-bg: #fbe6e4;
	--wait-bg: #ecebe6;
	--warn-bg: #fff4dc;
	--goal: #898781;
	--radius: 14px;
	--font: system-ui, -apple-system, "Segoe UI", sans-serif;
	--nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--page: #0d0d0d;
		--surface: #1a1a19;
		--surface-2: #252524;
		--ink: #f0efec;
		--ink-2: #c3c2b7;
		--muted: #8f8d86;
		--grid: #2c2c2a;
		--border: rgba(255, 255, 255, 0.10);
		--accent: #3987e5;
		--good: #3ec46d;
		--good-bg: #133321;
		--bad: #ef7a7a;
		--bad-bg: #3a1a1a;
		--wait-bg: #2a2a28;
		--warn-bg: #3a2e12;
		--goal: #8f8d86;
	}
}
:root[data-theme="dark"] {
	color-scheme: dark;
	--page: #0d0d0d; --surface: #1a1a19; --surface-2: #252524; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8f8d86;
	--grid: #2c2c2a; --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --good: #3ec46d; --good-bg: #133321;
	--bad: #ef7a7a; --bad-bg: #3a1a1a; --wait-bg: #2a2a28; --warn-bg: #3a2e12; --goal: #8f8d86;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	background: var(--page);
	color: var(--ink);
	font: 15px/1.45 var(--font);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }

.boot { padding: 48px 16px; text-align: center; color: var(--ink-2); }
.boot .err { color: var(--bad); margin-bottom: 12px; }

/* Layout */
.shell { max-width: 560px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.top {
	position: sticky; top: 0; z-index: 5;
	display: flex; align-items: center; gap: 10px;
	padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
	margin: 0 -16px 8px;
	background: color-mix(in srgb, var(--page) 88%, transparent);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
}
.top .title { font-weight: 650; font-size: 17px; margin-right: auto; white-space: nowrap; }
.demo-tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); background: var(--warn-bg); padding: 2px 6px; border-radius: 6px; margin-left: 6px; vertical-align: 2px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button, .seg label {
	border: 0; background: transparent; border-radius: 8px; padding: 6px 12px; cursor: pointer;
	font-weight: 550; color: var(--ink-2); min-height: 34px; display: inline-flex; align-items: center; justify-content: center;
}
.seg [aria-pressed="true"], .seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg.fill { display: flex; }
.seg.fill > * { flex: 1; }
.seg label { padding: 0; }
.seg label span { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; border-radius: 8px; padding: 8px 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.icon-btn {
	width: 38px; height: 38px; border-radius: 10px; border: 0; background: var(--surface-2);
	display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink-2);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

nav.tabs {
	position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
	display: flex; justify-content: center;
	background: var(--surface); border-top: 1px solid var(--border);
	padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs .inner { display: flex; width: 100%; max-width: 560px; }
nav.tabs button {
	flex: 1; height: var(--nav-h); border: 0; background: none; cursor: pointer;
	display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
	color: var(--muted); font-size: 11px; font-weight: 550;
}
nav.tabs svg { width: 22px; height: 22px; }
nav.tabs [aria-current="page"] { color: var(--accent); }

/* Blocks */
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin: 22px 0 8px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card + .card { margin-top: 10px; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

.picker { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; }
.picker .label { flex: 1; text-align: center; }
.picker .label strong { display: block; font-size: 17px; }
.picker .label span { font-size: 13px; color: var(--muted); }
.picker button { flex: none; }

.pill { display: inline-flex; align-items: center; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--wait-bg); color: var(--ink-2); white-space: nowrap; }
.pill.pass { background: var(--good-bg); color: var(--good); }
.pill.miss { background: var(--bad-bg); color: var(--bad); }
.pill.blank { background: transparent; color: var(--muted); padding-left: 0; padding-right: 0; }

.stat { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; }
.stat .k { font-size: 13px; color: var(--ink-2); font-weight: 550; }
.stat .v { font-size: 26px; font-weight: 650; letter-spacing: -.01em; line-height: 1.15; }
.stat .v small { font-size: 15px; font-weight: 500; color: var(--muted); }
.stat .sub { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.stat .pill { grid-row: 1 / span 2; grid-column: 2; align-self: start; }

.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 8px; grid-column: 1 / -1; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.over i { background: var(--bad); }

/* Week strip */
.strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.strip button {
	border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 6px 0 7px; cursor: pointer;
	display: flex; flex-direction: column; align-items: center; gap: 1px; min-height: 58px;
}
.strip .d { font-size: 11px; color: var(--muted); font-weight: 600; }
.strip .n { font-size: 16px; font-weight: 600; }
.strip .m { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--grid); display: flex; align-items: center; justify-content: center; }
.strip .done .m { background: var(--good); border-color: var(--good); }
.strip .done .m::after { content: ""; width: 7px; height: 4px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.strip .sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.strip .today .d { color: var(--accent); }
.strip .future { opacity: .45; }

.totals { display: flex; gap: 8px; margin-top: 10px; }
.totals > div { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; }
.totals .k { font-size: 12px; color: var(--muted); font-weight: 550; }
.totals .v { font-weight: 650; font-size: 16px; }
.totals .v small { color: var(--muted); font-weight: 500; font-size: 13px; }

/* Forms */
form .field { display: block; margin-top: 14px; }
form .field:first-child { margin-top: 0; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); font-weight: 550; margin-bottom: 5px; }
.field > span em { font-style: normal; color: var(--muted); font-weight: 400; }
input[type=text], input[type=number], input[type=date], input[type=password], input:not([type]), select, textarea {
	width: 100%; font-size: 16px; padding: 10px 12px; border-radius: 10px;
	border: 1px solid var(--border); background: var(--page); min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two .field { margin-top: 14px; }
.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 6px;
	min-height: 46px; padding: 0 18px; border-radius: 12px; border: 0; cursor: pointer;
	background: var(--accent); color: var(--accent-ink); font-weight: 650; font-size: 16px;
}
.btn.block { width: 100%; margin-top: 16px; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.quiet { background: none; color: var(--ink-2); min-height: 40px; padding: 0 8px; font-weight: 550; font-size: 14px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.state-line { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); margin: 0 0 12px; }
.state-line .ok { color: var(--good); font-weight: 650; }

.warn { background: var(--warn-bg); border-radius: 12px; padding: 10px 14px; font-size: 13px; margin-bottom: 12px; }
.warn ul { margin: 4px 0 0; padding-left: 18px; }
.error-line { color: var(--bad); font-size: 14px; margin-top: 10px; }

/* Tables */
table.days { width: 100%; border-collapse: collapse; font-size: 14px; }
table.days th { text-align: right; font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 0 6px; }
table.days th:first-child, table.days td:first-child { text-align: left; }
table.days td { text-align: right; padding: 8px 0; border-top: 1px solid var(--grid); }
table.days td.note { text-align: left; color: var(--muted); font-size: 12px; padding-top: 0; border-top: 0; }
table.days tr.off td { color: var(--muted); }

/* Planner */
.big-msg { font-size: 17px; line-height: 1.4; }
.big-msg strong { font-size: 22px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch input { appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--grid); position: relative; cursor: pointer; flex: none; margin: 0; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.sim-row { display: grid; grid-template-columns: 76px 1fr auto; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--grid); }
.sim-row:first-child { border-top: 0; }
.sim-row .day { font-weight: 600; }
.sim-row .day small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.sim-row input { min-height: 40px; padding: 8px 10px; }
.sim-row .locked { font-variant-numeric: tabular-nums; padding-left: 4px; }
.sim-row .tag { font-size: 11px; color: var(--muted); }

/* Phases */
.phase-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.phase-head strong { font-size: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; font-size: 14px; margin-top: 8px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.scores { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.scores span { font-size: 12px; background: var(--surface-2); border-radius: 8px; padding: 4px 8px; }
.scores b { font-variant-numeric: tabular-nums; }
.flag { margin-top: 10px; font-size: 13px; border-radius: 8px; padding: 6px 10px; }
.flag.bad { background: var(--bad-bg); color: var(--bad); }
.flag.good { background: var(--good-bg); color: var(--good); }
.card.future { background: transparent; border-style: dashed; }
.card.current { border-color: var(--accent); }

.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); font-family: var(--font); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 2px dashed var(--goal); vertical-align: middle; margin-right: 5px; }
.legend i.actual { border-top: 2px solid var(--accent); }

.ph-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; padding: 12px 0; border-top: 1px solid var(--grid); }
.ph-edit:first-of-type { border-top: 0; padding-top: 0; }
.ph-edit .head { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; }
.ph-edit .meta { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.ph-edit .meta .warn-text { color: var(--bad); }
.ph-edit .field { margin: 0; }
.chips { display: flex; gap: 6px; margin-top: 6px; }
.chips button { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 3px 10px; font-size: 13px; cursor: pointer; }
.chips button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.login { max-width: 360px; margin: 0 auto; padding: 18vh 16px 32px; }
.login h1 { font-size: 24px; margin: 0 0 4px; }
.login p { margin: 0 0 20px; color: var(--ink-2); }

#toast {
	position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(10px);
	background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 550;
	opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--bad); color: #fff; }

.foot { margin-top: 28px; font-size: 13px; color: var(--muted); }
.foot p { margin: 4px 0; }

@media (max-width: 380px) {
	.top .title { display: none; }
	.stat .v { font-size: 23px; }
}
