@font-face { font-family: 'PressStart'; src: url('../fonts/press-start-2p.woff2') format('woff2'); font-display: block; }
@font-face { font-family: 'VT323'; src: url('../fonts/vt323.woff2') format('woff2'); font-display: block; }

/* ---------- themes ---------- */
:root, [data-theme="pico"] {
  --bg: #1d2b53; --bg2: #141f3d; --panel: #2a3a6b; --panel2: #34468a;
  --text: #fff1e8; --muted: #c2c3c7; --dim: #83769c; --line: #000;
  --accent: #ff004d; --accent2: #ffec27; --good: #00e436; --info: #29adff; --warn: #ffa300;
  --card: #fff1e8; --cardtext: #1d2b53; --cardmuted: #5f574f; --shadow: #000;
  --paper: #fff1e8; --papertext: #1a1a2e;
}
[data-theme="gameboy"] {
  --bg: #306230; --bg2: #0f380f; --panel: #0f380f; --panel2: #306230;
  --text: #9bbc0f; --muted: #8bac0f; --dim: #8bac0f; --line: #0f380f;
  --accent: #0f380f; --accent2: #9bbc0f; --good: #9bbc0f; --info: #8bac0f; --warn: #9bbc0f;
  --card: #9bbc0f; --cardtext: #0f380f; --cardmuted: #306230; --shadow: #0f380f;
  --paper: #9bbc0f; --papertext: #0f380f;
}
[data-theme="nes"] {
  --bg: #fcfcfc; --bg2: #e4e4e4; --panel: #fcfcfc; --panel2: #e4e4e4;
  --text: #212529; --muted: #555; --dim: #888; --line: #212529;
  --accent: #e76e55; --accent2: #f7d51d; --good: #92cc41; --info: #209cee; --warn: #f7a51d;
  --card: #fff; --cardtext: #212529; --cardmuted: #666; --shadow: #212529;
  --paper: #fff; --papertext: #212529;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg2); color: var(--text);
  font-family: 'VT323', ui-monospace, monospace; font-size: 20px; line-height: 1.15;
  -webkit-font-smoothing: none; overscroll-behavior-y: none;
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; }
[hidden] { display: none !important; }
.ps { font-family: 'PressStart', monospace; text-transform: uppercase; letter-spacing: 0; }

body.scanlines::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 999;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,.07) 0 1px, transparent 1px 3px);
}

.px-icon { display: inline-block; width: 1em; height: 1em; vertical-align: -0.12em; flex: none; }
.px-icon svg { width: 100%; height: 100%; display: block; }

#app { max-width: 640px; margin: 0 auto; min-height: 100%; background: var(--bg); position: relative;
  padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

