/* 4 Gewinnt – Stil passend zur Startseite (blaue Akzente, automatisch hell/dunkel) */

:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #12162a;
  --muted: #5a6280;
  --line: #dfe3ee;
  --accent: #1f4fd8;
  --accent-ink: #ffffff;
  --bad: #d7263d;
  --good: #1f9d6b;

  --brass-a: #ecd08a;
  --brass-b: #bb8d33;
  --brass-ink: #2a1c05;

  /* Spielbrett */
  --frame-a: #2a52c4;
  --frame-b: #12235e;
  --board-a: #2f5ce0;
  --board-b: #1a3aa8;
  --hole-in: #0a1230;
  --hole-rim: rgba(255,255,255,.16);
  --slot-empty-a: #0d1740;
  --slot-empty-b: #060b22;

  --red-a: #ff9a9a;
  --red-b: #e6453d;
  --red-c: #8f1a14;
  --yellow-a: #fff3c4;
  --yellow-b: #f7c948;
  --yellow-c: #a8781a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0f16;
    --surface: #141925;
    --text: #eef0f8;
    --muted: #9aa3b8;
    --line: #232a3b;
    --accent: #7ba0ff;
    --accent-ink: #0b1020;
    --bad: #ff6b7d;
    --good: #3ecf8e;
    --brass-a: #d6b263;
    --brass-b: #9c7420;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0f16;
  --surface: #141925;
  --text: #eef0f8;
  --muted: #9aa3b8;
  --line: #232a3b;
  --accent: #7ba0ff;
  --accent-ink: #0b1020;
  --bad: #ff6b7d;
  --good: #3ecf8e;
  --brass-a: #d6b263;
  --brass-b: #9c7420;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

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

/* Kopfzeile */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 980px;
  margin: 0 auto;
  padding: 14px 16px;
}
.top-spacer { flex: 1; }
.back, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  padding: 0;
}
.back:hover, .icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.top-actions { display: flex; gap: 8px; }
#btn-sound .ic-off { display: none; }
#btn-sound[aria-pressed="true"] .ic-on { display: none; }
#btn-sound[aria-pressed="true"] .ic-off { display: block; }

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

main { max-width: 980px; margin: 0 auto; padding: 0 16px 48px; }
.screen { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hint { color: var(--muted); font-size: .92rem; }

/* Startseite */
#screen-start { max-width: 420px; margin: 0 auto; text-align: center; padding-top: 2vh; }
#screen-start .hero { display: flex; justify-content: center; align-items: center; height: 96px; margin-bottom: 2px; }
#screen-start .hero svg { filter: drop-shadow(0 8px 12px rgba(0,0,0,.22)); }
#screen-start h1 { font-size: 2.5rem; letter-spacing: -.02em; }
#screen-start .sub { margin: 4px 0 22px; color: var(--muted); }
#screen-start .card { text-align: left; }
#screen-start .hint { margin-top: 16px; }

/* Karten und Formulare */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
input[type="text"], input:not([type]), input[type="search"] {
  font: inherit; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .65em .8em;
  width: 100%;
}
input:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 0; border-color: var(--accent); }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; text-align: center; }
/* Code-Eingabe und Beitreten-Button in einer Zeile (wie bei Skyjo) */
.row:has(.code-input) { flex-wrap: nowrap; }
.row .code-input { width: auto; min-width: 0; flex: 1 1 auto; }
.row > .btn { flex: none; }

