@font-face {
  font-family: "Grenze Gotisch";
  src: url("/fonts/grenze-gotisch.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Grenze";
  src: url("/fonts/grenze-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Grenze";
  src: url("/fonts/grenze-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

:root {
  --basalt: #23272f;
  --travertine: #dedbcf;
  --gold: #e8b21f;
  --error-on-basalt: #ffa694;
  --error-on-travertine: #9c1c14;
  --danger: #d7362a;
  --danger-hover: #bd2c21;
  --display: "Grenze Gotisch", "Grenze", Georgia, serif;
  --text: "Grenze", Georgia, serif;
  --code: ui-monospace, "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--basalt);
  color: var(--travertine);
  font-family: var(--text);
  font-size: 1.1875rem;
  line-height: 1.4;
}

h1, h2, p { margin: 0; }

[hidden] { display: none !important; }

.band {
  --bg: var(--basalt);
  --fg: var(--travertine);
  --error: var(--error-on-basalt);
  background: var(--bg);
  color: var(--fg);
}

#challenges > .band:nth-child(odd),
dialog {
  --bg: var(--travertine);
  --fg: var(--basalt);
  --error: var(--error-on-travertine);
  color-scheme: light;
}

.inner {
  width: min(100%, 78rem);
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2.5rem);
}

/* Le fasce sottili si allargano fino alla prima challenge, come i corsi di
   basalto e travertino sui fianchi del Duomo. */
.courses {
  height: 4.5rem;
  background: linear-gradient(
    to bottom,
    var(--travertine) 0 3%, var(--basalt) 3% 7%,
    var(--travertine) 7% 14%, var(--basalt) 14% 22%,
    var(--travertine) 22% 36%, var(--basalt) 36% 52%,
    var(--travertine) 52%
  );
}

h1 {
  font-family: var(--display);
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

h2 {
  font-family: var(--display);
  font-weight: 500;
  line-height: 1;
  overflow-wrap: anywhere;
}

input {
  min-width: 0;
  min-height: 3rem;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--fg);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
}

input::placeholder { color: var(--fg); opacity: 0.72; }

button {
  flex: 0 0 auto;
  min-height: 3rem;
  padding: 0.5rem 1.125rem;
  border: 2px solid var(--fg);
  border-radius: 0;
  background: var(--fg);
  color: var(--bg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.quiet {
  background: transparent;
  color: var(--fg);
}

button:hover:not(:disabled) {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--basalt);
}

button:disabled { opacity: 0.6; cursor: progress; }

:focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 2px;
}

input:focus-visible { outline-color: var(--fg); }

.message {
  margin-top: 0.4rem;
  font-weight: 600;
}

.message:empty { margin-top: 0; }

.message[data-tone="error"],
.status[data-tone="error"] {
  color: var(--error);
  font-weight: 600;
}

.status { padding-block: 1.5rem; min-height: 4.75rem; }

.empty { margin: 0; padding-block: 2.5rem; }

.empty .inner { display: block; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Vista studenti */

.masthead { padding-block: 1.25rem clamp(2rem, 4vw, 3rem); }

.masthead-grid {
  display: grid;
  gap: 1.5rem;
}

.masthead h1 { font-size: clamp(3.5rem, 11vw, 8rem); }

.lede {
  margin-top: 0.75rem;
  font-size: clamp(1.25rem, 2.2vw, 1.625rem);
  max-width: 34ch;
}

.attribution { margin-top: 0.75rem; max-width: 60ch; }

.attribution a,
.next-steps a {
  color: inherit;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
}

.next-steps { padding-block: clamp(2rem, 4vw, 3rem) 0; }

.next-steps h2 { font-size: clamp(2.25rem, 5vw, 3.5rem); }

.next-steps p { margin-top: 0.75rem; max-width: 60ch; }

.next-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  font-weight: 600;
}

.identity {
  --identity-box: 2rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem 0.625rem;
  justify-self: end;
  overflow-wrap: anywhere;
}

.identity strong {
  display: flex;
  align-items: center;
  min-height: var(--identity-box);
  padding: 0 0.5em;
  background: var(--travertine);
  color: var(--basalt);
  font-weight: 600;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: var(--identity-box);
  height: var(--identity-box);
  min-height: 0;
  padding: 0;
}

.icon-button svg { width: 1.125rem; height: 1.125rem; }

.challenge { padding-block: clamp(2rem, 4vw, 3rem); }

.challenge-grid {
  display: grid;
  gap: 1.5rem;
  align-items: center;
}

.challenge h2 { font-size: clamp(2.75rem, 5.5vw, 4.25rem); }

.link-button {
  min-height: 0;
  margin-top: 0.5rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
}

.link-button:hover:not(:disabled) {
  border: 0;
  background: none;
  color: inherit;
  text-decoration-thickness: 4px;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.field-row input { flex: 1 1 12rem; }

.flag-input { font-family: var(--code); font-size: 1rem; }

.solved {
  display: flex;
  align-items: center;
  min-height: 3rem;
  padding: 0.5rem 0.75rem;
  background: var(--fg);
  color: var(--bg);
  font-weight: 600;
}

dialog {
  width: min(calc(100vw - 2rem), 30rem);
  padding: clamp(1.25rem, 4vw, 2rem);
  border: 0;
  background: var(--bg);
  color: var(--fg);
}

dialog::backdrop { background: rgb(35 39 47 / 0.88); }

dialog h2 { font-size: 3rem; }

#nick-hint { margin-top: 0.5rem; }

#challenge-dialog { width: min(calc(100vw - 2rem), 42rem); }

#challenge-title:focus { outline: none; }

.markdown { margin-top: 0.75rem; overflow-wrap: anywhere; }

.markdown > * { margin-block: 0.75rem; }

.markdown > :first-child { margin-top: 0; }

.markdown > :last-child { margin-bottom: 0; }

.markdown h3 {
  margin: 1.25rem 0 0.25rem;
  font-size: inherit;
  font-weight: 600;
}

.markdown ul,
.markdown ol { padding-left: 1.5rem; }

.markdown hr {
  margin-block: 1.5rem 0.75rem;
  border: 0;
  border-top: 2px solid var(--fg);
}

dialog a {
  color: inherit;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
}

code, pre { font-family: var(--code); font-size: 0.875em; }

code {
  padding: 0.1em 0.35em;
  background: var(--basalt);
  color: var(--travertine);
}

pre {
  padding: 0.75rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--basalt);
  color: var(--travertine);
}

dialog label {
  display: block;
  margin-top: 1.25rem;
  margin-bottom: 0.375rem;
  font-weight: 600;
}

dialog input { width: 100%; }

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Amministrazione */

.admin { padding-block: clamp(2rem, 4vw, 3rem); }

.admin h2 { font-size: clamp(2.25rem, 5vw, 3.5rem); }

.admin label { display: block; margin-block: 0.75rem 0.375rem; font-weight: 600; }

.admin label.visually-hidden { margin: 0; }

.admin-nav {
  --identity-box: 3rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--fg);
}

.admin-tabs,
.admin-actions {
  display: flex;
  gap: 0.25rem;
}

.admin-message { margin: -1rem 0 1.5rem; }

.admin-message:empty { display: none; }

.admin-tabs button {
  border-bottom: 0;
  background: transparent;
  color: var(--fg);
}

.admin-tabs button[aria-selected="true"] {
  background: var(--fg);
  color: var(--bg);
}

.admin-section + .admin-section { margin-top: clamp(2.5rem, 5vw, 4rem); }

.admin-section > p { margin-block: 0.75rem; }

.admin-players {
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.admin-new { margin-top: 1rem; }

.admin-challenge {
  --identity-box: 2.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-block: 0.625rem;
  border-top: 1px solid var(--fg);
}

.admin-order { display: grid; gap: 0.125rem; }

.admin-order button {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 1.375rem;
  min-height: 0;
  padding: 0;
  border-color: transparent;
}

.admin-order svg { width: 1.5rem; height: 0.75rem; }

.admin-order button:disabled { opacity: 0.35; cursor: default; }

.admin-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.admin-count { flex: 0 0 auto; white-space: nowrap; }

.with-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.with-icon svg { flex: none; width: 1.125rem; height: 1.125rem; }

.hover-danger:hover:not(:disabled),
.admin-challenge [data-delete]:hover:not(:disabled) {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

#edit-dialog { width: min(calc(100vw - 2rem), 48rem); }

#edit-dialog textarea {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--fg);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-family: var(--code);
  font-size: 0.875em;
  resize: vertical;
}

#edit-dialog textarea:focus-visible { outline-color: var(--fg); }

#delete-text { margin-top: 0.75rem; }

button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

button.danger:hover:not(:disabled) {
  border-color: var(--danger-hover);
  background: var(--danger-hover);
  color: #fff;
}

.reset-intro { margin-top: 0.75rem; }

dialog label.reset-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.75rem;
  margin-block: 0.75rem;
  padding: 0.75rem;
  border: 2px solid var(--fg);
  font-weight: 400;
  cursor: pointer;
}

dialog label.reset-option:has(:checked) { border-color: var(--danger); }

dialog .reset-option input {
  width: 1.125rem;
  height: 1.125rem;
  min-height: 0;
  margin: 0.2rem 0 0;
  accent-color: var(--danger);
}

.reset-option strong { display: block; font-weight: 600; }

.board-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin-top: 0.75rem;
}

.board-filters input { flex: 1 1 14rem; }

/* Pannello a destra: lo sfondo è leggero per vedere la tabella che cambia. */
#filter-dialog {
  width: min(100vw, 26rem);
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0 0 0 auto;
  padding: 0;
  animation: filter-open 180ms ease-out;
}

