/* ---- Colours ---- */

:root {
  color-scheme: light dark;
  /* Sign, pictogram, phase and marker colours stay the same in both themes, like real signs. */
  --sign-green: #00704a;
  --warn: #e67700;
  --lose: #b3261e;
  --clue: #1c6dd0;
  --marker: #d9480f;
  /* Interface colours, redefined below for dark mode. */
  --ink: #1d2327;
  --muted: #5b6770;
  --card: #ffffffee;
  --surface: #fff;
  --track: #d5ddd9;
  --page: #dfe6e2;
}

/* Declaring a dark theme also stops mobile browsers from force-darkening the page. */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e4e9e6;
    --muted: #a2afa9;
    --card: #1e2427ee;
    --surface: #2a3134;
    --track: #424d49;
    --page: #161a1c;
  }
}

/* ---- Base ---- */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--page);
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

#map {
  position: fixed;
  inset: 0;
}

#map.playing {
  cursor: crosshair;
}

/* ---- Signs: the pôle's, the neighbours' and the home screen title ---- */

.sign {
  min-height: 64px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sign-green);
  color: #fff;
  border-radius: 8px;
  outline: 3px solid #fff;
  outline-offset: -7px;
  font-family: "Arial Narrow", "Roboto Condensed", Arial, sans-serif;
  font-weight: 700;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.sign-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Pôles that are not towns, in italics like in the JO. */
.sign-line.italics {
  font-style: italic;
}

.sign-plane {
  flex: none;
  width: 1.4em;
  height: 1.4em;
}

/* Small signs for the neighbours. */
.mini-sign {
  display: inline-flex;
  vertical-align: middle;
  min-height: 0;
  /* Names are in capitals, so they sit high: more room on top than below. */
  padding: 5px 8px 3px;
  border-radius: 4px;
  outline-width: 1.5px;
  outline-offset: -3.5px;
  font-size: 0.8rem;
}

.mini-sign .sign-line {
  gap: 4px;
}

/* ---- Top centre: the pôle's sign and its neighbours ---- */

#top {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  /* Clear of the zoom buttons. */
  width: min(420px, calc(100% - 120px));
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: center;
  background: var(--card);
  border-radius: 10px;
  box-shadow: 0 4px 18px #0003;
}

/* Nothing to show before the first pôle. */
#top:has(#sign:empty) {
  display: none;
}

/* A miss ends the game: the signs turn red, like the timer. */
.lost #top .sign {
  background: var(--lose);
}

.clues {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-height: 30vh;
  overflow-y: auto;
}

/* New neighbours: the screen edges glow once. */
#flash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 80px 24px var(--clue);
}

#flash.flashing {
  animation: flash 0.9s ease-out;
}

@keyframes flash {
  from {
    opacity: 0.85;
  }

  to {
    opacity: 0;
  }
}

/* ---- Bottom centre: clue button, map button over the score, timer ---- */

#bottom {
  position: fixed;
  left: 12px;
  right: 12px;
  /* Above the map credits. */
  bottom: 28px;
  z-index: 1000;
  display: grid;
  grid-template-columns: 1fr auto auto auto 1fr;
  grid-template-areas: ". clue middle timer .";
  align-items: center;
  gap: 20px;
  /* The map stays clickable around the controls. */
  pointer-events: none;
}

#bottom>* {
  pointer-events: auto;
}

.clue-dial {
  grid-area: clue;
}

