/* AT Alarm — warm, low-glare themes for early mornings. No pure white, little blue light. */
:root, [data-theme="ember"] {
  --bg: #15110e; --surface: #1f1a16; --surface2: #2a231d; --line: #3a3029;
  --text: #eadfce; --muted: #a8998a; --faint: #6f6257;
  --accent: #e3a857; --accent-ink: #1d140b; --accent-soft: rgba(227,168,87,.14);
  --danger: #d9776a; --ok: #9cbf86; --shadow: 0 10px 30px rgba(0,0,0,.35);
}
[data-theme="night"] {
  --bg: #0b0606; --surface: #150b0a; --surface2: #1f100f; --line: #2e1916;
  --text: #d99a8c; --muted: #9a6559; --faint: #5e3a33;
  --accent: #c8664f; --accent-ink: #120605; --accent-soft: rgba(200,102,79,.14);
  --danger: #e0705a; --ok: #b08a5a; --shadow: 0 10px 30px rgba(0,0,0,.5);
}
[data-theme="moss"] {
  --bg: #0f1310; --surface: #171d18; --surface2: #202821; --line: #2e382f;
  --text: #dbe4d2; --muted: #96a48d; --faint: #5d6a58;
  --accent: #a9c98d; --accent-ink: #10180c; --accent-soft: rgba(169,201,141,.14);
  --danger: #d98a76; --ok: #a9c98d; --shadow: 0 10px 30px rgba(0,0,0,.35);
}
[data-theme="dawn"] {
  --bg: #efe6d8; --surface: #f7f0e5; --surface2: #e8dccb; --line: #d8c9b4;
  --text: #3b3027; --muted: #7a6958; --faint: #a8977f;
  --accent: #b06a25; --accent-ink: #fff7ec; --accent-soft: rgba(176,106,37,.12);
  --danger: #b5483a; --ok: #5d7f45; --shadow: 0 10px 30px rgba(80,55,30,.15);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: calc(16px * var(--fs, 1)); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  line-height: 1.4; min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + max(env(safe-area-inset-top, 0px), var(--safe-area-inset-top, 0px))) 16px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.today { font-weight: 700; font-size: 1.05rem; }
.next-up { color: var(--muted); font-size: .82rem; }
.topbar-right { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; font-size: 1.1rem;
}
.banner {
  margin: 12px 16px 0; padding: 12px 14px; border-radius: 14px; background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); font-size: .9rem; display: flex; gap: 10px; align-items: center;
}
.banner button { margin-left: auto; }

main { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.view { padding: 16px 0 24px; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h2 { font-size: 1.35rem; margin: 4px 0 14px; display: flex; align-items: center; gap: 10px; }
h2 .grow { flex: 1; }
h3 { font-size: 1rem; margin: 22px 0 10px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; border: 1px dashed var(--line); border-radius: 18px; }
.empty .big { font-size: 2.4rem; display: block; margin-bottom: 6px; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface2); border-radius: 12px; padding: 10px 14px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .45; }
.fab {
  position: fixed; right: 18px; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 15;
  width: 58px; height: 58px; border-radius: 20px; border: none; background: var(--accent); color: var(--accent-ink);
  font-size: 1.9rem; box-shadow: var(--shadow); display: grid; place-items: center;
}
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="url"], input[type="number"], input[type="date"], input[type="time"], input[type="datetime-local"], select, textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; outline: none;
  color-scheme: dark;
}
[data-theme="dawn"] input, [data-theme="dawn"] select, [data-theme="dawn"] textarea { color-scheme: light; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 110px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* segmented control */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  flex: 1 0 auto; border: 1px solid var(--line); background: var(--surface2); border-radius: 10px; padding: 8px 10px; font-size: .88rem;
}
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.days { display: flex; gap: 6px; }
.days button { flex: 1; aspect-ratio: 1; max-width: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface2); font-weight: 700; font-size: .85rem; padding: 0; }
.days button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* switch */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 30px; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; border-radius: 50%; background: var(--muted); transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); background: var(--accent-ink); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; margin-bottom: 10px; }
.card.tap { cursor: pointer; }
.alarm-card { display: flex; align-items: center; gap: 12px; }
.alarm-card .time { font-size: 2.2rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.05; }
.alarm-card .time small { font-size: 1rem; font-weight: 600; margin-left: 3px; color: var(--muted); }
.alarm-card.off .time, .alarm-card.off .meta { opacity: .45; }
.meta { color: var(--muted); font-size: .84rem; margin-top: 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: .75rem; padding: 3px 8px; border-radius: 20px; background: var(--surface2); color: var(--muted); border: 1px solid var(--line); }
.chip.acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- prayer ---------- */
.prayer-hero { text-align: center; padding: 20px 16px; background: linear-gradient(160deg, var(--surface2), var(--surface)); }
.prayer-hero .label { color: var(--muted); font-size: .9rem; }
.prayer-hero .name { font-size: 1.8rem; font-weight: 800; }
.prayer-hero .count { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.prayer-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.prayer-row:last-child { border-bottom: none; }
.prayer-row.next { background: var(--accent-soft); margin: 0 -10px; padding: 12px 14px; border-radius: 12px; border-bottom-color: transparent; }
.prayer-row .pn { flex: 1; font-weight: 600; }
.prayer-row .pn .ar { color: var(--muted); font-weight: 400; margin-left: 6px; }
.prayer-row .pt { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem; }
.prayer-row .bell { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface2); }
.prayer-row .bell.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.qibla { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--line); position: relative; flex: none; }
.qibla::after { content: "N"; position: absolute; top: 2px; left: 50%; transform: translateX(-50%); font-size: .6rem; color: var(--muted); }
.qibla i { position: absolute; left: 50%; top: 50%; width: 3px; height: 26px; background: var(--accent); transform-origin: 50% 100%; border-radius: 3px; }

