/* Cypher News: Fundament. Tokens, Basis, Gerüst, Navigation, Buttons, Formulare.
   Screens (Lesen, Karten, Profil, Zustände): app.css. Richtung und Begründung: DESIGN.md. */

@font-face { font-family: 'Newsreader'; src: url('/static/fonts/Newsreader.woff2') format('woff2'); font-weight: 200 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'Newsreader'; src: url('/static/fonts/Newsreader-Italic.woff2') format('woff2'); font-weight: 200 800; font-style: italic; font-display: swap; }
@font-face { font-family: 'SpaceGrotesk'; src: url('/static/fonts/SpaceGrotesk.ttf') format('truetype'); font-weight: 300 700; font-display: swap; }
@font-face { font-family: 'VT323'; src: url('/static/fonts/VT323.ttf') format('truetype'); font-display: swap; }

:root {
    color-scheme: dark;
    /* Papier und Tinte, dunkle Ausgabe: warmes Schwarz, ein Signalton */
    --bg: #0c0a08;
    --surface: #15120f;
    --surface-2: #221d17;
    --line: #28221b;
    --line-strong: #43392e;
    --ink: #f4eee3;
    --ink-2: #d2c8b9;
    --dim: #a3988b;
    --accent: #ff6a2b;          /* Flächen */
    --accent-ink: #1a0d05;      /* Text auf Akzentfläche */
    --accent-text: #ff8a55;     /* Akzent als Text/Link auf --bg */
    --danger: #ff7a68;
    --ok: #b6d65a;
    --focus: #ffb38a;
    --control: #80725f;       /* Rahmen von Bedienelementen: mind. 3:1 (WCAG 1.4.11) */
    --on-danger: #1a0705;
    --c-konzerte: #f0a640;
    --c-giveaways: #b6d65a;
    --c-drops: #f07aa0;
    --c-tech: #5ccbb5;
    --c-trends: #e9d75c;
    --c-news: #b3a496;
    --serif: 'Newsreader', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
    --sans: 'SpaceGrotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'VT323', ui-monospace, Consolas, Menlo, monospace;
    --ease: cubic-bezier(.22, .9, .24, 1);
    --r-s: 8px; --r-m: 12px; --r-l: 18px;
    --pad: 20px;
    --nav-h: 60px;
}
:root[data-theme="light"] {
    color-scheme: light;
    --bg: #f5efe3;
    --surface: #fbf7ee;
    --surface-2: #ece4d3;
    --line: #ddd3bf;
    --line-strong: #c4b79d;
    --ink: #1c1712;
    --ink-2: #483f33;
    --dim: #6c6053;
    --accent: #c0400c;
    --accent-ink: #ffffff;
    --accent-text: #b43a0a;
    --danger: #b3321f;
    --ok: #4d6b0c;
    --focus: #b43a0a;
    --control: #857a6a;
    --on-danger: #ffffff;
    --c-konzerte: #955400;
    --c-giveaways: #55750f;
    --c-drops: #b52b62;
    --c-tech: #0b7a66;
    --c-trends: #7d6a00;
    --c-news: #6c6053;
}
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        color-scheme: light;
        --bg: #f5efe3;
        --surface: #fbf7ee;
        --surface-2: #ece4d3;
        --line: #ddd3bf;
        --line-strong: #c4b79d;
        --ink: #1c1712;
        --ink-2: #483f33;
        --dim: #6c6053;
        --accent: #c0400c;
        --accent-ink: #ffffff;
        --accent-text: #b43a0a;
        --danger: #b3321f;
        --ok: #4d6b0c;
        --focus: #b43a0a;
        --control: #857a6a;
        --on-danger: #ffffff;
        --c-konzerte: #955400;
        --c-giveaways: #55750f;
        --c-drops: #b52b62;
        --c-tech: #0b7a66;
        --c-trends: #7d6a00;
        --c-news: #6c6053;
    }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; scroll-padding-top: 16px; }
