/* UNO Online – Oberfläche. Hell/Dunkel nach Systemeinstellung, mobil zuerst. */

:root {
  color-scheme: light dark;
  --bg: #f3efe7;
  --surface: #ffffff;
  --surface-2: #ece6da;
  --text: #1f1d1a;
  --muted: #6a645b;
  --border: #d9d1c3;
  --accent: #d32f2f;
  --accent-text: #ffffff;
  --ok: #2e7d32;
  --warn: #b26a00;
  --danger: #c62828;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.15);

  --red: #d32f2f;
  --yellow: #f9a825;
  --green: #2e7d32;
  --blue: #1565c0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1f2228;
    --surface-2: #2a2e36;
    --text: #f0ede6;
    --muted: #a39d92;
    --border: #3a3f49;
    --accent: #ef5350;
    --accent-text: #1a0a0a;
    --ok: #66bb6a;
    --warn: #ffb74d;
    --danger: #ef7070;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.6);

    --red: #e53935;
    --yellow: #fbc02d;
    --green: #43a047;
    --blue: #1e88e5;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-text-size-adjust: 100%;
  min-height: 100dvh;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- Bausteine ---------- */

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

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  min-height: 44px;
}
.btn:hover:not(:disabled) { filter: brightness(1.05); }
.btn:disabled { opacity: 0.5; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 0.85rem; }
.btn.block { width: 100%; }

.field {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.grow > * { flex: 1; }
/* minmax(0, 1fr): Inhalt (z. B. die Handkarten) darf die Spalte nicht aufweiten */
.stack { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }

.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: var(--warn); color: #fff; text-align: center; padding: 8px; font-weight: 600;
}
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: min(92vw, 460px); z-index: 60;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); text-align: center;
}
[hidden] { display: none !important; }

/* ---------- Startseite ---------- */

.start { max-width: 640px; margin: 0 auto; }
.logo {
  text-align: center; font-size: 2.4rem; font-weight: 900; letter-spacing: 2px;
  margin: 8px 0 16px; color: var(--accent);
}
.logo small { display: block; font-size: 0.9rem; letter-spacing: 0; color: var(--muted); font-weight: 500; }

.avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.avatar-btn {
  aspect-ratio: 1; font-size: 1.8rem; line-height: 1; border-radius: 12px;
  border: 2px solid var(--border); background: var(--bg);
}
.avatar-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--surface-2); box-shadow: 0 0 0 2px var(--accent) inset; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--bg); padding: 8px 14px; min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 700; }

.room-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.room-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.room-item .info { flex: 1; min-width: 0; }
.room-item .info b, .room-item .info span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.code-input { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 700; }

/* ---------- Raum ---------- */

