/* Sams Schatzsuche: Himmel-Grund, Brett als Seekarte, Stifte und die Rollen der
   Karte (--karte-*), die es in den Tokens nicht gibt. */

/* Berkshire Swash (Titel, Menüknöpfe), Alegreya Sans (Text) und Fira Sans (Zahlen),
   selbst gehostet, OFL. */
@font-face {
  font-family: "Berkshire Swash";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/berkshire-swash-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Alegreya Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/alegreya-sans-400-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Alegreya Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/alegreya-sans-700-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Fira Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/fira-sans-700-latin.woff2") format("woff2");
}

/* Alegreya Sans hat Mediävalziffern als Standard; Zahlen im Text stehen gleich hoch. */
body {
  font-feature-settings: "lnum";
}

:root {
  /* Gemessen an der Ergebnis-Karte: Rand, Titel, Sam über der Folie, Punkte, zwei Knöpfe. */
  --fan-reserve: 15rem;
  --result-overlap: 4.5rem;
  /* Pastell-Himmel als Papier unter dem Grund */
  --ground-paper: var(--color-bg);
  /* Berkshire Swash setzt keine Ziffern. Große Zahlen stehen in Fira Sans: Ihre
     Ziffern sind von Haus aus gleich hoch, auch auf dem Canvas der Teilen-Tafel,
     wo "lnum" nicht greift. */
  --font-number: "Fira Sans", var(--font-ui);
  --font-number-weight: 700;
  --share-number-size: 260px;
  /* Das n der Berkshire Swash liest sich wie ein eta: Adresse in Alegreya Sans. */
  --share-address-font: var(--font-ui);
  --share-address-weight: 700;
  --hl: color-mix(in srgb, var(--pin-sea) 30%, transparent);
  --grid-line: color-mix(in srgb, var(--pin-indigo) 28%, transparent);
  --grid-line-strong: color-mix(in srgb, var(--pin-indigo-deep) 75%, transparent);
  --wrong-text: var(--pin-rust-deep);

  /* Seekarte: Brett und Meer */
  --karte-pergament: var(--pin-parchment);
  --karte-rand: color-mix(in srgb, #965f28 40%, transparent);
  --karte-meer: var(--pin-sea);
  --karte-flachwasser: #a9d3e8;
  --karte-welle: #5e8fbf;
  --karte-schaum: #ffffff;
  --karte-sand: var(--pin-sand);
  --karte-land: var(--pin-land);
  --karte-land-innen: #7e9a55;
  --karte-rost: var(--pin-rust);
  --karte-schiff: #5a3a22;

  /* Landschaft: Bäume, Berge, Orte */
  --karte-stamm: #6b4a2b;
  --karte-wald: #3f5f2a;
  --karte-laub0: #5f7f3a;
  --karte-laub1: #6e8f45;
  --karte-laub2: #56743a;
  --karte-fels: #9c8a5e;
  --karte-fels-kontur: #5a4a2e;
  --karte-schnee: var(--pin-sail);
  --karte-huegel: #7e9a55;
  --karte-huegel-kontur: #4f6e33;
  --karte-vulkan: #8a7a5a;
  --karte-vulkan-kontur: #4a3a2a;
  --karte-lava: var(--pin-rust);
  --karte-rauch: var(--pin-wave);
  --karte-tinte: #4a3020;
  --karte-wand: #f3e7cb;
  --karte-dach0: var(--pin-rust);
  --karte-dach1: #9a5a3a;
  --karte-dach2: #b26a45;
  --karte-reet: #c9a55a;
  --karte-reet-halm: #8a6a2a;
  --karte-rund-dach: #b58a4a;
  --karte-flach0: #f3e7cb;
  --karte-flach1: #ead2a8;
  --karte-flach2: #f1ddc0;
  --karte-spitze: var(--pin-indigo);
  --karte-weg: #cdb37a;
}

/* Himmel mit Wolken, unten Aquarell-Meer: ein festes Element mit dem Bild (kein background-attachment: fixed,
   das iOS ignoriert). Feste Bildbreite statt cover: Die Größe hängt nicht an der Fensterhöhe, die sich am iPhone
   beim Scrollen ändert. Motive wie die Möwen liegen mehr als 240 px (halbe Spaltenbreite) neben der Mitte
   (x 675), also nie unter Kopf, Menü oder Fuß; bei schmalen Fenstern fallen sie aus dem Bild. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url("img/grund.svg") center bottom / 1350px auto no-repeat;
}

/* ---------- Startmenü ---------- */

/* Wortmarke als Schatzkarte (Pfade, Quelle tools/schatz-wortmarke.py). Sam schaut links
   hinter der Karte hervor: hinten Kopf und Oberkörper, vorn die Hände auf der Kante.
   Beide Ebenen aus tools/schatz-sam.py mit gleichem Ursprung, 104 Einheiten = 4,5rem;
   die Kante (y 138) liegt 0,86rem unter der Oberkante des Bildes. */
.start-logo {
  --sam-u: calc(4.5rem / 104);
  position: relative;
  flex-basis: 17.5rem;
  margin-top: 4.3rem;
}
.start-logo .start-mark {
  position: relative;
}
.start-logo .sam-window,
.start-logo .sam-hands {
  position: absolute;
  top: calc(0.86rem - 122 * var(--sam-u));
  left: 12%;
  width: calc(104 * var(--sam-u));
  height: calc(128 * var(--sam-u));
}
/* Fenster bis zur Kante der Karte: Darin taucht Sam ab, darunter ist nichts von ihr zu sehen. */
.start-logo .sam-window {
  height: calc(122 * var(--sam-u));
  overflow: hidden;
}
.start-logo .sam-peek {
  display: block;
  width: 100%;
  height: calc(128 * var(--sam-u));
  transform-origin: 50% 100%;
  animation: sam-versteckt 20s ease-in-out infinite;
}
.start-logo .sam-hands {
  animation: sam-haende 20s ease-in-out infinite;
}
/* Wie Baumi hinter den Büschen: Sam schaut, duckt sich hinter die Karte, taucht wieder auf und
   schaut sich um. Erst gehen die Hände weg, dann Sam; beim Auftauchen umgekehrt. */
@keyframes sam-versteckt {
  from,
  30% {
    transform: none;
  }
  34%,
  50% {
    transform: translateY(100%);
  }
  54%,
  62% {
    transform: none;
  }
  66% {
    transform: rotate(-6deg);
  }
  72% {
    transform: rotate(5deg);
  }
  76%,
  to {
    transform: none;
  }
}
@keyframes sam-haende {
  from,
  29% {
    opacity: 1;
    transform: none;
  }
  31%,
  53% {
    opacity: 0;
    transform: translateY(0.4rem);
  }
  55%,
  to {
    opacity: 1;
    transform: none;
  }
}
html[data-reduced-motion] .start-logo .sam-peek,
html[data-reduced-motion] .start-logo .sam-hands {
  animation: none;
}

/* Sam ist eine Zeichnung mit freiem Grund: ohne Kreis und Schatten des Porträts. */
.portrait {
  border-radius: 0;
  box-shadow: none;
}
/* Sam steht rechts vor der vorderen Folie. */
.portrait-result {
  width: auto;
  height: 6rem;
  margin-right: 0;
  transform: none;
}

/* ---------- Spielansicht ---------- */

.bar h2 {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: var(--text-l);
  color: var(--color-on-bg);
}
/* Überschriften der Neuigkeiten tragen Version und Datum. */
#newsList h3,
.play-size {
  font-family: var(--font-ui);
  font-weight: 700;
}
.code-copy {
  /* Ziffern und Codes nie in der Titelschrift, immer eindeutig in Alegreya Sans. */
  font-family: var(--font-ui);
}

/* Bedienknöpfe in der Textschrift; die Titelschrift bleibt Titeln und dem Startmenü (Rahmen setzt .btn auf --font-display). */
.btn {
  font-family: var(--font-ui);
  font-weight: 700;
}

.infos {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-s);
  font-weight: 700;
  color: var(--color-ink-soft);
}
.timer {
  /* Ziffern nie in der Titelschrift. */
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: var(--text-l);
  font-variant-numeric: tabular-nums;
  color: var(--color-ink);
}