html, body { min-height: 100%; }
body {
    font-family: var(--sans);
    font-size: 16px; line-height: 1.5;
    background: var(--bg); color: var(--ink);
    overflow-x: hidden;
    overscroll-behavior-y: none;
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}
body { background-image: radial-gradient(120% 60% at 50% -10%, color-mix(in oklab, var(--accent) 7%, transparent), transparent 70%); background-repeat: no-repeat; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
a { color: var(--accent-text); text-underline-offset: .18em; text-decoration-thickness: 1px; }
::selection { background: var(--accent); color: var(--accent-ink); }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.sprite { position: absolute; width: 0; height: 0; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 6px; }
:focus:not(:focus-visible) { outline: none; }
#main:focus, .page-title:focus, .today-empty h1:focus, .empty:focus { outline: none; }
.skip { position: absolute; z-index: 300; left: 12px; top: -80px; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: var(--r-s); font-weight: 600; text-decoration: none; }
.skip:focus { top: 12px; }

/* ── Regenfläche: nur Willkommen und Ladezustand ── */
#rainCanvas { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; opacity: 0; transition: opacity .8s var(--ease); }
body.rain-on #rainCanvas { opacity: .11; }
@media (prefers-color-scheme: light) { :root:not([data-theme]) body.rain-on #rainCanvas { opacity: .05; } }
:root[data-theme="light"] body.rain-on #rainCanvas { opacity: .05; }

/* ── Gerüst ── */
.shell { position: relative; z-index: 1; min-height: 100dvh; display: flex; flex-direction: column; max-width: 680px; margin: 0 auto; }
.rail { display: contents; }
.masthead { order: 0; margin: 0 var(--pad); padding: calc(env(safe-area-inset-top) + 16px) 0 12px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; border-bottom: 3px double var(--line-strong); }
.stage { order: 1; flex: 1; padding: 22px var(--pad) calc(var(--nav-h) + env(safe-area-inset-bottom) + 40px); min-width: 0; }
.footer { order: 2; padding: 0 var(--pad) calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); color: var(--dim); font-size: 12.5px; line-height: 1.6; }
.footer a { color: var(--dim); }
.footer a:hover { color: var(--ink); }
.footer p + p { margin-top: 2px; }

.logo { font-family: var(--serif); font-weight: 620; font-size: 28px; line-height: 1; letter-spacing: -.02em; color: var(--ink); text-decoration: none; display: inline-flex; align-items: baseline; gap: 5px; font-optical-sizing: auto; white-space: nowrap; }
.logo .cursor { width: .36em; height: .36em; background: var(--accent); display: inline-block; animation: cursor 1.1s steps(1) 1.2s 8; transform: translateY(.02em); }
@keyframes cursor { 50% { opacity: 0; } }
.edition { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); line-height: 1.2; text-align: right; }
.edition-name { color: var(--ink-2); font-weight: 600; }
.edition-date:empty { display: none; }

/* ── Navigation: unten auf dem Handy, links am Desktop ── */
.tabs { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; background: color-mix(in oklab, var(--bg) 88%, transparent); -webkit-backdrop-filter: blur(16px) saturate(1.4); backdrop-filter: blur(16px) saturate(1.4); border-top: 1px solid var(--line); padding: 0 max(8px, env(safe-area-inset-left)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-right)); }
.tab-btn { flex: 1 1 0; max-width: 150px; min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--dim); font-size: 11.5px; font-weight: 500; letter-spacing: .02em; position: relative; transition: color .18s var(--ease); }
.tab-ind { position: absolute; z-index: 1; top: -1px; left: 0; width: 28px; height: 2px; background: var(--accent); transform: translateX(var(--x, -40px)); transition: transform .5s var(--ease); pointer-events: none; }
.tab-btn.active { color: var(--ink); }
.tab-btn.active .ico { stroke-width: 2; }
.tab-btn:active .ico { transform: scale(.88); }
.tab-btn .ico { transition: transform .18s var(--ease); }
@media (hover: hover) { .tab-btn:hover { color: var(--ink); } }

