/* ───────── Tokens ───────── */
:root {
  --paper: #f2ebdd;
  --paper-2: #e9e0cd;
  --card: #fffaf0;
  --ink: #1d1a16;
  --ink-2: #5c554b;
  --ink-3: #8a8173;
  --line: #d6cbb5;
  --shelf: #b98b5e;
  --shelf-shadow: rgba(80, 50, 20, .25);
  --accent: #e2462b;
  --accent-ink: #fff;
  --focus: #1f6feb;

  --t-brett: #1f8a7a;
  --t-karten: #e2462b;
  --t-wuerfel: #d99a12;
  --t-sonstiges: #6d5bd0;

  --radius: 14px;
  --shadow: 0 1px 0 rgba(0,0,0,.04), 0 6px 18px -8px rgba(60,40,10,.25);
  --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16130f; --paper-2: #201c16; --card: #241f19;
    --ink: #f1e9da; --ink-2: #c3b8a5; --ink-3: #8f8574; --line: #3a3228;
    --shelf: #6b4a2c; --shelf-shadow: rgba(0,0,0,.5);
    --accent: #ff6a4d; --accent-ink: #1a0e0a; --focus: #7aa7ff;
    --t-brett: #3cc2ad; --t-karten: #ff6a4d; --t-wuerfel: #f2b938; --t-sonstiges: #a093ff;
    --shadow: 0 1px 0 rgba(255,255,255,.03), 0 8px 22px -10px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #16130f; --paper-2: #201c16; --card: #241f19;
  --ink: #f1e9da; --ink-2: #c3b8a5; --ink-3: #8f8574; --line: #3a3228;
  --shelf: #6b4a2c; --shelf-shadow: rgba(0,0,0,.5);
  --accent: #ff6a4d; --accent-ink: #1a0e0a; --focus: #7aa7ff;
  --t-brett: #3cc2ad; --t-karten: #ff6a4d; --t-wuerfel: #f2b938; --t-sonstiges: #a093ff;
  --shadow: 0 1px 0 rgba(255,255,255,.03), 0 8px 22px -10px rgba(0,0,0,.7);
  color-scheme: dark;
}

