/* Hintergrund/Oberflächen folgen dem System (hell/dunkel) oder der Wahl im Kopf, die Karten behalten immer ihre Skyjo-Farben. */
:root {
  color-scheme: light;
  --bg: #f3f4f7;
  --panel: #ffffff;
  --text: #1b1e27;
  --muted: #6a7282;
  --line: #e1e4ea;
  --accent: #3565d6;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 6px 18px rgba(20, 24, 40, .07);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12141a;
    --panel: #1b1e27;
    --text: #eceef4;
    --muted: #9aa2b1;
    --line: #2a2f3b;
    --accent: #7aa2f7;
    --on-accent: #0d1220;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 22px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12141a;
  --panel: #1b1e27;
  --text: #eceef4;
  --muted: #9aa2b1;
  --line: #2a2f3b;
  --accent: #7aa2f7;
  --on-accent: #0d1220;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 22px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
}
/* Im Spiel: keine erzwungene Mindesthöhe (sonst entsteht ein Scrollbereich) und kein Pull-to-Refresh */
body.ingame { min-height: 0; }
html.ingame { overscroll-behavior-y: none; }
[hidden], .hidden { display: none !important; }
button { font: inherit; color: inherit; touch-action: manipulation; }
h1, h2 { margin: 0; letter-spacing: -.02em; }
.wrap { max-width: 760px; margin: 0 auto; padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }

/* ---------- Buttons & Eingaben ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  padding: .7em 1.1em; border-radius: 12px; font-weight: 600; cursor: pointer;
  transition: transform .1s, filter .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { padding: .4em .8em; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: default; }
.link { appearance: none; background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 13px; }
input {
  width: 100%; padding: .7em .9em; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus-visible, .btn:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 14px; box-shadow: var(--shadow);
}

/* ---------- Kopfzeile (nur Start & Lobby, wie bei den anderen Spielen) ---------- */
.top { display: flex; align-items: center; gap: 12px; padding: 4px 0 6px; }
html.ingame .top { display: none; }
.top-spacer { flex: 1; }
.top-actions { display: flex; gap: 8px; }
.nav-back, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; padding: 0; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  cursor: pointer; text-decoration: none;
}
.nav-back:hover, .icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.nav-back:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.snd .ic-off { display: none; }
.snd[aria-pressed="true"] .ic-on { display: none; }
.snd[aria-pressed="true"] .ic-off { display: block; }

/* ---------- Start ---------- */
#view-start { text-align: center; padding-top: 2vh; }
.hero { display: flex; justify-content: center; align-items: flex-end; height: 92px; margin-bottom: 8px; }
.hero .card { margin: 0 4px; }
#view-start h1 { font-size: 40px; }
.sub { margin: 2px 0 22px; color: var(--muted); }
.form { max-width: 380px; margin: 0 auto; text-align: left; display: grid; gap: 12px; padding: 18px; }
.form label { margin: 0 0 -6px; }
.form .row { display: flex; gap: 8px; }
#code { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; width: 130px; flex: none; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.rules { max-width: 380px; margin: 18px auto 0; text-align: left; color: var(--muted); font-size: 14px; }
.rules summary { cursor: pointer; text-align: center; }
.rules ul { padding-left: 1.2em; margin: 10px 0 0; display: grid; gap: 6px; }

