/*
  Shared design baseline for every MVP in this repo.
  Apps override the tokens in :root (accent, surfaces, radius, fonts) so they feel
  related but not identical. Touch-first: 44px minimum targets, safe-area aware.
*/
:root {
  --accent: #3a6df0;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --ink: #1d1d1f;
  --ink-2: #5b5b61;
  --line: color-mix(in srgb, var(--ink) 12%, transparent);
  --good: #1f8a4c;
  --warn: #b26a00;
  --bad: #c0352b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 6px 20px rgb(0 0 0 / 6%);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font);
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --tap: 44px;
  --max: 980px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214;
    --surface: #1c1c1f;
    --surface-2: #26262a;
    --ink: #f2f2f4;
    --ink-2: #a3a3ab;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 20px rgb(0 0 0 / 30%);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
img, svg, canvas, video { max-width: 100%; display: block; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }
.mono { font-family: var(--font-mono); }

/* ---------- App shell ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.app-header .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-family: var(--font-display); font-size: 1.1rem; margin: 0; }
.app-header .brand img { width: 30px; height: 30px; border-radius: 8px; }
.app-header .spacer { flex: 1; }
.app-main {
  width: 100%; max-width: var(--max); margin: 0 auto;
  padding: 16px calc(16px + var(--safe-right)) calc(96px + var(--safe-bottom)) calc(16px + var(--safe-left));
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px calc(8px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(8px + var(--safe-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button, .tabbar a {
  flex: 1; max-width: 140px; min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--ink-2); font: inherit; font-size: .75rem; text-decoration: none;
  border-radius: var(--radius-sm); cursor: pointer;
}
.tabbar .icon { font-size: 1.3rem; line-height: 1; }
.tabbar [aria-current="page"], .tabbar [aria-selected="true"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 20px 0 10px; }
.section-title h2 { margin: 0; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list > li { padding: 12px 16px; border-bottom: 1px solid var(--line); min-height: var(--tap); }
.list > li:last-child { border-bottom: 0; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .875rem; }
.btn.block { width: 100%; }
.icon-btn { min-width: var(--tap); padding: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; font-size: .875rem; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"], .chip.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span, .field > label { font-size: .875rem; font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  font: inherit; font-size: 16px; /* 16px stops iOS zoom on focus */
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  min-height: var(--tap); padding: 10px 12px; width: 100%;
}
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); padding: 0; border: 0; background: none; }
.search { position: relative; }
.search input { padding-left: 40px; border-radius: 999px; }
.search::before { content: "⌕"; position: absolute; left: 14px; top: 50%; transform: translateY(-52%); color: var(--ink-2); font-size: 1.2rem; pointer-events: none; }

/* ---------- States ---------- */
.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-2); }
.empty-state .art { font-size: 2.6rem; margin-bottom: 8px; }
.empty-state h3 { color: var(--ink); }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); font-size: .9rem; }
.notice.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.notice.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.offline-pill {
  position: fixed; top: calc(8px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 50;
  padding: 4px 12px; border-radius: 999px; background: var(--ink); color: var(--bg); font-size: .8rem; font-weight: 600;
  display: none;
}
html.is-offline .offline-pill { display: block; }
.toast-host { position: fixed; left: 0; right: 0; bottom: calc(84px + var(--safe-bottom)); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; max-width: min(92vw, 480px); padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-size: .9rem; animation: toast-in .2s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Sheets / dialogs ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: min(100%, 640px); max-height: 88dvh;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 20px; } }
dialog.sheet::backdrop { background: rgb(0 0 0 / 40%); }
dialog.sheet .sheet-body { padding: 20px 20px calc(20px + var(--safe-bottom)); overflow: auto; max-height: 88dvh; }
dialog.sheet .sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------- Install hint (iPad Safari) ---------- */
.install-hint { margin: 12px 0; display: flex; gap: 12px; align-items: flex-start; }
.install-hint .close { margin-left: auto; }

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