:root {
  --bg: #14161f;
  --bg-2: #1b1e2b;
  --card: #222637;
  --card-2: #2a2f44;
  --line: #353b55;
  --text: #ecebf3;
  --muted: #9a9cb3;
  --accent: #f4b942;
  --accent-2: #ffd27a;
  --accent-ink: #1b1d2b;
  --good: #5fd38d;
  --bad: #ff6b6b;
  --felt: #1f5f4a;
  --felt-2: #18493a;
  --die: #fbf8f1;
  --pip: #1b1d2b;
  --radius: 14px;
  --shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3efe6;
    --bg-2: #ebe5d8;
    --card: #fffdf8;
    --card-2: #f5f0e5;
    --line: #ddd4c1;
    --text: #22222e;
    --muted: #6d6a7c;
    --accent: #e0a020;
    --accent-2: #c98a0e;
    --felt: #2c7a5f;
    --felt-2: #23624c;
    --shadow: 0 6px 20px rgb(60 40 0 / 0.08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, var(--bg-2), var(--bg));
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
small { font-size: .82em; }
code { background: var(--card-2); padding: 0 .3em; border-radius: 4px; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }

/* ---------- Kopfzeile ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .7rem clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.2rem; color: var(--text); text-decoration: none; letter-spacing: .02em; }
.brand-die { width: 26px; height: 26px; background: url(/favicon.svg) center / contain no-repeat; display: inline-block; transform: rotate(-8deg); }
.topbar nav { display: flex; gap: .3rem; }
.topbar nav a { color: var(--muted); text-decoration: none; padding: .35rem .7rem; border-radius: 8px; }
.topbar nav a:hover { color: var(--text); }
.topbar nav a.active { color: var(--text); background: var(--card); }
.me { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.me form { margin: 0; }
@media (max-width: 640px) {
  .topbar { gap: .5rem; }
  .me > span, .me .avatar { display: none; }
  .brand-name { display: none; }
  .topbar nav a { padding: .3rem .5rem; }
}

.container { max-width: 1200px; margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); }
.page-title { margin-bottom: 1rem; }

/* ---------- Bausteine ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.card.narrow { max-width: 480px; margin: 3rem auto; text-align: center; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
.grid-2 > .card + .card { margin-top: 0; }
.stack { display: grid; gap: .8rem; }
.row { display: flex; gap: .5rem; margin-top: .8rem; }
.row input { flex: 1; min-width: 0; }
.hero { margin: .5rem 0 1.5rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; color: var(--accent); margin: 0 0 .3rem; font-weight: 700; }

input:not([type=checkbox]):not([type=radio]) {
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: .6rem .8rem; width: 100%;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.code-input { text-transform: uppercase; letter-spacing: .2em; font-weight: 700; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  border-radius: 10px; padding: .55rem 1rem; text-decoration: none; display: inline-block;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: .3rem .7rem; font-size: .88rem; }
.btn.big { padding: .8rem 1.6rem; font-size: 1.1rem; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .9rem; padding: .2rem .4rem; border-radius: 6px; }
.icon-btn:hover { color: var(--bad); background: var(--card-2); }

.pill { font-size: .75rem; font-weight: 700; padding: .15rem .6rem; border-radius: 99px; background: var(--card-2); color: var(--muted); white-space: nowrap; }
.pill.waiting { background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--good); }
.pill.guest { background: color-mix(in srgb, #8fa8ff 20%, transparent); color: #8fa8ff; font-size: .68rem; padding: .05rem .45rem; vertical-align: middle; }
.pill.playing { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none;
  display: inline-grid; place-items: center; font-size: .8rem; font-weight: 700; color: #fff;
  background: hsl(220 40% 45%);
}
.avatar.small { width: 26px; height: 26px; font-size: .7rem; }
.avatar[data-hue="1"] { background: hsl(10 60% 50%); }
.avatar[data-hue="2"] { background: hsl(150 45% 38%); }
.avatar[data-hue="3"] { background: hsl(280 40% 50%); }
.avatar[data-hue="4"] { background: hsl(35 70% 45%); }
.avatar[data-hue="5"] { background: hsl(190 55% 38%); }
.avatar[data-hue="6"] { background: hsl(330 50% 50%); }
.avatar[data-hue="7"] { background: hsl(100 35% 40%); }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 150%);
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: .7rem 1.2rem; border-radius: 12px; box-shadow: var(--shadow);
  transition: transform .25s ease, opacity .25s; z-index: 50; max-width: 90vw;
  opacity: 0; visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.toast.error { border-color: var(--bad); }

/* ---------- Startseite ---------- */
.game-picker { display: grid; gap: .5rem; }
.game-option { display: flex; gap: .8rem; align-items: flex-start; padding: .8rem; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--bg); }
.game-option:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
.game-option input { margin-top: .3rem; accent-color: var(--accent); }
.game-option span { display: grid; gap: .15rem; }

