:root {
	--bg: #140d14;
	--card: #1f161f;
	--card2: #2a1e29;
	--line: #3a2a36;
	--text: #f6eaf1;
	--muted: #b49aaa;
	--accent: #ff6f91;
	--accent2: #e0457b;
	--good: #5fd38d;
	--bad: #ff6b6b;
	--radius: 16px;
	color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	-webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

h1 { font-size: 1.5rem; margin: 0.4rem 0; }
h2 { font-size: 1.05rem; margin: 0 0 0.8rem; letter-spacing: 0.01em; }
a { color: var(--accent); }
code { background: var(--card2); padding: 2px 6px; border-radius: 6px; word-break: break-all; font-size: 0.85rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--bad); min-height: 1.2em; margin: 0.5rem 0 0; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.logo { width: 72px; height: 72px; }
.login-card input { margin: 1rem 0 0.8rem; }

/* Layout */
.topbar {
	position: sticky; top: 0; z-index: 5;
	display: flex; align-items: center; justify-content: space-between;
	padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
	background: rgba(20, 13, 20, 0.92); backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.brand img { width: 30px; height: 30px; }
.alive { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.alive .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.alive.ok .dot { background: var(--good); box-shadow: 0 0 8px var(--good); }
.alive.bad .dot { background: var(--bad); }

.tabs {
	position: sticky; top: calc(50px + env(safe-area-inset-top)); z-index: 4;
	display: flex; gap: 8px; overflow-x: auto; padding: 6px 16px 12px;
	background: var(--bg); scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
	flex: none; border: 1px solid var(--line); background: var(--card); color: var(--muted);
	padding: 8px 14px; border-radius: 999px; font: inherit; font-size: 0.9rem; cursor: pointer;
}
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.tab { padding: 0 16px calc(28px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }

/* Form controls */
input[type="text"], input[type="password"], input[type="time"], input:not([type]), textarea, select {
	width: 100%; background: var(--card2); color: var(--text); border: 1px solid var(--line);
	border-radius: 12px; padding: 11px 12px; font: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 96px; }
label { display: block; font-size: 0.9rem; color: var(--muted); }
label > input, label > select { margin-top: 4px; color: var(--text); }
.field { margin: 0.6rem 0; }
.field label { margin: 0.35rem 0; color: var(--text); }
.field label select { width: auto; display: inline-block; padding: 6px 8px; margin: 0 0 0 4px; }
.row { display: flex; gap: 10px; align-items: flex-end; margin: 0.6rem 0; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); margin: 0.8rem 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); margin-top: 8px; }
input[type="radio"] { accent-color: var(--accent); }

.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 6px;
	border: 1px solid var(--line); background: var(--card2); color: var(--text);
	border-radius: 12px; padding: 11px 16px; font: inherit; font-weight: 600; cursor: pointer;
	text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border-color: transparent; color: #fff; }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; }
.btn.tiny { padding: 4px 10px; font-size: 0.8rem; border-radius: 8px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.upload { margin-top: 0.6rem; }

/* Switch rows */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; color: var(--text); font-size: 1rem; border-top: 1px solid var(--line); }
.card h2 + .switch-row { border-top: 0; }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

/* Segmented control & chips */
.seg { display: flex; background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px 4px; border-radius: 9px; font: inherit; font-size: 0.9rem; cursor: pointer; }
.seg button.active { background: var(--accent); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0.4rem 0; }
.chips button, .chips span { border: 1px solid var(--line); background: var(--card2); color: var(--text); border-radius: 999px; padding: 7px 13px; font: inherit; font-size: 0.9rem; cursor: pointer; }
.chips.removable span { display: inline-flex; align-items: center; gap: 6px; cursor: default; }
.chips.removable span button { border: 0; padding: 0 2px; background: none; color: var(--muted); font-size: 1.1rem; line-height: 1; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); padding: 12px 0; }
.list li:first-child { border-top: 0; }
.list .meta { color: var(--muted); font-size: 0.8rem; margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.list .actions { display: flex; gap: 8px; margin-top: 8px; }
.badge { background: var(--card2); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; font-size: 0.75rem; }
.badge.today { background: var(--accent); border-color: var(--accent); color: #fff; }
.peek { display: block; width: 100%; max-width: 360px; aspect-ratio: 9 / 16; object-fit: contain; margin: 0.8rem auto; background: #000; border: 1px solid var(--line); border-radius: 12px; }
.note-preview { font-family: "Snell Roundhand", "Segoe Script", cursive; font-size: 1.3rem; margin: 0 0 0.8rem; color: var(--text); }
.note-preview.muted { font-family: inherit; font-size: 1rem; color: var(--muted); }
.note-text { white-space: pre-wrap; word-wrap: break-word; }

/* Photos */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--card2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo.current { outline: 3px solid var(--accent); outline-offset: -3px; }
.photo button { position: absolute; top: 6px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 1rem; cursor: pointer; }
.photo .del { right: 6px; }
.photo .pin { left: 6px; }
.photo .pin.on { color: #ffd166; }

/* Status */
.status { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.status dt { color: var(--muted); }
.status dd { margin: 0; }

/* Spotify */
.spotify-status { display: flex; gap: 12px; align-items: center; margin: 0.4rem 0 1rem; }
.spotify-status img { width: 56px; height: 56px; border-radius: 8px; }
.steps { padding-left: 1.2rem; margin: 0; }
.steps li { margin: 0 0 0.9rem; }

/* Toast */
.toast {
	position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
	background: #2e2230; border: 1px solid var(--line); color: var(--text); padding: 11px 18px; border-radius: 999px;
	box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45); z-index: 10; max-width: calc(100vw - 32px); text-align: center;
}
.toast.err { border-color: var(--bad); }

/* Status colours */
.good-text { color: var(--good); }
.bad-text { color: var(--bad); }

/* Misc additions */
.sub { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 0 10px 14px; color: var(--muted); }
.sub input { width: auto; max-width: 60%; margin: 0; }
.list li.faded { opacity: 0.55; }
.row.wrap { flex-wrap: wrap; }
.row.tight { margin: 0; align-items: center; }
input[type="date"], input[type="number"] {
	background: var(--card2); color: var(--text); border: 1px solid var(--line);
	border-radius: 12px; padding: 10px 12px; font: inherit; outline: none;
}
label > input[type="number"] { width: 100%; }

/* Photos: one-time timer */
.photo .timer { left: 50%; transform: translateX(-50%); }
.onetime { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; margin: 0.6rem 0; }
.onetime-status { display: flex; align-items: center; gap: 12px; margin: 10px 0; min-height: 24px; }
.onetime-status img { width: 48px; height: 64px; object-fit: cover; border-radius: 8px; }

/* Font picker */
.mirror-preview {
	background: #000; color: var(--mp-bright, #fff); border-radius: 12px; padding: 16px; margin-bottom: 10px;
	border: 1px solid var(--line); overflow: hidden;
}
.mp-row { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.mp-date { color: #999; font-size: 0.85rem; }
.mp-time { font-size: 2.6rem; font-weight: 300; line-height: 1; display: flex; align-items: flex-start; }
.mp-side { display: inline-flex; flex-direction: column; font-size: 0.8rem; color: #999; margin-left: 4px; line-height: 1.1; margin-top: 4px; }
.mp-greet { font-size: 1.15rem; font-weight: 300; text-align: right; }
.mp-weather { color: #bbb; font-size: 0.85rem; margin-top: 12px; }
.mp-news { color: var(--mp-bright, #fff); font-size: 0.9rem; margin-top: 8px; text-align: center; }
.font-list { display: grid; gap: 6px; margin-top: 12px; max-height: 300px; overflow-y: auto; padding-right: 4px; }
.font-group { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; margin: 8px 0 0; }
.font-item {
	display: flex; justify-content: space-between; align-items: baseline; gap: 10px; text-align: left;
	background: var(--card2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; cursor: pointer;
}
.font-item .fi-name { font-size: 1.1rem; white-space: nowrap; }
.font-item .fi-sample { color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-item.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.font-item.current .fi-name::after { content: " ✓"; color: var(--good); }
#countdown-form #countdown-title { flex-basis: 100%; }
#countdown-form #countdown-date { flex: 1; }

/* Photo editor */
.editor-preview { display: flex; align-items: center; justify-content: center; background: #000; border-radius: 12px; min-height: 220px; max-height: 360px; overflow: hidden; margin-bottom: 10px; }
.editor-preview img { width: 100%; height: 320px; object-fit: contain; display: block; }
.photo img { cursor: pointer; }
.photo .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font-size: 0.7rem; line-height: 1.2; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, 0.75)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }

/* Wi-Fi */
.pw-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.pw-row input { flex: 1; margin-top: 0 !important; }
.wifi-list:empty { display: none; }
.wifi-list { max-height: 260px; overflow-y: auto; margin: 10px 0; }
.wifi-list li { padding: 0; border: 0; }
.wifi-net { width: 100%; display: flex; gap: 10px; align-items: center; text-align: left; background: var(--card2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; margin-bottom: 6px; }
.wifi-net.selected { border-color: var(--accent); }

/* iOS Safari zooms into any field under 16px */
input, select, textarea { font-size: 16px !important; }

/* Text colour */
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 12px 0; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; position: relative; }
.swatch.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent); }
.swatch.selected::after { content: "✓"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #000; font-weight: 700; font-size: 1.1rem; }
.color-custom { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--text); margin: 6px 0 4px; }
.color-custom input[type="color"] { width: 64px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--card2); }
