/* Grundlayout: Kopfzeile oben, Spielfeld füllt den Rest des Fensters. */

* {
  box-sizing: border-box;
}

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

body {
  display: flex;
  flex-direction: column;
  font-family: system-ui, sans-serif;
  background: #f1f3f5;
  color: #212529;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.4rem 0.75rem;
}

h1 {
  margin: 0;
  font-size: 1rem;
}

/* Werkzeugleiste: große Knöpfe, damit sie am Beamer und auf dem Tablet gut treffbar sind. */
.toolbar {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.toolbar-gap {
  flex: 1;
}

.toolbar button {
  min-height: 2.5rem;
  padding: 0 0.9rem;
  border: 1px solid #adb5bd;
  border-radius: 0.4rem;
  background: #ffffff;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.toolbar button:hover:not(:disabled) {
  background: #e9ecef;
}

.toolbar button:disabled {
  opacity: 0.4;
  cursor: default;
}

main {
  flex: 1;
  min-height: 0;
  padding: 0 0.25rem 0.25rem;
}

/* Die viewBox sorgt dafür, dass sich das Spielfeld dem Fenster anpasst (Spec 5.8). */
#board {
  display: block;
  width: 100%;
  height: 100%;
  /* Auf Touch-Geräten soll Ziehen das Teil bewegen, nicht die Seite scrollen oder zoomen. */
  touch-action: none;
  /* Die Greifpunkte an den Ecken dürfen über den Rand der Spielwiese hinausragen. */
  overflow: visible;
}

.field {
  fill: #ffffff;
  stroke: #adb5bd;
  stroke-width: 0.08;
}

.piece {
  stroke: #343a40;
  stroke-width: 0.06;
  stroke-linejoin: round;
  cursor: grab;
}

/* Während des Ziehens (Zeiger gedrückt) die geschlossene Hand zeigen. */
#board:active .piece {
  cursor: grabbing;
}

/* F3: Das ausgewählte Teil bekommt einen kräftigen Rand. */
.piece.selected {
  stroke: #212529;
  stroke-width: 0.12;
}

/* Drehen an den Ecken des ausgewählten Teils (Spec 5.27). */

/* Unsichtbare Greiffläche um jede Ecke: mit dem Finger leichter zu treffen. */
.corner-hit {
  fill: transparent;
  cursor: crosshair;
}

/* Kleiner sichtbarer Punkt auf der Ecke als Hinweis „hier kann man drehen“. */
.corner-dot {
  fill: #ffffff;
  stroke: #495057;
  stroke-width: 0.07;
  pointer-events: none;
}

/* ---------- Online-Spiel ---------- */

.room-info {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  padding: 0.3rem 0.75rem;
  font-size: 0.9rem;
  background: #e7f1ff;
  border-top: 1px solid #cfe2ff;
  border-bottom: 1px solid #cfe2ff;
}

.room-info[hidden] {
  display: none;
}

.status::before {
  content: "● ";
}

.status.ok {
  color: #198754;
}

.status.down {
  color: #dc3545;
}

.room-message {
  color: #dc3545;
  font-weight: 600;
}

/* Online hat nur der Builder Werkzeuge und den Hand-Zeiger; alle anderen schauen zu. */
body.online:not(.is-builder) .toolbar {
  display: none;
}

body.online:not(.is-builder) .piece {
  cursor: default;
}

/* ---------- Runde: Uhr, Spielleiter, 3-2-1 ---------- */

body.online .solo-only {
  display: none;
}

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
}

.clock[data-phase="running"] {
  color: #0d6efd;
}

.clock[data-phase="finished"] {
  color: #198754;
}

.leader-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  padding: 0.4rem 0.75rem;
  background: #fff8e1;
  border-bottom: 1px solid #ffe69c;
}

.leader-bar[hidden] {
  display: none;
}

.leader-bar button {
  min-height: 2.25rem;
  padding: 0 0.9rem;
  border: 1px solid #adb5bd;
  border-radius: 0.4rem;
  background: #ffffff;
  font: inherit;
  cursor: pointer;
}

.leader-bar button.primary:not(:disabled) {
  border-color: #198754;
  background: #198754;
  color: #ffffff;
}

.leader-bar button:disabled {
  opacity: 0.4;
  cursor: default;
}

.round-status {
  color: #495057;
}

main {
  position: relative;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(30vh, 14rem);
  font-weight: 800;
  color: #0d6efd;
  text-shadow: 0 0.05em 0.2em rgba(255, 255, 255, 0.9);
  pointer-events: none;
}

.countdown-overlay[hidden] {
  display: none;
}

/* ---------- Rollen: Teilnehmerliste und Erklärer ---------- */

