/* Base: reset, typography, controls, dialogs, toasts, effects. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--on-table);
  background-color: var(--table);
  background-image: radial-gradient(var(--table-dot) 1.5px, transparent 1.6px);
  background-size: 22px 22px;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0; }
p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
ul[role="list"], ol.review-steps { list-style: none; margin: 0; padding: 0; }
[hidden] { display: none !important; }

.icon {
  width: 1.25em; height: 1.25em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.rot-90 .icon, .icon.rot-90 { transform: rotate(90deg); }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 1rem; top: -4rem; z-index: 100;
  background: var(--sunny); color: var(--chip-ink); padding: .75rem 1.25rem;
  border: var(--line) solid var(--ink); border-radius: var(--radius-sm);
  font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: 1rem; }

/* Focus: thick sunny ring with a dark inner edge, visible on every surface. */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--focus-inner);
  border-radius: 8px;
}
h1:focus-visible, main:focus-visible { box-shadow: none; outline-offset: 4px; }

kbd {
  display: inline-block; min-width: 1.6em; padding: 0 .35em; text-align: center;
  font-family: var(--font-display); font-size: .85em; font-weight: 600;
  border: 2px solid currentColor; border-radius: 6px; line-height: 1.4;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: var(--tap); padding: .5rem 1.1rem;
  font-family: var(--font-display); font-weight: 600; font-size: 1rem; text-decoration: none;
  color: var(--card-text); background: var(--card);
  border: var(--line) solid var(--card-line); border-radius: 999px;
  box-shadow: 0 4px 0 var(--shadow);
  cursor: pointer; user-select: none;
  transition: transform .12s var(--spring), box-shadow .12s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--shadow); }
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--shadow); }
.btn:focus-visible { border-radius: 999px; }
.btn-sunny { background: var(--sunny); color: var(--chip-ink); border-color: var(--ink); }
.btn-teal { background: var(--teal); color: var(--chip-ink); border-color: var(--ink); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
:root[data-theme="dark"] .btn-primary { background: var(--sunny); color: var(--chip-ink); }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .btn-primary { background: var(--sunny); color: var(--chip-ink); } }
.btn-ghost { background: transparent; color: inherit; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { box-shadow: none; text-decoration: underline; }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: currentColor; box-shadow: none; }
.btn-small { min-height: 2.5rem; padding: .25rem .85rem; font-size: .9rem; box-shadow: 0 3px 0 var(--shadow); }
.btn-big { min-height: 3.5rem; padding: .75rem 1.6rem; font-size: 1.15rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: var(--tap); height: var(--tap);
  background: transparent; border: 0; border-radius: 50%; color: inherit; cursor: pointer;
  text-decoration: none;
}
.icon-btn:hover { background: rgb(255 255 255 / .15); }
.icon-btn .icon { width: 1.5rem; height: 1.5rem; }
.icon-danger { color: var(--danger); }
.button-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.center { display: flex; justify-content: center; margin-top: 2rem; }

/* ---------------------------------------------------------------- form controls */
.input {
  width: 100%; min-height: var(--tap); padding: .55rem .85rem;
  background: var(--field); color: var(--card-text);
  border: 2px solid var(--field-border); border-radius: var(--radius-sm);
}
.input:focus-visible { border-color: var(--card-line); }
.input::placeholder { color: var(--card-muted); opacity: 1; }
textarea.input { resize: vertical; min-height: 3rem; }
.input-small { width: auto; min-height: 2.5rem; padding: .3rem .6rem; }
.input-num { width: 6rem; }
.input-big { font-size: 1.2rem; min-height: 3.5rem; }
select.input { cursor: pointer; }
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field > label, .field > legend, fieldset > legend { font-weight: 700; font-size: .95rem; }
.field-inline { flex-direction: row; align-items: center; gap: .5rem; }
.field-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); align-items: start; }
.hint { font-size: .9rem; color: var(--card-muted); }
.field-error { color: var(--danger); font-weight: 700; font-size: .95rem; }
.field-error:empty { display: none; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--ink); }

/* Switches (checkbox role=switch) */
.switch { flex-direction: row; flex-wrap: wrap; align-items: center; gap: .65rem; }
.switch input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 3.2rem; height: 1.9rem; border-radius: 999px; margin: 0;
  background: var(--card-alt); border: 2px solid var(--field-border); position: relative; cursor: pointer;
  transition: background .2s;
}
.switch input::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 1.35rem; height: 1.35rem; border-radius: 50%;
  background: var(--card-text); transition: transform .25s var(--spring);
}
.switch input:checked { background: var(--teal); border-color: var(--card-line); }
.switch input:checked::after { transform: translateX(1.3rem); background: var(--chip-ink); }
.switch label { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; font-weight: 700; }
.switch .hint { flex-basis: 100%; }

