:root {
  --bg: #fff8ec;
  --bg2: #ffe9c7;
  --panel: #ffffff;
  --ink: #2b2d42;
  --muted: #6b6f85;
  --primary: #ff7a00;
  --primary-ink: #ffffff;
  --accent: #ffd23f;
  --ok: #1fa88f;
  --bad: #e63946;
  --info: #3a86ff;
  --line: #2b2d42;
  --shadow: 0 4px 0 var(--line);
  --radius: 14px;
  /* Kopfzeile bleibt in beiden Farbschemata dunkel mit hellem Text. */
  --topbar-bg: #2b2d42;
  --topbar-ink: #fff8ec;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1c2a;
    --bg2: #24263a;
    --panel: #2b2d42;
    --ink: #f4f1ea;
    --muted: #b4b7c9;
    --line: #0e0f18;
    --accent: #ffcc33;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 20% 0%, var(--bg2), var(--bg) 60%) fixed;
  color: var(--ink);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.15; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; margin-top: 1rem; }
em { font-style: normal; font-weight: 700; color: var(--primary); }

/* ───────── Kopfzeile ───────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--topbar-bg); color: var(--topbar-ink);
  border-bottom: 2px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.logo { font-weight: 900; font-size: 1.15rem; letter-spacing: .2px; color: inherit; text-decoration: none; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.logo span { color: #ffd23f; }
.topbar-right { display: flex; align-items: center; gap: .4rem; }
.room-badge { background: #ffd23f; color: #2b2d42; font-weight: 900; border-radius: 8px; padding: .15rem .5rem; letter-spacing: 2px; }
.age-badge { background: var(--bad); color: #fff; font-weight: 900; border-radius: 8px; padding: .15rem .45rem; }
.icon-btn {
  background: transparent; border: 2px solid rgba(255,255,255,.35); color: inherit; border-radius: 10px;
  width: 2.3rem; height: 2.3rem; font-size: 1.1rem; cursor: pointer;
}
.icon-btn[aria-pressed="false"] { opacity: .45; }

.conn-banner { background: var(--bad); color: #fff; text-align: center; padding: .4rem; font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; padding-bottom: max(1rem, env(safe-area-inset-bottom)); }

/* ───────── Bausteine ───────── */
.panel {
  background: var(--panel); border: 3px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem;
}
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: .6rem; }
.row.nowrap { flex-wrap: nowrap; }
.row.center { justify-content: center; }
.field { display: block; font-weight: 700; margin-bottom: .8rem; }
input, select {
  font: inherit; font-size: max(16px, 1em); /* iOS zoomt sonst beim Antippen */
  color: var(--ink); background: var(--bg); border: 2px solid var(--line);
  border-radius: 10px; padding: .55rem .7rem; width: 100%; margin-top: .3rem;
}
input:focus, select:focus { outline: 3px solid var(--accent); outline-offset: 1px; }
select:disabled, input:disabled { opacity: .65; }

.btn {
  font: inherit; font-weight: 800; cursor: pointer; border: 3px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--ink); padding: .6rem 1rem; box-shadow: 0 3px 0 var(--line);
  transition: transform .06s, box-shadow .06s; white-space: nowrap;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--line); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; }
.btn.small { padding: .35rem .7rem; font-size: .9rem; }
.btn.big { font-size: 1.25rem; padding: .8rem 1.6rem; }

.seg-group { display: flex; gap: 0; margin-top: .3rem; }
.seg {
  flex: 1; font: inherit; font-weight: 700; padding: .55rem .4rem; cursor: pointer;
  border: 2px solid var(--line); background: var(--bg); color: var(--ink);
}
.seg:first-child { border-radius: 10px 0 0 10px; }
.seg:last-child { border-radius: 0 10px 10px 0; border-left: 0; }
.seg.active { background: var(--accent); color: #2b2d42; }

.tag { background: var(--ink); color: var(--bg); border-radius: 999px; padding: .15rem .65rem; font-size: .85rem; font-weight: 700; }

/* ───────── Start ───────── */
.hero { text-align: center; margin: .5rem auto 1.2rem; max-width: 760px; }
.hero h1 { font-size: clamp(1.6rem, 5vw, 2.6rem); }
.hero p { font-size: 1.05rem; line-height: 1.5; }
.start-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.start-grid .panel { margin-bottom: 0; }
.code-input { text-transform: uppercase; letter-spacing: 6px; font-weight: 900; font-size: 1.3rem; text-align: center; max-width: 11rem; margin-top: 0; }
.public-rooms { list-style: none; margin: 0; padding: 0; }
.public-rooms li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .45rem 0; border-bottom: 1px dashed var(--muted); }
.public-rooms li:last-child { border-bottom: 0; }
.rules { margin-top: 1rem; }
.rules summary { font-weight: 800; cursor: pointer; }
.rules li { margin: .35rem 0; line-height: 1.45; }
.server-info { text-align: center; color: var(--muted); font-size: .85rem; }

