/* Handy-zuerst gedacht: Die Chefs halten das Ding am Spieltisch in der Hand,
   meist im Halbdunkel. Darum dunkler Hintergrund und satte Kachelfarben. */

:root {
  --bg: #14161c;
  --surface: #1e212b;
  --surface-hi: #272b37;
  --border: #363b4a;
  --text: #eceef2;
  --text-dim: #9aa1b1;
  --focus: #7dc4ff;

  --team-rot: #e5484d;
  --team-blau: #0c8ce9;
  --team-gruen: #2fa46a;
  --team-gelb: #d99516;
  --neutral: #b3aa96;
  --assassin: #0a0b0e;

  --radius: 12px;
  --gap: 6px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* Safe-Area, damit die Buttons nicht unter der iPhone-Home-Leiste landen. */
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  -webkit-text-size-adjust: 100%;
}

.view[hidden] {
  display: none;
}

.view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 560px;
  margin: 0 auto;
}

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

/* ---------------------------------------------------------------- Formular */

.setup-header {
  text-align: center;
  margin-top: 8px;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.subtitle,
.hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0;
}

#setup-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field > label {
  font-weight: 600;
  font-size: 0.92rem;
}

input[type='number'],
select {
  appearance: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font: inherit;
  width: 100%;
}

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 38px;
}

/* Segmentierte Auswahl statt Dropdown fuer Rastergroesse und Teamzahl —
   ein Tap statt drei, und man sieht alle Optionen auf einmal. */
.segmented {
  display: flex;
  gap: var(--gap);
}

.segmented button {
  flex: 1;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 0;
  font: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.segmented button[aria-checked='true'] {
  background: var(--surface-hi);
  border-color: var(--focus);
  color: var(--text);
  font-weight: 600;
}

/* Live-Aufteilung, damit man die Ueberbuchung sieht, bevor man tippt. */
.preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.chip::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--chip, var(--neutral));
  /* Ohne Ring verschwindet der Attentaeter-Punkt (fast schwarz) im Hintergrund. */
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.3);
}

.chip.is-starter {
  font-weight: 700;
}

.error {
  color: #ff9a9e;
  background: #3a1d20;
  border: 1px solid #6b2b2f;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 0;
  font-size: 0.85rem;
}

button.primary,
button.ghost {
  font: inherit;
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  border: 1px solid transparent;
}

button.primary {
  background: var(--focus);
  color: #0a1622;
  font-weight: 700;
  border: none;
}

button.primary:disabled {
  background: var(--surface-hi);
  color: var(--text-dim);
  cursor: not-allowed;
}

button.ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}

/* ------------------------------------------------------------------ Raster */

.starter-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius);
  /* --starter wird von app.js auf die Teamfarbe gesetzt. */
  background: color-mix(in srgb, var(--starter, var(--surface)) 22%, var(--surface));
  border: 1px solid var(--starter, var(--border));
  font-size: 1.05rem;
}

.starter-text b {
  color: var(--starter, var(--text));
}

