/*
 * The judge's phone: a one-row top bar (phase tag, clock, menu), the current
 * phase's work, and a bottom bar in the thumb zone with the undo strip and
 * the one big next step.
 */

/* --- Top bar ----------------------------------------------------------------- */

.judge-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--hairline);
}

/* No overflow clipping here: it would cut off the tag's slant and glow. */
.judge-top__phase {
  flex: 1;
  min-width: 0;
  padding-left: 4px;
  text-decoration: none;
}

.judge-top__phase .phase-tag { font-size: 0.95rem; vertical-align: middle; }

/* --- Popovers: the clock sheet and the ⋯ menu --------------------------------- */

.popover { position: relative; flex: none; }
.popover > summary { list-style: none; cursor: pointer; }
.popover > summary::-webkit-details-marker { display: none; }

.judge-menu > summary {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 1.35rem;
  line-height: 1;
}

.judge-clock > summary {
  padding: 0.25rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.judge-menu[open] > summary, .judge-clock[open] > summary { background: var(--surface-2); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }

.countdown--judge .countdown__time { font-size: 1.6rem; }
.countdown--judge .countdown__note { display: none; }
.countdown--judge.is-expired .countdown__time { font-size: 0.9rem; }

.popover__sheet {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
  display: grid;
  gap: 0.5rem;
  min-width: 13rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  box-shadow: 0 18px 40px #000a;
  animation: rise-in 0.15s ease-out;
}

.popover__sheet--clock { grid-template-columns: repeat(3, max-content); }
.popover__sheet--clock .button { width: 100%; padding-inline: 0.85rem; white-space: nowrap; }
.popover__sheet--clock .button--go { padding-inline: 1.1rem; font-size: 0.95rem; }

.popover__sheet--menu a, .popover__button {
  display: block;
  width: 100%;
  padding: 0.7rem 0.6rem;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.popover__sheet--menu a:hover, .popover__button:hover { background: var(--surface-2); }
.popover__button.is-armed { background: color-mix(in srgb, var(--gold) 20%, transparent); color: var(--gold); }
.popover__button--danger { color: var(--red-soft); }

/* --- Body ------------------------------------------------------------------------ */

.judge__main { padding-bottom: calc(160px + env(safe-area-inset-bottom)); gap: 12px; }

.judge-back { color: var(--muted); font-weight: 500; text-decoration: none; }
.page-title { font-size: 2rem; }

.now { display: grid; justify-items: center; gap: 0.25rem; padding: 0.75rem 0; text-align: center; }
.now--left { justify-items: start; text-align: left; }
.now__big { font-family: var(--display); font-weight: 200; font-size: 5.5rem; line-height: 0.95; color: var(--ink); font-variant-numeric: tabular-nums; }
.now__big span { color: var(--muted); font-size: 0.45em; }
.now__label { color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.22em; font-size: 0.78rem; }
.now__title { font-family: var(--display); font-weight: 800; font-style: italic; font-size: 2rem; line-height: 1.1; }

.judge-note { color: var(--muted); font-size: 0.95rem; }
.judge-note strong { color: var(--ink); font-weight: 600; }
.judge-hint { color: var(--muted); font-size: 0.85rem; text-align: center; }

.card--warn { border-color: color-mix(in srgb, var(--gold) 60%, transparent); }
.judge-callout { display: block; color: var(--gold); font-weight: 600; text-decoration: none; }

.name-list, .pairs { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.name-list a {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.3rem 0.8rem 0.3rem 0.3rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  animation: rise-in 0.3s ease-out;
}
.pairs { display: grid; gap: 0.3rem; }

/* --- Rows ---------------------------------------------------------------------- */

.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 60px;
  padding: 6px 8px 6px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.row__main { display: grid; min-width: 0; }
.row__main .badge { font-size: 1.05rem; }
.row__meta { font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__meta.is-penalty { color: var(--red-soft); }
.row__actions { display: flex; gap: 6px; flex: none; }
.row__go { color: var(--muted); font-size: 1.4rem; transition: transform 0.2s; }

.button--test { background: var(--gold); border-color: var(--gold); color: var(--accent-ink); min-height: 46px; padding-inline: 0.95rem; font-weight: 700; }
.button--flag { background: var(--surface-2); border-color: var(--line); color: var(--ink); min-height: 46px; width: 50px; padding: 0; font-size: 1.35rem; }

/* Nine teams on one screen above the bottom bar. */
.rows--build { gap: 5px; }
.rows--build .row { min-height: 54px; padding-block: 3px; }
.rows--build .row__main { grid-template-columns: 1fr; }
.judge-note--line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.9rem; }

/* Check-in rows open in place. */
.row--expand { display: block; padding: 0; }
.row--expand.is-done { border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.row--expand[open] { border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.row__summary { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-height: 60px; padding: 6px 14px; list-style: none; cursor: pointer; }
.row__summary::-webkit-details-marker { display: none; }
.row--expand[open] .row__go { transform: rotate(90deg); }

.measure { display: grid; gap: 0.75rem; padding: 0.25rem 14px 14px; }
.measure input[type="number"] { font-family: var(--display); font-size: 1.8rem !important; font-weight: 300; }

.chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 0; padding: 0; border: 0; }
.chips--eighths { grid-template-columns: repeat(8, 1fr); }
.chips legend { padding: 0; margin-bottom: 0.35rem; font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.chip { position: relative; }
.chip input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.chip span {
  display: grid;
  place-items: center;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-family: var(--display);
  font-weight: 300;
  font-size: 1.2rem;
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; box-shadow: var(--glow-soft); }
.chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- Racing ----------------------------------------------------------------------- */

/* The race being run is the one glowing card on the judge's phone. */
.race-control {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 22px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--surface);
  box-shadow: var(--glow-soft);
}

.race-control__title { display: flex; align-items: baseline; gap: 0.7rem; padding: 2px 4px 0; color: var(--muted); font-size: 0.95rem; }
.race-control__title span { color: var(--ink); font-weight: 800; font-style: italic; font-size: 2rem; line-height: 1; text-transform: uppercase; }
.race-control form.button_to { margin: 0; }

.button--winner {
  width: 100%;
  min-height: 100px;
  justify-content: flex-start;
  gap: 0.85rem;
  padding-inline: 1rem;
  border-radius: 16px;
  border: 1.5px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--ink);
  text-align: left;
  transition: background 0.15s;
}

.button--lane-2 { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 8%, transparent); }
.button--winner:active { background: color-mix(in srgb, var(--accent) 24%, transparent); }
.button--lane-2:active { background: color-mix(in srgb, var(--gold) 22%, transparent); }

.button__faces { font-size: 1.65rem; }
.button__stack { display: grid; justify-items: start; gap: 0.35rem; min-width: 0; }
.button__name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.45rem; font-weight: 700; font-style: italic; line-height: 1.1; }
.button--winner .lane { font-size: 0.72rem; }

.on-deck-card { display: grid; gap: 2px; padding: 12px 16px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); }
.on-deck-card .eyebrow { color: var(--gold); }