.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.list-item .play { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface2); flex: none; }
.list-item .play.on { background: var(--accent); color: var(--accent-ink); }
.pick { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

/* ---------- notes ---------- */
.notes-grid { columns: 2 160px; column-gap: 10px; }
.note { break-inside: avoid; margin-bottom: 10px; border-radius: 16px; padding: 12px 14px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.note h4 { margin: 0 0 4px; font-size: 1rem; }
.note p { margin: 0; white-space: pre-wrap; word-break: break-word; color: var(--text); opacity: .88; font-size: .92rem; max-height: 12em; overflow: hidden; }
.note .meta { margin-top: 8px; }
.note.done { opacity: .5; }
.note.done h4, .note.done p { text-decoration: line-through; }
.c-amber { background: color-mix(in srgb, #c98a3a 22%, var(--surface)); }
.c-rose { background: color-mix(in srgb, #b9645a 22%, var(--surface)); }
.c-sage { background: color-mix(in srgb, #7f9a68 22%, var(--surface)); }
.c-sky { background: color-mix(in srgb, #6a8798 22%, var(--surface)); }
.c-plum { background: color-mix(in srgb, #8a6a8e 22%, var(--surface)); }
.colors { display: flex; gap: 8px; }
.colors button { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--line); }
.colors button.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-day { position: relative; margin: 14px 0 8px; font-weight: 700; color: var(--muted); font-size: .9rem; }
.tl-day::before { content: ""; position: absolute; left: -20px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
.tl-day.past::before { background: var(--faint); }
.tl-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); font-size: .85rem; }

/* ---------- events ---------- */
.event-card { display: flex; gap: 12px; align-items: center; }
.event-card .badge { width: 54px; height: 58px; border-radius: 14px; background: var(--surface2); display: flex; flex-direction: column; align-items: center; justify-content: center; flex: none; border: 1px solid var(--line); }
.event-card .badge b { font-size: 1.3rem; line-height: 1; }
.event-card .badge span { font-size: .7rem; color: var(--muted); text-transform: uppercase; }
.event-card.today { border-color: var(--accent); background: var(--accent-soft); }
.countdown { font-weight: 700; color: var(--accent); white-space: nowrap; font-size: .9rem; }

/* ---------- sleep ---------- */
.amb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.amb { aspect-ratio: 1.1; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-weight: 600; font-size: .85rem; }
.amb .e { font-size: 1.8rem; }
.amb.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.yt-frame { position: relative; width: 100%; aspect-ratio: 16/9; border-radius: 14px; overflow: hidden; background: #000; margin-bottom: 10px; }
.yt-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.yt-item .thumb { width: 72px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface2); flex: none; }
.yt-item.playing { background: var(--accent-soft); margin: 0 -10px; padding: 10px; border-radius: 12px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  padding: 6px 6px calc(6px + max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px))); background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-top: 1px solid var(--line); backdrop-filter: blur(10px);
}
.tabbar button { flex: 1; max-width: 120px; border: none; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); padding: 6px 0; border-radius: 12px; }
.tabbar .ti { font-size: 1.3rem; filter: grayscale(.6); opacity: .8; }
.tabbar button.active { color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.tabbar button.active .ti { filter: none; opacity: 1; }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.sheet {
  position: relative; width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto; background: var(--surface);
  border-radius: 22px 22px 0 0; padding: 8px 18px calc(20px + env(safe-area-inset-bottom)); box-shadow: var(--shadow);
  animation: up .22s ease;
}
@media (min-width: 700px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 22px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 5px; background: var(--line); margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; position: sticky; top: -8px; background: var(--surface); padding: 6px 0; z-index: 2; }
.sheet-head h3 { margin: 0; flex: 1; color: var(--text); font-size: 1.15rem; }
.big-time { display: flex; justify-content: center; margin: 4px 0 18px; }
.big-time input { font-size: 2.6rem; font-weight: 700; text-align: center; width: auto; min-width: 200px; padding: 8px 16px; border-radius: 18px; }
.opt-box { border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 14px; background: var(--bg); }
.photo-ref { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; display: block; margin-bottom: 8px; }

/* ---------- ringing screen ---------- */
.ring {
  position: fixed; inset: 0; z-index: 60; background: radial-gradient(circle at 50% 30%, var(--surface2), var(--bg) 70%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); text-align: center; overflow-y: auto;
}
.ring .r-time { font-size: 4.6rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.03em; line-height: 1; }
.ring .r-label { font-size: 1.25rem; margin: 10px 0 4px; }
.ring .r-sub { color: var(--muted); margin-bottom: 30px; }
.ring .pulse { width: 120px; height: 120px; border-radius: 50%; background: var(--accent-soft); display: grid; place-items: center; font-size: 3rem; margin-bottom: 26px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); box-shadow: 0 0 0 0 var(--accent-soft); } 50% { transform: scale(1.06); box-shadow: 0 0 0 24px transparent; } }
.ring .actions { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.ring .btn { min-height: 58px; font-size: 1.1rem; border-radius: 18px; }
.ch-box { width: 100%; max-width: 380px; }
.ch-q { font-size: 2.3rem; font-weight: 800; margin: 10px 0; font-variant-numeric: tabular-nums; }
.ch-answer { font-size: 2rem; text-align: center; font-weight: 700; letter-spacing: .05em; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.keypad button { min-height: 58px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-size: 1.4rem; font-weight: 700; }
.keypad button.ok { background: var(--accent); color: var(--accent-ink); }
.progress { height: 8px; border-radius: 8px; background: var(--surface2); overflow: hidden; margin: 10px 0; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.shake-count { font-size: 4.5rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.shake-anim { font-size: 3.5rem; display: inline-block; animation: wob 0.6s ease-in-out infinite; }
@keyframes wob { 0%,100% { transform: rotate(-14deg); } 50% { transform: rotate(14deg); } }
.cam { width: 100%; aspect-ratio: 3/4; max-height: 52dvh; object-fit: cover; border-radius: 16px; background: #000; display: block; }
.shake-x { animation: shx .4s; }
@keyframes shx { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* ---------- bedside ---------- */
.bedside { position: fixed; inset: 0; z-index: 70; background: #000; color: #7a3a2c; display: flex; flex-direction: column; align-items: center; justify-content: center; user-select: none; text-align: center; padding: 20px; }
.bs-clock { font-size: min(26vw, 9rem); font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: -.03em; line-height: 1; }
.bs-date { font-size: 1.1rem; margin-top: 8px; opacity: .8; }
.bs-info { margin-top: 26px; font-size: 1rem; opacity: .75; line-height: 1.8; }
.bs-hint { position: absolute; bottom: calc(20px + env(safe-area-inset-bottom)); font-size: .75rem; opacity: .45; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 80; background: var(--surface2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px; box-shadow: var(--shadow); font-size: .9rem; max-width: calc(100% - 32px); }

.theme-swatch { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.theme-swatch button { border-radius: 14px; border: 2px solid var(--line); padding: 12px 6px; font-size: .8rem; font-weight: 700; }
.theme-swatch button.on { border-color: var(--accent); }
details summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kv label { font-size: .75rem; color: var(--muted); }
.kv input { padding: 8px; }
a { color: var(--accent); }

/* ---------- AT Note additions ---------- */
.checklist { list-style: none; margin: 4px 0 0; padding: 0; }
.checklist li { display: flex; align-items: flex-start; gap: 8px; padding: 3px 0; font-size: .92rem; }
.checklist li input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.checklist li.ticked span { text-decoration: line-through; opacity: .55; }
.checklist .more { color: var(--muted); font-size: .8rem; }
.item-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.item-row input[type="text"] { flex: 1; }
.item-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.tl-ev { border-left: 4px solid var(--accent); }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.summary .card { margin: 0; text-align: center; padding: 12px 6px; }
.summary b { display: block; font-size: 1.5rem; color: var(--accent); }
.summary span { font-size: .75rem; color: var(--muted); }