/* ---------- HUD ---------- */
.hud { position: sticky; top: 0; z-index: 20; background: var(--bg2); border-bottom: 4px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) 12px 8px; }
.hud-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.logo { margin: 0; font-family: 'PressStart'; font-size: 15px; color: var(--accent2); text-shadow: 3px 3px 0 var(--accent); white-space: nowrap; }
.logo span { color: var(--text); text-shadow: 3px 3px 0 var(--info); }
.hud-stats { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-family: 'PressStart'; font-size: 10px; }
.lv b { color: var(--accent2); }
.hud-actions { display: flex; gap: 8px; align-items: center; }
.px-btn.trust { font-size: 8px; padding: 8px 8px; animation: nudge 2s steps(2) infinite; }
.px-btn.trust .px-icon { font-size: 14px; }
@keyframes nudge { 50% { box-shadow: 3px 3px 0 var(--shadow), 0 0 0 3px var(--accent2); } }
.xpbar { flex: 1; height: 16px; background: var(--line); border: 2px solid var(--line); position: relative; box-shadow: 0 0 0 2px var(--muted); }
.xpbar > div { height: 100%; background: repeating-linear-gradient(90deg, var(--good) 0 6px, color-mix(in srgb, var(--good) 70%, #000) 6px 8px); width: 0; transition: width .6s steps(12); }
.xpbar span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 7px; color: #fff; text-shadow: 1px 1px 0 #000; }
.streak { color: var(--warn); display: flex; gap: 4px; align-items: center; }
.streak .px-icon { font-size: 14px; }
.status { margin-top: 8px; font-size: 18px; color: var(--muted); display: flex; align-items: baseline; gap: 8px; }
#statusText { flex: 1; min-width: 0; }
#syncStop { flex: none; font: inherit; }
.status .dot { flex: none; }
.status .dot { width: 8px; height: 8px; background: var(--good); display: inline-block; }
.status.offline .dot { background: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- buttons ---------- */
.px-btn { font-family: 'PressStart'; font-size: 10px; text-transform: uppercase; padding: 10px 12px;
  background: var(--panel2); color: var(--text); border: 3px solid var(--line); box-shadow: 3px 3px 0 var(--shadow);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; line-height: 1.3; }
.px-btn:active, .px-btn.pressed { transform: translate(3px, 3px); box-shadow: none; }
.px-btn.primary { background: var(--accent); color: #fff; }
.px-btn.gold { background: var(--accent2); color: #000; }
.px-btn.good { background: var(--good); color: #000; }
.px-btn.big { font-size: 12px; padding: 16px; width: 100%; }
.px-btn.icon { padding: 8px; font-size: 16px; }
.px-btn[disabled] { opacity: .5; }
.px-btn.spin .px-icon { animation: spin 1s steps(8) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- tabs & chips ---------- */
.tabs { display: flex; gap: 8px; padding: 12px 12px 4px; }
.tab { flex: 1; font-family: 'PressStart'; font-size: 10px; padding: 10px 4px; background: var(--panel); border: 3px solid var(--line); color: var(--muted); }
.tab.on { background: var(--accent2); color: #000; box-shadow: inset 0 -4px 0 rgba(0,0,0,.25); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; font-size: 20px; padding: 2px 10px; border: 2px solid var(--line); background: var(--panel); color: var(--muted); }
.chip.on { background: var(--info); color: #000; }
.filter-row { display: flex; justify-content: space-between; align-items: center; padding: 0 12px 6px; color: var(--muted); font-size: 18px; }
.toggle-link { text-decoration: underline; color: var(--accent2); }

/* ---------- cards ---------- */
#list, #savedList { padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 14px; }
.card { text-align: left; background: var(--card); color: var(--cardtext); border: 3px solid var(--line);
  box-shadow: 5px 5px 0 var(--shadow); padding: 10px; position: relative; width: 100%; display: block; }
.card:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--shadow); }
.card-meta { display: flex; align-items: center; gap: 8px; font-size: 17px; color: var(--cardmuted); margin-bottom: 6px; }
.lang { font-family: 'PressStart'; font-size: 8px; padding: 3px 4px; color: #fff; background: #000; }
.lang.de { background: linear-gradient(#000 0 33%, #dd0000 33% 66%, #ffce00 66%); text-shadow: 1px 1px 0 #000; }
.lang.en { background: #012169; box-shadow: inset 0 0 0 2px #c8102e; }
.src { font-family: 'PressStart'; font-size: 8px; color: var(--cardtext); }
.card-meta .time { margin-left: auto; }
.card-body { display: flex; gap: 10px; align-items: flex-start; }
.thumb { width: 84px; height: 63px; flex: none; image-rendering: pixelated; border: 2px solid var(--line); background: var(--cardmuted); }
.card h3 { margin: 0; font-size: 24px; line-height: 1; font-weight: normal; }
.card .sum { margin: 6px 0 0; font-size: 18px; color: var(--cardmuted); line-height: 1.05;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-family: 'PressStart'; font-size: 8px; }
.diff { padding: 3px 5px; border: 2px solid var(--line); }
.diff.easy { background: #00e436; color: #000; }
.diff.normal { background: #29adff; color: #000; }
.diff.hard { background: #ff004d; color: #fff; }
.xp { color: #ab5236; }
.mins { color: var(--cardmuted); }
.saved-mark { color: #ffa300; font-size: 14px; }
.card.cleared { opacity: .62; }
.card.cleared .xp { visibility: hidden; }
.card.cleared::after { content: 'CLEARED'; position: absolute; right: 10px; bottom: 26px; transform: rotate(-12deg);
  font-family: 'PressStart'; font-size: 11px; color: #00a12b; border: 3px solid #00a12b; padding: 4px 6px; background: rgba(255,255,255,.7); }
.card.new::before { content: 'NEW!'; position: absolute; top: -10px; left: -6px; font-family: 'PressStart'; font-size: 8px;
  background: var(--accent); color: #fff; padding: 4px; border: 2px solid var(--line); animation: blink 1.2s steps(2) infinite; }
.more { margin: 4px 12px 16px; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big-icon { font-size: 64px; color: var(--accent2); }
.empty h2 { font-family: 'PressStart'; font-size: 13px; color: var(--text); line-height: 1.6; }
.empty p { font-size: 20px; }

.banner { margin: 10px 12px 0; padding: 10px; border: 3px solid var(--line); background: var(--warn); color: #000; font-size: 19px; display: flex; gap: 10px; align-items: center; }
.banner b { font-family: 'PressStart'; font-size: 9px; }
.banner.info { background: var(--info); }

/* ---------- bottom nav ---------- */
.bottom-nav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 640px; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr); background: var(--bg2); border-top: 4px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.nav-btn { padding: 10px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-family: 'PressStart'; font-size: 7px; color: var(--dim); }
.nav-btn .px-icon { font-size: 22px; }
.nav-btn.on { color: var(--accent2); }
.nav-btn.on .px-icon { animation: bob .6s steps(2) infinite alternate; }
@keyframes bob { to { transform: translateY(-3px); } }
.badge-dot { position: relative; }

/* ---------- reader ---------- */
.reader { position: fixed; inset: 0; z-index: 50; background: var(--bg2); display: flex; flex-direction: column; }
.reader-bar { max-width: 640px; width: 100%; margin: 0 auto; display: flex; gap: 10px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px; background: var(--bg2); border-bottom: 4px solid var(--line); }
.hp { flex: 1; height: 14px; background: #000; border: 2px solid var(--muted); }
.hp > div { height: 100%; width: 0; background: var(--accent); transition: width .1s steps(4); }
.reader-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.paper { max-width: 640px; margin: 0 auto; background: var(--paper); color: var(--papertext); min-height: 100%;
  padding: 18px 18px calc(40px + env(safe-area-inset-bottom)); -webkit-user-select: text; user-select: text; }
.paper .r-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 18px; color: #5f574f; }
.paper h1 { font-family: 'VT323'; font-weight: normal; font-size: 36px; line-height: 1; margin: 12px 0; }
.paper .hero { width: 100%; border: 3px solid #000; display: block; margin: 8px 0 14px; background: #ddd; }
.paper .hero.pixel { image-rendering: pixelated; }
.r-content { font-size: var(--reader-size, 19px); line-height: 1.6; }
.r-content.serif { font-family: Charter, 'Iowan Old Style', Georgia, serif; -webkit-font-smoothing: auto; }
.r-content.sans { font-family: -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif; -webkit-font-smoothing: auto; }
.r-content.pixel { font-family: 'VT323', monospace; font-size: calc(var(--reader-size, 19px) * 1.25); line-height: 1.25; }
.r-content img { max-width: 100%; height: auto; border: 2px solid #000; }
.r-content a { color: #1d6fd1; }
.r-content blockquote { margin: 1em 0; padding: 4px 12px; border-left: 6px solid #ff004d; background: rgba(0,0,0,.05); }
.r-content h2, .r-content h3, .r-content h4 { font-family: 'PressStart'; font-size: 12px; line-height: 1.6; margin: 1.6em 0 .6em; }
.r-content table { display: block; overflow-x: auto; border-collapse: collapse; font-size: .85em; }
.r-content td, .r-content th { border: 1px solid #999; padding: 4px; }
.r-content figure { margin: 1em 0; }
.r-content figcaption { font-size: .8em; color: #666; }
.teaser-note { margin-top: 18px; padding: 10px; border: 3px dashed #5f574f; font-size: 19px; color: #5f574f; }
.r-end { margin-top: 26px; display: flex; flex-direction: column; gap: 12px; }
.orig { font-family: 'PressStart'; font-size: 9px; color: #1d6fd1; text-align: center; padding: 8px; display: flex; justify-content: center; gap: 8px; }
.complete-done { text-align: center; font-family: 'PressStart'; font-size: 11px; color: #00a12b; padding: 14px; border: 3px solid #00a12b; }

/* ---------- panels (quests/settings) ---------- */
.panel { margin: 12px; padding: 12px; background: var(--panel); border: 3px solid var(--line); box-shadow: 4px 4px 0 var(--shadow); }
.panel h2 { margin: 0 0 12px; font-family: 'PressStart'; font-size: 11px; color: var(--accent2); display: flex; gap: 8px; align-items: center; }
.panel p.hint { color: var(--muted); font-size: 18px; margin: 6px 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 2px dashed rgba(255,255,255,.12); }
[data-theme="nes"] .row { border-bottom-color: rgba(0,0,0,.12); }
.row:last-child { border-bottom: 0; }
.row label, .row .lbl { flex: 1; font-size: 20px; }
.row small { display: block; color: var(--muted); font-size: 16px; }
.sw { width: 52px; height: 26px; flex: none; background: #000; border: 3px solid var(--line); position: relative; box-shadow: 0 0 0 2px var(--muted); }
.sw::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: var(--muted); transition: left .15s steps(3); }
.sw.on { background: var(--good); }
.sw.on::after { left: 28px; background: #fff; }
.seg { display: flex; border: 3px solid var(--line); flex: none; }
.seg button { font-family: 'PressStart'; font-size: 8px; padding: 7px 7px; background: var(--panel2); color: var(--muted); }
.seg button.on { background: var(--accent2); color: #000; }
.px-input { width: 100%; padding: 8px; background: #000; color: var(--good); border: 3px solid var(--line); box-shadow: 0 0 0 2px var(--muted); font-size: 18px; -webkit-user-select: text; user-select: text; }
.ip-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.ip { font-size: 18px; background: #000; color: var(--good); padding: 2px 8px; display: flex; gap: 8px; align-items: center; }
.ip button { color: var(--accent); }
.feed-group-title { font-family: 'PressStart'; font-size: 9px; color: var(--muted); margin: 12px 0 2px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.btn-row .px-btn { flex: 1; }

.profile { display: flex; gap: 14px; align-items: center; }
.avatar { width: 72px; height: 72px; flex: none; background: var(--bg2); border: 3px solid var(--line); display: grid; place-items: center; font-size: 46px; color: var(--accent2); }
.profile .ttl { font-family: 'PressStart'; font-size: 11px; color: var(--accent2); line-height: 1.6; }
.profile .sub { color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--bg2); border: 2px solid var(--line); padding: 8px 4px; text-align: center; }
.stat b { display: block; font-family: 'PressStart'; font-size: 13px; color: var(--accent2); margin-bottom: 4px; }
.stat span { font-size: 16px; color: var(--muted); }
.quest { display: flex; gap: 10px; align-items: center; padding: 8px 0; }
.quest .qbox { width: 22px; height: 22px; border: 3px solid var(--muted); flex: none; display: grid; place-items: center; color: var(--good); }
.quest.done .qbox { border-color: var(--good); }
.quest.done .qt { text-decoration: line-through; color: var(--muted); }
.quest .qt { flex: 1; font-size: 20px; }
.quest .qp { font-family: 'PressStart'; font-size: 8px; color: var(--accent2); }
.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bdg { text-align: center; padding: 8px 2px; border: 2px solid var(--line); background: var(--bg2); }
.bdg .px-icon { font-size: 30px; color: var(--accent2); }
.bdg div { font-family: 'PressStart'; font-size: 6px; margin-top: 6px; line-height: 1.5; }
.bdg.locked { opacity: .3; filter: grayscale(1); }

/* ---------- modal / toast / background download ---------- */
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.7); display: grid; place-items: center; padding: 20px; }
.dialog { width: 100%; max-width: 380px; background: var(--panel); border: 4px solid var(--line); box-shadow: 0 0 0 4px var(--text), 8px 8px 0 4px #000; padding: 18px; animation: pop .25s steps(4); }
@keyframes pop { from { transform: scale(.6); } to { transform: scale(1); } }
.dialog h2 { font-family: 'PressStart'; font-size: 12px; color: var(--accent2); line-height: 1.6; margin: 0 0 10px; display: flex; gap: 10px; align-items: center; }
.dialog h2 .px-icon { font-size: 22px; }
.dialog p { font-size: 20px; margin: 8px 0; }
.dialog .actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.dialog .tiny { font-size: 16px; color: var(--muted); }
.typewriter { overflow: hidden; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 200%); z-index: 90;
  background: #000; color: #fff; border: 3px solid var(--accent2); padding: 10px 14px; font-family: 'PressStart'; font-size: 9px; line-height: 1.6;
  max-width: 90%; text-align: center; transition: transform .25s steps(5), visibility 0s .25s; pointer-events: none; visibility: hidden; }
.toast.show { transform: translate(-50%, 0); visibility: visible; transition: transform .25s steps(5); }

/* Background download: a thin progress line under the top bar (and under the reader bar), never a blocking screen. */
.reader-bar { position: relative; }
body.syncing .hud::after, body.syncing .reader-bar::after { content: ''; position: absolute; left: 0; bottom: -4px; height: 4px;
  width: var(--sync, 0%); min-width: 12px; background: var(--good); transition: width .2s steps(6); }
body.syncing .status .dot { background: var(--accent2); animation: blink 1s steps(2) infinite; }

.fanfare { position: fixed; inset: 0; z-index: 95; pointer-events: none; display: grid; place-items: center; }
.fanfare div { background: rgba(0,0,0,.85); border: 4px solid var(--accent2); padding: 18px 22px; font-family: 'PressStart'; font-size: 20px; color: var(--accent2); text-shadow: 4px 4px 0 var(--accent), -2px -2px 0 #000; text-align: center; line-height: 1.6; animation: fan 1.8s steps(12) forwards; }
@keyframes fan { 0% { transform: scale(.2); opacity: 0; } 20% { transform: scale(1.15); opacity: 1; } 30% { transform: scale(1); } 80% { opacity: 1; } 100% { transform: translateY(-60px); opacity: 0; } }
.xp-pop { position: fixed; z-index: 96; pointer-events: none; font-family: 'PressStart'; font-size: 14px; color: var(--accent2); text-shadow: 2px 2px 0 #000; animation: xpup 1.2s steps(10) forwards; }
@keyframes xpup { to { transform: translateY(-80px); opacity: 0; } }

.install-hint { margin: 12px; }