.corrections { list-style: none; margin: 0.75rem 0 0; padding: 0; display: grid; gap: 0.6rem; }
.corrections__item { display: grid; gap: 0.45rem; justify-items: start; padding-top: 0.6rem; border-top: 1px solid var(--hairline); }

.correction__swap { font-size: 1.2rem; }
.correction__cleared { margin: 0; padding-left: 1.2rem; display: grid; gap: 0.3rem; color: var(--gold); }

/* --- Bottom bar ------------------------------------------------------------------- */

.judge-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  gap: 8px;
  padding: 10px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--hairline);
}

.judge-bottom > * { width: 100%; max-width: 528px; margin-inline: auto; }
.judge-bottom .button--go { min-height: 58px; font-size: 1.15rem; }
.judge-bottom .button--go.is-armed { --slant-fill: var(--gold); --slant-glow: var(--glow-gold); animation: pulse 0.8s ease-in-out infinite alternate; }
.judge-bottom__row { display: grid; grid-template-columns: 72px 1fr; gap: 8px; }
.judge-bottom__row .button { width: 100%; min-height: 58px; }

.races-left { display: grid; gap: 8px; padding: 12px 16px 14px; border-radius: 16px; background: var(--surface-2); }
.races-left__count { display: flex; align-items: baseline; gap: 0.6rem; }
.races-left__n { font-size: 2rem; font-weight: 200; line-height: 1; font-variant-numeric: tabular-nums; }
.races-left__label { font-size: 0.8rem; font-weight: 500; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.races-left__run { margin-left: auto; font-size: 0.85rem; font-weight: 300; color: var(--muted); }
.races-left__bar { position: relative; display: block; height: 6px; border-radius: 3px; background: rgb(159 184 170 / 0.18); }
.races-left__bar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--done); border-radius: 3px; background: var(--accent); box-shadow: 0 0 10px rgb(64 209 52 / 0.6); }

.undo-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 6px 6px 6px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  animation: undo-flash 1.2s ease-out;
}

.undo-strip__text { font-size: 0.92rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@keyframes undo-flash { from { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface-solid)); } }
@keyframes pulse { to { filter: brightness(1.15); } }

/* --- Menu pages ------------------------------------------------------------------- */

.roster { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.roster__item { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--hairline); }
.roster__form { display: flex; gap: 0.4rem; flex: 1 1 14rem; }
.roster__meta { font-size: 0.8rem; color: var(--muted); flex: 1 1 auto; }
.grow { flex: 1 1 auto; font-weight: 500; }

.warnings { margin: 0; padding-left: 1.1rem; color: var(--gold); display: grid; gap: 0.3rem; font-size: 0.92rem; }
.preview { font-size: 1.15rem; font-weight: 500; color: var(--accent); }

.log { list-style: none; margin: 0; display: grid; gap: 0.45rem; font-size: 0.9rem; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 0.4rem; }
.log .is-undone { opacity: 0.55; }

.team-edit { display: grid; grid-template-columns: auto 1fr auto; gap: 0.5rem; align-items: center; font-size: 1.1rem; }
.team-edit input { min-width: 0; font-size: 1rem; }
.roster__form { align-items: center; }

/* Toasts sit under the top bar so they never cover the big bottom button. */
body.judge .toasts { top: calc(66px + env(safe-area-inset-top)); bottom: auto; }
