:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --line: #d3d8e0;
  --text: #131922;
  --muted: #626c7a;
  --accent: #2f6df6;
  --given: #131922;
  --solved: #2f6df6;
  --warn: #b45309;
  --error: #c62b2b;
  --fresh: #12894a;
  --focus: #8a6d1f;
  /* Bimaru: ein Schiffsfeld ist eine Fläche, kein Zeichen — deshalb eine eigene
     Farbe statt einer Schriftfarbe. Wasser bleibt ein zurückhaltender Punkt. */
  --ship: #3b4657;
  --water: #9aa6b5;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131a;
    --surface: #161d27;
    --line: #2a3441;
    --text: #e8edf4;
    --muted: #9aa6b5;
    --accent: #5b93ff;
    --given: #e8edf4;
    --solved: #5b93ff;
    --warn: #e0a44a;
    --error: #ff6b6b;
    --fresh: #3ddc84;
    --focus: #e0c15a;
    --ship: #c3ccd9;
    --water: #5b6675;
  }
}

* {
  box-sizing: border-box;
}

/* Muss die display-Regeln der Komponenten schlagen (.btn, .actions …). */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  /* Ein Zug nach unten am Rasterrand darf nicht die Seite neu laden — der
     Spielstand wäre zwar gesichert, der Schreck bliebe. */
  overscroll-behavior-y: contain;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

.topbar {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 8px;
}

.topbar h1 {
  font-size: 1.45rem;
  margin: 0;
  letter-spacing: -0.02em;
}

/* Auf kleinen Schirmen zählt jede Zeile: der Kopf wird schmaler, sobald es eng wird. */
@media (max-height: 45rem), (max-width: 24rem) {
  .topbar {
    padding: 12px 16px 4px;
  }

  .topbar h1 {
    font-size: 1.2rem;
  }

  .sub {
    font-size: 0.82rem;
  }
}

/* Vom Home-Bildschirm gestartet ist der Titel überflüssig — er steht schon aussen dran. */
@media (display-mode: standalone), (display-mode: minimal-ui) {
  .topbar {
    padding-top: 10px;
  }

  .topbar h1 {
    font-size: 1.1rem;
  }
}

.sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ------------------------------------------------------------ spielauswahl */

/* Zwei Reiter, mehr braucht es nicht. Das laufende Spiel ist kein Link — man kann
   nicht dorthin wechseln, wo man schon ist. */
