/* Retro Arcade - ein Stylesheet fuer alle Seiten */

/* Pixel-Schrift lokal ausgeliefert (SIL Open Font License, siehe fonts/OFL.txt) - kein Google Fonts */
@font-face {
  font-family: "Press Start 2P";
  src: url("fonts/press-start-2p-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
:root {
  --bg: #0f1117;
  --bg-2: #161a23;
  --card: #1c212c;
  --card-2: #242a37;
  --line: #2e3544;
  --text: #e6e9ef;
  --muted: #9aa3b5;
  --accent: #ff4f7b;
  --accent-2: #5ad1ff;
  --ok: #43d17a;
  --warn: #ffb547;
  --bad: #ff5c5c;
  --star: #ffc93c;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  color-scheme: dark;
}
/* Hell: bei hellem System (ausser manuell "dunkel" gewaehlt) oder manuell "hell" */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f8; --bg-2: #ffffff; --card: #ffffff; --card-2: #eef0f4; --line: #dde1e8;
    --text: #1b1f27; --muted: #5d6677; --accent: #e0245e; --accent-2: #0a8fc4;
    --ok: #1f9d55; --warn: #c77800; --bad: #d64545; --star: #e0a800;
    --shadow: 0 4px 16px rgba(20, 30, 50, .08); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4f5f8; --bg-2: #ffffff; --card: #ffffff; --card-2: #eef0f4; --line: #dde1e8;
  --text: #1b1f27; --muted: #5d6677; --accent: #e0245e; --accent-2: #0a8fc4;
  --ok: #1f9d55; --warn: #c77800; --bad: #d64545; --star: #e0a800;
  --shadow: 0 4px 16px rgba(20, 30, 50, .08); color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); min-height: 100vh; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
small, .muted { color: var(--muted); }
code { background: var(--card-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 10px 20px; background: color-mix(in srgb, var(--bg-2) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.logo { font-family: var(--pixel); font-size: 13px; color: var(--text); letter-spacing: 1px; white-space: nowrap; }
.logo span { color: var(--accent); }
.logo:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a, .nav button {
  color: var(--muted); padding: 6px 12px; border-radius: 8px; font: inherit; background: none; border: 0; cursor: pointer;
}
.nav a:hover, .nav button:hover { background: var(--card); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--card); }
.nav .right { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.nav form { margin: 0; }

main { padding: 20px; max-width: 1600px; margin: 0 auto; min-width: 0; }

/* Seitenlayout mit rechtem Panel */
.page.with-side { display: grid; grid-template-columns: minmax(0, 1fr) 300px; max-width: 1920px; margin: 0 auto; }
.page.with-side main { max-width: none; margin: 0; width: 100%; }
.side-collapsed .page.with-side { grid-template-columns: minmax(0, 1fr); }
.side-collapsed .side-panel { display: none; }
.side-panel {
  position: sticky; top: 57px; align-self: start; max-height: calc(100vh - 57px); overflow-y: auto;
  padding: 20px 16px 20px 0; display: flex; flex-direction: column; gap: 10px;
}
.side-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0; }
.side-box > summary {
  list-style: none; cursor: pointer; padding: 10px 12px; font-weight: 600; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center; user-select: none;
}
.side-box > summary::-webkit-details-marker { display: none; }
.side-box > summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
.side-box:not([open]) > summary::after { transform: rotate(-90deg); }
.side-box .body { padding: 0 12px 12px; font-size: 13px; }
.side-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; min-width: 0; }
.side-row > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.side-row small { color: var(--muted); white-space: nowrap; }
.side-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.side-kpis div { background: var(--card-2); border-radius: 8px; padding: 6px 8px; }
.side-kpis b { display: block; font-size: 15px; }
.side-kpis small { color: var(--muted); font-size: 11px; }
.side-bar { height: 4px; background: var(--card-2); border-radius: 3px; overflow: hidden; margin-top: 2px; }
.side-bar div { height: 100%; background: var(--accent-2); }
.dot-online { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; margin-right: 6px; flex: none; }
.dot-online.playing { animation: pulse 1.6s infinite; }
.side-play { color: var(--accent); font-size: 12px; }
#theme-toggle, #side-toggle { font-size: 15px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 30px 0 20px; }

/* ---------- Bausteine ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card-2); color: var(--text); font: inherit;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--accent-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn.on { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.badge {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px;
  background: var(--card-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.alert { padding: 10px 14px; border-radius: 8px; background: color-mix(in srgb, var(--bad) 15%, var(--card)); margin-bottom: 12px; }
.alert.info { background: color-mix(in srgb, var(--accent-2) 15%, var(--card)); }
.stars { color: var(--star); letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: var(--line); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.table-wrap { overflow-x: auto; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(120px);
  background: var(--card-2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 8px;
  box-shadow: var(--shadow); transition: transform .25s; z-index: 100; max-width: calc(100% - 32px);
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--bad); }

/* ---------- Login ---------- */
.auth-box { max-width: 380px; margin: 8vh auto; }
.auth-box h1 { font-family: var(--pixel); font-size: 16px; text-align: center; margin-bottom: 24px; }
.auth-box input { width: 100%; }
.auth-box .btn { width: 100%; justify-content: center; margin-top: 18px; }

/* ---------- Bibliothek ---------- */
.library { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
.library > section { min-width: 0; }  /* sonst waechst die Spalte mit den scrollbaren System-Reihen mit */
.sidebar { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow-y: auto; padding: 8px; }
.sidebar h3 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 12px 8px 6px; }
.sys-link {
  display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 8px;
  color: var(--text); cursor: pointer; font-size: 14px;
}
.sys-link:hover { background: var(--card-2); text-decoration: none; }
.sys-link.active { background: var(--accent); color: #fff; }
.sys-link.active small { color: #fff; }
.sys-link.empty { opacity: .45; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1 1 220px; }
.more-filters { display: none; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.more-filters.open { display: flex; }
.more-filters input[type=number] { width: 90px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--bg-2); color: var(--muted); border: 0; padding: 7px 12px; font: inherit; cursor: pointer; }
.seg button.active { background: var(--accent); color: #fff; }
.result-info { color: var(--muted); font-size: 13px; margin-bottom: 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.tile {
  position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; color: var(--text); transition: transform .12s, border-color .12s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent-2); text-decoration: none; }
.tile.missing { opacity: .55; }
.tile.missing:hover { opacity: .9; }
.cover { position: relative; aspect-ratio: 3/4; background: var(--card-2); display: grid; place-items: center; overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: contain; position: absolute; inset: 0; }
.cover .ph { padding: 12px; text-align: center; font-size: 13px; color: var(--muted); }
.cover .ph b { display: block; font-family: var(--pixel); font-size: 9px; color: var(--accent); margin-bottom: 8px; }
.tile .meta { padding: 8px 10px; font-size: 13px; }
.tile .meta .t { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .meta small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .corner { position: absolute; top: 6px; left: 6px; display: flex; gap: 4px; z-index: 2; }
.tile .play-fab {
  position: absolute; right: 8px; bottom: 8px; z-index: 2; width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 16px;
  opacity: 0; transition: opacity .15s; box-shadow: var(--shadow);
}
.tile:hover .play-fab { opacity: 1; }
/* "Alle Systeme": je System eine horizontal scrollbare Reihe */
.grid.grouped { display: block; }
.sys-group { margin-bottom: 26px; }
.sys-group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.sys-group-head h2 { margin: 0; font-size: 1.1rem; }
.sys-group-head h2 a { color: var(--text); }
.sys-group-head small { font-weight: 400; margin-left: 6px; }
.sys-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: 150px; gap: 14px;
  overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity;
}
.sys-row .tile { scroll-snap-align: start; }
.pager { display: flex; justify-content: center; gap: 8px; margin: 24px 0; align-items: center; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }

/* ---------- Spiel-Detail ---------- */
.game-hero { display: grid; grid-template-columns: 280px 1fr; gap: 28px; }
.game-hero .cover { border-radius: var(--radius); border: 1px solid var(--line); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 14px; margin: 14px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 20px; }
.shots img { width: 100%; border-radius: 8px; border: 1px solid var(--line); image-rendering: pixelated; background: #000; }
.desc { max-width: 75ch; white-space: pre-line; }
.rate-input { font-size: 28px; cursor: pointer; user-select: none; }
.rate-input span { color: var(--line); transition: color .1s; }
.rate-input span.on { color: var(--star); }
.review { border-top: 1px solid var(--line); padding: 12px 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 24px; }

/* ---------- Emulator ---------- */
.play-wrap { display: grid; grid-template-columns: 1fr 280px; gap: 16px; height: calc(100vh - 110px); min-height: 420px; }
#game { width: 100%; height: 100%; background: #000; border-radius: var(--radius); overflow: hidden; }
.states { overflow-y: auto; }
.state { display: grid; grid-template-columns: 96px 1fr; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.state img { width: 96px; border-radius: 4px; background: #000; image-rendering: pixelated; }

/* ---------- Upload ---------- */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 50px 20px; text-align: center;
  color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.dropzone b { font-family: var(--pixel); font-size: 12px; color: var(--text); display: block; margin-bottom: 10px; }
.queue-item { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.progress { grid-column: 1 / -1; height: 4px; background: var(--card-2); border-radius: 4px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent-2); width: 0; transition: width .2s; }

/* ---------- Admin ---------- */
.admin-nav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat b { display: block; font-size: 1.6rem; }
.stat small { color: var(--muted); }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(18px); }
.bar { height: 6px; background: var(--card-2); border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar div { height: 100%; background: var(--ok); }
pre.details { margin: 0; font-size: 12px; white-space: pre-wrap; word-break: break-word; max-width: 520px; color: var(--muted); }

/* ---------- Live / Statistik ---------- */
.live-list { display: flex; flex-wrap: wrap; gap: 8px; }
.live {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px;
  background: var(--card-2); border: 1px solid var(--line); color: var(--text); font-size: 14px;
}
.live:hover { border-color: var(--ok); text-decoration: none; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 70%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.live-strip { margin-bottom: 14px; padding: 10px 14px; }
.stat.kpi { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.stat.kpi b { color: var(--accent); }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.chart .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; }
.chart .val { width: 100%; max-width: 40px; background: var(--accent-2); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart small { color: var(--muted); font-size: 11px; }
.scores td:first-child { width: 36px; }
.suggestion { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.vote { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; width: 56px; padding: 6px 0; }
.vote b { font-size: 1.1rem; }

/* ---------- Sammlungen / RA / Glocke ---------- */
.mosaic { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; background: var(--card-2); aspect-ratio: 16/7; overflow: hidden; }
.mosaic img { width: 100%; height: 100%; object-fit: cover; }
.ra-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.ra-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px; border-radius: 8px; background: var(--card-2); }
.ra-item img { border-radius: 6px; flex: none; }
.ra-item.locked img { filter: grayscale(1) opacity(.45); }
.ra-item.locked b { color: var(--muted); }
.bell { position: relative; }
.bell .count {
  position: absolute; top: 0; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px;
  background: var(--accent); color: #fff; font-size: 10px; line-height: 16px; text-align: center; font-weight: 700;
}

/* ---------- Speedrun-Timer ---------- */
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.sr { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.sr-time { font-size: 2.2rem; font-weight: 700; margin: 8px 0 0; letter-spacing: .02em; }
.sr-time.running { color: var(--ok); }
.sr-time.behind { color: var(--bad); }
.sr-time.done { color: var(--accent-2); }
.sr-sub { font-size: 12px; color: var(--muted); }
.sr-splits { list-style: none; margin: 8px 0; padding: 0; font-size: 13px; }
.sr-splits li { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; padding: 3px 4px; border-radius: 4px; }
.sr-splits li.current { background: var(--card-2); }
.sr-splits .d { min-width: 56px; text-align: right; }
.sr-splits .t { min-width: 64px; text-align: right; }
.sr-splits .ahead { color: var(--ok); }
.sr-splits .behind { color: var(--bad); }
.sr-splits .gold { color: var(--star); }
.sr-result { margin: 8px 0; padding: 10px; border-radius: 8px; background: var(--card-2); }

/* ---------- Mobil ---------- */
/* Unter 1200px: Panel unter den Inhalt */
@media (max-width: 1200px) {
  .page.with-side { grid-template-columns: minmax(0, 1fr); }
  .side-panel { position: static; max-height: none; padding: 0 20px 20px; display: grid;
                grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); align-items: start; }
}

@media (max-width: 860px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; gap: 8px; }
  .library { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; display: flex; overflow-x: auto; gap: 4px; padding: 0 0 6px; }
  .sidebar h3 { display: none; }
  .sys-link { flex: 0 0 auto; background: var(--card); }
  .sys-link small { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .game-hero { grid-template-columns: 1fr; }
  .game-hero .cover { max-width: 260px; }
  .two-col { grid-template-columns: 1fr; }
  .play-wrap { grid-template-columns: 1fr; height: auto; }
  #game { height: 62vh; }
  .tile .play-fab { opacity: 1; }
}
