:root {
  /* Light: pale chambray background, ivory cards, Comfort Colors-style washed accents */
  --bg: #e3eaf1;
  --panel: #fdfcf8;
  --panel-2: #d5dfe9;
  --line: #ccd7e2;
  --line-soft: #ebeef1;
  --text: #3b3632;
  --muted: #6c7380;
  --faint: #9aa3ae;
  --jason: #87a3c2;
  --jami: #9dbb94;
  --both: #bf9db6;
  --now: #d9776a;
  --good: #6f9a6b;
  --good-soft: #d8e8d4;
  --warn: #c9973f;
  --bad: #c4645a;
  --ev-text: #2a2622;
  --ev-border: rgba(60, 45, 30, .14);
  --past: rgba(70, 90, 115, .07);
  --scrim: rgba(50, 65, 85, .35);
  --press: #c6d3df;
  --amb-bg: #dde5ed;
  --amb-fg: #7a8492;
  --amb-time: #4d5560;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color-scheme: light;
}
:root:not([data-theme="dark"]) .col, :root:not([data-theme="dark"]) .wbody, :root:not([data-theme="dark"]) .tile, :root:not([data-theme="dark"]) .card { box-shadow: 0 1px 2px rgba(40, 60, 85, .06), 0 2px 8px rgba(40, 60, 85, .05); }
:root[data-theme="dark"] {
  /* Dark: pepper and graphite with the same muted accents */
  --bg: #1f1d1b;
  --panel: #282522;
  --panel-2: #33302b;
  --line: #3d3833;
  --line-soft: #312d29;
  --text: #ece5da;
  --muted: #a39a8d;
  --faint: #756d62;
  --jason: #839fba;
  --jami: #94b08c;
  --both: #b598ad;
  --now: #e0826f;
  --good: #94b08c;
  --good-soft: #2f3a2d;
  --warn: #d6aa5c;
  --bad: #d47a6c;
  --ev-text: #1d1b19;
  --ev-border: rgba(0, 0, 0, .3);
  --past: rgba(0, 0, 0, .22);
  --scrim: rgba(10, 9, 8, .7);
  --press: #45403a;
  --amb-bg: #151312;
  --amb-fg: #857c70;
  --amb-time: #cfc7bb;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#app {
  height: 100dvh; display: grid; grid-template-rows: auto 1fr auto;
  padding: max(14px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  gap: 12px;
}

/* Top bar */
.top { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 24px; }
.time { font-size: 52px; font-weight: 600; letter-spacing: -1.5px; line-height: 1; font-variant-numeric: tabular-nums; }
.date { font-size: 17px; color: var(--muted); margin-top: 4px; }
.nextup { font-size: 19px; color: var(--muted); line-height: 1.35; min-width: 0; }
.nextup b { color: var(--text); font-weight: 600; }
.nextup .who { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.top-right { display: flex; align-items: center; gap: 12px; }
.badge { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--warn); border: 1px solid currentColor; padding: 4px 8px; border-radius: 6px; }
.lock-btn { width: 52px; height: 52px; border-radius: 50%; background: var(--panel-2); display: grid; place-items: center; }
.lock-btn svg { width: 24px; height: 24px; }
.lock-btn.open { background: var(--good-soft); color: var(--good); }

/* Tabs */
.tabs { display: flex; justify-content: center; gap: 8px; }
.tabs button { padding: 10px 26px; border-radius: 999px; color: var(--muted); font-size: 17px; font-weight: 500; }
.tabs button.on { background: var(--panel-2); color: var(--text); }

.view { min-height: 0; position: relative; }

/* Day view */
.day { height: 100%; display: grid; grid-template-rows: auto auto 1fr; gap: 8px; }
.day-head { display: flex; align-items: center; gap: 10px; }
.day-head .title { font-size: 22px; font-weight: 600; margin-right: auto; }
.day-head .title small { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 16px; }
.navbtn { width: 44px; height: 44px; border-radius: 50%; background: var(--panel); font-size: 22px; color: var(--muted); }
.todaybtn { padding: 0 16px; height: 44px; border-radius: 22px; background: var(--panel); color: var(--muted); font-size: 15px; }
.cols-head, .allday { display: grid; grid-template-columns: 52px 1fr 1fr; gap: 0 10px; }
.cols-head .who { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; padding: 0 2px; }
.cols-head .who i { width: 12px; height: 12px; border-radius: 50%; }
.cols-head .who span { color: var(--muted); font-weight: 400; font-size: 14px; }
.allday .cell { display: flex; flex-wrap: wrap; gap: 6px; min-height: 0; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 6px; background: var(--panel-2); color: var(--muted); }

.grid { position: relative; display: grid; grid-template-columns: 52px 1fr 1fr; gap: 0 10px; min-height: 0; }
.gutter { position: relative; }
.gutter .h { position: absolute; right: 4px; font-size: 12px; color: var(--faint); transform: translateY(-50%); font-variant-numeric: tabular-nums; }
.col { position: relative; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.hline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line-soft); }
.span-layer { position: absolute; top: 0; bottom: 0; left: 62px; right: 0; pointer-events: none; }
.span-layer .ev { pointer-events: auto; }
.now { position: absolute; left: 52px; right: 0; height: 0; border-top: 2px solid var(--now); z-index: 5; pointer-events: none; }
.now::before { content: ""; position: absolute; left: -5px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--now); }
.past-shade { position: absolute; left: 0; right: 0; top: 0; background: var(--past); pointer-events: none; z-index: 3; }

