:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --border: #d7dbe2;
  --danger: #b91c1c;
  --active: #fef3c7;
  --active-border: #fcd34d;
  --radius: 12px;

  /* Flächen, die früher hartcodiert waren (für Theming ausgelagert) */
  --input-bg: #ffffff;
  --btn-bg: #eef1f6;
  --btn-bg-hover: #e2e7ef;
  --placeholder-bg: #e5e7eb;
  --badge-bg: #e0e7ff;
  --badge-text: var(--primary-dark);
  --badge-me-bg: #dcfce7;
  --badge-me-text: #166534;

  /* Würfel */
  --die-white-bg: #ffffff;
  --die-white-text: #1f2933;
  --die-border: rgba(0, 0, 0, 0.15);
  --die-shadow: rgba(0, 0, 0, 0.12);
}

/* Dunkles Design: manuelle Wahl (data-theme="dark") ... */
:root[data-theme="dark"] {
  --bg: #0f141a;
  --card: #1a2028;
  --text: #e5e9f0;
  --muted: #9aa5b1;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --border: #2c333d;
  --danger: #f87171;
  --active: #3a3320;
  --active-border: #a1873c;

  --input-bg: #12181f;
  --btn-bg: #262e39;
  --btn-bg-hover: #313b48;
  --placeholder-bg: #2a313b;
  --badge-bg: #2b3550;
  --badge-text: #c7d2fe;
  --badge-me-bg: #14351f;
  --badge-me-text: #86efac;

  --die-white-bg: #e8eaed;
  --die-white-text: #1f2933;
  --die-border: rgba(0, 0, 0, 0.45);
  --die-shadow: rgba(0, 0, 0, 0.4);
}

