/* "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: 16px;
}

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

* { box-sizing: border-box; }

/* hidden skal altid vinde – også over display: grid/flex på skærme og elementer */
[hidden] { display: none !important; }

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; }

/* --- Startside: altid mørk med billedet som baggrund (ens i lys og mørk tilstand) --- */
.start {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: grid;
  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));
  background: #050814;
  color: #fff;
  isolation: isolate; /* billedet (z-index: -1) ligger bag indholdet, men foran baggrundsfarven */
}

.start::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url('img/duel-start.webp') center top / cover no-repeat;
}

/* Liggende: billedet er på højkant, så det bruges sløret og mørklagt som stemning bag knapperne */
@media (orientation: landscape) {
  .start::before {
    background-position: center;
    filter: blur(10px) brightness(0.4);
    transform: scale(1.15); /* skjuler de slørede kanter */
  }
}

/* Højkant: billedet vises skarpt med sin egen titel – knapperne ligger nederst på en mørk overgang */
@media (orientation: portrait) {
  .start::after {
    content: "";
    position: fixed;
    inset: auto 0 0;
    height: 60%;
    z-index: -1;
    background: linear-gradient(to bottom, rgb(5 8 20 / 0), rgb(5 8 20 / 0.92) 45%);
  }

  .start .start-inner { margin: auto auto 0; } /* nederst – højere specificitet end den fælles .start-inner længere nede */

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

.start-inner {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(560px, 100%);
  margin: auto; /* centreres når der er plads, ellers kan siden scrolles fra toppen */
  text-align: center;
}

.start-title {
  margin: 0;
  font-size: clamp(40px, 12vmin, 72px);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
  text-shadow: 0 2px 16px rgb(0 0 0 / 0.5);
}

.start-tagline { margin: 0; color: rgb(255 255 255 / 0.85); font-size: 17px; font-weight: 600; }

.focus { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }

.focus-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgb(255 255 255 / 0.85);
}

.focus-btn {
  min-width: 140px;
  min-height: 56px;
  padding: 10px 20px;
  border: 2px solid rgb(255 255 255 / 0.35);
  border-radius: 16px;
  background: rgb(5 8 20 / 0.6);
  color: #fff;
  font: inherit;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.focus-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.lineup { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
.lineup-text { margin: 0; font-size: 16px; font-weight: 600; }

.lineup-name {
  --team: #d62839;
  --team-fg: #ffffff;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--team);
  color: var(--team-fg);
}

/* Opsætning på startsiden: halvgennemsigtig mørk knap, så den kan læses oven på billedet */
.start .btn:not(.btn-primary) {
  border-color: rgb(255 255 255 / 0.35);
  background: rgb(5 8 20 / 0.6);
  color: #fff;
}

.link-btn {
  min-height: 44px;
  padding: 8px 16px;
  border: 0;
  background: none;
  color: rgb(255 255 255 / 0.85);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* --- Lodtrækning --- */
.draw-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  padding: var(--gap);
  background: var(--vault);
  color: var(--vault-text);
  text-align: center;
}

.draw-name {
  --team: #d62839;
  --team-fg: #ffffff;
  max-width: 90vw;
  margin: 0;
  padding: 0.1em 0.6em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 0.3em;
  background: var(--team);
  color: var(--team-fg);
  font-size: clamp(40px, 16vmin, 112px);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.draw-text { margin: 0; min-height: 1.3em; font-size: clamp(20px, 6vmin, 36px); font-weight: 800; }

/* --- Urene; 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 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: 24px;
  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-role {
  min-height: 1.2em;
  font-size: clamp(12px, 7cqh, 24px);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.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.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; }

.team.is-paused .team-status {
  font-weight: 800;
  letter-spacing: 0.12em;
  animation: blink 1s steps(1, end) infinite;
}

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

@keyframes blink {
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .team.is-paused .team-status { animation: none; }
  .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,
.btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn svg { width: 18px; height: 18px; vertical-align: -3px; }

.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 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; }

.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; }

/* Den store knap på startsiden – .btn.btn-big, så den vinder over den fælles .btn ovenfor */
.btn.btn-big { min-height: 56px; padding: 14px 28px; border-radius: 16px; font-size: 18px; }

/* Startsiden er altid mørk: mint fokusring og en lidt tydeligere slået-fra "Træk lod og start" */
.start :focus-visible { outline-color: var(--accent); }
.start .btn-primary:disabled { opacity: 0.55; }

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