.lobby-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.lobby-list .empty { padding: 1.5rem 0; text-align: center; }
.lobby-item {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .8rem 1rem; border-radius: 12px; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); text-decoration: none;
}
.lobby-item:hover { border-color: var(--accent); }
.lobby-item span:first-child { display: grid; min-width: 0; }
.lobby-item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Lobby ---------- */
.lobby-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .lobby-layout { grid-template-columns: 1fr; } }
.side { display: grid; gap: 1rem; position: sticky; top: 4.5rem; }
.side .card + .card { margin-top: 0; }
@media (max-width: 900px) { .side { position: static; } }

.members-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.members-head h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code { font: inherit; font-family: ui-monospace, monospace; font-weight: 700; letter-spacing: .12em; background: var(--card-2); border: 1px dashed var(--line); color: var(--accent); padding: .2rem .5rem; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.code-big { font-family: ui-monospace, monospace; font-size: 1.3em; letter-spacing: .15em; color: var(--accent); }
.member-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .45rem; }
.member-list li { display: flex; align-items: center; gap: .6rem; }
.member-list li.offline { opacity: .5; }
.member-list .grow { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }

.chat { display: flex; flex-direction: column; }
.chat-log { list-style: none; margin: 0; padding: 0; height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: .3rem; font-size: .92rem; overflow-wrap: anywhere; }
.chat-log li.sys { color: var(--muted); font-style: italic; font-size: .85rem; }
.chat .row { margin-top: .6rem; }

.waiting { text-align: center; padding: 2.5rem 1.5rem; }
.waiting .btn.big { margin-top: 1rem; }
.options { border: 1px solid var(--line); border-radius: 12px; text-align: left; max-width: 520px; margin: 1.2rem auto; padding: .6rem 1rem 1rem; }
.options legend { padding: 0 .4rem; color: var(--muted); font-size: .85rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; }
.check input { accent-color: var(--accent); margin-top: .3rem; }
.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }

#stage-extra { margin-top: 1rem; }
.results h2 { margin-bottom: 1rem; }
.podium { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .4rem; }
.podium li { display: flex; align-items: center; gap: .8rem; padding: .6rem .9rem; border-radius: 10px; background: var(--bg); font-size: 1.1rem; }
.podium li.mine { outline: 2px solid var(--accent); }
.podium .medal { width: 2rem; text-align: center; font-size: 1.4rem; }

