/* Termine: Basis (Reset, Typografie, gemeinsame Bausteine). Tokens stehen in tokens.css. */

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; background: var(--ground); }
body {
  min-height: 100dvh;
  background: var(--ground);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
  transition: background-color 300ms ease, color 300ms ease;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 60; padding: 10px 14px; border-radius: var(--pill); background: var(--accent); color: var(--on-accent); }
.skip:focus { left: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
[hidden] { display: none !important; }

.wrap { width: 100%; max-width: 680px; margin: 0 auto; padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }

/* ---------- Bar ---------- */
.bar { background: var(--ground); }
.bar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 56px; }
.bar-inner > .scheme { margin-right: -10px; }
.mark { font: 400 20px/1 var(--serif); letter-spacing: -0.015em; color: var(--ink); text-decoration: none; white-space: nowrap; }
/* Wortmarke „when’s best?“: klein, „best“ kursiv, der Apostroph ist der Tintentropfen der Marke (--drop). */
.mark-text { display: inline-block; } /* messbar wie die Wortmarke im Intro (js/intro.js fliegt sie hierher) */
.mark i { font-style: italic; }
.mark-drop { color: var(--drop); font-weight: 600; }
.bar-end { display: flex; align-items: center; gap: 6px; min-width: 0; margin-right: -10px; }

/* ---------- Farbschema-Schalter (System → Hell → Dunkel) ---------- */
.scheme { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; color: var(--quiet);
  transition: color 150ms ease, transform 120ms var(--ease-out); }
.scheme:active { transform: scale(0.92); }
@media (hover: hover) and (pointer: fine) { .scheme:hover { color: var(--ink); } }
.scheme svg { grid-area: 1 / 1; display: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.scheme .fill { fill: currentColor; stroke: none; }
:root:not([data-scheme]) .scheme .i-system,
:root[data-scheme="light"] .scheme .i-light,
:root[data-scheme="dark"] .scheme .i-dark { display: block; }
/* Erst nach dem ersten Klick: das neue Symbol dreht sich ein (beim Laden steht es still). */
.scheme.is-live svg { animation: scheme-in 320ms var(--ease-out) both; }
@keyframes scheme-in { from { opacity: 0; transform: rotate(-60deg) scale(0.7); } }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 22px; border-radius: var(--pill); background: var(--sunk); color: var(--ink); font-size: 16px; font-weight: 600; white-space: nowrap; text-decoration: none;
  transition: background-color 150ms ease, transform 120ms var(--ease-out); }
.btn:active { transform: scale(0.97); }
.btn--main { background: var(--accent); color: var(--on-accent); }
@media (hover: hover) and (pointer: fine) { .btn--main:hover { background: var(--accent-press); } }
.btn--wide { width: 100%; }

/* ---------- Haken: ein Knopf bestätigt, dass gespeichert ist (ui.js checkMorph) ---------- */
.btn { position: relative; }
.btn .check { position: absolute; top: 50%; left: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; pointer-events: none;
  fill: none; stroke: var(--on-yes); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 2; stroke-dashoffset: 1; opacity: 0; }
.btn.is-done, .btn.is-done:hover { background: var(--yes); color: transparent; }
.btn.is-done .check { opacity: 1; stroke-dashoffset: 0; transition: stroke-dashoffset 350ms var(--ease-out) 60ms; }

/* ---------- Stempel: „Du bist dabei“, „Steht fest“ (ui.js stampIn) ---------- */
.stamp { display: inline-block; padding: 3px 10px 4px; border: 1.5px solid currentColor; border-radius: 4px; font: italic 400 17px/1.15 var(--serif); letter-spacing: -0.01em; white-space: nowrap; transform: rotate(-2deg); }

/* ---------- Tintenpunkte (ui.js burst) ---------- */
.burst { position: fixed; inset: 0; z-index: 35; pointer-events: none; overflow: hidden; }
.burst-dot { position: absolute; border-radius: 50%; background: var(--accent); }
.burst-dot.is-yes { background: var(--yes); }
.burst.is-on-field .burst-dot { background: var(--on-field); }
.burst.is-on-field .burst-dot.is-yes { background: var(--yes); }

/* ---------- Toast (mit optionalem Rückgängig und Zeitbalken) ---------- */
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 30; width: max-content; max-width: calc(100% - 40px); text-align: center; padding: 12px 18px; border-radius: var(--pill); background: var(--ink); color: var(--ground); font-size: 15px; font-weight: 500;
  opacity: 0; transform: translate(-50%, 10px) scale(0.98); pointer-events: none; transition: opacity 220ms var(--ease-out), transform 220ms var(--ease-out); }