.participants {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  width: 100%;
  margin: 0.2rem 0 0;
  padding: 0;
  list-style: none;
}

.participants li {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.3rem 0.2rem 0.6rem;
  background: #ffffff;
  border: 1px solid #ffe69c;
  border-radius: 999px;
}

.participants li.participants-empty {
  padding: 0.3rem 0.6rem;
  color: #6c757d;
  font-style: italic;
}

.participant-name {
  font-weight: 600;
  margin-right: 0.2rem;
}

.leader-bar .participants button {
  min-height: 1.9rem;
  padding: 0 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
}

.leader-bar .participants button.active {
  border-color: #0d6efd;
  background: #e7f1ff;
  color: #0a58ca;
  opacity: 1;
}

.explainer-banner {
  padding: 0.45rem 0.75rem;
  background: #212529;
  color: #ffffff;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
}

.explainer-banner.me {
  background: #198754;
}

.explainer-banner[hidden] {
  display: none;
}

/* ---------- Countdown und Bonus ---------- */

.clock.warning {
  color: #dc3545;
}

.clock[data-phase="timeout"] {
  color: #dc3545;
}

.bonus-flash {
  margin-left: 0.35rem;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: #198754;
  color: #ffffff;
  font-weight: 700;
  animation: bonus-pop 0.4s ease-out;
}

.bonus-flash[hidden] {
  display: none;
}

@keyframes bonus-pop {
  from { transform: scale(1.8); }
  to { transform: scale(1); }
}

.leader-bar button.bonus:not(:disabled) {
  border-color: #198754;
  color: #198754;
  font-weight: 700;
}

.settings {
  display: inline-flex;
  gap: 0.6rem;
  margin-left: auto;
  font-size: 0.9rem;
}

.settings input {
  width: 4.2rem;
  padding: 0.2rem 0.3rem;
  border: 1px solid #adb5bd;
  border-radius: 0.3rem;
  font: inherit;
}

/* Ergebnis über dem Spielfeld: kleiner als das 3-2-1, mit hellem Hintergrund. */
.countdown-overlay.result {
  font-size: min(9vh, 4rem);
  color: #198754;
}

.countdown-overlay.lost {
  color: #dc3545;
}

/* ---------- Fragen-Fenster (Stufe 4c) ---------- */

.leader-bar button.question-button:not(:disabled) {
  border-color: #6f42c1;
  color: #6f42c1;
  font-weight: 700;
}

/* Ebene über allem; sie selbst fängt keine Klicks, nur die Fenster darin. */
.question-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

/* Der Builder sieht keine Fragen – doppelt abgesichert (der Server schickt sie ihm ohnehin nicht). */
body.is-builder .question-layer,
body.is-builder .question-toast {
  display: none;
}

.question-window {
  position: absolute;
  width: 340px;
  pointer-events: auto;
  background: #ffffff;
  border: 2px solid #6f42c1;
  border-radius: 0.6rem;
  box-shadow: 0 0.6rem 1.6rem rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.question-window.taken {
  border-color: #fd7e14;
}

.question-window.mine {
  border-color: #198754;
}

.question-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: #6f42c1;
  color: #ffffff;
  font-weight: 700;
  cursor: move;
  user-select: none;
  touch-action: none;
}

.question-window.taken .question-head {
  background: #fd7e14;
}

.question-window.mine .question-head {
  background: #198754;
}