#filter-dialog::backdrop { background: rgb(35 39 47 / 0.45); }

@keyframes filter-open {
  from { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
  #filter-dialog { animation: none; }
}

.filter-panel { min-height: 100%; padding: clamp(1.25rem, 4vw, 2rem); }

.filter-section {
  min-width: 0;
  margin: 1.5rem 0 0;
  padding: 0;
  border: 0;
}

.filter-section legend {
  margin-bottom: 0.5rem;
  padding: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Due slider nativi sovrapposti: il riquadro lascia passare i clic e solo i pallini li prendono. */
.filter-slider {
  --thumb: 1.375rem;
  --span: calc(100% - var(--thumb));
  position: relative;
  height: 2.5rem;
}

.filter-slider::before,
.filter-slider::after {
  content: "";
  position: absolute;
  top: calc(50% - 0.125rem);
  height: 0.25rem;
  background: var(--fg);
}

.filter-slider::before { inset-inline: 0; opacity: 0.25; }

.filter-slider::after {
  left: calc(var(--low, 0) * var(--span) + var(--thumb) / 2);
  right: calc((1 - var(--high, 0)) * var(--span) + var(--thumb) / 2);
}

#filter-dialog .filter-slider input {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  min-height: 0;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  appearance: none;
  background: transparent;
  pointer-events: none;
}

.filter-slider input::-webkit-slider-runnable-track { background: transparent; }

.filter-slider input::-moz-range-track { background: transparent; }

.filter-slider input::-webkit-slider-thumb {
  width: var(--thumb);
  height: var(--thumb);
  border: 3px solid var(--bg);
  border-radius: 50%;
  appearance: none;
  background: var(--fg);
  cursor: grab;
  pointer-events: auto;
}

.filter-slider input::-moz-range-thumb {
  box-sizing: border-box;
  width: var(--thumb);
  height: var(--thumb);
  border: 3px solid var(--bg);
  border-radius: 50%;
  background: var(--fg);
  cursor: grab;
  pointer-events: auto;
}

.filter-slider input:focus-visible::-webkit-slider-thumb { outline: 3px solid var(--fg); outline-offset: 1px; }

.filter-slider input:focus-visible::-moz-range-thumb { outline: 3px solid var(--fg); outline-offset: 1px; }

.filter-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.filter-choices label {
  position: relative;
  margin: 0;
  font-weight: 600;
  cursor: pointer;
}

.filter-choices span {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 3rem;
  padding: 0.5rem;
  border: 2px solid var(--fg);
  text-align: center;
}

.filter-choices input:checked + span {
  background: var(--fg);
  color: var(--bg);
}

.filter-choices input:focus-visible + span { outline: 3px solid var(--fg); outline-offset: 2px; }

.filter-checks { margin-top: 0.75rem; }

.filter-checks label {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  margin: 0;
  padding-block: 0.375rem;
  font-weight: 400;
  overflow-wrap: anywhere;
  cursor: pointer;
}

#filter-dialog .filter-checks input {
  flex: 0 0 auto;
  width: 1.25rem;
  min-height: 0;
  height: 1.25rem;
  margin: 0.125rem 0 0;
  accent-color: var(--fg);
}