/* ... sowie als Systemvorgabe, solange keine manuelle Wahl gesetzt ist. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0f141a;
    --card: #1a2028;
    --text: #e5e9f0;
    --muted: #9aa5b1;
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --border: #2c333d;
    --danger: #f87171;
    --active: #3a3320;
    --active-border: #a1873c;

    --input-bg: #12181f;
    --btn-bg: #262e39;
    --btn-bg-hover: #313b48;
    --placeholder-bg: #2a313b;
    --badge-bg: #2b3550;
    --badge-text: #c7d2fe;
    --badge-me-bg: #14351f;
    --badge-me-text: #86efac;

    --die-white-bg: #e8eaed;
    --die-white-text: #1f2933;
    --die-border: rgba(0, 0, 0, 0.45);
    --die-shadow: rgba(0, 0, 0, 0.4);
  }
}

/* Self-hosted Display-Schrift für die Wortmarke (Baloo 2, OFL, latin-Subset). */
@font-face {
  font-family: "Baloo 2";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/baloo2-bold.woff2") format("woff2");
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.site-header {
  position: relative;
  overflow: hidden;
  padding: 20px 0 12px;
}

/* Dezente Würfelpunkte im Hintergrund (Punkt-Raster, sehr niedrige Deckkraft). */
.header-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  color: var(--muted);
  opacity: 0.08;
  background-image: radial-gradient(currentColor 1.5px, transparent 1.6px);
  background-size: 22px 22px;
  background-position: -6px -6px;
  -webkit-mask-image: linear-gradient(180deg, #000 0%, transparent 100%);
          mask-image: linear-gradient(180deg, #000 0%, transparent 100%);
}

/* Marke: Illustration + Wortmarke/Untertitel – als Block linksbündig, am selben
 * linken Rand wie der Footer (max-width 680px zentriert, Inhalt 16px eingerückt). */
.brand {
  position: relative;
  z-index: 1;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
}
.brand-art {
  --cup-bg: var(--primary);
  --cup-mouth: var(--primary-dark);
  --cup-edge: rgba(0, 0, 0, 0.28);
  flex: 0 0 auto;
}
.brand-art svg { display: block; height: 108px; width: auto; }
.brand-text { text-align: left; }

.wordmark {
  margin: 0;
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
  font-size: 2.4rem;
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--text);
}
.subtitle { margin: 4px 0 0; color: var(--muted); }

/* Umschalter (Töne, Light/Dark Mode) – oben rechts. */
.header-toggles {
  position: absolute;
  top: 16px;
  right: max(16px, calc((100% - 680px) / 2 + 16px));
  z-index: 2;
  display: flex;
  gap: 8px;
}
.toggle-btn {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 12px;
  font-size: 1.25rem;
  line-height: 1;
}

/* Schmale Ansicht: Illustration über den Text stapeln, alles zentriert. */
@media (max-width: 560px) {
  .site-header { padding-top: 64px; }
  .brand { flex-direction: column; gap: 8px; }
  .brand-text { text-align: center; }
  .brand-art svg { height: 90px; }
  .wordmark { font-size: 2rem; }
}

.view { max-width: 680px; margin: 0 auto; padding: 16px; }
.hidden { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

label { display: block; font-weight: 600; margin: 12px 0 4px; }
.label-small { display: block; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

input[type="text"] {
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
}
#code-input { text-transform: uppercase; letter-spacing: 0.1em; }

/* Auswahl der Würfel-Variante im Startbildschirm (F-16) – gleiche Optik wie die
   Textfelder darüber, damit die Maske ruhig bleibt. */
.variant-select {
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
}
#variant-hint { margin: 6px 0 0; }

.actions { display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap; }

button {
  flex: 1 1 auto;
  min-height: 52px; /* tippfreundlich auf Tablets (N-02/N-06) */
  padding: 12px 18px;
  font-size: 1.05rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
}
button:hover { background: var(--btn-bg-hover); }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.ghost { flex: 0 0 auto; background: transparent; border-color: var(--border); color: var(--muted); min-height: 40px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.divider { display: flex; align-items: center; text-align: center; color: var(--muted); margin: 20px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.divider span { padding: 0 12px; }

.error { color: var(--danger); font-weight: 600; min-height: 1.2em; margin: 12px 0 0; }
.hint { color: var(--muted); font-size: 0.9rem; }

.room-header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.room-header > div { flex: 0 0 auto; }
.room-header .ghost { margin-left: auto; }
.room-code { font-size: 1.4rem; letter-spacing: 0.1em; }

/* Ausgeschaltete Admin-Ansicht: Das Zahnrad hat kein Gegensymbol wie 🔊/🔇,
   deshalb kennzeichnet die Abblendung den Zustand. Bewusst nur für diesen
   Button – sonst wäre auch der Design-Umschalter im hellen Modus blass. */
#admin-toggle[aria-pressed="false"] { opacity: 0.55; }

/* Zeitlimit je Zug (F-14): Einstellung und Countdown */
.timer-settings { margin: 4px 0 8px; }
.timer-settings label { margin: 0 0 4px; }
.timer-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.timer-select {
  min-height: 40px; /* tippfreundlich (N-02) */
  padding: 8px 10px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
}
.timer-readonly { color: var(--muted); font-size: 0.95rem; }

.timer-display { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.timer-remaining {
  flex: 0 0 auto;
  min-width: 5.5em;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--muted);
}
.timer-track {
  flex: 1 1 auto;
  height: 8px;
  border-radius: 999px;
  background: var(--placeholder-bg);
  overflow: hidden;
}
.timer-fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.25s linear;
}
/* Letzte 10 bzw. 5 Sekunden deutlich sichtbar machen. */
.timer-display.warn .timer-remaining { color: #b45309; }
.timer-display.warn .timer-fill { background: #f59e0b; }
.timer-display.critical .timer-remaining { color: var(--danger); }
.timer-display.critical .timer-fill { background: var(--danger); animation: timer-pulse 1s ease-in-out infinite; }
:root[data-theme="dark"] .timer-display.warn .timer-remaining { color: #fbbf24; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .timer-display.warn .timer-remaining { color: #fbbf24; }
}

@keyframes timer-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) {
  .timer-fill { transition: none; }
  .timer-display.critical .timer-fill { animation: none; }
}

/* Nur für Screenreader (Countdown-Ansagen). */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

h2 { font-size: 1.15rem; margin: 24px 0 8px; }

.participants { list-style: none; padding: 0; margin: 0; }
.participants li {
  /* Umbruch, damit Badges und Buttons bei langen Namen auf schmalen Geräten
     nicht aus der Karte laufen (N-02). */
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 8px; background: var(--card);
}
.participants li.active { background: var(--active); border-color: var(--active-border); }
.participants .pos { font-weight: 700; color: var(--muted); min-width: 1.5em; }
.participants .pname { flex: 1; }
.participants .badge { font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--badge-bg); color: var(--badge-text); }
.participants .badge.me { background: var(--badge-me-bg); color: var(--badge-me-text); }
.order-btns { display: flex; gap: 4px; }
.order-btns button { flex: 0 0 auto; min-height: 36px; padding: 4px 12px; font-size: 1rem; }
.order-btns .admin-btn { margin-right: 6px; } /* setzt die Krone von den Pfeilen ab */

/* Würfel */
/* Auswahl der Würfel im Spiel (F-15): Schaltflächen sind reine Würfel-Träger,
   deshalb wird die globale Button-Optik hier zurückgesetzt. */
.dice-settings { margin: 4px 0 8px; }
.dice-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.dice-controls button {
  flex: 0 0 auto;
  min-height: 0; padding: 4px; margin: 0;
  background: none; border: none; border-radius: 8px;
  line-height: 0;
}
.dice-controls button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
/* Ausgeschiedener Würfel: abgeblendet und durchgestrichen. */
.die.excluded { position: relative; opacity: 0.45; }
.die.excluded::after {
  content: "";
  position: absolute; left: -2px; right: -2px; top: 50%;
  height: 2px; background: var(--text);
  transform: rotate(-45deg);
}

/* Anklickbarer Würfel im Ergebnis (F-16): Der Button ist reiner Träger. */
.die-btn {
  flex: 0 0 auto;
  min-height: 0; padding: 0; margin: 0;
  background: none; border: none; border-radius: 14px;
  line-height: 0; cursor: pointer;
}
.die-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
/* Für den nächsten Wurf markiert: hervorgehoben und leicht angehoben. */
.die.reroll {
  border-color: var(--primary);
  box-shadow: inset 0 -3px 0 var(--die-shadow), 0 0 0 3px var(--primary);
  transform: translateY(-4px);
}

.dice-area { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 12px 0; min-height: 72px; }
.die {
  width: 60px; height: 60px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--die-border);
  box-shadow: inset 0 -3px 0 var(--die-shadow);
}
.die.placeholder { background: var(--placeholder-bg); color: transparent; }

/* Augenzahl als Punkte (Pips): 3x3-Raster, Punktfarbe erbt currentColor je Würfel */
.die .pips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 76%; height: 76%;
  gap: 6%;
}
.die .pip-cell { display: flex; align-items: center; justify-content: center; }
.die .pip-cell.on::before {
  content: "";
  width: 68%; aspect-ratio: 1;
  border-radius: 50%;
  background: currentColor;
}
.die.white  { background: var(--die-white-bg); color: var(--die-white-text); }
.die.red    { background: #ef4444; color: #fff; }
.die.blue   { background: #3b82f6; color: #fff; }
.die.green  { background: #22c55e; color: #fff; }
.die.yellow { background: #facc15; color: #1f2933; }

@keyframes shake {
  0%, 100% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-6px) rotate(-12deg); }
  50% { transform: translateY(4px) rotate(10deg); }
  75% { transform: translateY(-3px) rotate(-6deg); }
}
.die.rolling { animation: shake 0.35s linear infinite; }

.turn-info { text-align: center; font-weight: 600; margin-top: 12px; min-height: 1.4em; }

/* Wurfprotokoll: einklappbar via <details>; Summary wie eine Überschrift. */
.log-details { margin: 24px 0 0; }
.log-details > summary {
  list-style: none; /* Standard-Dreieck ausblenden, eigenes über ::before */
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  min-height: 44px; /* tippfreundlich (N-02/N-06) */
  margin: 0 0 8px;
  font-size: 1.15rem; font-weight: 700; /* wie h2 */
}
.log-details > summary::-webkit-details-marker { display: none; }
.log-details > summary::before {
  content: "▸"; color: var(--muted); font-size: 0.9em;
  transition: transform 0.15s ease;
}
.log-details[open] > summary::before { transform: rotate(90deg); }
.log-count {
  font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--badge-bg); color: var(--badge-text);
}
.log-count:empty { display: none; }

.log { list-style: none; padding: 0; margin: 0; max-height: 240px; overflow-y: auto; }
.log li {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px;
  font-size: 0.9rem; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.log .log-time { color: var(--muted); }
.log-dice { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.log .empty { color: var(--muted); font-style: italic; }

/* Kennzeichnung des Wurfes im Protokoll (nur in Mehrwurf-Varianten, F-16). */
.log-roll {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--placeholder-bg);
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

/* Mini-Würfel im Protokoll (verkleinerte Variante von .die). */
.die.mini { width: 26px; height: 26px; border-radius: 6px; border-width: 1px; box-shadow: inset 0 -2px 0 var(--die-shadow); }
.die.mini .pips { gap: 8%; }

@media (max-width: 480px) {
  .actions { flex-direction: column; }
}

/* ---------------------------------------------------------------------------
 * Footer (drei Spalten: Logo, Realisierung/Version, Info-Links)
 * ------------------------------------------------------------------------- */
.site-footer {
  max-width: 680px;
  margin: 24px auto 16px;
  padding: 20px 16px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 24px;
  align-items: start;
  color: var(--muted);
  font-size: calc(0.9rem - 2pt);
}
.footer-col--info { display: flex; flex-direction: column; gap: 4px; }
.footer-col--links { display: flex; flex-direction: column; gap: 4px; text-align: right; }
.site-footer a { color: var(--primary); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* Logo je nach Anzeigemodus einblenden. Nach dem Laden setzt app.js immer
 * data-theme; der @media-Zweig deckt nur den kurzen Moment davor ab. */
.footer-logo { display: block; height: auto; max-width: 80px; width: 100%; }
.footer-logo--dark { display: none; }
:root[data-theme="dark"] .footer-logo--light { display: none; }
:root[data-theme="dark"] .footer-logo--dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .footer-logo--light { display: none; }
  :root:not([data-theme]) .footer-logo--dark { display: block; }
}

@media (max-width: 560px) {
  .site-footer { grid-template-columns: 1fr; text-align: center; gap: 16px; }
  .footer-col--links { text-align: center; }
  .footer-logo { margin: 0 auto; }
}
