:root {
  --bg: #1f1a3d;
  --bg-2: #2c2555;
  --ink: #fff8ec;
  --muted: #b9b2d8;
  --gold: #ffc43d;
  --gold-dark: #e8a200;
  --red: #ff5a5f;
  --green: #3ddc97;
  --blue: #5ec8ff;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% -20%, #3d3475 0%, transparent 60%), var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus:not(:focus-visible) { outline: none; }

.screen { display: none; height: 100dvh; position: relative; overflow: hidden; }
.screen.active { display: flex; flex-direction: column; }

/* ---------- Dobble-Karte ---------- */
.dcard {
  --d: 300px;
  position: relative; width: var(--d); height: var(--d); flex: none;
  border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 calc(var(--d) * .018) #fff, 0 0 0 calc(var(--d) * .035) var(--gold), 0 14px 30px rgba(0,0,0,.35);
  transition: transform .25s ease;
}
.dcard.enter { animation: enter .28s cubic-bezier(.3,1.4,.5,1); }
@keyframes enter { from { transform: scale(.6) rotate(-25deg); opacity: .2; } }
.sym {
  position: absolute; border-radius: 50%; overflow: hidden; padding: 0;
  background: #fff; transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1px rgba(0,0,0,.06);
  transition: box-shadow .15s, transform .15s;
}
.sym img {
  width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%;
  display: block; pointer-events: none; transform: rotate(var(--rot, 0deg)) scale(1.02);
}
.sym:active { transform: translate(-50%, -50%) scale(.94); }
.sym.hit { box-shadow: 0 0 0 5px var(--green), 0 0 24px var(--green); z-index: 2; }
.sym.miss { box-shadow: 0 0 0 5px var(--red); animation: shake .35s; }
@keyframes shake {
  25% { transform: translate(calc(-50% + 5px), -50%); }
  75% { transform: translate(calc(-50% - 5px), -50%); }
}
.dcard.locked { filter: grayscale(.8) brightness(.8); }

/* ---------- Start ---------- */
#start { overflow-y: auto; }
.start-inner {
  width: 100%; max-width: 440px; margin: auto;
  padding: calc(20px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  text-align: center;
}
.logo-card { --d: 190px; margin: 14px auto 18px; animation: spin 40s linear infinite; }
.logo-card .sym { pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }
h1 { font-size: 52px; margin: 6px 0 0; letter-spacing: -1px; line-height: 1; color: var(--gold); text-shadow: 0 4px 0 #b36b00; }
.sub { color: var(--muted); margin: 12px 0 22px; line-height: 1.45; }
.sub b { color: var(--ink); }

.modes { display: grid; gap: 12px; }
.mode {
  display: grid; text-align: left; gap: 2px; padding: 16px 18px; border-radius: 20px;
  background: var(--gold); color: #3a2400; box-shadow: 0 5px 0 var(--gold-dark);
  transition: transform .08s, box-shadow .08s;
}
.mode + .mode { background: var(--blue); color: #06263a; box-shadow: 0 5px 0 #2a8fc4; }
.mode:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--gold-dark); }
.mode-title { font-size: 22px; font-weight: 900; }
.mode-text { font-size: 14px; opacity: .8; }
.mode-best { font-size: 13px; font-weight: 800; }
.mode-best:empty { display: none; }

.toggle { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 22px 0 6px; color: var(--muted); cursor: pointer; }
.toggle input { position: absolute; opacity: 0; }
.switch { width: 44px; height: 26px; border-radius: 13px; background: rgba(255,255,255,.15); position: relative; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + .switch { background: var(--green); }
.toggle input:checked + .switch::after { transform: translateX(18px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--gold); outline-offset: 2px; }

.rules { text-align: left; background: var(--bg-2); border-radius: 16px; padding: 12px 16px; margin-top: 14px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.rules summary { cursor: pointer; font-weight: 800; color: var(--ink); }
.rules b { color: var(--ink); }
.link { color: var(--muted); margin-top: 14px; text-decoration: underline; text-underline-offset: 3px; padding: 8px; }

.primary {
  width: 100%; height: 56px; border-radius: 18px; background: var(--gold); color: #3a2400;
  font-size: 20px; font-weight: 800; box-shadow: 0 5px 0 var(--gold-dark);
}
.primary:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--gold-dark); }
.secondary { width: 100%; height: 50px; border-radius: 16px; background: rgba(255,255,255,.1); font-size: 17px; font-weight: 700; }

/* ---------- Leiste ---------- */
.bar { display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-top)) 10px 8px; flex: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: rgba(255,255,255,.08); flex: none; }
.icon-btn.ghost { visibility: hidden; }
.status { flex: 1; display: flex; justify-content: center; gap: 8px; font-size: 16px; }
.stat { background: rgba(255,255,255,.08); border-radius: 12px; padding: 6px 14px; white-space: nowrap; }
.stat b { color: var(--gold); font-variant-numeric: tabular-nums; }