/* Schmaler Rand, damit das Brett bei 375 px möglichst breit wird. */
.board-card {
  padding: var(--space-1) var(--space-2) var(--space-2) var(--space-1);
}

/* ---------- Brett ---------- */

.board {
  display: grid;
  grid-template-columns: auto 1fr;
  font-size: clamp(0.75rem, calc(7.5rem / var(--n)), 1.1rem);
  font-variant-numeric: tabular-nums;
  color: var(--color-ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.clues-cols {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
}
.clues-rows {
  display: grid;
  grid-template-rows: repeat(var(--n), 1fr);
}
.clue-col,
.clue-row {
  display: flex;
  align-items: center;
  font-weight: 700;
  line-height: 1.15;
  border-radius: 4px;
}
.clue-col {
  flex-direction: column;
  justify-content: flex-end;
  padding-bottom: 3px;
}
.clue-row {
  justify-content: flex-end;
  gap: 0.35em;
  padding-right: 5px;
}
/* Jede fünfte Linie auch am Rand betont, wie im Netz. */
.clue-col.five {
  box-shadow: inset -1.5px 0 0 var(--grid-line-strong);
  border-radius: 0;
}
.clue-row.five {
  box-shadow: inset 0 -1.5px 0 var(--grid-line-strong);
  border-radius: 0;
}
.clue-col.is-active,
.clue-row.is-active {
  background: var(--hl);
}
.clue-col.is-hint,
.clue-row.is-hint {
  background: var(--color-hint);
  color: var(--color-ink);
}
/* Erfüllt: durchgestrichen und blasser. Zu viel Land: wellig unterstrichen. Nie nur über die Farbe. */
.is-done b {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  opacity: 0.5;
}
.is-over b {
  text-decoration: underline wavy var(--color-wrong);
  text-underline-offset: 2px;
}
.is-solved .is-done b {
  text-decoration: none;
  opacity: 1;
}

.field {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--karte-pergament);
  border-radius: 4px;
  touch-action: none;
  cursor: pointer;
}
/* Eingebrannter Rand des Pergaments, über der Karte. */
.field::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow:
    inset 0 0 0 2px var(--karte-rand),
    inset 0 0 22px var(--karte-rand);
}
.field > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Billige Vorschau, bis die Karte neu gezeichnet ist; liegt unter ihr und verschwindet hinter dem Land. */
.flat {
  fill: var(--karte-land);
  visibility: hidden;
}
.flat.is-land {
  visibility: visible;
  transform-box: fill-box;
  transform-origin: center;
  animation: land-pop var(--duration-base) var(--ease-out);
}
@keyframes land-pop {
  from {
    transform: scale(0.5);
    opacity: 0.4;
  }
}