.games {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.game-link {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
}

.game-link[aria-current='page'] {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

/* ---------------------------------------------------------------- buttons */

/* Auf dem Handy zwei Knöpfe pro Zeile, der wichtigste über die ganze Breite —
   ausgewachsene Ziele statt einer Reihe schmaler Schaltflächen. Was alleine in
   einer Zeile landet, wächst von selbst auf die volle Breite. */
.capture {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 8px;
}

.capture .btn {
  flex: 1 1 calc(50% - 5px);
}

.capture .btn.primary {
  flex-basis: 100%;
}

@media (min-width: 34rem) {
  .capture .btn,
  .capture .btn.primary {
    flex: 0 1 auto;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation; /* kein Doppeltipp-Zoom auf Knöpfen */
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.ghost {
  background: transparent;
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

/* -------------------------------------------------------------- generator */

.gen {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 4px 0 2px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.gen-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.gen .field {
  flex: 1 1 9rem;
  justify-content: space-between;
}

.gen .field.grow {
  flex: 1 1 14rem;
}

.gen .field select,
.gen .field input {
  flex: 1 1 auto;
  min-width: 6rem;
}

.gen .field input {
  min-height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.gen .btn {
  flex: 1 1 100%;
}

@media (min-width: 30rem) {
  .gen .btn {
    flex: 0 0 auto;
  }
}

/* ------------------------------------------------------------ rätsel-code */

.code-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 12px 2px 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.code {
  flex: 1 1 12rem;
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--text);
  user-select: all;
}

.btn.small {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn.icon {
  padding: 0;
  width: 38px;
  flex: 0 0 auto;
}

/* ------------------------------------------------------- hinweis-leiste (PWA) */

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.bar-text {
  flex: 1 1 auto;
  margin: 0;
  font-size: 0.85rem;
  color: var(--text);
}

/* ----------------------------------------------------------------- status */

.status {
  min-height: 1.4em;
  margin: 10px 2px;
  color: var(--muted);
  font-size: 0.95rem;
}

.status.error {
  color: var(--error);
}

.status.ok {
  color: var(--accent);
}

.status.warn {
  color: var(--warn);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

@media (min-width: 34rem) {
  .toolbar {
    justify-content: space-between;
  }
}

.field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.field select {
  min-height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px; /* Fingerbreite, nicht Kästchenbreite */
  font-size: 0.9rem;
  color: var(--muted);
}

.switch input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

/* ------------------------------------------------------------------ board */

/* Quer gehalten oder auf einem kurzen Schirm ist nicht die Breite die Grenze,
   sondern die Höhe: sonst steht das Raster unten aus dem Bild heraus. */
.stage {
  position: relative;
  width: min(100%, 70svh);
  margin-inline: auto;
  aspect-ratio: 1 / 1;
  container-type: inline-size;
}

.photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  object-fit: cover;
}

.board {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 2px;
  padding: 2px;
  background: var(--line);
  border: 2px solid var(--line);
  border-radius: 8px;
  touch-action: manipulation;
}

.board.over-photo {
  background: transparent;
  border-color: rgba(128, 128, 128, 0.6);
  gap: 1px;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 0;
  border-radius: 3px;
  padding: 0;
  color: var(--given);
  /* Die Symbolgrösse hängt an der Zelle, nicht am Bildschirm: ein 4×4 hat
     riesige Zellen, ein 14×14 winzige — mit `vw` bekämen beide dasselbe X.
     Die erste Zeile bleibt als Rückfall für Browser ohne Container-Einheiten. */
  font-size: clamp(12px, 4.2vw, 26px);
  font-size: clamp(11px, calc(60cqw / var(--n, 10)), 40px);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: manipulation;
  min-width: 0;
  min-height: 0;
}

.board.over-photo .cell {
  background: rgba(255, 255, 255, 0.55);
}

@media (prefers-color-scheme: dark) {
  .board.over-photo .cell {
    background: rgba(20, 26, 34, 0.55);
  }
}

/* ---------------------------------------------------- rand und schiffsformen */

/* Bimaru braucht rechts und unten je eine Zellbreite für die Zahlen. Das Brett
   bleibt absolut positioniert und rückt nur ein Stück ein — so gelten alle Regeln
   darüber unverändert weiter, auch die fürs Foto und für den Lösungsweg. */
.stage.edged {
  --edge: calc(100% / (var(--n, 10) + 1));
}

.stage.edged .board {
  inset: 0 var(--edge) var(--edge) 0;
}

.edge {
  position: absolute;
  display: grid;
  color: var(--muted);
  font-size: clamp(9px, calc(52cqw / var(--n, 10)), 30px);
  font-weight: 700;
  line-height: 1;
}

.edge span {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Eine Zahl, die aufgeht, tritt zurück; eine überschrittene meldet sich. Dieselbe
   Sprache wie im Raster, damit man nicht zweierlei lesen muss. */
.edge span.done {
  opacity: 0.35;
}

.edge span.over {
  color: var(--error);
}

.edge-rows {
  top: 0;
  right: 0;
  bottom: var(--edge);
  width: var(--edge);
  grid-template-rows: repeat(var(--n), 1fr);
}

.edge-cols {
  left: 0;
  right: var(--edge);
  bottom: 0;
  height: var(--edge);
  grid-template-columns: repeat(var(--n), 1fr);
}

/* Die Flotte, die beim Spielen abschmilzt. */
.fleet {
  max-width: 720px;
  margin: 10px auto 0;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
}

.fleet.done {
  color: var(--fresh);
  font-weight: 600;
}

/* Ein Schiffsfeld ist eine Fläche, kein Buchstabe: gezeichnet wird ein Block, der
   an der offenen Seite rund ist und zum eigenen Schiff hin flach — so wachsen
   benachbarte Felder optisch zu einem Schiff zusammen. Welche Form ein Feld
   bekommt, entscheidet das Spiel (games/bimaru/shape.js), nicht das Stylesheet. */
.cell[data-shape]::before {
  content: '';
  display: block;
  width: 76%;
  height: 76%;
  background: var(--ship);
}

.cell[data-shape='water']::before {
  width: 18%;
  height: 18%;
  border-radius: 50%;
  background: var(--water);
}

.cell[data-shape='single']::before {
  border-radius: 50%;
}

/* Die Enden: rund nach aussen, und über den Rand der Zelle hinaus zum Nachbarn,
   damit zwischen zwei Feldern desselben Schiffs keine Lücke steht. */
.cell[data-shape='left']::before {
  width: 88%;
  border-radius: 999px 0 0 999px;
  margin-left: 24%;
}

.cell[data-shape='right']::before {
  width: 88%;
  border-radius: 0 999px 999px 0;
  margin-right: 24%;
}

.cell[data-shape='top']::before {
  height: 88%;
  border-radius: 999px 999px 0 0;
  margin-top: 24%;
}

.cell[data-shape='bottom']::before {
  height: 88%;
  border-radius: 0 0 999px 999px;
  margin-bottom: 24%;
}

.cell[data-shape='middle-h']::before {
  width: 100%;
}

.cell[data-shape='middle-v']::before {
  height: 100%;
}

/* Ein vorgegebenes Mittelstück, das noch keine Nachbarn hat, weiss seine Richtung
   nicht — es bleibt ein Quadrat, bis daneben etwas steht. */
.cell[data-shape='middle']::before {
  border-radius: 2px;
}

/* Selbst gesetzte Schiffe in der Lösungsfarbe, damit man sieht, was von einem
   selbst stammt — dasselbe, was bei Binoxxo die Schriftfarbe tut. */
.cell.solved[data-shape]::before {
  background: var(--solved);
}

.cell.solved[data-shape='water']::before {
  background: var(--solved);
  opacity: 0.5;
}

.cell.solved {
  color: var(--solved);
  font-weight: 600;
}

/* Vorgaben eines erzeugten Rätsels: gesperrt, leicht abgesetzt */
.board .cell.clue {
  background: color-mix(in srgb, var(--text) 7%, var(--surface));
  cursor: default;
}

.cell.unsure {
  outline: 2px dashed var(--warn);
  outline-offset: -3px;
}

.cell.conflict {
  background: color-mix(in srgb, var(--error) 22%, var(--surface));
  color: var(--error);
}

/* Quer gehaltenes Handy: breit, aber flach. Untereinander geht sich da nichts
   aus — also Raster links, Bedienung rechts, und alles ist ohne Scrollen da. */
@media (min-width: 40rem) and (max-height: 34rem) {
  .panel {
    display: grid;
    grid-template-columns: min(78svh, 46%) 1fr;
    column-gap: 16px;
    align-items: start;
  }

  .stage {
    grid-column: 1;
    grid-row: 1 / span 20;
    width: 100%;
  }

  .toolbar,
  .hint,
  .steps,
  .win,
  .actions,
  .code-row,
  .panel > .help {
    grid-column: 2;
  }

  .toolbar {
    margin-bottom: 0;
  }

  .actions {
    position: static;
    margin-inline: 0;
    padding: 0;
    background: none;
    backdrop-filter: none;
  }
}

/* ---------------------------------------------------------------- gelöst */

/* Die Welle läuft diagonal von links oben durchs Raster: jede Zelle wartet auf
   ihren Abstand zur Ecke (`--d`, in app.js gesetzt) und leuchtet dann kurz auf. */
.board.won .cell {
  animation: win-wave 0.9s ease-out both;
  animation-delay: calc(var(--d, 0) * 60ms);
}

@keyframes win-wave {
  35% {
    transform: scale(1.14);
    color: var(--fresh);
  }
  60% {
    transform: scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  .board.won .cell {
    animation: none;
  }
}

.win {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--fresh) 40%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--fresh) 8%, var(--surface));
}

.win-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--fresh);
}

/* Grösse, Zeit, Bestzeit, Tipps, Züge — durch Punkte getrennt in einer Zeile,
   auf dem Handy umbrechend. */
.win-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin: 6px 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.win-fact + .win-fact::before {
  content: '·';
  margin-right: 10px;
  opacity: 0.6;
}

.win-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.win-nav .btn {
  flex: 1 1 auto;
}

.win-nav #winAgain {
  flex: 2 1 140px;
}

/* ------------------------------------------------------------ lösungsweg */

/* Zellen, die der aktuelle Schritt begründet ...
   (eine Klasse mehr als `.board.over-photo .cell`, damit sie auch über dem Foto greifen) */
.board .cell.step-line {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.board .cell.step-focus {
  background: color-mix(in srgb, var(--focus) 30%, var(--surface));
  color: var(--focus);
}

/* ... und die Zelle(n), die er setzt. */
.board .cell.step-new {
  background: color-mix(in srgb, var(--fresh) 26%, var(--surface));
  color: var(--fresh);
  outline: 2px solid var(--fresh);
  outline-offset: -2px;
  animation: pop 0.25s ease-out;
}

@keyframes pop {
  from {
    transform: scale(0.72);
    opacity: 0.4;
  }
}

@media (prefers-reduced-motion: reduce) {
  .board .cell.step-new {
    animation: none;
  }
}

.board.stepping .cell {
  cursor: default;
}

.steps {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}

.step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
}

/* Schritte, die nicht aus einer Regel folgen, sondern geraten sind. */
.badge.guess {
  background: color-mix(in srgb, var(--warn) 20%, transparent);
  color: var(--warn);
}

.step-count {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.step-text {
  margin: 0 0 10px;
  font-size: 0.92rem;
  min-height: 3.6em;
}

.step-range {
  display: block;
  width: 100%;
  height: 40px; /* der Regler ist auf dem Handy sonst kaum zu treffen */
  margin: 0 0 4px;
  accent-color: var(--accent);
  touch-action: pan-y;
}

/* Während des Lösungswegs zählen nur Raster und Schritt-Knöpfe — der Rest der
   Seite verschwindet, damit beides auf einen Handybildschirm passt. */
body.stepping .capture,
body.stepping .gen,
body.stepping .toolbar,
body.stepping .code-row,
body.stepping .panel > .help {
  display: none;
}

/* Auf dem flachen Schirm muss zusätzlich der Kopf weichen. */
@media (max-height: 34rem) {
  body.stepping .topbar {
    display: none;
  }
}

.step-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.step-nav .btn {
  flex: 1 1 auto;
  min-height: 48px;
  padding: 0 12px;
}

.step-nav #stepPrev {
  flex: 0 0 64px;
}

.step-nav #stepNext {
  flex: 2 1 140px;
}

.step-nav #stepExit {
  flex: 0 1 auto;
}

.steps .help {
  margin-top: 10px;
}

.hint {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 1.2em;
}

/* Die Knöpfe bleiben in Daumenreichweite am unteren Rand kleben, solange man im
   Raster ist — sonst muss man auf dem Handy für jedes «Lösen» erst scrollen.
   Am Ende der Tafel löst sich der Balken von selbst wieder. */
.actions {
  position: sticky;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px -8px 0;
  padding: 8px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.actions .btn {
  flex: 1 1 calc(50% - 5px);
}

/* Alles Weitere scrollt normal mit — der Balken bleibt eine Zeile hoch. */
.actions.extra {
  position: static;
  margin: 10px 0 0;
  padding: 0;
  background: none;
  backdrop-filter: none;
}

/* Erst wenn der Schirm in beide Richtungen Platz hat, steht die Leiste still —
   quer gehaltene Handys sind breit, aber eben nicht hoch. */
@media (min-width: 34rem) and (min-height: 46rem) {
  .actions {
    position: static;
    margin-inline: 0;
    padding: 0;
    background: none;
    backdrop-filter: none;
  }

  .actions .btn {
    flex: 0 1 auto;
  }
}

.help {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.85rem;
}

.help summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.help ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.help li + li {
  margin-top: 6px;
}

/* Ein Satz dazu, was die Technik überhaupt macht. */
.technique-help {
  display: block;
  color: var(--muted);
  opacity: 0.85;
}

.steps .help b {
  color: var(--text);
  font-weight: 600;
}

footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 28px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.busy {
  opacity: 0.6;
  pointer-events: none;
}

/* ---------------------------------------------------------------- drucken */

/* Das Blatt steht immer im Dokument und wird nie angezeigt — bis der Druckdialog
   kommt. Dann kehrt sich das Verhältnis um: nur das Blatt bleibt übrig.
   Das Aussehen steht ausserhalb von `@media print`, damit es sich auch ansehen
   lässt, ohne zu drucken; sichtbar macht es trotzdem erst der Druck. */
.sheet {
  display: none;
  /* Papier ist immer hell — die Farbvariablen der App gelten hier nicht. */
  background: #fff;
  color: #000;
  font: 10pt/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

.p-block {
  /* Ein Rätsel darf nie über zwei Seiten gehen — dann wäre es keines mehr. */
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 8mm;
}

.p-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6mm;
  margin: 0 0 2mm;
  max-width: var(--w, 104mm);
  font-size: 11pt;
}

.p-head span {
  color: #444;
  font-size: 9pt;
}

/* Kein Farbfüllen, nur Linien: so kommt das Raster auch heraus, wenn der Dialog
   Hintergrundgrafiken weglässt — was er standardmässig tut. */
.p-grid {
  /* Zwei Rätsel müssen auf eine A4-Seite passen: 273 mm bedruckbare Höhe, also
     bleiben je Block rund 126 mm — Kopfzeile, Raster und Regeln zusammen. */
  --w: 104mm;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  width: var(--w);
  height: var(--w);
  border: 0.8pt solid #000;
  margin: 0 0 2mm;
}

.p-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 0.3pt solid #888;
  border-bottom: 0.3pt solid #888;
  font-size: calc(var(--w) / var(--n) * 0.6);
  font-weight: 600;
  line-height: 1;
}

/* Der Rand eines Bimaru: die Zahlen stehen im selben Gitter wie die Zellen, nur
   ohne Linien — sonst sähe das Raster einen Kasten grösser aus, als es ist. */
.p-edge {
  border-color: transparent;
  font-weight: 700;
}

.p-corner {
  border-color: transparent;
}

.p-fleet {
  max-width: var(--w, 104mm);
  margin: 0 0 1.5mm;
  color: #333;
  font-size: 7.5pt;
  font-weight: 600;
}

.p-rules {
  max-width: var(--w, 104mm);
  margin: 0;
  color: #555;
  font-size: 7pt;
  line-height: 1.35;
}

/* Der Rätsel-Code darf ruhig klein sein — abgetippt wird er nur, wenn jemand das
   Blatt wieder aufs Handy holen will. */
.p-rules code {
  display: block;
  margin-top: 1mm;
  color: #888;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 6.5pt;
  word-break: break-all;
}

.p-solutions h2 {
  margin: 0 0 4mm;
  font-size: 12pt;
}

.p-sol-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8mm;
}

.p-sol-head {
  margin: 0 0 1.5mm;
  font-size: 8pt;
  color: #444;
}

.p-grid-small {
  --w: 52mm;
  margin-bottom: 0;
}

/* Fett ist, was vorgegeben war — dann sieht man beim Nachschauen sofort, was man
   selber gefunden hat. */
.p-clue {
  font-weight: 700;
}

.p-grid-small .p-cell:not(.p-clue) {
  color: #555;
  font-weight: 400;
}

@media print {
  html,
  body {
    background: #fff;
    color: #000;
    padding: 0;
    margin: 0;
  }

  body > *:not(.sheet) {
    display: none !important;
  }

  .sheet {
    display: block;
  }

  @page {
    size: A4 portrait;
    margin: 12mm;
  }

  .p-page {
    break-after: page;
    page-break-after: always;
  }

  .p-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }
}