/* Segmented radio/checkbox groups */
.segmented { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg label {
  display: inline-flex; align-items: center; gap: .35rem; min-height: 2.6rem; padding: .3rem .85rem;
  border: 2px solid var(--field-border); border-radius: 999px; cursor: pointer; font-weight: 700;
  background: var(--field); color: var(--card-text); user-select: none;
}
.seg label .icon { width: 1.1rem; height: 1.1rem; }
.seg input:checked + label { background: var(--ink); color: #fff; border-color: var(--ink); }
:root[data-theme="dark"] .seg input:checked + label { background: var(--sunny); color: var(--chip-ink); border-color: var(--sunny); }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .seg input:checked + label { background: var(--sunny); color: var(--chip-ink); border-color: var(--sunny); } }
.seg.ctx-pink input:checked + label, .seg.ctx-teal input:checked + label, .seg.ctx-orange input:checked + label,
.seg.ctx-sunny input:checked + label, .seg.ctx-sky input:checked + label, .seg.ctx-lime input:checked + label,
.seg.ctx-violet input:checked + label, .seg.ctx-coral input:checked + label { background: var(--ctx); color: var(--chip-ink); border-color: var(--card-line); }
.seg input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 2px var(--focus-inner); }

.range { width: 100%; accent-color: var(--teal); min-height: var(--tap); }

/* ---------------------------------------------------------------- chips */
.chip {
  display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem;
  border-radius: 999px; font-size: .85rem; font-weight: 700; white-space: nowrap;
  border: 2px solid var(--card-line);
}
.chip .icon { width: 1rem; height: 1rem; }
.chip-overdue { background: var(--overdue-bg); color: var(--overdue-text); border-color: currentColor; }
.chip-today { background: var(--today-bg); color: var(--today-text); }
.chip-soon { background: var(--soon-bg); color: var(--card-text); }
.chip-date { background: var(--date-bg); color: var(--card-text); }

.chip-row { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0 1rem; }
.filter-chip {
  display: inline-flex; align-items: center; gap: .4rem; min-height: 2.75rem; padding: .3rem .9rem;
  background: rgb(255 255 255 / .12); color: var(--on-table);
  border: 2px solid rgb(255 255 255 / .55); border-radius: 999px; cursor: pointer;
  font-family: var(--font-display); font-weight: 600;
}
.filter-chip .icon { width: 1.1rem; height: 1.1rem; }
.filter-chip:hover { background: rgb(255 255 255 / .22); }
.filter-chip[aria-pressed="true"] { background: var(--ctx, var(--sunny)); color: var(--chip-ink); border-color: var(--ink); box-shadow: 0 3px 0 var(--shadow); }
.filter-chip .chip-count { font-size: .8rem; opacity: .85; }
.filter-chip .chip-count:empty { display: none; }

.count-pill {
  display: inline-grid; place-items: center; min-width: 1.75rem; height: 1.75rem; padding: 0 .45rem;
  background: rgb(255 255 255 / .2); border-radius: 999px; font-size: .9rem;
}

