/* Where's My Cake. Tokens and components from design.md; every colour is a light/dark pair. */

:root {
  --canvas: #faf8f5; --surface: #ffffff; --surface-raised: #ffffff; --surface-sunken: #f3f0eb;
  --border: #e4dfd8; --border-strong: #8f8a82;
  --text: #1d1e1c; --text-ui: #46443f; --text-secondary: #5c5a56; --text-tertiary: #6e6b66;
  --accent: #7b3f9e; --accent-hover: #663283; --accent-subtle: #f0e7f6; --on-accent: #ffffff;
  --accent-inverse: #cfa3ec;
  --danger: #b42318;
  --shadow: 0 4px 16px rgba(29, 30, 28, 0.12), 0 0 0 1px rgba(29, 30, 28, 0.06);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --row: 40px; --row-pad: 12px; --date-col: 72px; --sh: 32px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --canvas: #171614; --surface: #201f1c; --surface-raised: #2a2825; --surface-sunken: #131210;
  --border: #35322e; --border-strong: #76716a;
  --text: #f0ede8; --text-ui: #cdc8bf; --text-secondary: #b3aea6; --text-tertiary: #9a958c;
  --accent: #cfa3ec; --accent-hover: #dcbcf1; --accent-subtle: #2f2239; --on-accent: #21132b;
  --accent-inverse: #7b3f9e;
  --danger: #ff8a7a;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(240, 237, 232, 0.08);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --canvas: #171614; --surface: #201f1c; --surface-raised: #2a2825; --surface-sunken: #131210;
    --border: #35322e; --border-strong: #76716a;
    --text: #f0ede8; --text-ui: #cdc8bf; --text-secondary: #b3aea6; --text-tertiary: #9a958c;
    --accent: #cfa3ec; --accent-hover: #dcbcf1; --accent-subtle: #2f2239; --on-accent: #21132b;
    --accent-inverse: #7b3f9e;
    --danger: #ff8a7a;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(240, 237, 232, 0.08);
    color-scheme: dark;
  }
}
@media (max-width: 720px) {
  :root { --row: 48px; --row-pad: 16px; --date-col: 56px; --sh: 40px; }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--canvas); color: var(--text); }
body { font: 400 16px/1.4 var(--sans); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ic { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.meta { font-size: 13px; color: var(--text-secondary); margin: 0; }
.caption { font-size: 12px; font-weight: 500; line-height: 1.35; color: var(--text-tertiary); margin: 0; }
.title { font-size: 20px; font-weight: 600; line-height: 1.3; margin: 0 0 16px; }
[hidden] { display: none !important; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 14px;
  border-radius: 8px; border: 1px solid transparent; cursor: pointer; font-size: 15px; white-space: nowrap;
  transition: background 120ms var(--ease); }
.btn.primary { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); text-decoration: none; }
.btn.primary:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn.wide { width: 100%; }
.text-btn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: inherit;
  display: inline-flex; align-items: center; gap: 4px; }
.text-btn:hover { text-decoration: underline; }
.danger { color: var(--danger); }
.icon-btn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: none; border-radius: 8px; color: var(--text-ui); cursor: pointer; }
.icon-btn:hover { background: var(--surface-sunken); }
@media (max-width: 720px) { .btn { height: 44px; } }

/* Fields */
.field { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--text); }
.field::placeholder { color: var(--text-tertiary); }
.field:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field.invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }
.field-error:empty { display: none; }
select.field { appearance: auto; }

/* Top bar */
.top { position: sticky; top: 0; z-index: 20; height: 56px; display: flex; align-items: center; gap: 8px;
  max-width: 720px; margin: 0 auto; padding: 0 12px; background: var(--canvas); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text-ui); font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 5px; }
.page-title { display: none; }
.spacer { flex: 1; }
.phone-avatar { display: none; }
.avatar { width: 28px; height: 28px; border-radius: 999px; background: var(--surface-sunken); color: var(--text-ui);
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; }
.avatar:hover { text-decoration: none; background: var(--border); }
.offline { display: none; color: var(--text-tertiary); }
body.is-offline .offline { display: inline-flex; }
@media (max-width: 720px) {
  .top { padding: 0 16px; }
  .brand, .desk-avatar, .add-top { display: none; }
  .phone-avatar { display: inline-flex; }
  .page-title { display: block; font-size: 20px; font-weight: 600; margin: 0; }
}