#filter-dialog .dialog-actions { margin-top: 2rem; }

/* Scorre dentro il riquadro: intestazione e nickname restano sempre in vista. */
.board-scroll {
  position: relative;
  max-height: 75vh;
  margin-top: 1rem;
  overflow: auto;
}

.admin-board {
  --identity-box: 2.25rem;
  --rank-width: 3rem;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.admin-board th,
.admin-board td {
  padding: 0.375rem 0.625rem;
  border-top: 1px solid var(--fg);
  text-align: left;
  white-space: nowrap;
}

.admin-board thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  border-top: 0;
  border-bottom: 2px solid var(--fg);
  background: var(--bg);
  vertical-align: bottom;
}

.admin-board tbody tr:first-child > * { border-top: 0; }

.admin-board .board-rank,
.admin-board .board-name {
  position: sticky;
  background: var(--bg);
}

/* Larghezza fissa: il nome si ferma esattamente dove finisce la posizione. */
.admin-board .board-rank {
  left: 0;
  width: var(--rank-width);
  min-width: var(--rank-width);
  padding-inline: 0.5rem;
}

.admin-board .board-name {
  left: var(--rank-width);
  max-width: 17rem;
  padding-left: 0;
}

.admin-board thead .board-rank,
.admin-board thead .board-name { z-index: 2; }