/* Im Raum füllt die Seite genau das Fenster und scrollt nicht: Kopfzeile, Status, Tisch (füllt den Rest), Hand */
body.in-room { height: 100dvh; overflow: hidden; }
.page.room {
  height: 100dvh; display: flex; flex-direction: column; gap: 8px; overflow: hidden;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.page.room > * { flex: 0 0 auto; min-width: 0; }
.page.room > .arena, .page.room > .room-body { flex: 1 1 0; min-height: 0; }
.room-body { overflow-y: auto; align-content: start; }

.topbar { display: flex; align-items: center; gap: 6px; }
.topbar .lbl { display: none; }
@media (min-width: 560px) { .topbar .lbl { display: inline; } .topbar { gap: 8px; } }
.topbar .code {
  font-weight: 800; letter-spacing: 3px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 12px;
}
.topbar .spacer { flex: 1; }
@media (max-width: 480px) { .topbar .me { display: none; } }

.status {
  padding: 6px 12px; border-radius: 12px; font-weight: 700; text-align: center; font-size: 0.95rem;
  background: var(--surface); border: 1px solid var(--border);
}
.status.mine { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.status.info { background: var(--surface-2); font-weight: 600; }

/* Mitspieler sitzen im Kreis um den Tisch (Position kommt als left/top in % aus app.js) */
.pchip {
  position: absolute; transform: translate(-50%, -50%); z-index: 1;
  display: grid; justify-items: center; gap: 1px; width: 80px;
  padding: 6px 4px 5px; border-radius: 12px; background: var(--surface); border: 2px solid var(--border);
}
@media (min-width: 520px) { .pchip { width: 100px; padding: 8px 6px 6px; } }
.pchip.turn { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.pchip.offline { opacity: 0.7; border-style: dashed; }
.pchip .av { font-size: 1.9rem; line-height: 1.1; }
.pchip .nm { font-weight: 700; font-size: 0.85rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Verdeckte Karten des Mitspielers: eine pro Handkarte, bei vielen Karten überlappend (passt immer ins Feld) */
.mini-hand {
  --cw: 14px; --avail: 66px; /* Kartenbreite und verfügbare Breite im Feld */
  display: flex; justify-content: center; align-items: center; width: 100%; height: 24px; margin-top: 2px;
}
@media (min-width: 520px) { .mini-hand { --cw: 16px; --avail: 86px; } }
.mini-card {
  flex: none; width: var(--cw); height: calc(var(--cw) * 1.5); border-radius: 3px;
  border: 1.5px solid #fff; background: radial-gradient(ellipse at center, var(--red) 0 34%, #1b1b1f 36%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
/* Abstand: höchstens 2 px Lücke; bei vielen Karten negativ, sodass alle genau in --avail passen */
.mini-card + .mini-card { margin-left: min(2px, calc((var(--avail) - var(--n) * var(--cw)) / (var(--n) - 1))); }
.pchip .tag {
  font-size: 0.7rem; font-weight: 800; padding: 1px 6px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
}
.pchip .tag.dc { background: var(--warn); color: #fff; }
.pchip .tag.spec { background: var(--muted); color: var(--surface); }

/* Höhe richtet sich nach dem Fenster, damit Tisch und Hand zusammen auf den Bildschirm passen */
.arena {
  position: relative; overflow: hidden; /* Höhe: füllt den Rest des Fensters (flex in .page.room) */
  border-radius: 16px; background: color-mix(in srgb, var(--green) 22%, var(--surface));
  border: 1px solid var(--border);
}
.arena-center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(48%, 320px); display: grid; justify-items: center; gap: 8px;
}
.arena .piles { gap: 12px; }
.arena .card.big { --w: 62px; }
@media (min-width: 520px) and (min-height: 820px) { .arena .piles { gap: 18px; } .arena .card.big { --w: 84px; } }
@media (min-width: 520px) and (max-height: 819px) { .arena .piles { gap: 16px; } .arena .card.big { --w: 70px; } }
@media (min-width: 520px) { .arena-center { width: min(60%, 380px); } } /* Badges passen dann in eine Zeile */
@media (max-height: 700px) { .arena .card.big { --w: 56px; } .arena .piles { gap: 14px; } }
.arena .badge { font-size: 0.8rem; padding: 3px 8px; }
.arena .timer { width: 100%; }
@media (max-height: 819px) { .arena .last { display: none; } } /* steht ohnehin im Verlauf */
.dir-text { display: none; }
@media (min-width: 520px) { .dir-text { display: inline; } }
.piles { display: flex; align-items: center; justify-content: center; gap: 18px; flex-wrap: wrap; }
.pile { display: grid; justify-items: center; gap: 4px; }
.pile .label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.discard-ring {
  border-radius: 14px; padding: 5px; background: var(--ring, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ring, transparent) 50%, #000 0%);
}
.badges { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-weight: 700; font-size: 0.9rem;
}
.badge.pending { background: var(--danger); color: #fff; border-color: transparent; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; background: var(--c, #888); border: 1px solid rgba(0, 0, 0, 0.3); }
.dot.red { --c: var(--red); } .dot.yellow { --c: var(--yellow); } .dot.green { --c: var(--green); } .dot.blue { --c: var(--blue); }

.last { font-size: 0.9rem; min-height: 1.3em; text-align: center; }

.timer {
  position: relative; width: min(100%, 360px); height: 22px; border-radius: 999px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
}
.timer .fill { position: absolute; inset: 0 auto 0 0; width: 100%; background: var(--ok); transition: width 0.25s linear, background 0.3s; }
.timer.low .fill { background: var(--danger); }
.timer .txt { position: relative; display: block; text-align: center; font-size: 0.8rem; font-weight: 800; line-height: 20px; color: var(--text); mix-blend-mode: normal; }

.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; min-height: 0; }
.uno-btn {
  background: var(--red); color: #fff; border: 3px solid #fff; border-radius: 999px;
  font-weight: 900; font-size: 1.15rem; letter-spacing: 1px; padding: 4px 24px; min-height: 44px;
  box-shadow: var(--shadow);
}
.uno-btn.urgent { animation: pulse 0.8s ease-in-out infinite; }
.catch-btn { background: var(--yellow); color: #1a1400; border: 2px solid #1a1400; font-weight: 800; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* ---------- Karten ---------- */

.card {
  --w: 64px;
  position: relative; flex: 0 0 auto;
  width: var(--w); height: calc(var(--w) * 1.5); padding: 0;
  border-radius: 9px; border: 3px solid #fff; color: #fff;
  background: var(--cc, #444); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  display: grid; place-items: center; font-weight: 900; user-select: none; overflow: hidden;
}
.card.c-red { --cc: var(--red); }
.card.c-yellow { --cc: var(--yellow); color: #1a1400; }
.card.c-green { --cc: var(--green); }
.card.c-blue { --cc: var(--blue); }
.card.c-wild { --cc: #1b1b1f; }
.card .face {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  width: 70%; aspect-ratio: 1 / 1.25; border-radius: 50%;
  background: rgba(255, 255, 255, 0.92); color: var(--cc); transform: rotate(-12deg);
  font-size: calc(var(--w) * 0.42); line-height: 1; letter-spacing: -1px;
}
.card.c-yellow .face { color: #7a5600; }
.card .corner { position: absolute; font-size: calc(var(--w) * 0.2); line-height: 1; }
.card .corner.tl { top: 3px; left: 4px; }
.card .corner.br { bottom: 3px; right: 4px; transform: rotate(180deg); }
.card.c-wild .face { background: transparent; }
.card .quad {
  position: absolute; width: 72%; aspect-ratio: 1 / 1.25; border-radius: 50%; transform: rotate(-12deg);
  background: conic-gradient(var(--red) 0 25%, var(--blue) 0 50%, var(--green) 0 75%, var(--yellow) 0);
  border: 2px solid #fff;
}
.card.c-wild .face { position: relative; z-index: 1; color: #fff; text-shadow: 0 1px 3px #000, 0 0 2px #000; }
.card.v-skip .face, .card.v-reverse .face { font-size: calc(var(--w) * 0.5); }
.card.v-draw2 .face, .card.v-wild4 .face { font-size: calc(var(--w) * 0.36); }
.card.back { --cc: #1b1b1f; border-color: #fff; }
.card.back .face { background: var(--red); color: #fff; font-size: calc(var(--w) * 0.3); letter-spacing: 0; }
.card.big { --w: 84px; }

/* Alle Handkarten sehen gleich aus: keine Hervorhebung spielbarer Karten (kein Tipp) */
.hand.active button.card { cursor: pointer; }
.hand.active button.card:hover { transform: translateY(-10px); }
button.card.fresh { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--blue), 0 6px 10px rgba(0, 0, 0, 0.45); }
button.pile-btn { background: none; border: 0; padding: 0; }
button.pile-btn:disabled .card { opacity: 0.75; }
button.pile-btn:not(:disabled):hover .card { transform: translateY(-3px); }
button.pile-btn.ready .card { box-shadow: 0 0 0 3px var(--yellow), 0 4px 8px rgba(0, 0, 0, 0.45); }

/* Hand: alle Karten in einer Zeile; app.js setzt --gap (negativ = Überlappung), sodass alle passen */
.hand-wrap { display: grid; gap: 4px; }
.hand {
  display: flex; justify-content: safe center; overflow-x: auto; overflow-y: hidden;
  padding: 14px 8px 4px; scrollbar-width: none;
}
.hand::-webkit-scrollbar { display: none; }
.hand .card { --w: 62px; margin-left: var(--gap, -20px); }
.hand .card:first-child { margin-left: 0; }
@media (min-width: 700px) and (min-height: 700px) { .hand .card { --w: 78px; } }
@media (max-height: 640px) { .hand .card { --w: 52px; } }
.hand-wrap .actions { margin-bottom: 0; }

/* ---------- Seitenleiste ---------- */

.side { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.table-list { width: 100%; border-collapse: collapse; table-layout: fixed; }
.table-list td { padding: 6px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table-list tr:last-child td { border-bottom: 0; }
.table-list .who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.table-list .who .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.table-list .av { font-size: 1.4rem; }
.table-list .wins { text-align: right; font-weight: 800; white-space: nowrap; width: 56px; }
.table-list .act { text-align: right; width: 92px; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 260px; overflow-y: auto; font-size: 0.9rem; }
.log li { display: flex; gap: 8px; align-items: baseline; }
.log li:first-child { font-weight: 700; }

.invite { display: grid; gap: 10px; justify-items: center; text-align: center; padding: 18px 14px; }
.invite .big-code { font-size: 2.2rem; font-weight: 900; letter-spacing: 6px; }
.result { text-align: center; padding: 18px 14px; }
.result .trophy { font-size: 3rem; line-height: 1; }

/* ---------- Dialoge ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, 0.55);
}
.dialog {
  width: min(100%, 420px); max-height: 90dvh; overflow-y: auto;
  background: var(--surface); border-radius: 16px; padding: 18px; box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.color-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.color-btn {
  min-height: 72px; border-radius: 14px; border: 3px solid #fff; font-weight: 900; font-size: 1.1rem;
  color: #fff; background: var(--cc); box-shadow: var(--shadow);
}
.color-btn.yellow { color: #1a1400; }
.pick-list { display: grid; gap: 8px; margin: 12px 0; }
.pick {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--bg); text-align: left; width: 100%;
}
.pick:hover { border-color: var(--accent); }
.pick .av { font-size: 1.8rem; }
.pick .nm { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }

/* Emoji-Reaktionen */
.react-backdrop { position: fixed; inset: 0; z-index: 44; }
.react-pop {
  /* bottom setzt app.js so, dass die Auswahl direkt über den Handkarten sitzt */
  position: fixed; z-index: 45; bottom: 24px; left: 50%; transform: translateX(-50%);
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.react-toggle { font-size: 1.4rem; line-height: 1; padding: 6px 12px; }
/* Handkarten per Ziehen sortieren: Finger/Maus greift die Karte (kein Scrollen der Hand dabei) */
.hand .card { touch-action: none; transition: transform 0.14s ease; -webkit-user-drag: none; }
.hand .card.dragging {
  transition: none; z-index: 30; cursor: grabbing;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.55), 0 0 0 2px var(--accent);
}
body.dragging-card, body.dragging-card * { cursor: grabbing !important; user-select: none; }
.react-btn { font-size: 1.7rem; line-height: 1; width: 52px; height: 52px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); }
.react-btn:hover { background: var(--surface-2); }
.fx-react {
  position: fixed; transform: translate(-50%, -50%); opacity: 0; text-align: center;
  padding: 4px 12px; border-radius: 999px; background: var(--surface); border: 2px solid var(--border);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); white-space: nowrap;
}
.fx-react .emoji { font-size: 2.4rem; line-height: 1.2; }
/* UNO-Ruf: gleiche Sprechblase wie die Emojis, aber rot mit weißer Schrift */
.fx-react.uno { background: var(--red); border: 3px solid #fff; padding: 2px 16px; }
.fx-react .label { display: block; font-size: 1.8rem; font-weight: 900; letter-spacing: 1px; line-height: 1.35; color: #fff; }
.fx-react small { display: block; font-size: 0.75rem; font-weight: 700; color: var(--muted); }

.motion { margin-top: 10px; }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }

/* ---------- Animationen (eigene Ebene über der Seite) ---------- */

#fx { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.fly { position: fixed; left: 0; top: 0; will-change: transform, opacity; }
.fly .card { box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5); }
.card.hold { visibility: hidden; } /* Karte ist noch unterwegs und landet gleich */

.fx-banner {
  position: fixed; transform: translate(-50%, -50%); opacity: 0;
  padding: 10px 24px; border-radius: 999px; text-align: center; white-space: nowrap;
  font-weight: 900; font-size: 1.5rem; line-height: 1.15; color: #fff;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.fx-banner small { display: block; font-size: 0.8rem; font-weight: 700; opacity: 0.9; }
.fx-banner.turn { background: var(--accent); }
.fx-banner.uno {
  background: var(--red); color: #fff; border: 4px solid #fff; font-size: 2.6rem; letter-spacing: 2px; padding: 8px 30px;
}
.fx-banner.uno small { font-size: 1rem; }
.fx-banner.caught { background: var(--yellow); color: #1a1400; border: 4px solid #1a1400; font-size: 2.6rem; padding: 8px 30px; }
.fx-banner.caught small { font-size: 1rem; }
.fx-banner.win { background: var(--yellow); color: #1a1400; border: 4px solid #fff; font-size: 2.4rem; padding: 10px 34px; }
.confetti { position: fixed; top: 0; width: 9px; height: 14px; border-radius: 2px; will-change: transform; }
@media (max-width: 519px) {
  .fx-banner { font-size: 1.25rem; }
  .fx-banner.uno { font-size: 2.1rem; padding: 6px 22px; }
  .fx-banner.effect { font-size: 2.2rem; padding: 6px 24px; }
  .fx-banner.win { font-size: 1.7rem; padding: 8px 22px; }
  .fx-banner.caught { font-size: 2.1rem; padding: 6px 22px; }
}
.fx-banner.warn { background: #222; color: #fff; font-size: 1.2rem; }
/* +2, +4, Farbwahl: groß, in der Farbe der Karte bzw. der gewünschten Farbe */
.fx-banner.effect { font-size: 2.8rem; padding: 8px 32px; border: 4px solid #fff; background: #222; color: #fff; }
.fx-banner.effect small { font-size: 0.95rem; }
.fx-banner.col-red { background: var(--red); color: #fff; }
.fx-banner.col-green { background: var(--green); color: #fff; }
.fx-banner.col-blue { background: var(--blue); color: #fff; }
.fx-banner.col-yellow { background: var(--yellow); color: #1a1400; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