/* ── Desktop: Rail links, Lesespalte rechts ── */
@media (min-width: 960px) {
    :root { --nav-h: 0px; }
    .shell { max-width: 1080px; display: grid; grid-template-columns: 236px minmax(0, 660px); column-gap: 72px; padding: 0 32px; justify-content: center; align-items: start; }
    .rail { display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; padding: 44px 0 32px; }
    .masthead { flex-direction: column; align-items: flex-start; gap: 14px; margin: 0; padding: 0 0 18px; }
    .logo { font-size: 34px; }
    .edition { align-items: flex-start; text-align: left; flex-direction: row; gap: 10px; }
    .edition-date::before { content: '·'; margin-right: 10px; color: var(--line-strong); }
    .tabs { position: static; display: flex; flex-direction: column; justify-content: flex-start; background: none; -webkit-backdrop-filter: none; backdrop-filter: none; border: 0; padding: 20px 0 0; gap: 2px; }
    .tab-btn { flex: none; max-width: none; flex-direction: row; justify-content: flex-start; gap: 14px; min-height: 46px; padding: 0 14px; border-radius: var(--r-m); font-size: 15px; transition: color .18s var(--ease), background .18s var(--ease); }
    .tabs { position: relative; }
    .tab-ind { top: 0; width: 3px; height: 18px; border-radius: 2px; transform: translateY(var(--y, 0)); }
    .tab-btn.active { background: var(--surface); }
    .tab-btn:hover { background: var(--surface); }
    .footer { order: 0; margin-top: auto; padding: 0; }
    .stage { padding: 52px 0 120px; min-height: 100dvh; }
}

/* ── Buttons ── */
.btn-drop, .btn-small, .modal-btn { font-family: var(--sans); font-weight: 600; letter-spacing: .005em; border-radius: var(--r-m); transition: transform .14s var(--ease), background-color .18s, border-color .18s, color .18s, opacity .18s; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-drop { width: 100%; min-height: 54px; padding: 0 24px; font-size: 17px; background: var(--accent); color: var(--accent-ink); }
.btn-small { min-height: 46px; padding: 0 18px; font-size: 15px; background: var(--accent); color: var(--accent-ink); }
.btn-small.icon { min-width: 46px; padding: 0; font-size: 24px; font-weight: 500; }
.btn-small.ghost { background: transparent; color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--control); }
.btn-small.danger { color: var(--danger); }
.btn-drop:active, .btn-small:active, .modal-btn:active { transform: scale(.97); }
.btn-drop[aria-disabled="true"], .btn-small[aria-disabled="true"] { opacity: .55; cursor: progress; transform: none; }
.btn-drop.is-busy::after, .btn-small.is-busy::after { content: ''; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (hover: hover) {
    .btn-drop:hover, .btn-small:not(.ghost):hover { background: color-mix(in oklab, var(--accent) 90%, var(--ink)); }
    .btn-small.ghost:hover { box-shadow: inset 0 0 0 1px var(--ink-2); color: var(--ink); }
}
.btn-link { background: none; border: 0; padding: 12px 0; min-height: 44px; font-size: 14.5px; color: var(--accent-text); text-decoration: underline; text-underline-offset: .2em; text-decoration-thickness: 1px; text-align: left; }
.btn-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ── Formulare ── */
input[type=text], input[type=password], select, textarea { width: 100%; min-height: 48px; background: var(--surface); color: var(--ink); border: 1px solid var(--control); border-radius: var(--r-m); padding: 12px 14px; font-size: 16px; /* 16px: iOS zoomt sonst ins Feld */ line-height: 1.4; transition: border-color .18s, box-shadow .18s, background-color .18s; -webkit-appearance: none; appearance: none; }
input::placeholder, textarea::placeholder { color: var(--dim); opacity: 1; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 28%, transparent); }
select { padding-right: 40px; background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%); background-position: calc(100% - 22px) 52%, calc(100% - 16px) 52%; background-size: 6px 6px; background-repeat: no-repeat; cursor: pointer; }
textarea { resize: vertical; min-height: 96px; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); box-shadow: inset 3px 0 0 var(--danger); }
input[aria-invalid="true"]:focus, textarea[aria-invalid="true"]:focus, select[aria-invalid="true"]:focus { border-color: var(--danger); box-shadow: inset 3px 0 0 var(--danger), 0 0 0 3px color-mix(in oklab, var(--danger) 28%, transparent); }

/* Fehlertext direkt am Feld: bleibt stehen, bis der Fehler behoben ist (role=alert, aria-describedby, kein Farb-Signal allein: "!"-Marke + Text) */
.field-error { display: flex; align-items: flex-start; gap: 9px; color: var(--danger); font-size: 14.5px; line-height: 1.45; font-weight: 500; overflow-wrap: anywhere; }
.field-error::before { content: '!'; content: '!' / ''; flex: none; width: 18px; height: 18px; margin-top: 1px; display: grid; place-items: center; border: 1.5px solid currentColor; border-radius: 50%; font-size: 12px; font-weight: 700; line-height: 1; }