/* ---------- Solo ---------- */
.timebar { height: 6px; margin: 0 16px; background: rgba(255,255,255,.08); border-radius: 3px; overflow: hidden; flex: none; }
.timebar div { height: 100%; width: 100%; background: var(--gold); transform-origin: left; }
.timebar div.low { background: var(--red); }
.solo-area {
  flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly;
  padding: 8px 16px calc(12px + var(--safe-bottom));
  --d: min(82vw, calc((100dvh - 250px - var(--safe-top) - var(--safe-bottom)) / 2), 420px);
}
@media (orientation: landscape) {
  .solo-area { flex-direction: row; --d: min(44vw, calc(100dvh - 150px - var(--safe-top) - var(--safe-bottom)), 480px); }
}
.solo-area .dcard { --d: inherit; }
.card-slot { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.slot-label { color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }

/* ---------- Duell ---------- */
#duell { justify-content: space-between; --d: min(82vw, calc((100dvh - 200px - var(--safe-top) - var(--safe-bottom)) / 3), 380px); }
#duell .dcard { --d: inherit; }
.duel-half { display: flex; align-items: center; justify-content: center; gap: 10px; flex-direction: column; flex: 1; min-height: 0; }
.duel-half.top { transform: rotate(180deg); padding-bottom: calc(6px + var(--safe-top)); }
.duel-half.bottom { padding-bottom: calc(6px + var(--safe-bottom)); }
.duel-info { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.duel-info b { background: var(--gold); color: #3a2400; min-width: 36px; height: 30px; border-radius: 15px; display: grid; place-items: center; padding: 0 10px; font-variant-numeric: tabular-nums; }
.top .duel-info b { background: var(--blue); color: #06263a; }
.duel-mid { display: flex; align-items: center; justify-content: center; position: relative; flex: none; }
.duel-mid .icon-btn { position: absolute; left: 12px; }
.pile-count { position: absolute; right: 14px; display: grid; text-align: center; color: var(--muted); font-size: 12px; }
.pile-count b { color: var(--ink); font-size: 22px; }
.duel-half.win .dcard { box-shadow: 0 0 0 calc(var(--d) * .018) #fff, 0 0 0 calc(var(--d) * .035) var(--green), 0 0 40px var(--green); }

@media (orientation: landscape) {
  #duell { flex-direction: row; --d: min(31vw, calc(100dvh - 90px), 420px); }
  .duel-half.top { transform: rotate(180deg); padding: 0; }
  .duel-mid { flex-direction: column; }
  .duel-mid .icon-btn { left: auto; top: calc(-60px); }
}

/* ---------- Countdown ---------- */
.countdown {
  position: absolute; inset: 0; display: none; place-items: center; z-index: 20;
  background: rgba(15,12,35,.6); backdrop-filter: blur(3px);
  font-size: 120px; font-weight: 900; color: var(--gold); text-shadow: 0 6px 0 #b36b00;
}
.countdown.on { display: grid; }
.countdown span { animation: pulse .9s ease-out; }
@keyframes pulse { from { transform: scale(1.8); opacity: 0; } 40% { opacity: 1; } }

/* ---------- Galerie ---------- */
.gallery-grid {
  flex: 1; overflow-y: auto; display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  padding: 6px 16px calc(20px + var(--safe-bottom));
}
.gallery-grid figure { margin: 0; background: #fff; border-radius: 50%; overflow: hidden; position: relative; aspect-ratio: 1; }
.gallery-grid img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; display: block; }
.gallery-grid figcaption {
  position: absolute; inset: auto 0 0 0; padding: 10px 4px 12px; text-align: center;
  background: linear-gradient(transparent, rgba(0,0,0,.72)); color: #fff; font-size: 12px; font-weight: 800;
}

/* ---------- Ergebnis ---------- */
dialog { border: 0; border-radius: 26px; padding: 0; background: var(--bg-2); color: var(--ink); width: min(92vw, 380px); box-shadow: 0 30px 80px rgba(0,0,0,.5); }
dialog::backdrop { background: rgba(10,8,25,.7); backdrop-filter: blur(4px); }
dialog[open] { animation: rise .35s cubic-bezier(.3,1.4,.5,1); }
@keyframes rise { from { transform: translateY(30px) scale(.94); opacity: 0; } }
.result-inner { padding: 26px 20px 20px; text-align: center; }
#resultTitle { font-size: 30px; margin: 0 0 10px; color: var(--gold); }
#resultBody { color: var(--muted); margin-bottom: 20px; line-height: 1.5; }
#resultBody .big { font-size: 64px; font-weight: 900; color: var(--ink); line-height: 1.1; }
#resultBody .rec { color: var(--green); font-weight: 800; }
.result-actions { display: grid; gap: 10px; }

.confetti { position: fixed; top: -12px; width: 10px; height: 14px; z-index: 50; pointer-events: none; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  .logo-card, .dcard.enter, .sym.miss, dialog[open], .countdown span { animation: none; }
}

/* ---------- Online ---------- */
.mode.online { background: var(--green); color: #053322; box-shadow: 0 5px 0 #20a36c; }
.form-wrap { width: 100%; max-width: 420px; margin: 0 auto; padding: 12px 16px calc(24px + var(--safe-bottom)); display: grid; gap: 14px; overflow-y: auto; }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.field input {
  height: 52px; border-radius: 14px; border: 2px solid transparent; background: rgba(255,255,255,.08);
  color: var(--ink); padding: 0 16px; font: inherit; font-size: 18px; outline: none; text-transform: none; letter-spacing: 0;
  -webkit-user-select: text; user-select: text;
}
.field input:focus { border-color: var(--gold); }
.code-input { text-transform: uppercase !important; letter-spacing: .4em !important; font-weight: 900; text-align: center; font-size: 26px !important; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: rgba(255,255,255,.12); }
.error { color: var(--red); font-weight: 700; margin: 0; min-height: 1.3em; text-align: center; }
.lobby-hint { color: var(--muted); text-align: center; margin: 0; }
.lobby-code { font-size: 64px; font-weight: 900; letter-spacing: .15em; text-align: center; color: var(--gold); text-shadow: 0 4px 0 #b36b00; line-height: 1; margin: -4px 0 4px; }
.list-head { font-size: 13px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 8px 0 -4px; }
.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.player-list li { display: flex; align-items: center; gap: 10px; background: var(--bg-2); border-radius: 14px; padding: 12px 14px; font-weight: 700; }
.player-list .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.player-list .tag { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 700; }
.player-list .off { opacity: .45; }

.scores { flex: 1; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; padding: 4px 2px; }
.scores::-webkit-scrollbar { display: none; }
.score-chip {
  display: flex; align-items: center; gap: 6px; flex: none; padding: 5px 10px 5px 8px; border-radius: 12px;
  background: rgba(255,255,255,.07); font-size: 14px; font-weight: 700; max-width: 140px; transition: transform .2s, background .2s;
}
.score-chip .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-chip b { font-variant-numeric: tabular-nums; }
.score-chip .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.score-chip.me { box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
.score-chip.pop { transform: scale(1.12); background: color-mix(in srgb, var(--pc) 35%, transparent); }
.score-chip.off { opacity: .4; }
.stat.small { padding: 6px 10px; font-size: 14px; flex: none; }

.flash {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.8); z-index: 15;
  display: flex; align-items: center; gap: 12px; padding: 10px 20px 10px 10px; border-radius: 999px;
  background: var(--bg-2); box-shadow: 0 0 0 3px var(--pc, var(--gold)), 0 20px 50px rgba(0,0,0,.5);
  font-size: 20px; font-weight: 900; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .15s, transform .2s;
}
.flash.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.flash img { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; object-position: 50% 30%; background: #fff; }
.offline {
  position: absolute; left: 50%; bottom: calc(16px + var(--safe-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--red); color: #fff; font-weight: 800; padding: 10px 16px; border-radius: 12px; display: none; white-space: nowrap;
}
.offline.on { display: block; }
.ranking { display: grid; gap: 6px; margin-bottom: 8px; }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(255,255,255,.05); color: var(--ink); text-align: left; }
.rank-row .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.rank-row.win { background: color-mix(in srgb, var(--gold) 20%, transparent); color: var(--gold); font-weight: 800; }