.admin-board thead .board-name { padding-left: calc(var(--identity-box) + 0.375rem); }

.board-player {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.board-player span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.board-player button { flex: 0 0 auto; border: 0; }

/* Da telefono la parte fissa non deve coprire le challenge: il nome intero resta nel tooltip. */
@media (max-width: 40rem) {
  .board-player span { max-width: 6.5rem; }
}

.admin-board .board-score { font-weight: 600; }

.admin-board .board-cell {
  min-width: 5.5rem;
  max-width: 8rem;
  border-left: 2px solid var(--bg);
  font-size: 0.875em;
  text-align: center;
  white-space: normal;
}

.board-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.375em;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: inherit;
}

.board-sort:hover:not(:disabled) {
  border: 0;
  background: transparent;
  color: var(--gold);
}

.board-sort[data-direction]::after {
  content: "";
  flex: none;
  width: 0.45em;
  height: 0.45em;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
}

.board-sort[data-direction="up"]::after { transform: translateY(0.1em) rotate(225deg); }

.board-sort[data-direction="down"]::after { transform: translateY(-0.1em) rotate(45deg); }

.board-datetime { display: block; line-height: 1.25; }

.board-title {
  min-width: 0;
  overflow-wrap: anywhere;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.admin-board td.board-cell[data-solved] {
  background: var(--gold);
  color: var(--basalt);
  font-weight: 600;
}

.admin-board .board-rank,
.admin-board .board-score,
.admin-board .board-last,
.admin-board .board-actions { text-align: center; }

.admin-board [data-delete]:hover:not(:disabled) {
  border-color: var(--error-on-travertine);
  background: var(--error-on-travertine);
  color: #fff;
}

/* Vista da trasmettere: riempie lo schermo e si legge da lontano. */

.live-head { padding-block: 1rem 0.75rem; }

.live-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 2rem;
}