/* ───────── Lobby ───────── */
.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.big-code { font-size: 2.6rem; font-weight: 900; letter-spacing: 10px; }
.invite { display: flex; gap: .5rem; align-items: center; flex: 1; min-width: 240px; max-width: 520px; }
.invite input { margin: 0; font-size: .85rem; }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.lobby-grid .panel { margin-bottom: 0; }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem .8rem; }
.settings label { font-weight: 700; font-size: .92rem; }
.settings label.check { display: flex; gap: .5rem; align-items: center; grid-column: span 2; font-weight: 600; }
.settings label.check input { width: auto; margin: 0; transform: scale(1.25); }
body:not(.is-host) .host-only { display: none !important; }
body.is-host .guest-only { display: none !important; }

.player-list { list-style: none; margin: 0; padding: 0; }
.player-list li {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem; border-radius: 10px;
  background: var(--bg); margin-bottom: .4rem; border: 2px solid transparent;
}
.player-list li.me { border-color: var(--primary); }
.player-list li.offline { opacity: .5; }
.player-list .pname { font-weight: 800; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: .75rem; font-weight: 800; border-radius: 6px; padding: .05rem .35rem; background: var(--ink); color: var(--bg); }
.badge.host { background: var(--accent); color: #2b2d42; }
.badge.bot { background: var(--info); color: #fff; }
.remove-btn { border: 0; background: transparent; color: var(--bad); font-size: 1.1rem; cursor: pointer; padding: 0 .2rem; }

/* ───────── Spiel ───────── */
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 1rem; align-items: start; }
.round-info { display: flex; justify-content: space-between; align-items: center; font-weight: 800; margin-bottom: .4rem; }
.timer { height: 12px; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--panel); }
#timer-bar { height: 100%; width: 100%; background: var(--ok); transition: background-color .3s; }
#timer-bar.warn { background: var(--accent); }
#timer-bar.hurry { background: var(--bad); }
#timer-bar.paused { background: var(--info); }

.question-card {
  margin: .9rem 0 1.1rem; background: var(--accent); color: #2b2d42; border: 3px solid var(--line);
  border-radius: 18px; box-shadow: 0 6px 0 var(--line); padding: 1.2rem 1rem; text-align: center; min-height: 7.5rem;
  display: flex; flex-direction: column; justify-content: center;
}
.q-prefix { font-weight: 700; opacity: .7; }
#question-text { font-size: clamp(1.5rem, 4.6vw, 2.4rem); font-weight: 900; line-height: 1.15; word-break: break-word; }
.question-card.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(.85); } 70% { transform: scale(1.04); } 100% { transform: scale(1); } }

.hand { display: flex; flex-wrap: wrap; gap: .7rem; justify-content: center; min-height: 6.5rem; padding: .3rem 0 .9rem; }
.card {
  position: relative; width: 66px; height: 92px; border-radius: 12px; border: 3px solid var(--line);
  background: linear-gradient(160deg, #ffffff, #fff1d0); color: #2b2d42; box-shadow: 0 4px 0 var(--line);
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 2.3rem;
  transition: transform .15s, background-color .15s; user-select: none;
}
.card.combo { font-size: 1.05rem; text-align: center; line-height: 1.05; padding: 0 .2rem; }
.card.match { transform: translateY(-10px) rotate(-3deg); background: var(--ok); color: #fff; }
.card.gone { animation: fly .6s ease-in forwards; }
@keyframes fly { to { transform: translateY(-80px) rotate(25deg); opacity: 0; } }
.card .swap {
  position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%); border: 2px solid var(--line);
  background: var(--panel); color: var(--ink); border-radius: 999px; width: 28px; height: 28px; font-size: .85rem; cursor: pointer; padding: 0;
}
.hand-empty { font-weight: 800; color: var(--ok); align-self: center; }

.answer-form { display: flex; gap: .5rem; }
.answer-form input { font-size: 1.35rem; font-weight: 700; margin: 0; padding: .75rem .9rem; border-width: 3px; }
.answer-form .btn { font-size: 1.4rem; padding: 0 1.1rem; }
.answer-form.shake { animation: shake .35s; }
.answer-form.inactive input, .answer-form.locked input { opacity: .6; }
.answer-form.locked input { border-color: var(--bad); }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.answer-hint { min-height: 1.5rem; margin-top: .4rem; font-weight: 700; text-align: center; }
.answer-hint.bad { color: var(--bad); }
.answer-hint.ok { color: var(--ok); }

.game-side .player-list li { padding: .4rem .5rem; }
.mini-cards { font-weight: 900; font-size: .9rem; white-space: nowrap; }
.typing { display: inline-flex; gap: 2px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--primary); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }

.feed { list-style: none; padding: 0; margin: 0 0 1rem; max-height: 300px; overflow-y: auto; font-size: .88rem; }
.feed li { padding: .3rem .1rem; border-bottom: 1px dashed rgba(127,127,127,.35); line-height: 1.35; word-break: break-word; }
.feed li.ok { color: var(--ok); font-weight: 700; }
.feed li.wrong { color: var(--bad); }

/* ───────── Overlay ───────── */
.overlay {
  position: fixed; inset: 0; background: rgba(20, 20, 35, .55); display: flex; align-items: center; justify-content: center;
  z-index: 30; padding: 1rem; backdrop-filter: blur(2px);
}
.overlay.passive { pointer-events: none; background: rgba(20, 20, 35, .25); }
/* Prüfung/Abstimmung: Karte oben, Eingabefeld darunter bleibt bedienbar. */
.overlay.top { align-items: flex-start; padding-top: 4.2rem; background: transparent; backdrop-filter: none; }
.overlay.voting { pointer-events: none; }
.overlay.voting .overlay-card { pointer-events: auto; }
.overlay-card {
  background: var(--panel); border: 3px solid var(--line); border-radius: 20px; box-shadow: 0 8px 0 var(--line);
  padding: 1.4rem 1.2rem; max-width: 520px; width: 100%; text-align: center; animation: pop .3s ease-out;
}
.overlay-card .big { font-size: clamp(3.5rem, 18vw, 6.5rem); font-weight: 900; line-height: 1; color: var(--primary); }
.overlay-card .answer { font-size: clamp(1.4rem, 6vw, 2.2rem); font-weight: 900; margin: .4rem 0; word-break: break-word; }
.overlay-card .who { font-size: 1.3rem; font-weight: 800; }
.overlay-card .sub { color: var(--muted); margin-top: .4rem; }
.overlay-card .vote-row { display: flex; gap: .8rem; justify-content: center; margin-top: 1rem; }
.overlay-card .vote-row .btn { font-size: 1.15rem; flex: 1; max-width: 12rem; }
.overlay-card .vote-row .btn.chosen { outline: 4px solid var(--accent); }
.mini-timer { height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; margin-top: 1rem; border: 2px solid var(--line); }
.mini-timer > div { height: 100%; background: var(--info); width: 100%; }

/* ───────── Ende ───────── */
.over { text-align: center; max-width: 640px; margin: 1rem auto; }
.ranking { list-style: none; padding: 0; margin: 1rem 0; text-align: left; }
.ranking li {
  display: grid; grid-template-columns: 3rem 1fr auto; align-items: center; gap: .6rem; padding: .7rem .8rem;
  border-radius: 12px; background: var(--bg); margin-bottom: .5rem; border: 2px solid transparent;
}
.ranking li.me { border-color: var(--primary); }
.ranking .place { font-size: 1.8rem; text-align: center; }
.ranking .stats { color: var(--muted); font-size: .88rem; text-align: right; }