.middle {
  grid-area: middle;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.timer {
  grid-area: timer;
}

/* Round buttons: clue and timer. */
.dial {
  width: 96px;
  height: 96px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 4px 14px #0004;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.dial:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: 0 6px 18px #0005;
}

.dial:not(:disabled):active {
  transform: scale(0.97);
}

.dial:disabled {
  cursor: default;
  opacity: 0.6;
}

.dial svg {
  display: block;
  width: 100%;
  height: 100%;
}

.timer-track,
.timer-arc,
.clue-segment {
  fill: none;
  stroke-width: 8;
}

/* Timer: ring and icon green, then orange, then red as time runs out. */
.timer {
  --timer-color: var(--sign-green);
}

.timer[data-phase="1"] {
  --timer-color: var(--warn);
}

.timer[data-phase="2"] {
  --timer-color: var(--lose);
}

.lost .timer {
  --timer-color: var(--lose);
}

.timer-track {
  stroke: var(--track);
}

.timer-arc {
  stroke: var(--timer-color);
}

.timer-icon {
  fill: var(--timer-color);
  stroke: var(--timer-color);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#timer-check,
#timer-next,
#timer-restart {
  fill: none;
}

/* Clue button: a "?" in a ring of one segment per clue left in the stock. */
.clue-segment {
  stroke: var(--clue);
}

.clue-segment.spent {
  stroke: var(--track);
}

.clue-mark {
  fill: var(--clue);
  font: 700 46px system-ui, sans-serif;
  text-anchor: middle;
  dominant-baseline: central;
}

.clue-dial.empty .clue-mark {
  fill: var(--track);
}

/* No neighbour left: the button shakes its head and its "?" greys for a moment. */
.clue-dial.nothing {
  animation: shake-no 0.4s ease-in-out;
}

.clue-dial.nothing .clue-mark {
  animation: grey-out 0.6s ease-out;
}

@keyframes shake-no {

  20%,
  60% {
    transform: translateX(-8px);
  }

  40%,
  80% {
    transform: translateX(8px);
  }
}

@keyframes grey-out {

  from,
  50% {
    fill: var(--track);
  }
}

/* Map button: a small round button. */
.small-button {
  width: 40px;
  height: 40px;
  padding: 9px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  box-shadow: 0 2px 8px #0003;
  cursor: pointer;
}

.small-button svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.small-button:hover {
  color: var(--ink);
}

.dial:focus-visible,
.small-button:focus-visible,
.start-button:focus-visible,
.lang-switch a:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* Map areas, opened centred above the map button (placed by game.js). */
.areas {
  position: fixed;
  inset: auto;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px;
  border: none;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 4px 18px #0004;
}

.areas:popover-open {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.areas button {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
}

.areas button:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

/* Score: pôles found in this game. */
.score {
  width: 56px;
  height: 56px;
  padding: 4px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 2px 8px #0003;
}

.score svg {
  display: block;
  width: 100%;
  height: 100%;
}

.score-track {
  fill: none;
  stroke-width: 10;
  stroke: var(--track);
}

.score-value {
  font-size: 40px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  fill: var(--ink);
  text-anchor: middle;
  dominant-baseline: central;
}

.score.pop {
  animation: score-pop 0.5s ease-out;
}

@keyframes score-pop {
  50% {
    transform: scale(1.25);
  }
}

/* ---- Home screen, over the map: before the first game and after each one ---- */

.home {
  position: fixed;
  inset: 0;
  z-index: 2000;
  overflow-y: auto;
  padding: 24px 12px;
  background: color-mix(in srgb, var(--page) 85%, transparent);
  backdrop-filter: blur(3px);
}

.home-card {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 8px 30px #0005;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* FR | EN, top right of the card: links to the page in each language, its own raised. */
.lang-switch {
  align-self: flex-end;
  margin-bottom: -8px;
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.lang-switch a {
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
}

.lang-switch a[aria-current="page"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px #0003;
}

.home-title {
  margin: 0;
  width: 100%;
}

.home-pitch {
  margin: 0;
  text-align: center;
  color: var(--muted);
}

.start-button {
  padding: 12px 48px;
  border: none;
  border-radius: 999px;
  background: var(--sign-green);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px #0004;
}

.start-button:disabled {
  cursor: default;
  opacity: 0.6;
}

.load-error {
  margin: 0;
  color: var(--lose);
  font-weight: 600;
}

/* Help and credits, folded. */
.home-section {
  align-self: stretch;
}

.home-section summary {
  cursor: pointer;
  font-weight: 700;
}

.home-section li {
  margin-bottom: 6px;
}

.credits {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Miniatures of the timer, clue and map buttons in the help text. */
.mini-dial {
  width: 1.7em;
  height: 1.7em;
  vertical-align: middle;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 4px #0004;
}

.mini-dial .timer-arc {
  stroke: var(--sign-green);
}

.mini-dial .timer-icon {
  fill: none;
  stroke: var(--sign-green);
}

.mini-map {
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Reduced motion ---- */

@media (prefers-reduced-motion: reduce) {

  #flash.flashing,
  .score.pop,
  .clue-dial.nothing {
    animation: none;
  }
}

/* ---- Narrow screens ---- */

@media (max-width: 600px) {
  #top {
    top: 8px;
    width: calc(100% - 16px);
    padding: 10px;
    gap: 6px;
  }

  #sign {
    font-size: 1.3rem;
    min-height: 52px;
  }

  /* ? and timer under the thumbs. */
  #bottom {
    left: 8px;
    right: 8px;
    column-gap: 10px;
  }

  .dial {
    width: 80px;
    height: 80px;
  }

  .middle {
    gap: 4px;
  }

  .small-button {
    width: 36px;
    height: 36px;
    padding: 8px;
  }

  .score {
    width: 48px;
    height: 48px;
  }

  .clues {
    max-height: 22vh;
  }

  /* Pinch to zoom instead. */
  .leaflet-control-zoom {
    display: none;
  }
}