.question-timer {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.question-withdraw {
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.question-withdraw[hidden] {
  display: none;
}

.question-text {
  margin: 0;
  padding: 0.6rem 0.75rem 0.3rem;
  font-weight: 600;
}

.question-answers {
  margin: 0;
  padding: 0 0.75rem;
  list-style: none;
}

.question-answer {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
  margin: 0.2rem 0;
  padding: 0.35rem 0.5rem;
  border: 1px solid #dee2e6;
  border-radius: 0.4rem;
  background: #f8f9fa;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.question-answer:disabled {
  color: #212529;
  cursor: default;
}

.question-answer.selected {
  border-color: #198754;
  background: #d1e7dd;
  font-weight: 700;
}

.answer-letter {
  display: inline-block;
  width: 1.4rem;
  font-weight: 700;
  color: #6f42c1;
}

.question-foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem 0.65rem;
}

.question-foot button {
  min-height: 2.2rem;
  padding: 0 0.9rem;
  border-radius: 0.4rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.question-foot button[hidden],
.question-status[hidden] {
  display: none;
}

.question-take {
  border: 1px solid #6f42c1;
  background: #6f42c1;
  color: #ffffff;
}

.question-push {
  margin-left: auto;
  border: 1px solid #198754;
  background: #198754;
  color: #ffffff;
}

.question-foot button:disabled {
  opacity: 0.45;
  cursor: default;
}

.question-status {
  color: #495057;
  font-style: italic;
}

.question-toast {
  position: fixed;
  top: 6.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  background: #212529;
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 0.4rem 1rem rgba(0, 0, 0, 0.25);
}

.question-toast.correct {
  background: #198754;
}

.question-toast.wrong {
  background: #dc3545;
}

.question-toast[hidden] {
  display: none;
}

/* ---------- Team-Tabelle oben links (nicht beim Builder) ----------
   Eigene Spalte links neben dem Spielfeld, damit sie keine Teile verdeckt. */

main {
  display: flex;
  gap: 0.5rem;
}

#board {
  flex: 1;
  min-width: 0;
}

.team-table {
  align-self: flex-start;
  flex: none;
  margin-top: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: #ffffff;
  border: 1px solid #dee2e6;
  border-radius: 0.5rem;
  box-shadow: 0 0.2rem 0.6rem rgba(0, 0, 0, 0.08);
  font-size: 0.8rem;
}

.team-table table {
  border-collapse: collapse;
}

.team-table th,
.team-table td {
  padding: 0.1rem 0.45rem;
  text-align: left;
}

.team-table th {
  font-weight: 600;
  color: #6c757d;
  border-bottom: 1px solid #dee2e6;
}

.team-table th:nth-child(n+3),
.team-table td:nth-child(n+3) {
  text-align: center;
}

.team-table tr.me td:first-child {
  font-weight: 700;
}

.team-open {
  margin: 0.3rem 0 0;
  color: #495057;
}

.team-table[hidden],
body.is-builder .team-table {
  display: none;
}

/* ---------- Vorlage rechts neben dem Spielfeld (template.js) ---------- */

.template-panel {
  position: relative;
  z-index: 1; /* über dem großen „Geschafft“-Schriftzug */
  align-self: flex-start;
  flex: none;
  width: 16rem;
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem 0.75rem;
  background: #ffffff;
  border: 1px solid #dee2e6;
  border-radius: 0.5rem;
  box-shadow: 0 0.2rem 0.6rem rgba(0, 0, 0, 0.08);
}

.template-panel[hidden] {
  display: none;
}

.template-panel h2 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}

.template {
  display: block;
  width: 100%;
  height: 18rem;
}

.template-note {
  margin: 0.3rem 0 0;
  font-size: 0.8rem;
  color: #6c757d;
}

.template-note:empty {
  display: none;
}

/* Schwierigkeit: farbig (Farbe am Teil), mit Linien, Silhouette. */
.template-piece.color {
  stroke: #343a40;
  stroke-width: 0.06;
  stroke-linejoin: round;
}

.template-piece.lines {
  fill: #2b3035;
  stroke: #ffffff;
  stroke-width: 0.12;
  stroke-linejoin: round;
}

/* Kontur in Flächenfarbe schließt die feinen Spalten zwischen den Teilen. */
.template-piece.silhouette {
  fill: #2b3035;
  stroke: #2b3035;
  stroke-width: 0.06;
  stroke-linejoin: round;
}

/* ---------- Galerie des Spielleiters ---------- */

.figure-gallery {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem 1rem;
  background: rgba(33, 37, 41, 0.45);
}

.figure-gallery[hidden] {
  display: none;
}

.gallery-window {
  width: min(56rem, 100%);
  max-height: calc(100vh - 6rem);
  overflow: auto;
  background: #ffffff;
  border-radius: 0.75rem;
  box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, 0.3);
}

.gallery-head {
  position: sticky;
  top: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  background: #ffffff;
  border-bottom: 1px solid #dee2e6;
}

.gallery-difficulty {
  display: flex;
  gap: 0.75rem;
  margin-right: auto;
}

.gallery-head button {
  border: none;
  background: none;
  font-size: 1.1rem;
  cursor: pointer;
}

.gallery-figures {
  padding: 0.5rem 1rem 1rem;
}

.gallery-figures h3 {
  margin: 0.75rem 0 0.4rem;
  font-size: 0.9rem;
  color: #495057;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: 0.6rem;
}

.figure-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.5rem;
  border: 2px solid #dee2e6;
  border-radius: 0.5rem;
  background: #ffffff;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.figure-card:hover {
  border-color: #6c757d;
}

.figure-card.selected {
  border-color: #0d6efd;
  background: #e7f1ff;
}

.figure-card.none {
  margin-top: 0.5rem;
  flex-direction: row;
  width: auto;
}

.figure-preview {
  width: 100%;
  height: 6rem;
}