/* ---------- Lobby ---------- */
#view-lobby h2 { text-align: center; margin: 2vh 0 16px; font-size: 26px; }
.lobby { max-width: 420px; margin: 0 auto; display: grid; gap: 14px; padding: 18px; }
.codebox { display: grid; justify-items: center; gap: 6px; }
.codebox .lbl { font-size: 13px; color: var(--muted); }
.code { font-size: 44px; font-weight: 800; letter-spacing: .18em; padding-left: .18em; font-variant-numeric: tabular-nums; }
.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.plist li {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line); min-height: 46px;
}
.plist li.empty { border-style: dashed; background: transparent; color: var(--muted); font-size: 14px; }
.plist .ln { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.plist .x { appearance: none; border: 0; background: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.plist .x:hover { color: #d4402f; }
.hint { margin: 0; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- Spiel ---------- */
.gbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; min-height: 32px; }
.gtitle { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 800; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; }
.gtitle #ginfo { font-weight: 500; font-size: 12px; color: var(--muted); margin-left: 6px; }
.glast { font-size: 11px; font-weight: 700; margin-left: 6px; padding: 1px 8px; border-radius: 99px; background: var(--accent); color: var(--on-accent); }
.gbtns { display: flex; gap: 6px; flex: none; }
.gbtns .btn { padding: .3em .8em; white-space: nowrap; }
.gbtns .ib { padding: .3em .45em; display: inline-flex; align-items: center; }

/* Gegner: Grösse nur nach Breite, damit die Höhe des Blocks stabil bleibt */
.opps { display: flex; justify-content: center; gap: 8px; --cw: clamp(20px, min(6.4vw, 30px), 30px); }
.opps[data-n="1"] { --cw: clamp(26px, min(8vw, 34px), 34px); }
.opps[data-n="2"] { --cw: clamp(24px, min(7vw, 32px), 32px); }
.opps .panel { padding: 6px 8px 8px; flex: 0 1 auto; min-width: 0; }

.phead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; font-size: 13px; min-width: 0; }
.pname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ptotal { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: none; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 99px; background: var(--accent); color: var(--on-accent); margin-left: 6px; vertical-align: 1px; }
.panel.fin .badge { display: inline-block; }
.panel.turn { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent), var(--shadow); }
.panel.off .pname::after { content: " · offline"; font-weight: 400; color: var(--muted); }
#me { margin-top: 6px; }
#me .panel { padding: 8px 12px 10px; }
#me .phead { font-size: 15px; margin-bottom: 6px; }
.pinfo { font-size: 12px; color: var(--muted); }

/* Status: immer genau eine Zeile fester Höhe */
.status {
  margin: 8px 0; padding: 0 12px; height: 38px; display: flex; align-items: center; justify-content: center;
  border-radius: 14px; background: var(--panel); border: 1px solid var(--line);
  text-align: center; font-weight: 600; font-size: 14.5px;
}
.status #status-main { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sacts { display: flex; gap: 6px; flex: none; }
.sacts:not(:empty) { margin-left: 10px; }
.status.wait { border-color: #d4402f; }
.status.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }

/* Rundenergebnis */
.result { margin: 8px 0; padding: 14px; text-align: center; display: grid; gap: 10px; }
.result h2 { font-size: 20px; }
.result .win { color: var(--accent); font-weight: 700; }
.result table { border-collapse: collapse; margin: 0 auto; font-variant-numeric: tabular-nums; font-size: 14px; }
.result th, .result td { padding: 5px 12px; text-align: center; }
.result th { color: var(--muted); font-weight: 600; font-size: 12px; }
.result td:first-child, .result th:first-child { text-align: left; color: var(--muted); }
.result tbody td { border-top: 1px solid var(--line); }
.result tfoot td { border-top: 2px solid var(--line); font-weight: 800; }
.result .best { color: var(--accent); }
.result .dbl::after { content: "×2"; font-size: 10px; font-weight: 700; color: #d4402f; margin-left: 3px; vertical-align: 2px; }

/* Tisch: Stapel */
/* --u (Kartenbreite des eigenen Bretts) setzt app.js passend zur sichtbaren Höhe */
#view-game { --u: 60px; }
.table { display: flex; justify-content: center; align-items: flex-start; gap: clamp(12px, 4vw, 26px); margin: 4px 0 0; --cw: calc(var(--u) * .8); }
.pile { display: grid; justify-items: center; gap: 4px; }
.pile .lbl { height: 24px; display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.pill {
  appearance: none; height: 24px; padding: 0 14px; border-radius: 99px; cursor: pointer;
  border: 1.5px solid var(--accent); background: transparent; color: var(--accent); font-size: 12px; font-weight: 700;
}
.pill.on { background: var(--accent); color: var(--on-accent); }
.slot .card.gone::before { border-color: var(--muted); opacity: .45; }
.slot.draw .card .back { box-shadow: 2px 2px 0 #26266f, 4px 4px 0 #1f1f5c, 0 1px 2px rgba(0, 0, 0, .3); }

/* Brett */
.board {
  display: grid; grid-template-rows: repeat(3, auto); grid-auto-flow: column;
  grid-template-columns: repeat(4, auto); gap: var(--gap, 4px); justify-content: center;
}
.board.big { --cw: var(--u); --gap: clamp(4px, 1.4vw, 8px); }
.board.mini { --gap: 3px; }

/* ---------- Karten ---------- */
.card {
  position: relative; flex: none; padding: 0; border: 0; background: none; margin: 0;
  width: var(--cw); height: calc(var(--cw) * 1.34); perspective: 700px; cursor: default;
  -webkit-tap-highlight-color: transparent; transition: transform .15s;
}
.card .inner {
  position: absolute; inset: 0; display: block; transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.3, .7, .3, 1);
}
.card.up .inner { transform: rotateY(180deg); }
.notrans .inner, .card.notrans .inner { transition: none; }
.card .face {
  position: absolute; inset: 0; display: grid; place-items: center;
  border-radius: calc(var(--cw) * .15);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3), inset 0 0 0 calc(var(--cw) * .05) rgba(255, 255, 255, .88);
}
.card .front { transform: rotateY(180deg); color: #fff; }
.card .n { font-size: calc(var(--cw) * .5); font-weight: 800; letter-spacing: -.03em; font-style: normal; text-shadow: 0 1px 0 rgba(0, 0, 0, .18); }
.card .k { position: absolute; font-size: calc(var(--cw) * .19); font-weight: 700; font-style: normal; opacity: .9; }
.card .k.tl { top: 7%; left: 11%; }
.card .k.br { bottom: 7%; right: 11%; transform: rotate(180deg); }
.mini .k, .hero .k { display: none; }

/* Skyjo-Farben: -2/-1 dunkelblau, 0 hellblau, 1–4 grün, 5–8 gelb, 9–12 rot */
.c-navy   { background: linear-gradient(160deg, #3560c4, #1f3e8e); }
.c-cyan   { background: linear-gradient(160deg, #95d6f5, #5fb8e6); color: #0c3653 !important; }
.c-green  { background: linear-gradient(160deg, #4ab75f, #2e9042); }
.c-yellow { background: linear-gradient(160deg, #f8d658, #efba2b); color: #4a3500 !important; }
.c-yellow .n, .c-cyan .n { text-shadow: none; }
.c-red    { background: linear-gradient(160deg, #f16d55, #d3402f); }

/* Kartenrücken */
.card .back {
  background:
    radial-gradient(circle at 50% 50%, transparent 0 calc(var(--cw) * .13), rgba(255, 214, 90, .95) calc(var(--cw) * .135) calc(var(--cw) * .18), transparent calc(var(--cw) * .185)),
    repeating-linear-gradient(135deg, #3d3da3 0 calc(var(--cw) * .09), #30308a calc(var(--cw) * .09) calc(var(--cw) * .18));
}

.card.gone { pointer-events: none; }
.card.gone .inner { opacity: 0; }
.card.gone::before {
  content: ""; position: absolute; inset: 0; border-radius: calc(var(--cw) * .15);
  border: 2px dashed var(--line); opacity: .8;
}

.card.can { cursor: pointer; }
@media (hover: hover) { .card.can:hover { transform: translateY(-3px); } }
.card.can .face { box-shadow: 0 0 0 3px var(--accent), 0 6px 14px rgba(0, 0, 0, .3); }
.card.pulse .face { animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent), 0 0 0 3px rgba(0, 0, 0, 0); }
  50%      { box-shadow: 0 0 0 3px var(--accent), 0 0 0 9px color-mix(in srgb, var(--accent) 25%, transparent); }
}
.card.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(.82); } 60% { transform: scale(1.09); } 100% { transform: scale(1); } }

/* ---------- Log, Toast, Netz ---------- */
.log { margin: 6px 2px 0; height: 34px; font-size: 12px; line-height: 16px; color: var(--muted); display: grid; align-content: start; gap: 2px; }
.log div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log div:last-child { color: var(--text); }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 70;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; max-width: 90vw;
  background: #22252e; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.net { position: sticky; top: 0; z-index: 5; margin: -10px -14px 8px; padding: 6px; text-align: center; font-size: 13px; background: #d4402f; color: #fff; }

/* ---------- Regeln ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 0;
  background: var(--panel); color: var(--text); width: min(520px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.rules-in { padding: 18px 20px 20px; display: grid; gap: 12px; }
.rules-in h2 { font-size: 20px; }
.rules-in ul { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; font-size: 14.5px; }

/* ---------- Sieger ---------- */
.victory {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(6, 8, 14, .6); backdrop-filter: blur(3px); animation: vfade .3s ease;
}
@keyframes vfade { from { opacity: 0; } to { opacity: 1; } }
.vcard {
  width: min(420px, 100%); max-height: calc(100% - 8px); overflow: auto;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 20px;
  padding: 20px 20px 18px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5); animation: vpop .55s cubic-bezier(.2, 1.3, .3, 1);
}
@keyframes vpop { from { transform: scale(.6) translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.crown { animation: crown 1.6s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes crown { 0%, 100% { transform: rotate(-4deg) translateY(0); } 50% { transform: rotate(4deg) translateY(-6px); } }
.vcard h2 { font-size: 24px; }
.vsub { margin: 0; color: var(--muted); font-size: 14px; }
.standings { width: 100%; border-collapse: collapse; margin: 4px 0; font-variant-numeric: tabular-nums; font-size: 15px; }
.standings th { font-size: 12px; font-weight: 600; color: var(--muted); padding: 2px 8px; text-align: right; }
.standings td { padding: 7px 8px; border-top: 1px solid var(--line); text-align: right; }
.standings th:nth-child(2), .standings td:nth-child(2) { text-align: left; }
.standings td:first-child { color: var(--muted); width: 2.5em; text-align: left; }
.standings tr.first td { font-weight: 800; color: var(--accent); }
.vbtns { align-self: stretch; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 4px; }
.vbtns .btn { flex: 1 1 150px; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

@media (prefers-reduced-motion: reduce) {
  .card .inner, .card, .btn { transition: none; }
  .card.pulse .face, .card.pop, .crown, .victory, .vcard { animation: none; }
}