.live-head h1 {
  margin-right: auto;
  font-size: clamp(2.75rem, 9vh, 6rem);
}

.players { font-size: clamp(1.25rem, 3.5vh, 2.25rem); font-weight: 600; }

.live .status:empty { display: none; }

.live .empty { font-size: clamp(1.25rem, 3.5vh, 2.25rem); }

.live .status {
  padding-block: 0;
  min-height: 0;
  font-size: clamp(1rem, 2vh, 1.375rem);
}

.live .courses { height: clamp(2.25rem, 5vh, 3.5rem); }

.live-row {
  display: flex;
  align-items: center;
  padding-block: 1.25rem;
}

.live-grid {
  display: grid;
  gap: 1rem;
  align-items: center;
}

.live-row h2 { font-size: clamp(2.5rem, min(7vh, 4.2vw), 5rem); }

.progress-count {
  margin-bottom: 0.375rem;
  font-size: clamp(1.375rem, 3.75vh, 2.5rem);
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: lining-nums tabular-nums;
}

/* Traccia scura su entrambe le fasce: l'oro sul travertino non si leggerebbe. */
.progress-track {
  height: clamp(1.25rem, 3.5vh, 2.25rem);
  border: 2px solid var(--fg);
  background: var(--basalt);
}

.progress-fill {
  min-width: 0.375rem;
  height: 100%;
  background: var(--gold);
  transition: width 900ms ease-out;
}

.top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.125rem 0;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: clamp(1.0625rem, min(2.6vh, 1.5vw), 1.75rem);
  line-height: 1.25;
}

.top li {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  column-gap: 0.75em;
  align-items: center;
  padding-inline: 0.625rem;
  font-weight: 600;
}

.top li > :first-child { white-space: nowrap; }

/* Il nome non va mai a capo: le cinque righe devono restare dentro lo schermo. */
.top-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.top-time { font-weight: 400; font-variant-numeric: lining-nums tabular-nums; }

/* La tessera del mosaico: resta dorata su entrambe le fasce. */
.top li:first-child {
  padding-block: 0.125rem;
  background: var(--gold);
  color: var(--basalt);
}

.top li:first-child .top-name {
  font-family: var(--display);
  font-size: clamp(1.5rem, min(4.25vh, 2.4vw), 3rem);
  line-height: 1.1;
}

.top li:first-child .top-name[data-long] { font-size: clamp(1.25rem, min(3vh, 1.7vw), 2.25rem); }

.top li[data-fresh] { animation: tessera 900ms ease-out; }

@keyframes tessera {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

@media (min-width: 60rem) {
  .masthead-grid { grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
  .identity { grid-column: 2; grid-row: 1; }
  .challenge-grid { grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); gap: 2.5rem; }

  body.live {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
  }
  .live main {
    flex: 1;
    display: grid;
    grid-auto-rows: 1fr;
  }
  .live-row { padding-block: 0.5rem; }
  .live-row h2 { grid-area: title; }
  .live-row .top { grid-area: top; }
  .live-row .progress { grid-area: bar; }
  .live-grid {
    grid-template-columns: minmax(0, 3.5fr) minmax(0, 8fr) minmax(0, 8.5fr);
    grid-template-areas: "title top bar";
    gap: 2.5rem;
  }
  .live .inner { width: 100%; }
}

@media (min-width: 80rem) {
  .live-grid { grid-template-columns: minmax(0, 4fr) minmax(0, 7fr) minmax(0, 9fr); }
}

@media (prefers-reduced-motion: reduce) {
  .top li[data-fresh] { animation: none; }
  .progress-fill { transition: none; }
}
