:root {
  --bg: #0b0d12;
  --panel: #161a22;
  --text: #f2f4f8;
  --muted: #9aa3b2;
  --accent: #39d3ff;
  --warn: #ff4d4d;
  --ok: #3ddc84;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* --- Layout: Hochformat = Bild oben, Leiste unten ------------------------ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

#video {
  /* Das Video wird auf das Canvas gezeichnet; das Element selbst bleibt unsichtbar. */
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

#controls {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
}

#controls button { flex: 1; }
#btn-settings { flex: 0 0 56px; }

/* Querformat: Leiste rechts senkrecht */
@media (orientation: landscape) {
  #app { flex-direction: row; }
  #controls {
    flex-direction: column;
    width: 128px;
    justify-content: center;
  }
  #controls button { flex: 0 0 auto; min-height: 56px; }
  #btn-settings { flex: 0 0 auto; }
}

/* --- Buttons ------------------------------------------------------------- */
button {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid #2a3040;
  border-radius: var(--radius);
  background: #202634;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: default; transform: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #041018; }

/* --- HUD im Bild ------------------------------------------------------- */
#hud {
  position: absolute;
  inset: 8px 8px auto 8px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
#hud > * {
  background: rgba(0, 0, 0, 0.55);
  border-radius: var(--radius);
  padding: 6px 10px;
  backdrop-filter: blur(4px);
}
#phase-box { display: flex; flex-direction: column; font-size: 14px; }
#phase-label { font-weight: 700; }
#round-label { color: var(--muted); }
#clock {
  font-size: clamp(28px, 8vmin, 56px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
#counters { display: flex; flex-direction: column; font-size: 14px; text-align: right; }
#counters b { font-size: 18px; font-variant-numeric: tabular-nums; }

body[data-phase="round"] #clock { color: var(--ok); }
body[data-phase="rest"] #clock { color: var(--accent); }
body[data-phase="prep"] #clock { color: #ffd23f; }

#warning {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  padding: 12px 22px;
  border-radius: var(--radius);
  background: rgba(255, 77, 77, 0.9);
  color: #fff;
  font-size: clamp(22px, 7vmin, 44px);
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
#warning.show { opacity: 1; }

#status {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 6px 12px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.6);
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}
#status:empty { display: none; }

#debug {
  position: absolute;
  left: 8px;
  bottom: 8px;
  margin: 0;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  font: 12px/1.35 ui-monospace, Menlo, monospace;
  pointer-events: none;
}

/* --- Dialoge ------------------------------------------------------------- */
dialog {
  width: min(92vw, 440px);
  max-height: 90dvh;
  overflow: auto;
  border: 1px solid #2a3040;
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
dialog h1, dialog h2 { margin: 0 0 12px; }
dialog ol { padding-left: 20px; }
dialog li { margin-bottom: 6px; }
dialog > button { width: 100%; margin-top: 12px; }
.small { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
a { color: var(--accent); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0;
}
.row.check { justify-content: flex-start; }
fieldset.row {
  flex-direction: column;
  align-items: stretch;
  border: 1px solid #2a3040;
  border-radius: var(--radius);
  padding: 8px 12px;
}
fieldset label { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
input[type="number"], select {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid #2a3040;
  border-radius: 8px;
  background: #0f1219;
  color: var(--text);
  font: inherit;
}
input[type="number"] { width: 80px; text-align: center; }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; accent-color: var(--accent); }

/* Auswertungstabelle */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 4px; border-bottom: 1px solid #2a3040; text-align: right; }
th:first-child, td:first-child { text-align: left; }
tr.total td { font-weight: 700; border-bottom: none; }