/* ───────── Toasts & Konfetti ───────── */
.toasts { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 50; width: min(92vw, 460px); }
.toast {
  background: var(--ink); color: var(--bg); padding: .7rem 1rem; border-radius: 12px; font-weight: 700;
  box-shadow: 0 4px 12px rgba(0,0,0,.25); animation: toast-in .2s ease-out;
}
.toast.error { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 60; }
.confetti span { position: absolute; top: -2rem; font-size: 1.6rem; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

/* ───────── Handy ───────── */
@media (max-width: 820px) {
  .start-grid, .lobby-grid { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .game-side { order: 2; }
  .feed { max-height: 180px; }
  .settings { grid-template-columns: 1fr; }
  .settings label.check { grid-column: span 1; }
  .big-code { font-size: 2.1rem; letter-spacing: 7px; }
}
@media (max-width: 420px) {
  main { padding: .7rem; }
  .topbar { padding-inline: .6rem; gap: .3rem; }
  .icon-btn { width: 2rem; height: 2rem; font-size: 1rem; }
  .room-badge { letter-spacing: 1px; }
  .overlay.top { padding-top: 3.6rem; }
  .card { width: 54px; height: 76px; font-size: 1.9rem; }
  .card.combo { font-size: .9rem; }
  .hand { gap: .45rem; }
  .logo { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ───────── Konten ───────── */
.account-bar > div { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem .8rem; }
.account-bar .row { margin-top: 0; }
.verified { color: var(--ok); font-weight: 900; }
.login-required { margin: .6rem 0 0; font-weight: 700; color: var(--bad); }
.small-text { font-size: .85rem; }
.row.space { justify-content: space-between; margin-top: 0; }
.panel.narrow { max-width: 640px; margin-left: auto; margin-right: auto; }
.stack { display: flex; flex-direction: column; gap: .7rem; }
.stack label { font-weight: 700; }
.check-line { display: flex; gap: .5rem; align-items: center; font-weight: 600; margin-top: 1rem; }
.check-line input { width: auto; margin: 0; transform: scale(1.25); }
.form-error { color: var(--bad); font-weight: 700; min-height: 1.2em; margin: 0; }
.danger-zone { border-color: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .6rem; margin-top: .6rem; }
.stat { background: var(--bg); border-radius: 12px; padding: .7rem .5rem; text-align: center; }
.stat-value { font-size: 1.6rem; font-weight: 900; color: var(--primary); }
.stat-label { font-size: .8rem; color: var(--muted); font-weight: 700; }

.board { list-style: none; padding: 0; margin: 0; }
.board li { display: grid; grid-template-columns: 2.2rem auto 1fr; align-items: center; gap: .5rem; padding: .45rem .3rem; border-bottom: 1px dashed rgba(127,127,127,.35); }
.board li.muted { display: block; }
.board .place { font-size: 1.3rem; text-align: center; }
.board .stats { display: block; color: var(--muted); font-size: .85rem; text-align: right; margin: 0; }

.dialog {
  border: 3px solid var(--line); border-radius: 18px; box-shadow: 0 8px 0 var(--line); padding: 1.2rem;
  background: var(--panel); color: var(--ink); width: min(92vw, 440px);
}
.dialog::backdrop { background: rgba(20, 20, 35, .55); }
.dialog h2 { margin-bottom: .2rem; }

.table-wrap { overflow-x: auto; margin-top: .8rem; }
.users { width: 100%; border-collapse: collapse; font-size: .9rem; }
.users th, .users td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid rgba(127,127,127,.3); white-space: nowrap; }
.users td.actions { display: flex; gap: .3rem; flex-wrap: wrap; white-space: normal; }
.badge.bad { background: var(--bad); color: #fff; }
.temp-password { margin-top: .8rem; padding: .7rem .9rem; border-radius: 12px; background: var(--accent); color: #2b2d42; font-weight: 600; }
.temp-password code { font-size: 1.2rem; font-weight: 900; background: #fff; padding: .1rem .4rem; border-radius: 6px; letter-spacing: 1px; }

@media (max-width: 820px) {
  .board li { grid-template-columns: 2.2rem 1fr; }
  .board .stats { grid-column: 2; text-align: left; }
}

.stat-note { font-size: .75rem; color: var(--muted); margin-top: .25rem; word-break: break-word; }
.board-tabs { margin: .2rem 0 .5rem; flex-wrap: wrap; }
.board-tabs .seg { font-size: .85rem; padding: .4rem .3rem; }
.board-tabs .seg + .seg { border-left: 0; }
.board-tabs .seg:not(:first-child):not(:last-child) { border-radius: 0; }

.form-error.full { flex-basis: 100%; }
