/* "Boks"-designet: lyst tema på :root, mørkt når telefonen er mørk. Holdfelterne er altid mørke bokse. */
:root {
  color-scheme: light dark;
  --bg: #eef1f8;
  --surface: #ffffff;
  --border: #d6dcea;
  --text: #0f1530;
  --muted: #566086;
  --accent: #3ce0b0;
  --on-accent: #04241b;
  --focus: #0b7a5c;
  --vault: #070b18;
  --vault-text: #e6ecff;
  --vault-muted: #8a94b8;
  --gap: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #121a33;
    --border: #26315a;
    --text: #e6ecff;
    --muted: #8a94b8;
    --focus: #3ce0b0;
    --vault: #050814;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; touch-action: manipulation; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.sprite { display: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

/* Spillet fylder hele skærmen; liggende: felt | bjælke | felt */
.game {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: var(--gap);
  padding:
    max(var(--gap), env(safe-area-inset-top))
    max(var(--gap), env(safe-area-inset-right))
    max(var(--gap), env(safe-area-inset-bottom))
    max(var(--gap), env(safe-area-inset-left));
}

.team {
  --team: #d62839;
  --team-fg: #ffffff;
  position: relative;
  container-type: size;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  justify-items: center;
  align-items: center;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 12px;
  border: 3px solid var(--team);
  border-radius: 20px;
  background: var(--vault);
  color: var(--vault-text);
  font: inherit;
  touch-action: manipulation;
  cursor: pointer;
  transition: background-color 120ms, box-shadow 120ms, opacity 200ms;
}

.team-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(16px, 11cqh, 44px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--team);
}

.team-time {
  font-size: min(40cqh, 32cqw);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.team-status {
  min-height: 1.3em;
  font-size: clamp(14px, 7cqh, 28px);
  font-weight: 600;
  text-align: center;
}

.team-moves {
  font-size: clamp(14px, 7cqh, 26px);
  color: var(--vault-muted);
  font-variant-numeric: tabular-nums;
}

/* Resultat i vinderens felt (og begge ved uafgjort) – inde i feltet, så bjælken aldrig dækkes */
.team-result {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-4deg);
  max-width: 92%;
  padding: 0.15em 0.5em;
  border-radius: 0.3em;
  background: var(--accent);
  color: var(--on-accent);
  font-size: min(20cqh, 13cqw);
  font-weight: 900;
  line-height: 1.1;
  white-space: nowrap;
  box-shadow: 0 12px 48px rgb(0 0 0 / 0.5);
  pointer-events: none;
}

.team-result[hidden] { display: none; }

.team.is-running {
  background: var(--team);
  color: var(--team-fg);
  box-shadow: 0 0 32px var(--team);
}

.team.is-running .team-name,
.team.is-running .team-moves { color: var(--team-fg); }

.team.is-done > :not(.team-result) { opacity: 0.55; }

.team.is-waiting { animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse {
  50% { box-shadow: 0 0 36px var(--team); }
}

@media (prefers-reduced-motion: reduce) {
  .team.is-waiting { animation: none; box-shadow: 0 0 24px var(--team); }
}

.bar {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
}

.bar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 64px;
  min-height: 52px;
  padding: 4px 2px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 10px;
  font-weight: 600;
  touch-action: manipulation;
  cursor: pointer;
}

.bar-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.version { font-size: 11px; color: var(--muted); }

/* Højkant: felterne over hinanden, bjælken vandret imellem */
@media (orientation: portrait) {
  .game { grid-template-columns: 1fr; grid-template-rows: 1fr auto 1fr; }
  .bar { flex-direction: row; }
  .bar-btn { width: 58px; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  align-items: center;
  width: max-content;
  max-width: min(560px, calc(100vw - 24px));
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.35);
  font-size: 14px;
}

.toast[hidden] { display: none; }
.toast p { margin: 0; }

/* Dialoger */
.sheet {
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}

.sheet::backdrop { background: rgb(5 8 20 / 0.6); }
.sheet h2 { margin: 0 0 12px; font-size: 22px; }
.sheet h3 { margin: 18px 0 6px; font-size: 16px; }
.sheet ul { margin: 0; padding-left: 1.2em; }
.sheet li { margin: 4px 0; line-height: 1.4; }
.sheet p { line-height: 1.4; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sheet-head h2 { margin: 0; }

fieldset {
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
}

legend { padding: 0 6px; font-weight: 700; }

.field-time { display: flex; gap: 12px; }

label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }

select, input {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  -webkit-user-select: text;
  user-select: text;
}

@media (orientation: landscape) {
  .setup-teams { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
}

.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.swatch {
  width: 44px;
  height: 44px;
  border: 3px solid transparent;
  border-radius: 12px;
  background: var(--swatch);
  cursor: pointer;
}

.swatch[aria-pressed="true"] { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }
.swatch:disabled { opacity: 0.25; cursor: default; }

.hint { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.hint[hidden] { display: none; }

.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.btn {
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn:disabled { opacity: 0.4; cursor: default; }

.muted { color: var(--muted); }