/* ───────── Base ───────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.45 var(--font);
  background-image: radial-gradient(var(--paper-2) 1px, transparent 1.2px);
  background-size: 22px 22px;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
main { max-width: 1240px; margin: 0 auto; padding: 0 16px 48px; }

/* ───────── Masthead ───────── */
.masthead { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.masthead__inner { max-width: 1240px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand__die { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); position: relative; transform: rotate(-8deg); box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 60%, #000); flex: none; }
.brand__die i { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-ink); }
.brand__die i:nth-child(1) { top: 8px; left: 8px; }
.brand__die i:nth-child(2) { top: 16px; left: 16px; }
.brand__die i:nth-child(3) { bottom: 8px; right: 8px; }
.brand__title { margin: 0; font-size: clamp(1.25rem, 3.2vw, 1.75rem); font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.brand__sub { margin: 4px 0 0; font: 600 .75rem/1 var(--mono); color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }

.tabs { display: flex; background: var(--paper-2); border-radius: 999px; padding: 4px; border: 1px solid var(--line); }
.tab { border: 0; background: none; padding: 7px 16px; border-radius: 999px; font-weight: 600; color: var(--ink-2); }
.tab.is-active { background: var(--ink); color: var(--paper); }
.masthead__tools { display: flex; gap: 6px; align-items: center; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); list-style: none; }
.icon-btn::-webkit-details-marker { display: none; }
.menu { position: relative; }
.menu__panel { position: absolute; right: 0; top: 48px; width: 260px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; display: grid; }
.menu__panel button, .menu__file { text-align: left; background: none; border: 0; padding: 10px 12px; border-radius: 10px; font-weight: 600; cursor: pointer; }
.menu__panel button:hover, .menu__file:hover { background: var(--paper-2); }
.menu__file input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.menu__file:focus-within { outline: 3px solid var(--focus); }
.menu__hint { margin: 4px 12px 8px; font-size: .78rem; color: var(--ink-3); }
.danger-text { color: var(--accent) !important; }

/* ───────── Controls ───────── */
.controls { margin: 24px 0 8px; display: grid; gap: 14px; }
.search { display: flex; align-items: center; gap: 10px; background: var(--card); border: 2px solid var(--ink); border-radius: 16px; padding: 0 16px; box-shadow: 4px 4px 0 var(--ink); }
.search svg { color: var(--ink-3); flex: none; }
.search input { flex: 1; min-width: 0; border: 0; background: none; padding: 14px 0; font-size: 1.05rem; outline: none; }
.filters { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-end; }
.filter { display: grid; gap: 6px; }
.filter__label { font: 600 .7rem/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.seg button { border: 1px solid var(--line); background: var(--card); padding: 7px 12px; border-radius: 10px; font-weight: 600; font-size: .9rem; color: var(--ink-2); }
.seg button.is-on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
select { border: 1px solid var(--line); background: var(--card); padding: 8px 12px; border-radius: 10px; font-weight: 600; min-width: 170px; }
.btn.filters-toggle { display: none; }
#filter-badge:not(:empty) { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 7px; font-size: .8rem; }
.stepper { justify-self: start; display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--card); overflow: hidden; }
.stepper button { border: 0; background: none; width: 38px; height: 38px; font-size: 1.15rem; font-weight: 800; }
.stepper button:hover { background: var(--paper-2); }
.stepper output { min-width: 56px; text-align: center; font: 600 .95rem var(--mono); }

.actionbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; border-top: 1px dashed var(--line); padding-top: 12px; }
.actionbar__right { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.result-count { margin: 0; font: 600 .85rem var(--mono); color: var(--ink-2); }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: .9rem; color: var(--ink-2); margin-right: 6px; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.btn { border: 2px solid var(--ink); border-radius: 12px; padding: 8px 14px; font-weight: 700; background: var(--card); color: var(--ink); display: inline-flex; align-items: center; gap: 6px; transition: transform .08s, box-shadow .08s; }
.btn:active { transform: translate(2px, 2px); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.btn--primary:active { box-shadow: 1px 1px 0 var(--ink); }
.btn--ghost { border-color: var(--line); background: var(--card); }
.btn--danger { border-color: var(--accent); color: var(--accent); background: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.dice-mini { font-size: 1.2rem; line-height: 1; }

/* ───────── Shelf ───────── */
.shelf { display: grid; gap: 34px; margin-top: 18px; }
.group__head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 12px; }
.group__title { margin: 0; font-size: clamp(1.4rem, 4vw, 2rem); font-weight: 800; letter-spacing: -.02em; }
.group__count { font: 600 .8rem var(--mono); color: var(--ink-3); }
.group__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; padding-bottom: 16px; position: relative; }
.group__grid::after { /* Regalbrett */
  content: ""; position: absolute; left: -8px; right: -8px; bottom: 0; height: 9px; border-radius: 3px;
  background: linear-gradient(var(--shelf), color-mix(in srgb, var(--shelf) 70%, #000));
  box-shadow: 0 6px 10px -4px var(--shelf-shadow);
}
.empty { text-align: center; padding: 60px 16px; color: var(--ink-2); border: 2px dashed var(--line); border-radius: var(--radius); }
.empty strong { display: block; font-size: 1.3rem; color: var(--ink); margin-bottom: 4px; }

.game {
  --t: var(--t-brett);
  position: relative; display: flex; flex-direction: column; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 14px 12px 22px; box-shadow: var(--shadow); text-align: left; width: 100%;
  transition: transform .12s ease, box-shadow .12s ease; overflow: hidden;
}
.game::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 8px; background: var(--t); }
.game:hover { transform: translateY(-3px) rotate(-.4deg); box-shadow: 0 14px 26px -12px rgba(60,40,10,.45); }
.game[data-typ="karten"] { --t: var(--t-karten); }
.game[data-typ="würfel"] { --t: var(--t-wuerfel); }
.game[data-typ="sonstiges"] { --t: var(--t-sonstiges); }
.game__top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.game__typ { font: 600 .68rem/1 var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--t); display: inline-flex; gap: 6px; align-items: center; }
.game__typ svg { width: 14px; height: 14px; }
.badge-unsure { font: 600 .66rem/1 var(--mono); text-transform: uppercase; letter-spacing: .06em; border: 1.5px dashed var(--accent); color: var(--accent); padding: 4px 6px; border-radius: 6px; transform: rotate(3deg); }
.game__title { margin: 0; font-size: 1.12rem; font-weight: 800; line-height: 1.15; letter-spacing: -.01em; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: .74rem; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: color-mix(in srgb, var(--t) 14%, transparent); color: var(--ink-2); }
.stats { display: flex; gap: 6px; margin-top: auto; padding: 8px 26px 0 0; border-top: 1px dashed var(--line); font: 600 .78rem var(--mono); color: var(--ink-2); flex-wrap: wrap; }
.stat { display: inline-flex; gap: 4px; align-items: center; }
.stat svg { width: 14px; height: 14px; color: var(--ink-3); }
.stat + .stat::before { content: "·"; color: var(--ink-3); margin-right: 2px; }
.game__edit { position: absolute; right: 8px; bottom: 8px; border: 0; background: none; color: var(--ink-3); padding: 6px; border-radius: 8px; opacity: 0; transition: opacity .12s; }
.game:hover .game__edit, .game:focus-within .game__edit { opacity: 1; }
.game__edit:hover { background: var(--paper-2); color: var(--ink); }
@media (hover: none) { .game__edit { opacity: 1; } }
.game.is-pick { animation: pick .6s ease; }
@keyframes pick { 0% { transform: scale(.96); } 50% { transform: scale(1.03) rotate(-1deg); } 100% { transform: none; } }

/* ───────── Dialoge ───────── */
.dlg { border: 2px solid var(--ink); border-radius: 20px; background: var(--card); color: var(--ink); padding: 22px; width: min(560px, calc(100vw - 32px)); box-shadow: 8px 8px 0 var(--ink); }
.dlg::backdrop { background: rgba(20, 14, 8, .55); backdrop-filter: blur(2px); }
.dlg__close { position: absolute; top: 10px; right: 10px; margin: 0; }
.dlg__close button { border: 0; background: none; font-size: 1.6rem; line-height: 1; width: 36px; height: 36px; border-radius: 10px; }
.dlg__close button:hover { background: var(--paper-2); }
.dlg__actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.dlg__actions form { margin: 0; }
.eyebrow { margin: 0 0 10px; font: 600 .75rem var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); }
.dlg--random .game { box-shadow: none; padding: 20px 18px 16px 28px; }
.dlg--random .game::before { width: 12px; }
.dlg--random .game__title { font-size: 1.8rem; }
.dlg--random .game:hover { transform: none; }
.slot { font-size: 1.8rem; font-weight: 800; min-height: 2.4em; display: flex; align-items: center; color: var(--ink-3); filter: blur(.5px); }
.game__note { margin: 0; color: var(--ink-2); font-size: .92rem; }