/* ── Segment-Schalter mit gleitendem Daumen ── */
.seg { --n: 2; --idx: 0; position: relative; display: grid; grid-template-columns: repeat(var(--n), 1fr); background: var(--surface); border: 1px solid var(--control); border-radius: var(--r-m); padding: 3px; isolation: isolate; }
/* Auswahl: 2-px-Rahmen in --accent (Rahmen/Spur mind. 3:1, WCAG 1.4.11) + Fettdruck + Haken; die Farbe allein trägt den Zustand nicht */
.seg::before { content: ''; position: absolute; z-index: -1; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / var(--n)); border-radius: calc(var(--r-m) - 3px); background: var(--surface-2); box-shadow: inset 0 0 0 2px var(--accent), 0 2px 6px rgba(0, 0, 0, .18); transform: translateX(calc(var(--idx) * 100%)); transition: transform .32s var(--ease); }
.seg > button { min-height: 44px; padding: 0 14px; border-radius: calc(var(--r-m) - 3px); font-size: 14.5px; font-weight: 600; color: var(--dim); transition: color .18s; display: inline-flex; align-items: center; justify-content: center; }
.seg > button::before { content: ''; width: 0; height: 8px; margin-right: 0; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(40deg) translateY(-2px); opacity: 0; transition: width .22s var(--ease), margin .22s var(--ease), opacity .22s; flex: none; }
.seg > button[aria-pressed="true"], .seg > button.active { color: var(--ink); font-weight: 700; }
.seg > button[aria-pressed="true"]::before, .seg > button.active::before { width: 5px; margin-right: 9px; opacity: 1; }
@media (hover: hover) { .seg > button:hover { color: var(--ink); } }

/* ── Toast ── */
.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); max-width: min(92vw, 440px); transform: translate(-50%, 12px); background: var(--ink); color: var(--bg); border-radius: var(--r-m); padding: 12px 18px; font-size: 14.5px; line-height: 1.4; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .22s var(--ease), transform .3s var(--ease); box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: var(--on-danger); }
@media (min-width: 960px) { .toast { bottom: 32px; } }

/* ── Dialog ── */
.modal-overlay { position: fixed; inset: 0; z-index: 200; display: flex; overflow-y: auto; overscroll-behavior: contain; padding: 20px; background: rgba(8, 6, 4, .78); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); animation: fade .25s var(--ease); }
.modal-card { margin: auto; /* mittig, bei Zoom 400 % oben bündig und scrollbar */ background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-l); padding: 26px 24px 22px; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, .5); animation: rise .4s var(--ease); }
.modal-title { font-family: var(--serif); font-weight: 600; font-size: 26px; letter-spacing: -.01em; line-height: 1.1; }
.modal-hint { color: var(--ink-2); font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; }
.code { font-family: var(--mono); font-size: clamp(26px, 8vw, 34px); line-height: 1.1; color: var(--accent-text); text-align: center; letter-spacing: .08em; padding: 16px 10px; background: var(--bg); border: 1px dashed var(--line-strong); border-radius: var(--r-m); user-select: all; overflow-wrap: anywhere; }
.modal-note { color: var(--ink-2); font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.modal-note:empty { display: none; }
.modal-title:focus { outline: none; }
.modal-actions { display: flex; gap: 10px; }
.modal-btn { flex: 1; min-height: 50px; font-size: 15.5px; }
.modal-btn.cancel { background: transparent; box-shadow: inset 0 0 0 1px var(--control); color: var(--ink-2); }
.modal-btn.confirm { background: var(--accent); color: var(--accent-ink); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }

/* ── Windows-Kontrastmodus: Zustände ohne Farbe erkennbar ── */
@media (forced-colors: active) {
    .chip, .source-chip, .seg, .btn-small.ghost, .modal-btn.cancel, .stepper button { border: 1px solid ButtonText; box-shadow: none; }
    .chip.active, .chip[aria-pressed="true"], .seg > button[aria-pressed="true"], .tab-btn.active { outline: 2px solid Highlight; outline-offset: -2px; }
    .seg::before, .tab-ind { display: none; }
}

/* ── Weniger Bewegung ── */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
    #rainCanvas { display: none; }
    .stories-container { scroll-behavior: auto !important; }
    .logo .cursor { animation: none; }
}