/* Layout */
.layout { max-width: 720px; margin: 0 auto; }
.col { max-width: 720px; margin: 0 auto; padding: 0 12px 120px; }
@media (max-width: 720px) { .col { padding: 0 0 120px; } }

/* Next up */
.nextup { display: flex; gap: 16px; padding: 16px 12px 20px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.nextup .cd { width: 96px; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.nextup .cd strong { font: 600 48px/1 var(--mono); font-variant-numeric: tabular-nums; color: var(--text); }
.nextup .cd small { font-size: 12px; font-weight: 500; color: var(--text-tertiary); margin-top: 4px; }
.nu-body { min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.nu-name { font-size: 20px; font-weight: 600; line-height: 1.3; margin: 0; }
.nu-name a { color: var(--text); }
.nextup .plan { color: var(--text-tertiary); }
.nextup.today { background: var(--accent-subtle); border-radius: 12px; border-bottom: 0; }
.nextup.today .cd { color: var(--accent); }
.nextup.today .cd small { color: var(--accent); }
.nextup.today .plan, .nextup.today .plan .ic { color: var(--text-secondary); }
@media (max-width: 720px) {
  .nextup { margin: 0 16px 16px; padding: 12px 0 16px; }
  .nextup.today { padding: 12px; }
  .nextup .cd strong { font-size: 40px; }
  .nextup .cd { width: 72px; }
}

/* Plan sentence */
.plan { display: flex; gap: 6px; align-items: flex-start; font-size: 13px; color: var(--text-secondary); margin: 0; }
.plan .ic { color: var(--text-tertiary); margin-top: 1px; }

/* Filters and find */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span { display: inline-flex; align-items: center; height: 32px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); color: var(--text-ui); transition: background 120ms var(--ease); }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 720px) { .chip span { height: 44px; } }
.filters { padding: 0 12px 16px; }
.find { padding: 0 12px 16px; }
.find input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); }
.find input:focus { outline: 2px solid var(--accent); }
.find .caption { margin-top: 4px; }
.nomatch { padding: 0 12px; }
@media (max-width: 720px) { .filters, .find, .nomatch { padding-left: 16px; padding-right: 16px; } }

/* Sections and rows */
.sect { margin-bottom: 24px; }
.sh { position: sticky; top: 56px; z-index: 5; height: var(--sh); display: flex; align-items: center; gap: 8px;
  margin: 0; padding: 0 var(--row-pad); background: var(--canvas); color: var(--text-ui); font-size: 16px; font-weight: 600; }
.sh.is-today { color: var(--accent); }
.sh .n { font-size: 12px; font-weight: 500; color: var(--text-tertiary); }
.rows { list-style: none; margin: 0; padding: 0; }
.row { position: relative; height: var(--row); display: flex; align-items: center; gap: 0; padding: 0 var(--row-pad);
  border-radius: 6px; cursor: pointer; transition: background 120ms var(--ease); }
/* The hairline is drawn apart from the row, so the row's rounded hover does not bend it. */
.row::after { content: ""; position: absolute; left: var(--row-pad); right: var(--row-pad); bottom: 0; height: 1px; background: var(--border); }
.row:hover, .row.opened { background: var(--surface-sunken); }
.row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.row.today { background: var(--accent-subtle); }
.row.today .name { font-weight: 600; }
.row .date { width: var(--date-col); flex: none; font: 13px var(--mono); font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.row.today .date { color: var(--accent); display: flex; align-items: center; }
.row .who { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; overflow: hidden; white-space: nowrap; }
.row .name { overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.row .turns { font-size: 13px; color: var(--text-secondary); flex: none; }
.row .icons { display: flex; gap: 6px; color: var(--text-tertiary); flex: none; margin-left: 8px; }
.row.today .icons { color: var(--text-secondary); }
.row .count { width: 88px; flex: none; text-align: right; font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .row { border-radius: 0; }
  .row.far .count { display: none; }
  .row .count { width: auto; margin-left: 8px; }
}

/* Empty state */
.empty { padding: 64px 16px; text-align: center; }
.display { font-size: 28px; font-weight: 600; line-height: 1.2; margin: 0 0 24px; }

/* Corner add button (phone) */
.corner { display: none; }
@media (max-width: 720px) {
  .corner { position: fixed; right: 0; bottom: 0; z-index: 30; width: 96px; height: 96px; border: 0; padding: 0;
    border-top-left-radius: 96px; background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow);
    display: block; cursor: pointer; }
  .corner .ic { position: absolute; right: 28px; bottom: 28px; }
  .settings-page .corner, body.sheet-open .corner { display: none; }
}

/* Layers: add sheet */
.layer { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .28); }
.sheet { position: relative; width: 480px; max-width: calc(100vw - 24px); max-height: calc(100vh - 48px); overflow: auto;
  background: var(--surface-raised); border-radius: 12px; box-shadow: var(--shadow); }