.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Buttons */
.btn {
  font: inherit; font-weight: 650;
  padding: .7em 1.2em;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform .08s, filter .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.small { padding: .35em .8em; font-size: .85rem; border-radius: 9px; }
.btn.ghost { background: transparent; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

/* Lobby */
.lobby { max-width: 520px; }
.roomcode { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.roomcode strong { font-size: 2rem; letter-spacing: .25em; 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: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
.plist li .grow { flex: 1; font-weight: 600; }
.tag { font-size: .75rem; padding: .1em .6em; border-radius: 99px; background: var(--line); color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); flex: none; }
.dot.off { background: #8b93a7; }

/* Setup: Farbe / Startspieler */
.setup { max-width: 520px; }
.choice { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.choice legend { font-size: .9rem; color: var(--muted); padding: 0; margin-bottom: 6px; width: 100%; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.swatch span {
  display: inline-flex; align-items: center; gap: 8px; padding: .6em 1.1em;
  border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); background: var(--bg); cursor: pointer; font-weight: 650;
}
.swatch span::before { content: ""; width: 16px; height: 16px; border-radius: 50%; background: var(--line); flex: none; }
.swatch.red span::before { background: radial-gradient(circle at 35% 30%, var(--red-a), var(--red-b) 60%, var(--red-c)); }
.swatch.yellow span::before { background: radial-gradient(circle at 35% 30%, var(--yellow-a), var(--yellow-b) 60%, var(--yellow-c)); }
.choice input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.choice input:disabled + span { opacity: .45; cursor: not-allowed; }
.choice input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.reveal { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 4px; }
.reveal-line { margin: 0; font-weight: 600; }

/* Spiel */
.gamebar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.gamebar .btn { margin-left: auto; }
.chip {
  display: inline-flex; gap: 6px; padding: .25em .8em;
  border: 1px solid var(--line); border-radius: 99px; background: var(--surface);
  font-size: .9rem; color: var(--muted);
}
.chip strong { color: var(--text); letter-spacing: .12em; font-variant-numeric: tabular-nums; }

.scoreboard {
  list-style: none; margin: 0 0 16px; padding: 0;
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.pl {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px 12px;
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.pl.turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
  transform: translateY(-2px);
}
.pl .name { display: flex; align-items: center; gap: 7px; font-weight: 650; min-width: 0; }
.pl .name span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl .swatchdot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.pl .swatchdot.red { background: radial-gradient(circle at 35% 30%, var(--red-a), var(--red-b) 60%, var(--red-c)); }
.pl .swatchdot.yellow { background: radial-gradient(circle at 35% 30%, var(--yellow-a), var(--yellow-b) 60%, var(--yellow-c)); }
.pl .score { font-size: 1.3rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.15; margin-top: 2px; }
.pl .meta { color: var(--muted); font-size: .82rem; display: flex; justify-content: space-between; gap: 8px; min-height: 1.3em; }
.pl .me { font-size: .7rem; padding: .05em .5em; border-radius: 99px; background: var(--accent); color: var(--accent-ink); }

/* Eigener Steine-Haufen: unter dem Raster, als Reihe überlappender Scheiben */
.mypile { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 4px; max-width: 100%; }
.mypile-label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.mypile-row {
  display: flex; flex-wrap: wrap; justify-content: center;
  max-width: 100%;
}
.pile-chip {
  --s: 28px;
  width: var(--s); height: var(--s);
  border-radius: 50%;
  margin-left: -11px;
  box-shadow: inset 0 2px 3px rgba(255,255,255,.55), inset 0 -3px 4px rgba(0,0,0,.35), 0 2px 3px rgba(0,0,0,.4);
  flex: none;
}
.mypile-row .pile-chip:first-child { margin-left: 0; }
.pile-chip.red { background: radial-gradient(circle at 35% 28%, var(--red-a), var(--red-b) 55%, var(--red-c)); }
.pile-chip.yellow { background: radial-gradient(circle at 35% 28%, var(--yellow-a), var(--yellow-b) 55%, var(--yellow-c)); }
.pile-chip.leaving { animation: chiplift .4s ease forwards; }
@keyframes chiplift { to { transform: translateY(-24px) scale(.6); opacity: 0; } }
.pile-count { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }

.board-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; }
.plate {
  padding: 8px 18px;
  border-radius: 10px;
  text-align: center;
  font-weight: 650;
  color: var(--brass-ink);
  background: linear-gradient(180deg, var(--brass-a), var(--brass-b));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 2px 5px rgba(0,0,0,.45);
  min-height: 2.4em;
  display: flex; align-items: center; justify-content: center;
  max-width: 100%;
}
.plate.bad { background: linear-gradient(180deg, #ef8a8a, #b83a3a); color: #fff; }

.board {
  --cols: 7; --rows: 6;
  --cell: clamp(34px, 8.4vw, 58px);
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  gap: calc(var(--cell) * .12);
  padding: calc(var(--cell) * .16);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.14), rgba(0,0,0,.1)),
    linear-gradient(160deg, var(--board-a), var(--board-b));
  border: calc(var(--cell) * .1) solid;
  border-image: linear-gradient(160deg, var(--frame-a), var(--frame-b)) 1;
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,.08),
    inset 0 10px 24px rgba(0,0,0,.35),
    0 16px 34px rgba(10, 20, 60, .45);
  max-width: 100%;
}
.board.can .slot { cursor: pointer; }
.board.can .col-hit .col { cursor: pointer; }
.col-hit { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--cols), 1fr); pointer-events: none; }
.col-hit .col { pointer-events: auto; }
.col-hit .col:hover { background: rgba(255,255,255,.06); border-radius: 10px; }

.slot {
  position: relative;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, var(--slot-empty-a), var(--slot-empty-b) 72%);
  box-shadow: inset 0 3px 6px rgba(0,0,0,.65), inset 0 -1px 0 var(--hole-rim), 0 1px 0 rgba(255,255,255,.05);
}

/* Spielstein: Grundform gilt überall (im Loch oder als frei fallende Animation) */
.disc {
  border-radius: 50%;
  box-shadow: inset 0 3px 4px rgba(255,255,255,.55), inset 0 -4px 6px rgba(0,0,0,.35), 0 2px 4px rgba(0,0,0,.4);
}
.disc.red { background: radial-gradient(circle at 35% 28%, var(--red-a), var(--red-b) 55%, var(--red-c)); }
.disc.yellow { background: radial-gradient(circle at 35% 28%, var(--yellow-a), var(--yellow-b) 55%, var(--yellow-c)); }
.disc.win { animation: winpulse 1s ease-in-out infinite; }
@keyframes winpulse { 0%, 100% { box-shadow: inset 0 3px 4px rgba(255,255,255,.55), inset 0 -4px 6px rgba(0,0,0,.35), 0 0 0 0 rgba(255,255,255,.6); } 50% { box-shadow: inset 0 3px 4px rgba(255,255,255,.55), inset 0 -4px 6px rgba(0,0,0,.35), 0 0 0 6px rgba(255,255,255,0); } }

.slot .disc { position: absolute; inset: 6%; }
.disc.falling { animation-fill-mode: forwards; will-change: transform; }

.ooo { text-align: center; }

/* Sieger */
.win {
  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: fade .3s ease;
}
.win-card {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 22px 22px 20px;
  width: min(440px, 100%);
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  animation: pop .55s cubic-bezier(.2, 1.3, .3, 1);
}
@keyframes pop { 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); } }
.win-card h2 { font-size: 1.6rem; }
.standings { width: 100%; border-collapse: collapse; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.standings th { font-size: .75rem; font-weight: 600; color: var(--muted); text-align: right; padding: 2px 6px; }
.standings th:first-child, .standings td:first-child { text-align: left; }
.standings td { padding: 6px; border-top: 1px solid var(--line); text-align: right; }
.standings tr.first td { font-weight: 750; color: var(--accent); }
.win .row { justify-content: center; margin-top: 4px; }

/* Regeln */
dialog {
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--text);
  width: min(560px, 92vw); padding: 0;
}
dialog::backdrop { background: rgba(0,0,0,.55); }
.rules-in { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.rules-in ol { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; font-size: .95rem; }

/* Hinweis */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: .7em 1.1em; border-radius: 12px; z-index: 70;
  max-width: min(92vw, 460px); text-align: center; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  animation: fade .2s ease;
}
.toast.bad { background: var(--bad); color: #fff; }

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

/* Schmale Bildschirme */
@media (max-width: 560px) {
  .pile-chip { --s: 22px; margin-left: -9px; }
  .roomcode strong { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

.slot, .plate, .pile-chip { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