.toast.is-on { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast.has-undo { display: flex; align-items: center; gap: 14px; padding: 8px 8px 8px 18px; overflow: hidden; }
.toast.has-undo.is-on { pointer-events: auto; }
.toast .undo { min-height: 34px; padding: 0 14px; border-radius: var(--pill); background: color-mix(in srgb, var(--ground) 18%, transparent); color: var(--ground); font-weight: 600; font-size: 14px; }
.toast .timer { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: var(--ground); opacity: .5; transform-origin: left; animation: timer 6s linear both; }
@keyframes timer { to { transform: scaleX(0); } }

/* ---------- Sheet (ziehbar, schließt mit Schwung) ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity 320ms ease; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 560px; margin: 0 auto; max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--raised); border-radius: 20px 20px 0 0; box-shadow: var(--float-shadow);
  transform: translateY(105%); transition: transform 420ms var(--ease-drawer); will-change: transform; }
.sheet.is-dragging { transition: none; }
.is-sheet .scrim { opacity: 1; pointer-events: auto; }
.is-sheet .sheet { transform: translateY(0); }
.grab { padding: 10px 20px 4px; touch-action: none; cursor: grab; }
.grab::before { content: ''; display: block; width: 40px; height: 5px; margin: 0 auto 14px; border-radius: 3px; background: var(--sunk); }
.grab h2 { font: 400 26px/1.1 var(--serif); letter-spacing: -0.02em; }
.grab p { margin-top: 6px; font-size: 15px; color: var(--quiet); }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 8px 20px calc(20px + env(safe-area-inset-bottom)); }

/* ---------- Schalter ---------- */
.switch { position: relative; flex: none; width: 50px; height: 30px; border-radius: var(--pill); background: var(--sunk); transition: background-color 200ms ease; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--raised); transition: transform 240ms var(--ease-out); }
:root[data-scheme="dark"] .switch::after { background: var(--ink); }
@media (prefers-color-scheme: dark) { :root:not([data-scheme="light"]) .switch::after { background: var(--ink); } }
.switch[aria-checked="true"] { background: var(--yes); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.switch:active::after { width: 28px; }
.switch[aria-checked="true"]:active::after { transform: translateX(16px); }

/* ---------- Segment (zwei Stellungen) mit gleitendem Daumen ---------- */
.toggle { position: relative; display: inline-grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: var(--pill); background: var(--sunk); flex: none; }
.toggle button { position: relative; z-index: 1; padding: 6px 11px; font-size: 13px; font-weight: 500; color: var(--quiet); transition: color 200ms ease; }
.toggle button[aria-pressed="true"] { color: var(--ink); }
.toggle-thumb { position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); border-radius: var(--pill); background: var(--raised); transition: transform 260ms var(--ease-out); }
.toggle[data-on="grid"] .toggle-thumb { transform: translateX(100%); }

/* ---------- Einstieg und Übergänge ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes fade { from { opacity: 0; } }
.enter { animation: rise 520ms var(--ease-out) both; animation-delay: calc(var(--i, 0) * 60ms); }

::view-transition-old(root) { animation: vt-out 180ms var(--ease-out) both; }
::view-transition-new(root) { animation: vt-in 320ms var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-6px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(10px); } }

/* Farbschema: das neue Bild liegt oben und wird per clip-path aus dem Schalter heraus aufgezogen (ui.js). */
:root.scheme-vt::view-transition-old(root),
:root.scheme-vt::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
:root.scheme-vt::view-transition-new(root) { z-index: 2; }
:root.scheme-vt * { view-transition-name: none !important; }
/* Im Moment des Umschaltens keine Farbübergänge, sonst blendet das neue Bild erst noch über. */
:root.scheme-instant, :root.scheme-instant * { transition: none !important; }
/* Ohne View Transition oder bei reduzierter Bewegung: Farben blenden kurz über. */
:root.scheme-fade, :root.scheme-fade * { transition: background-color 240ms ease, color 240ms ease, border-color 240ms ease, fill 240ms ease, stroke 240ms ease !important; }

@media (prefers-reduced-motion: reduce) {
  .enter, main .enter { animation: fade 200ms ease both; }
  .toggle-thumb { transition: opacity 200ms ease, background-color 200ms ease; }
  .sheet { transition: opacity 200ms ease; }
  .switch::after { transition-duration: 1ms; }
  .btn:active { transform: none; }
  .toast { transform: translate(-50%, 0); transition: opacity 200ms ease; }
  .toast .timer { animation: none; }
  .scheme:active { transform: none; }
  .scheme.is-live svg { animation: fade 200ms ease both; }
  .btn.is-done .check { transition: opacity 200ms ease; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}