.edit { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.edit h3 { grid-column: 1 / -1; margin: 0 0 4px; font-size: 1.4rem; font-weight: 800; }
.field { display: grid; gap: 4px; font: 600 .72rem var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.field small { text-transform: none; letter-spacing: 0; }
.field input, .field select, .field textarea { font: 500 1rem var(--font); text-transform: none; letter-spacing: 0; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0; }
.field--wide { grid-column: 1 / -1; }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: .92rem; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }
.edit__error { grid-column: 1 / -1; margin: 0; color: var(--accent); font-weight: 600; min-height: 1em; }
.edit__actions { grid-column: 1 / -1; margin-top: 4px; }
.spacer { flex: 1; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; visibility: hidden; background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-weight: 600; transition: transform .25s ease, opacity .25s ease, visibility .25s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.is-on { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.toast:empty { display: none; }

/* ───────── Turnier ───────── */
.tn { margin-top: 24px; display: grid; gap: 20px; }
.tn-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 20px; box-shadow: var(--shadow); }
.tn-card h3 { margin: 0 0 4px; font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.tn-card > p.lead { margin: 0 0 16px; color: var(--ink-2); }
.tn-setup { display: grid; gap: 18px; }
.tn-row { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: flex-end; }
.tn-names { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tn-names input, .tn-score input { width: 100%; border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 9px 11px; }
.tn-avail { font: 600 .85rem var(--mono); color: var(--ink-2); margin: 0; }
.tn-avail strong { color: var(--accent); }

.tn-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 820px) { .tn-layout { grid-template-columns: 1fr; } }
.tn-round__head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.round-no { font: 800 .8rem var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.progress { display: flex; gap: 4px; margin: 10px 0 16px; }
.progress i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.progress i.done { background: var(--ink); }
.progress i.now { background: var(--accent); }
.tn-game { margin-bottom: 16px; }
.tn-game .game:hover { transform: none; }
.tn-score { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tn-score label { display: grid; gap: 4px; font-weight: 700; font-size: .92rem; overflow-wrap: anywhere; }
.tn-score input { font: 600 1.1rem var(--mono); }

.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.board li { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; background: var(--paper); border: 1px solid var(--line); }
.board .pos { font: 800 .95rem var(--mono); color: var(--ink-3); }
.board li:nth-child(1) .pos { color: var(--t-wuerfel); }
.board .name { font-weight: 700; overflow-wrap: anywhere; }
.board .pts { font: 800 1.05rem var(--mono); }
.history { width: 100%; border-collapse: collapse; font-size: .88rem; }
.history-wrap { overflow-x: auto; margin-top: 14px; }
.history th, .history td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.history td.num, .history th.num { text-align: right; font-family: var(--mono); }
.history th { font: 600 .7rem var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }

.podium { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: 10px; max-width: 520px; margin: 10px auto 24px; text-align: center; }
.podium div { border: 2px solid var(--ink); border-radius: 14px 14px 4px 4px; padding: 10px 6px; background: var(--card); }
.podium .p1 { height: 170px; background: var(--t-wuerfel); color: #1d1a16; order: 2; }
.podium .p2 { height: 130px; order: 1; }
.podium .p3 { height: 100px; order: 3; }
.podium b { display: block; font-size: 1.05rem; overflow-wrap: anywhere; }
.podium span { font: 600 .85rem var(--mono); }
.podium em { display: block; font: 800 1.6rem var(--mono); font-style: normal; }

.foot { max-width: 1240px; margin: 0 auto; padding: 0 16px 28px; color: var(--ink-3); font-size: .82rem; }

/* ───────── Mobil ───────── */
@media (max-width: 640px) {
  .masthead__inner { gap: 10px; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; }
  .controls { margin-top: 16px; }
  .btn.filters-toggle { display: inline-flex; justify-self: start; }
  .stats { gap: 4px 10px; }
  .stat + .stat::before { content: none; }
  .filters { gap: 12px; display: none; }
  .controls.is-open .filters { display: flex; }
  .filter { width: 100%; }
  .filter select { width: 100%; }
  .actionbar__right { width: 100%; }
  .actionbar__right .btn--primary { flex: 1; justify-content: center; }
  .group__grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .game { padding: 12px 10px 10px 16px; }
  .game::before { width: 6px; }
  .game__title { font-size: 1rem; }
  .edit { grid-template-columns: 1fr 1fr; }
  .dlg { padding: 18px; }
}
@media (max-width: 380px) { .group__grid { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