.round-badge {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

.grid {
  display: grid;
  /* --n = Rasterkante, von app.js gesetzt. */
  grid-template-columns: repeat(var(--n, 5), 1fr);
  gap: var(--gap);
  width: min(94vw, 520px);
  aspect-ratio: 1;
  /* Erlaubt cqmin auf den Kacheln, damit die Symbole mit dem Raster skalieren. */
  container-type: size;
}

@media (orientation: landscape) {
  .grid {
    width: min(70vh, 520px);
  }
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 9px;
  background: var(--tile);
  color: #ffffff;
  /* Symbol skaliert mit der Kachelgroesse: Rasterbreite / Spaltenzahl. */
  font-size: calc(100cqmin / var(--n, 5) * 0.4);
  line-height: 1;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.12s, filter 0.12s;
}

.tile[data-kind='rot'] {
  --tile: var(--team-rot);
}
.tile[data-kind='blau'] {
  --tile: var(--team-blau);
}
.tile[data-kind='gruen'] {
  --tile: var(--team-gruen);
}
.tile[data-kind='gelb'] {
  --tile: var(--team-gelb);
}
.tile[data-kind='neutral'] {
  --tile: var(--neutral);
  color: #3a3527;
}
.tile[data-kind='assassin'] {
  --tile: var(--assassin);
  /* Sonst verschwindet Schwarz auf dunklem Grund. */
  box-shadow: inset 0 0 0 2px #4d525f;
}

/* Erraten: stark abgeschwaecht, aber die Farbe bleibt erkennbar. */
.tile[aria-pressed='true'] {
  opacity: 0.22;
  filter: grayscale(0.55);
}

.score {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  font-size: 0.87rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

/* ------------------------------------------------------------- Eigene Wörter */

/* Wörter statt Symbol auf den eigenen Kacheln. Deutlich kleiner als das Symbol und
   umbruchfähig, damit auch "SCHRAUBENZIEHER" in ein Feld passt. */
.tile.has-word {
  font-size: calc(100cqmin / var(--n, 5) * 0.15);
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  line-height: 1.1;
  padding: 2px;
  overflow-wrap: anywhere;
}

/* Deutsche Karten werden lang. Kleiner setzen ist besser als ein Umbruch
   mitten im Wort — "SCHRAUBE/NZIEHER" liest niemand gern. */
.tile.has-word.is-long {
  font-size: calc(100cqmin / var(--n, 5) * 0.115);
}

.tile.has-word.is-verylong {
  font-size: calc(100cqmin / var(--n, 5) * 0.088);
}

/* Erratene Wortkacheln nicht so weit runterdimmen wie reine Farbkacheln —
   man will noch lesen können, was schon gefallen ist. */
.tile.has-word[aria-pressed='true'] {
  opacity: 0.45;
}

.words-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.words-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.words-team {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.words-head select {
  width: auto;
  flex: 1;
  padding: 8px 34px 8px 10px;
  background-position: calc(100% - 16px) 50%, calc(100% - 10px) 50%;
}

.words-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.word {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text);
  background: color-mix(in srgb, var(--word-team, var(--surface-hi)) 26%, var(--surface-hi));
  border: 1px solid color-mix(in srgb, var(--word-team, var(--border)) 55%, transparent);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  transition: opacity 0.12s;
}

/* Erraten: durchgestrichen und zurückgenommen, aber lesbar — man will noch
   sehen, was schon dran war. */
.word[aria-pressed='true'] {
  opacity: 0.4;
  text-decoration: line-through;
}

.word.is-unknown {
  color: var(--text-dim);
  font-weight: 400;
  border-style: dashed;
}

.words-progress {
  align-self: center;
  font-size: 0.78rem;
  color: var(--text-dim);
  padding: 7px 2px;
}

.words-edit[hidden] {
  display: none;
}

.words-edit {
  padding: 10px 14px;
  font-size: 0.9rem;
}

.words-dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 20px;
  max-width: min(92vw, 460px);
  width: min(92vw, 460px);
}

.words-dialog::backdrop {
  background: rgb(0 0 0 / 0.72);
}

.words-dialog h2 {
  font-size: 1.15rem;
  margin: 0 0 6px;
}

.words-dialog .hint {
  margin-bottom: 12px;
}

#words-input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font: inherit;
  line-height: 1.6;
  resize: vertical;
}

.words-count {
  margin: 8px 0 14px;
  font-size: 0.82rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.words-count.is-over {
  color: #ff9a9e;
}

.dialog-actions {
  display: flex;
  gap: 8px;
}

.dialog-actions button {
  flex: 1;
}

/* ----------------------------------------------------------------- Sharing */

.share {
  width: 100%;
}

.qr-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.qr-thumb {
  flex: none;
  width: 52px;
  height: 52px;
  background: #ffffff;
  border-radius: 6px;
  padding: 3px;
}

.qr-thumb svg,
.qr-big svg {
  display: block;
  width: 100%;
  height: auto;
}

.share-code {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.share-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

#share-code {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 1.02rem;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.app-footer {
  color: var(--text-dim);
  font-size: 0.72rem;
  opacity: 0.65;
  margin-top: 2px;
}

/* ------------------------------------------------------------- QR-Dialog */

.qr-dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 20px;
  max-width: min(92vw, 380px);
  text-align: center;
}

.qr-dialog::backdrop {
  background: rgb(0 0 0 / 0.72);
}

.qr-big {
  background: #ffffff;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
}

.qr-url {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
  margin: 0 0 10px;
}

.qr-dialog .hint {
  margin-bottom: 14px;
}

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