/* Tipp: gelbe Fläche mit Rahmen; ein Fehler als gestrichelter Rahmen in Rost. */
.hint-cell {
  fill: var(--color-hint);
  stroke: var(--color-ink);
  stroke-width: 0.6;
  opacity: 0.85;
}
.hint-cell.is-wrong {
  fill: none;
  stroke: var(--color-wrong);
  stroke-width: 1;
  stroke-dasharray: 2 1.2;
  opacity: 1;
}
.hint {
  margin: 0;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-m);
  background: var(--color-hint);
  color: var(--color-ink);
  font-weight: 700;
}
.hint[hidden] {
  display: none;
}
.report {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}
.report-text {
  width: 100%;
  min-height: 10rem;
  padding: var(--space-3);
  border: 0;
  border-radius: var(--radius-m);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-ink);
  background: var(--color-surface);
}
.report-text[hidden] {
  display: none;
}

.cross {
  fill: none;
  stroke: var(--color-wrong);
  stroke-width: 1.2;
  stroke-linecap: round;
  visibility: hidden;
}
.cross.is-shown {
  visibility: visible;
  opacity: 0.45;
}
.water {
  fill: var(--karte-meer);
  shape-rendering: crispEdges;
  visibility: hidden;
}
.water.is-sea {
  visibility: visible;
}
.ripple {
  fill: none;
  stroke: var(--karte-welle);
  stroke-width: 0.8;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  animation: ripple-out 0.8s ease-out both;
}
.ripple.late {
  animation-delay: 160ms;
}
@keyframes ripple-out {
  from {
    transform: scale(0.9);
    opacity: 0.8;
  }
  to {
    transform: scale(2);
    opacity: 0;
  }
}
.is-solved .flat-layer,
.is-solved .ripple-layer,
.is-solved .cross-layer {
  display: none;
}

.grid-line {
  fill: none;
  stroke: var(--grid-line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.grid-line.five {
  stroke: var(--grid-line-strong);
  stroke-width: 1.6;
}

/* Eigene Grafik-Ebene: Die Karte hat teure Filter. Wellen und Land-Pop darunter sollen sie
   nicht bei jedem Bild neu zeichnen lassen, sonst staut sich schnelles Tippen am iPhone. */
.map-layer {
  will-change: transform;
}

/* Gelöst: das Meer blendet ein, danach zeichnet sich die Route. Ohne Bewegung steht alles sofort. */
.map-layer.reveal {
  animation: map-in 0.8s ease-out;
}
@keyframes map-in {
  from {
    opacity: 0;
  }
}
.route-reveal {
  /* Lücke länger als die Route: sonst steht am Ende ein Strich der Länge null, den die runde Kappe als Punkt zeigt. */
  stroke-dasharray: 1 2;
  stroke-dashoffset: 0;
}
.map-layer.reveal .route-reveal {
  stroke-dashoffset: 1;
  animation: route-in 1.2s ease-in-out 0.8s forwards;
}
@keyframes route-in {
  to {
    stroke-dashoffset: 0;
  }
}
html[data-reduced-motion] .map-layer.reveal,
html[data-reduced-motion] .flat.is-land {
  animation: none;
}
html[data-reduced-motion] .map-layer.reveal .route-reveal {
  animation: none;
  stroke-dashoffset: 0;
}

/* ---------- Stift ---------- */

.tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-1);
  margin: 0;
  padding: var(--space-1);
  border: 0;
  background: var(--color-surface);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-raised);
}
.tool {
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-ink-soft);
  cursor: pointer;
}
.tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
}
.tool-fill {
  fill: var(--karte-land);
  stroke-width: 2;
}
.tool-empty {
  stroke-width: 2.8;
}
.tool[aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.tool:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.result-open {
  align-self: stretch;
}
.result {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.actions .btn {
  flex: 1 1 40%;
  padding: 0.6rem 0.3rem;
  border-radius: var(--radius-m);
}