/* ---------- Würfelblock ---------- */
.dice-card {
  background: radial-gradient(ellipse at 50% 0%, var(--felt), var(--felt-2));
  border-color: color-mix(in srgb, var(--felt) 70%, black);
  color: #f1f5ef;
  text-align: center;
}
.dice-card .muted { color: #bcd3c7; }
.dice-card.my-turn { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.turn { display: flex; flex-direction: column; gap: .1rem; min-height: 3rem; }
.turn strong { font-size: 1.2rem; }
.tray { display: flex; justify-content: center; gap: clamp(.4rem, 2vw, 1rem); margin: 1.4rem 0; }
.die {
  --size: clamp(50px, 14vw, 72px);
  width: var(--size); height: var(--size); flex: none;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: calc(var(--size) * .16); gap: calc(var(--size) * .04);
  background: var(--die); border: 0; border-radius: 18%;
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / .15), 0 4px 10px rgb(0 0 0 / .35);
  cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.die:disabled { cursor: default; }
.die:not(:disabled):hover { transform: translateY(-3px); }
.die.held { transform: translateY(-8px); box-shadow: 0 0 0 4px var(--accent), 0 10px 16px rgb(0 0 0 / .4); }
.die.rolling { animation: tumble .5s cubic-bezier(.3, 1.4, .6, 1); }
@keyframes tumble {
  0% { transform: rotate(-200deg) scale(.6); opacity: .4; }
  60% { transform: rotate(15deg) scale(1.08); opacity: 1; }
  100% { transform: rotate(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) { .die.rolling { animation: none; } }
.pip { background: var(--pip); border-radius: 50%; align-self: center; justify-self: center; width: 78%; height: 78%; }
.pos-1 { grid-area: 1 / 1; } .pos-2 { grid-area: 1 / 2; } .pos-3 { grid-area: 1 / 3; }
.pos-4 { grid-area: 2 / 1; } .pos-5 { grid-area: 2 / 2; } .pos-6 { grid-area: 2 / 3; }
.pos-7 { grid-area: 3 / 1; } .pos-8 { grid-area: 3 / 2; } .pos-9 { grid-area: 3 / 3; }
.roll-row { display: flex; align-items: center; justify-content: center; gap: 1rem; }
.rolls { display: flex; gap: .35rem; }
.roll-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #bcd3c7; }
.roll-dot.on { background: var(--accent); border-color: var(--accent); }
.hint { font-size: .85rem; margin: .8rem 0 0; }

.table-scroll { overflow-x: auto; }
.sheet { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.sheet th, .sheet td { padding: .35rem .6rem; border-bottom: 1px solid var(--line); }
.sheet thead th { font-size: .9rem; white-space: nowrap; border-bottom: 2px solid var(--line); }
.sheet thead th.current { color: var(--accent); }
.sheet thead th.mine { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 4px; }
.sheet tbody th { text-align: left; font-weight: 600; white-space: nowrap; }
.sheet tbody th small { display: block; font-weight: 400; color: var(--muted); font-size: .72rem; }
.sheet .num { text-align: center; min-width: 4rem; }
.sheet td.zero { color: var(--muted); }
.sheet tr.sum th, .sheet tr.sum td { background: var(--card-2); font-weight: 700; }
.sheet tr.total th, .sheet tr.total td { font-size: 1.15rem; color: var(--accent); border-bottom: 0; }
.score-btn {
  font: inherit; font-weight: 700; width: 100%; min-height: 1.9rem; cursor: pointer;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border: 1px dashed var(--accent); color: var(--accent); border-radius: 8px;
}
.score-btn:hover { background: var(--accent); color: var(--accent-ink); border-style: solid; }
.score-btn.strike { border-color: var(--line); color: var(--muted); background: transparent; }
.score-btn.strike:hover { background: var(--bad); border-color: var(--bad); color: #fff; }

/* ---------- Bestenliste ---------- */
.table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.table th, .table td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); text-align: left; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.recent { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.recent .winner { font-weight: 700; color: var(--accent); }

/* ---------- Anmeldeseite ---------- */
.auth-page { display: grid; place-items: center; padding: 1rem; }
.auth-card { max-width: 420px; width: 100%; text-align: center; }
.auth-card form { display: grid; gap: .8rem; margin-top: 1rem; }
.auth-card .btn { width: 100%; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: .5rem; font-weight: 800; font-size: 1.1rem; margin-bottom: 1.2rem; }
.form-error { color: var(--bad); margin: 0; }
.divider { display: flex; align-items: center; gap: .8rem; color: var(--muted); font-size: .85rem; margin: 1.2rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.small-print { font-size: .82rem; margin: 1rem 0 0; }