.ev { position: absolute; border-radius: 7px; padding: 4px 8px; overflow: hidden; font-size: 14px; line-height: 1.25; color: var(--ev-text);
  border: 1px solid var(--ev-border); z-index: 2; }
.ev .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev .s { font-size: 12.5px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.p-jason { background: var(--jason); }
.ev.p-jami { background: var(--jami); }
.ev.p-both { background: var(--both); }
.ev.tentative { background-image: repeating-linear-gradient(135deg, transparent 0 7px, rgba(255,255,255,.45) 7px 12px); }
.ev.free { background: transparent !important; color: var(--muted); border: 1px dashed var(--faint); }
.ev.short { padding-top: 1px; padding-bottom: 1px; }
.ev.short .s { display: none; }
.ev.tiny { padding: 0 8px; display: flex; align-items: center; font-size: 12.5px; line-height: 1; }
.wbody .ev.tiny { padding: 0 4px; font-size: 10.5px; }
.ev.overlap { box-shadow: 0 0 0 2px var(--warn); }

/* Week view */
.week { height: 100%; display: grid; grid-template-rows: auto 1fr; gap: 8px; }
.week-grid { display: grid; grid-template-columns: 40px repeat(7, 1fr); gap: 6px; min-height: 0; }
.wday { display: grid; grid-template-rows: auto auto 1fr; gap: 4px; min-height: 0; border-radius: var(--radius); padding: 0; }
.wday .wh { text-align: center; padding: 6px 0 2px; }
.wday .wh b { display: block; font-size: 20px; }
.wday .wh span { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.wday.today .wh b { color: var(--now); }
.wday .wad { display: flex; flex-direction: column; gap: 2px; min-height: 18px; }
.wday .wad .chip { font-size: 11px; padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wbody { position: relative; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.wbody .ev { font-size: 11px; padding: 2px 4px; border-radius: 4px; }
.wbody .ev .t { font-weight: 600; }
.wgutter { position: relative; }
.wgutter .h { position: absolute; right: 2px; font-size: 11px; color: var(--faint); transform: translateY(-50%); }
.legend { display: flex; gap: 18px; align-items: center; color: var(--muted); font-size: 14px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend .hatch { border-radius: 3px; background: repeating-linear-gradient(135deg, var(--faint) 0 3px, transparent 3px 6px); }

/* Finance */
.fin { height: 100%; display: grid; grid-template-rows: auto auto 1fr; gap: 14px; min-height: 0; }
.fin-head { display: flex; align-items: baseline; gap: 12px; }
.fin-head h2 { margin: 0; font-size: 22px; }
.fin-head span { color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tile { background: var(--panel); border-radius: var(--radius); padding: 16px 18px; }
.tile .k { color: var(--muted); font-size: 14px; }
.tile .v { font-size: 36px; font-weight: 600; letter-spacing: -.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.tile.good .v { color: var(--good); } .tile.warn .v { color: var(--warn); } .tile.bad .v { color: var(--bad); }
.meter { height: 10px; border-radius: 5px; background: var(--panel-2); overflow: hidden; margin-top: 10px; }
.meter i { display: block; height: 100%; border-radius: 5px; }
.fin-body { display: grid; grid-template-columns: 1.2fr 1fr; gap: 12px; min-height: 0; }
.card { background: var(--panel); border-radius: var(--radius); padding: 16px 18px; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.card h3 { margin: 0 0 10px; font-size: 15px; color: var(--muted); font-weight: 500; }
.bars { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; align-items: end; min-height: 120px; position: relative; }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.bar .amt { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar .col-b { width: 100%; max-width: 46px; border-radius: 4px 4px 0 0; background: var(--jason); min-height: 2px; }
.bar .col-b.future { background: var(--panel-2); }
.bar .lbl { font-size: 13px; color: var(--muted); }
.bar.today .lbl { color: var(--text); font-weight: 600; }
.paceline { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--faint); pointer-events: none; }
.paceline span { position: absolute; right: 0; top: -18px; font-size: 11px; color: var(--faint); }
.tx { list-style: none; margin: 0; padding: 0; overflow: auto; }
.tx li { display: grid; grid-template-columns: 54px 1fr auto; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); font-size: 15px; }
.tx li .d { color: var(--muted); font-size: 13px; padding-top: 1px; }
.tx li .m { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx li .a { font-variant-numeric: tabular-nums; }
.tx li .a.neg { color: var(--good); }
.tx li .tag { font-size: 11px; color: var(--warn); margin-left: 6px; }
.locked-card { height: 100%; display: grid; place-items: center; text-align: center; color: var(--muted); }
.locked-card button { margin-top: 16px; padding: 14px 30px; border-radius: 999px; background: var(--panel-2); color: var(--text); font-size: 18px; }
.locked-card svg { width: 44px; height: 44px; opacity: .6; }

/* Overlays */
.overlay { position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center; z-index: 50; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.overlay[hidden] { display: none; }
.pin-card { background: var(--panel); border-radius: 22px; padding: 28px 30px; width: 360px; text-align: center; }
.pin-title { font-size: 20px; font-weight: 600; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 20px 0 8px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.f { background: var(--text); border-color: var(--text); }
.pin-msg { min-height: 22px; color: var(--bad); font-size: 14px; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 10px; }
.pin-keys button { height: 68px; border-radius: 50%; background: var(--panel-2); font-size: 28px; font-weight: 500; aspect-ratio: 1; justify-self: center; }
.pin-keys button:active { background: var(--press); }
.pin-keys button.soft { background: none; font-size: 16px; color: var(--muted); }
.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-10px); } 40%,80% { transform: translateX(10px); } }

.sheet-card { background: var(--panel); border-radius: 20px; padding: 24px 26px; width: min(560px, 92vw); max-height: 80vh; overflow: auto; }
.sheet-card h2 { margin: 0 0 6px; font-size: 24px; }
.sheet-card .meta { color: var(--muted); margin-bottom: 14px; }
.sheet-card .row { padding: 10px 0; border-top: 1px solid var(--line-soft); font-size: 16px; }
.sheet-card .row .k { color: var(--muted); font-size: 13px; display: block; margin-bottom: 2px; }
.sheet-card .notes { white-space: pre-wrap; font-size: 15px; color: var(--text); -webkit-user-select: text; user-select: text; }
.sheet-card .close { margin-top: 16px; width: 100%; padding: 14px; border-radius: 12px; background: var(--panel-2); font-size: 17px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; color: var(--ev-text); font-weight: 600; margin-right: 6px; }

/* Ambient / night */
.ambient { position: fixed; inset: 0; background: var(--amb-bg); z-index: 80; display: grid; place-items: center; transition: background 1s; }
.ambient[hidden] { display: none; }
.amb-inner { text-align: center; transition: transform 2s; }
.amb-time { font-size: 150px; font-weight: 200; letter-spacing: -4px; color: var(--amb-time); font-variant-numeric: tabular-nums; line-height: 1; }
.amb-date { font-size: 28px; color: var(--amb-fg); margin-top: 10px; }
.amb-next { font-size: 22px; color: var(--amb-fg); margin-top: 30px; }
.ambient.night { background: #000; }
body, .panel, .col, .tile, .card, .wbody { transition: background-color .8s, color .8s; }
.ambient.night .amb-time { color: #5a4636; font-size: 120px; }
.ambient.night .amb-date, .ambient.night .amb-next { color: #3b3028; }

/* Portrait / small */
@media (max-width: 900px) {
  .time { font-size: 42px; }
  .nextup { font-size: 16px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .fin-body { grid-template-columns: 1fr; }
  .amb-time { font-size: 110px; }
}
@media (max-width: 600px) {
  #app { padding-left: 16px; padding-right: 16px; }
  .top { grid-template-columns: 1fr auto; }
  .nextup { grid-column: 1 / -1; grid-row: 2; }
  .tabs button { padding: 10px 16px; }
  .week-grid { grid-template-columns: 0 repeat(7, 1fr); gap: 3px; }
  .wgutter { visibility: hidden; }
}

/* Settings */
.settings { height: 100%; display: grid; grid-template-rows: auto 1fr; gap: 12px; min-height: 0; }
.set-head { display: flex; align-items: baseline; gap: 12px; }
.set-head h2 { margin: 0; font-size: 22px; }
.set-head span { color: var(--muted); }
.set-cols { display: grid; grid-template-columns: 1.5fr 1fr; gap: 12px; min-height: 0; }
.set-col { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.set-card { overflow: auto; }
.set-card h3 { margin-bottom: 12px; }
.set-note { color: var(--muted); font-size: 14px; line-height: 1.45; margin: 4px 0 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg.seg-2 { grid-template-columns: repeat(2, 1fr); }
.seg button { padding: 12px 6px; border-radius: 9px; font-size: 16px; font-weight: 500; color: var(--muted); line-height: 1.2; }
.seg button small { display: block; font-size: 11.5px; font-weight: 400; margin-top: 2px; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.acct { border-top: 1px solid var(--line-soft); padding: 10px 0 6px; }
.acct:first-of-type { border-top: 0; padding-top: 0; }
.acct-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.acct-head b { display: block; font-size: 16px; }
.acct-head span { color: var(--muted); font-size: 13px; }
.cal-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 8px 0; }
.cal-row.err .cal-name { color: var(--bad); }
.cal-name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-name em { font-style: normal; font-size: 12px; color: var(--muted); margin-left: 4px; }
.cal-row select { font: inherit; font-size: 14px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.sw { position: relative; width: 46px; height: 28px; display: inline-block; }
.sw input { opacity: 0; width: 0; height: 0; position: absolute; }
.sw i { position: absolute; inset: 0; border-radius: 14px; background: var(--line); transition: background .2s; }
.sw i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .2s; }
.sw input:checked + i { background: var(--good); }
.sw input:checked + i::after { transform: translateX(18px); }
.add-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.pill-btn { display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 999px; background: var(--panel-2); font-size: 15px; font-weight: 500; }
.pill-btn:active { background: var(--press); }
.link { color: var(--muted); font-size: 14px; padding: 6px 4px; }
.link.danger { color: var(--bad); }
.qr { display: grid; place-items: center; margin: 8px auto 4px; width: 260px; height: 260px; background: #fff; border-radius: 14px; padding: 10px; }
.qr svg { width: 100%; height: 100%; }
@media (max-width: 900px) { .set-cols { grid-template-columns: 1fr; overflow: auto; } }