/* ---------------------------------------------------------------- dialogs */
.dialog {
  width: min(42rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem);
  padding: 0; margin: auto; overflow: auto;
  color: var(--card-text); background: var(--surface);
  border: var(--line) solid var(--card-line); border-radius: calc(var(--radius) + 4px);
  box-shadow: 8px 8px 0 var(--shadow);
}
.dialog::backdrop { background: var(--backdrop); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1rem .25rem 1.5rem; position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.dialog-title { font-size: 1.35rem; }
.dialog-body { padding: .5rem 1.5rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.dialog .icon-btn:hover { background: var(--card-alt); }
.dialog-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .75rem; margin-top: .5rem; }
.dialog-small { width: min(26rem, calc(100vw - 2rem)); }
.dialog-message { font-size: 1.1rem; }
.dialog-menu { width: min(22rem, calc(100vw - 2rem)); }
.dialog-menu.is-anchored { position: fixed; margin: 0; }
.dialog-menu .dialog-title { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.menu { display: flex; flex-direction: column; gap: .5rem; }
.menu-label { font-weight: 700; font-size: .9rem; color: var(--card-muted); }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin-bottom: .5rem; }
.menu-list { display: flex; flex-direction: column; gap: .15rem; list-style: none; margin: 0; padding: 0; }
.menu-item {
  display: flex; align-items: center; gap: .75rem; width: 100%; min-height: var(--tap); padding: .5rem .75rem;
  background: transparent; border: 2px solid transparent; border-radius: var(--radius-sm); cursor: pointer;
  text-align: start; text-decoration: none; font-weight: 700; color: var(--card-text);
}
.menu-grid .menu-item { border-color: var(--field-border); }
.menu-item:hover { background: var(--card-alt); }
.menu-item .nav-count { margin-inline-start: auto; }
.menu-danger { color: var(--danger); }

/* Bottom sheets on small screens */
@media (max-width: 599px) {
  .dialog.dialog, .dialog-menu.is-anchored {
    width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; inset: auto 0 0 0; position: fixed;
    border-radius: 24px 24px 0 0; border-bottom: 0; box-shadow: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .dialog-head::before {
    content: ''; position: absolute; top: .4rem; left: 50%; width: 3rem; height: .3rem; margin-left: -1.5rem;
    background: var(--field-border); border-radius: 999px;
  }
  .dialog-body { padding: .5rem 1rem 1.25rem; }
  .dialog-head { padding: 1.1rem .5rem .25rem 1rem; }
}

/* ---------------------------------------------------------------- toasts */
.toasts {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: .5rem; width: min(30rem, calc(100vw - 2rem));
}
.toast {
  display: flex; align-items: center; gap: .75rem; padding: .5rem .5rem .5rem 1rem;
  background: var(--ink); color: #fff; border: var(--line) solid var(--card-line); border-radius: var(--radius);
  box-shadow: 0 5px 0 var(--shadow); animation: toast-in .35s var(--spring);
}
:root[data-theme="dark"] .toast { background: var(--card-alt); }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .toast { background: var(--card-alt); } }
.toast p { flex: 1; font-weight: 700; }
.toast .icon { color: var(--teal); }
.toast-error .icon { color: #FF9AAA; }
.toast .icon-btn { width: 2.5rem; height: 2.5rem; }
.toast .icon-btn .icon { color: inherit; width: 1.2rem; height: 1.2rem; }
.toast.leaving { opacity: 0; transform: translateY(10px); transition: all .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(20px) scale(.9); } }

/* ---------------------------------------------------------------- effects */
.ghost-card {
  position: fixed; z-index: 80; pointer-events: none; overflow: hidden;
  background: var(--card); color: var(--card-text); border: var(--line) solid var(--card-line); border-radius: var(--radius);
  box-shadow: 4px 4px 0 var(--shadow); padding: 1rem; font-family: var(--font-display); font-weight: 600;
}
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti { position: absolute; width: 10px; height: 14px; border-radius: 2px; }
.confetti.star { width: 14px; height: 14px; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.banner {
  position: fixed; z-index: 95; left: 50%; top: 40%; pointer-events: none;
  padding: 1rem 2.25rem; background: var(--sunny); color: var(--chip-ink);
  font-family: var(--font-display); font-weight: 700; font-size: clamp(1.8rem, 6vw, 3.25rem); white-space: nowrap;
  border: 4px solid var(--ink); border-radius: 24px; box-shadow: 8px 8px 0 var(--ink);
  transform: translate(-50%, -50%);
}

.loading { display: grid; place-items: center; min-height: 60vh; }
.loading-card {
  width: 5rem; height: 7rem; border-radius: var(--radius); background: var(--card);
  border: var(--line) solid var(--ink); box-shadow: 5px 5px 0 var(--shadow);
  animation: loading-flip 1.2s ease-in-out infinite;
}
@keyframes loading-flip { 50% { transform: rotateY(180deg); } }
.noscript { padding: 2rem; text-align: center; font-size: 1.25rem; }

/* Motion settings */
:root[data-motion="reduced"] *, :root[data-motion="off"] * {
  animation-duration: .01ms !important; animation-iteration-count: 1 !important;
  transition-duration: .01ms !important; scroll-behavior: auto !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Windows high contrast / forced colours */
@media (forced-colors: active) {
  .card, .btn, .dialog, .toast, .chip, .filter-chip, .deck-face { border-color: CanvasText; }
  .filter-chip[aria-pressed="true"], .seg input:checked + label { forced-color-adjust: none; background: Highlight; color: HighlightText; }
}
