:root {
  --bg: #141a33; --bg2: #1d2547; --panel: #232c55; --line: #34407a; --text: #eef1ff; --muted: #9aa4d6;
  --accent: #ffb547; --accent2: #7c6cff; --ok: #3ad1a4; --warn: #ff6b8b;
  --card-w: min(19vw, 84px, 8vh); --mini-w: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% -10%, #2b3570 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Kopfzeile ---------- */
header {
  display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  background: rgba(10, 14, 32, .55); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; color: var(--text); text-decoration: none; letter-spacing: .3px; }
.logo-card {
  display: grid; place-items: center; width: 24px; height: 34px; border-radius: 5px; font-size: 12px; font-weight: 900;
  background: linear-gradient(150deg, var(--accent), #ff7a59); color: #2a1600; transform: rotate(-8deg);
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.top-room { flex: 1; text-align: center; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-room b { color: var(--text); letter-spacing: 2px; }
.top-btns { display: flex; gap: 6px; }
.icon-btn {
  position: relative; min-width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); font-size: 17px; padding: 0 8px;
}
.icon-btn:active { transform: scale(.95); }
.badge { position: absolute; top: -4px; right: -4px; background: var(--warn); color: #fff; font-size: 11px; border-radius: 9px; padding: 1px 5px; font-weight: 700; }

main { max-width: 1100px; margin: 0 auto; padding: 14px 12px calc(20px + var(--safe-b)); }

/* ---------- Allgemein ---------- */
.panel { background: rgba(35, 44, 85, .8); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 14px; }
h1 { font-size: 28px; margin: 6px 0 4px; }
h2 { font-size: 19px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px;
  padding: 12px 18px; font-weight: 700; background: var(--panel); border: 1px solid var(--line);
}
.btn.primary { background: linear-gradient(135deg, var(--accent), #ff8a4c); color: #2a1600; border: 0; box-shadow: 0 4px 14px rgba(255,150,60,.25); }
.btn.violet { background: linear-gradient(135deg, var(--accent2), #4f8cff); border: 0; color: #fff; }
.btn.danger { background: transparent; border-color: var(--warn); color: var(--warn); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:not(:disabled):active { transform: scale(.98); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
input[type=text], select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); outline: none;
}
input[type=text]:focus { border-color: var(--accent2); }
.code-input { text-transform: uppercase; letter-spacing: 6px; font-weight: 800; text-align: center; }
label.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
label.check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent2); flex: none; }

/* ---------- Startseite ---------- */
.hero { text-align: center; padding: 18px 8px 8px; }
.hero-cards { display: flex; justify-content: center; gap: 6px; margin: 4px 0 14px; }
.hero-cards .card { --w: 46px; }
.hero-cards .card:nth-child(1) { transform: rotate(-12deg) translateY(6px); }
.hero-cards .card:nth-child(2) { transform: rotate(-4deg); }
.hero-cards .card:nth-child(3) { transform: rotate(4deg); }
.hero-cards .card:nth-child(4) { transform: rotate(12deg) translateY(6px); }
.home-grid { display: grid; gap: 14px; grid-template-columns: 1fr; max-width: 520px; margin: 0 auto; }
.or { text-align: center; color: var(--muted); margin: 12px 0; font-size: 14px; }

/* ---------- Lobby ---------- */
.lobby { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 820px) { .lobby { grid-template-columns: 1.2fr 1fr; } }
.code-big { font-size: 42px; font-weight: 900; letter-spacing: 10px; text-align: center; margin: 4px 0; color: var(--accent); }
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid rgba(255,255,255,.06); }
.plist li:last-child { border: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #10142a; flex: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.off { background: #59607f; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--bg2); color: var(--muted); border: 1px solid var(--line); }
.tag.host { color: var(--accent); border-color: rgba(255,181,71,.5); }
.x-btn { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 18px; padding: 4px 8px; }

/* ---------- Karten ---------- */
.card {
  --w: var(--card-w);
  width: var(--w); height: calc(var(--w) * 1.42); border-radius: calc(var(--w) * .12); position: relative;
  display: grid; place-items: center; font-weight: 900; font-size: calc(var(--w) * .46); user-select: none;
  box-shadow: 0 2px 6px rgba(0,0,0,.35), inset 0 0 0 1px rgba(255,255,255,.18);
  transition: transform .15s, box-shadow .15s; flex: none;
}
.card .corner { position: absolute; font-size: calc(var(--w) * .17); top: 5%; left: 9%; opacity: .8; }
.card .corner.br { top: auto; left: auto; bottom: 5%; right: 9%; transform: rotate(180deg); }
.card .num { text-shadow: 0 1px 0 rgba(255,255,255,.25); position: relative; }
.card.face::before {
  content: ""; position: absolute; inset: 9%; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.35), rgba(255,255,255,0) 70%);
}
/* Farben nach Wert */
.c-n2 { background: linear-gradient(155deg, #ffe08a, #e9a417); color: #4a2a00; }
.c-n1 { background: linear-gradient(155deg, #ffeab5, #f0bd43); color: #4a2a00; }
.c-0  { background: linear-gradient(155deg, #ffffff, #c9d0e6); color: #2b3155; }
.c-1, .c-2 { background: linear-gradient(155deg, #a8f5df, #3fcfa8); color: #073a2d; }
.c-3, .c-4 { background: linear-gradient(155deg, #8be8e6, #22a9b8); color: #05323a; }
.c-5, .c-6 { background: linear-gradient(155deg, #9ec4ff, #4c7cf0); color: #0b1d4d; }
.c-7, .c-8 { background: linear-gradient(155deg, #c3b0ff, #7a5cf0); color: #1e0f55; }
.c-9, .c-10 { background: linear-gradient(155deg, #f7a8ef, #c94fd0); color: #43063f; }
.c-11, .c-12 { background: linear-gradient(155deg, #ff9fbf, #e33a74); color: #4b0520; }
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.05) 0 6px, transparent 6px 12px),
    linear-gradient(155deg, #3a2f8f, #1b2160);
  color: rgba(255,255,255,.55);
}
.card.back .num { font-size: calc(var(--w) * .3); border: 2px solid rgba(255,255,255,.35); border-radius: 50%; width: 1.7em; height: 1.7em; display: grid; place-items: center; text-shadow: none; }
.card.gone { background: transparent; box-shadow: inset 0 0 0 2px rgba(255,255,255,.08); }
.card.empty { background: rgba(255,255,255,.04); box-shadow: inset 0 0 0 2px dashed rgba(255,255,255,.1); }
.card.pick { cursor: pointer; box-shadow: 0 0 0 3px var(--accent), 0 6px 16px rgba(255,181,71,.35); }
.card.pick:hover { transform: translateY(-3px); }
.card.pick:active { transform: scale(.96); }
.card.flip-in { animation: flipIn .45s ease; }
.card.pop { animation: pop .45s ease; }
.card.vanish { animation: vanish .7s ease forwards; }
@keyframes flipIn { 0% { transform: rotateY(90deg) scale(1.05); } 100% { transform: rotateY(0); } }
@keyframes pop { 0% { transform: scale(1.25); filter: brightness(1.4); } 100% { transform: scale(1); } }
@keyframes vanish { 0% { transform: scale(1); } 40% { transform: scale(1.15); filter: brightness(1.6); } 100% { transform: scale(.2); opacity: 0; } }

.mini .card { --w: var(--mini-w); font-size: calc(var(--w) * .5); border-radius: 4px; }
.mini .card .corner, .mini .card.face::before { display: none; }
.mini .card.back .num { display: none; }

/* ---------- Spieltisch ---------- */
.table { display: flex; flex-direction: column; gap: 12px; }
.banner { text-align: center; padding: 10px 14px; border-radius: 12px; background: rgba(124,108,255,.18); border: 1px solid rgba(124,108,255,.45); font-weight: 600; }
.banner.final { background: rgba(255,107,139,.15); border-color: rgba(255,107,139,.55); }
.banner .btn { padding: 6px 12px; margin-left: 8px; font-size: 14px; }
.opps { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 8px; scroll-snap-type: x proximity; }
.opps.wrap { flex-wrap: wrap; justify-content: center; overflow: visible; }
.opp {
  flex: none; scroll-snap-align: start; background: rgba(29,37,71,.85); border: 1px solid var(--line); border-radius: 14px;
  padding: 8px 9px; min-width: 112px; transition: border-color .2s, box-shadow .2s;
}
.opp.turn { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,181,71,.35); }
.opp-head { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; margin-bottom: 6px; max-width: 150px; }
.opp-head .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; gap: 8px; }
.grid { display: grid; grid-template-columns: repeat(4, auto); gap: 4px; justify-content: center; }
.mine .grid { gap: min(2.2vw, 10px); }
.center { display: flex; justify-content: center; align-items: flex-end; gap: min(5vw, 28px); padding: 4px 0; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.pile .card { --w: min(15vw, 66px, 7.2vh); }
.holding .card { --w: min(17vw, 76px, 8.4vh); animation: pop .35s ease; box-shadow: 0 0 0 3px #fff, 0 10px 26px rgba(0,0,0,.5); }
.holding { color: var(--text); font-weight: 700; }
.mine { background: rgba(29,37,71,.6); border: 1px solid var(--line); border-radius: 18px; padding: 12px 10px 10px; }
.mine.turn { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,181,71,.3); }
.mine-head { display: flex; justify-content: space-between; align-items: center; margin: 0 4px 10px; font-weight: 700; }
.hint { text-align: center; font-weight: 600; min-height: 1.4em; margin: 2px 0; }
.hint.go { color: var(--accent); }
.actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.lastmove { text-align: center; font-size: 13px; color: var(--muted); min-height: 1.3em; }
@media (min-width: 820px) {
  :root { --mini-w: 28px; --card-w: min(86px, 9vh); }
  .opps { flex-wrap: wrap; justify-content: center; overflow: visible; }
}

/* ---------- Punkte-Tabelle ---------- */
table.scores { width: 100%; border-collapse: collapse; font-size: 15px; }
table.scores th, table.scores td { padding: 7px 6px; text-align: right; border-bottom: 1px solid rgba(255,255,255,.07); }
table.scores th:first-child, table.scores td:first-child { text-align: left; }
table.scores tr.win td { color: var(--accent); font-weight: 800; }
.dbl { color: var(--warn); font-weight: 800; }
.scroll-x { overflow-x: auto; }

/* ---------- Modal / Chat / Toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(5,8,20,.6); z-index: 50; display: grid; place-items: center; padding: 16px; backdrop-filter: blur(3px); }
.modal-box { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 20px; width: min(560px, 100%); max-height: 86vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.modal-box h2 { display: flex; justify-content: space-between; align-items: center; }
.modal-box ul { padding-left: 20px; }
.modal-box li { margin: 4px 0; }
.menu-list { display: grid; gap: 8px; }
.chat {
  position: fixed; right: 12px; bottom: calc(12px + var(--safe-b)); width: min(360px, calc(100vw - 24px)); height: min(460px, 70vh);
  background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; z-index: 40; display: flex; flex-direction: column;
  box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--line); }
.chat-list { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.msg { font-size: 14px; word-wrap: break-word; }
.msg b { color: var(--accent); }
.msg.sys { color: var(--muted); font-style: italic; font-size: 13px; }
.msg.me b { color: var(--ok); }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); outline: none; min-width: 0; }
.chat-form button { border: 0; border-radius: 10px; padding: 0 14px; background: var(--accent2); color: #fff; font-weight: 700; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: #0d1124; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; max-width: 90vw; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: pop .3s ease;
}
.toast.err { border-color: var(--warn); }
.confetti { font-size: 46px; text-align: center; animation: pop .6s ease; }

/* Hilfsklassen (keine Inline-Styles wegen CSP) */
.tc { text-align: center; } .mt0 { margin-top: 0; } .mt6 { margin-top: 6px; } .mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt40 { margin-top: 40px; }
.sp12 { height: 12px; } .sp14 { height: 14px; }
.narrow { max-width: 480px; margin: 10px auto; }
.auto-w { width: auto !important; }
.modal-box h2.center-h { justify-content: center; text-align: center; }
.av0 { background: #ffb547; } .av1 { background: #7c9cff; } .av2 { background: #3ad1a4; } .av3 { background: #ff7eb6; }
.av4 { background: #c79bff; } .av5 { background: #5fd3f3; } .av6 { background: #ffd36b; } .av7 { background: #9be27a; }