.sheet-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 20px; font-weight: 600; margin: 0; }
.sheet-foot { display: flex; align-items: center; gap: 12px; padding-top: 4px; }
@media (max-width: 720px) {
  .layer { align-items: flex-end; }
  .sheet { width: 100%; max-width: 100%; max-height: 100dvh; height: 100dvh; border-radius: 12px 12px 0 0; }
  .desk { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .sheet, #detail.open { animation: rise 180ms var(--ease); }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

/* Date picker */
.months, .days { display: grid; gap: 4px; }
.months { grid-template-columns: repeat(4, 1fr); }
.days { grid-template-columns: repeat(7, 1fr); }
.cellbtn { position: relative; }
.cellbtn input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.cellbtn span { height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 8px;
  background: var(--surface-sunken); color: var(--text-ui); transition: background 120ms var(--ease); }
.days .cellbtn span { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.cellbtn input:checked + span { background: var(--accent); color: var(--on-accent); }
.cellbtn input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
form:not(:has(input[name=birth_month]:checked)) .days { display: none; }
form:has(input[name=birth_month][value="2"]:checked) .d30,
form:has(input[name=birth_month][value="2"]:checked) .d31,
form:has(input[name=birth_month][value="4"]:checked) .d31,
form:has(input[name=birth_month][value="6"]:checked) .d31,
form:has(input[name=birth_month][value="9"]:checked) .d31,
form:has(input[name=birth_month][value="11"]:checked) .d31 { display: none; }
.leap { display: none; font-size: 12px; color: var(--text-tertiary); margin: 0; }
form:has(input[name=birth_month][value="2"]:checked):has(input[name=birth_day][value="29"]:checked) .leap { display: block; }
@media (max-width: 720px) {
  .months { grid-template-columns: repeat(3, 1fr); }
  .months .cellbtn span { height: 48px; }
  .days .cellbtn span { height: 44px; }
}
.year-row { display: flex; align-items: center; gap: 12px; }
.year-row .year { width: 96px; flex: none; }

/* Reminder grid */
.add-plan-line { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.add-rem .grid { display: none; margin-top: 8px; }
form.show-grid .add-rem .grid { display: block; }
.grid { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.grow { display: grid; grid-template-columns: 1fr 64px 64px; align-items: center; border-top: 1px solid var(--border); }
.grow:first-child { border-top: 0; }
.ghead { background: var(--surface-sunken); font-size: 12px; font-weight: 500; text-transform: uppercase; color: var(--text-tertiary); height: 32px; }
.ghead > span { padding: 0 12px; }
.ghead > span:not(:first-child) { text-align: center; padding: 0; text-transform: none; }
.ghead a { text-transform: none; }
.when { display: flex; flex-direction: column; padding: 8px 12px; }
.when small { font-size: 13px; color: var(--text-tertiary); }
.cell { height: 100%; min-height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.cell input { appearance: none; width: 18px; height: 18px; margin: 0; border: 1.5px solid var(--border-strong); border-radius: 4px;
  background: var(--surface); display: grid; place-content: center; cursor: pointer; transition: background 120ms var(--ease); }
.cell input:checked { background: var(--accent); border-color: var(--accent); }
.cell input:checked::after { content: ""; width: 10px; height: 6px; border: 2px solid var(--on-accent); border-top: 0; border-right: 0;
  transform: rotate(-45deg) translate(1px, -1px); }
.cell.off input { border-color: var(--text-tertiary); }
.cell.off input:checked { background: var(--text-tertiary); border-color: var(--text-tertiary); }

/* Person detail */
#detail:not(.open) { display: none; }
/* Wide enough for both: the column moves left so the 400px panel sits beside it. */
#detail.open { position: fixed; top: 56px; right: max(0px, calc((100vw - 1132px) / 2)); width: 400px; bottom: 0; z-index: 40;
  background: var(--surface); border-left: 1px solid var(--border); overflow: auto; padding: 16px 20px 40px; }
@media (min-width: 1141px) {
  body:has(#detail.open) .layout, body:has(#detail.open) .top { margin-left: max(0px, calc((100vw - 1132px) / 2)); }
}
@media (max-width: 1140px) {
  #detail.open { right: 0; background: var(--surface-raised); box-shadow: var(--shadow); border-left: 0; }
}
@media (max-width: 720px) {
  #detail.open { top: 24px; width: 100%; border-radius: 12px 12px 0 0; }
}
.detail-form { display: flex; flex-direction: column; }
.dhead { display: flex; gap: 8px; align-items: center; }
.dname { font-size: 20px; font-weight: 600; height: 44px; border-color: transparent; background: transparent; padding: 0 8px; margin-left: -8px; }
.dname:hover { border-color: var(--border); }
.dblock { padding: 16px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 12px; }
details.dblock > summary { list-style: none; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
details.dblock > summary::-webkit-details-marker { display: none; }
.ddate { color: var(--text); }
.dremove { margin-top: 32px; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; }
.toast { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-radius: 8px; background: var(--text); color: var(--canvas);
  box-shadow: var(--shadow); font-size: 15px; white-space: nowrap; }
.toast button { background: none; border: 0; color: var(--accent-inverse); font-weight: 600; cursor: pointer; padding: 0; }
@media (max-width: 720px) { #toast { bottom: 112px; } }

/* Settings */
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; margin: 8px 0 12px; }
.settings-page .col { padding: 0 12px 64px; }
@media (max-width: 720px) { .settings-page .col { padding: 0 16px 64px; } .settings-page .title { display: none; } }
.sblock { margin-bottom: 24px; }
.sbh { font-size: 16px; font-weight: 600; color: var(--text-ui); margin: 0 0 4px; }
.srow, .toggle-row { display: flex; gap: 16px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--border); }
.srow.stack { flex-wrap: wrap; }
.slabel { width: 120px; flex: none; padding-top: 8px; }
.sval { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.sval.v { padding-top: 8px; color: var(--text); }
.toggle-row { align-items: center; cursor: pointer; }
.tl { flex: 1; display: flex; flex-direction: column; }
.switch { appearance: none; width: 36px; height: 20px; border-radius: 999px; background: var(--border-strong); position: relative;
  cursor: pointer; margin: 0; flex: none; transition: background 120ms var(--ease); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 999px; background: #fff;
  transition: transform 120ms var(--ease); }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); }
.push-reg { flex-direction: column; gap: 6px; }
.pr-state { display: flex; align-items: center; gap: 6px; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: inline-flex; height: 32px; align-items: center; padding: 0 14px; color: var(--text-ui); }
.segmented input:checked + span { background: var(--accent); color: var(--on-accent); }
.pk { display: flex; align-items: center; gap: 10px; color: var(--text-secondary); }
.pkt { flex: 1; display: flex; flex-direction: column; color: var(--text); }
.pk-none { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.tz-offer { font-size: 13px; color: var(--text-secondary); margin: 0; }
.signout { margin-top: 32px; }
@media (max-width: 720px) { .slabel { width: 100%; padding-top: 0; } .srow:not(.stack) { flex-wrap: wrap; gap: 6px; } }

/* Sign-in */
.signin { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; }
.signin form { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.signin .text-btn { align-self: center; }
.signin .code { font-size: 24px; letter-spacing: 6px; text-align: center; height: 52px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
