/*
 * Mogli – Tempelflucht.
 *
 * Alle Farben stehen als --hc-* hier oben; in den Regeln darunter und in den
 * JS-Modulen kommen keine losen Hex-Werte vor. Die Spielgrafik selbst hat ihre
 * eigene, gleichwertige Quelle in src/render/palette.js.
 *
 * Die Seite besteht aus genau einem Element: dem Spielfeld. Es füllt den
 * Bildschirm, und alles Weitere – Bestenliste, Sprache, Ton – liegt als
 * Einblendung darüber. Es gibt nichts zu scrollen, an dem man vorbeikommen
 * könnte.
 */

:root {
  --hc-bg: #050a09;
  --hc-surface: #0d1a16;
  --hc-surface-2: #14261f;
  --hc-border: #1d3a2c;
  --hc-text: #dbe8cf;
  --hc-muted: #8fa383;
  --hc-accent: #3fe3a8;
  --hc-accent-strong: #14a072;
  --hc-primary: #2b5a3d;
  --hc-primary-hover: #46874f;
  --hc-warn: #f5c53a;
  --hc-danger: #d9330f;
  --hc-gold: #f5c53a;

  --hc-radius: 10px;

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/*
 * Nichts scrollt, nichts markiert sich beim Langdrücken.
 *
 * Das Spiel hat genau einen Knopf, und der ist die ganze Spielfläche. Ein
 * gehaltener Finger würde sonst die Textmarkierung, die Lupe und auf iOS das
 * Kontextmenü auslösen – mitten im Sprung. Das Namensfeld nimmt sich weiter
 * unten wieder aus.
 */
html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--hc-bg);
  color: var(--hc-text);
  font-family: ui-monospace, 'SFMono-Regular', 'Cascadia Mono', Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.5;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* --- Spielfeld ----------------------------------------------------------- */

/*
 * 100dvh statt 100vh: auf dem Handy wächst und schrumpft die sichtbare Höhe,
 * wenn die Adressleiste ein- und ausfährt. Mit 100vh stünde das Spiel dann
 * teils unter dem Bildschirmrand. Für ältere Browser bleibt 100vh als
 * Rückfall stehen.
 */
.stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  /*
   * Der Schacht ist 16 Kacheln breit und wird ganzzahlig vergrössert; auf
   * manchen Geräten bleibt seitlich ein schmaler Rand. Statt ihn schwarz zu
   * lassen, ist er der dunkle Rahmen, den das Vorbild um die ganze Anlage hat:
   * aussen tiefes Grün, nach innen auslaufend.
   */
  background:
    radial-gradient(ellipse 120% 80% at 50% 50%, var(--hc-surface) 0%, var(--hc-bg) 70%),
    var(--hc-bg);
  overflow: hidden;
  /* Kein Wischen, kein Zoomen, keine 300-ms-Wartezeit auf einen Doppeltipp:
     die Fläche ist ein Knopf, sonst nichts. Die Einblendung darüber nimmt
     sich davon wieder aus, sonst liesse sie sich nicht scrollen. */
  touch-action: none;
  cursor: pointer;
}

#screen {
  display: block;
  /* Gürtel und Hosenträger: die eigentliche Schärfe kommt aus der
     ganzzahligen Skalierung in engine/canvas.js. */
  image-rendering: pixelated;
  image-rendering: -webkit-optimize-contrast;
}

/* --- Anzeige im Spiel ---------------------------------------------------- */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(10px, env(safe-area-inset-top)) 14px 16px;
  pointer-events: none;
  /* Ein weicher Schleier nach unten. Ohne ihn steht die Anzeige direkt auf dem
     bemoosten Stein und ist genau dann unlesbar, wenn es darauf ankommt. */
  background: linear-gradient(rgb(5 10 9 / 85%) 40%, rgb(5 10 9 / 0%));
}

.hud[hidden] {
  display: none;
}

.hud__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.hud__value {
  color: var(--hc-text);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgb(0 0 0 / 85%);
}

.hud__value--big {
  font-size: clamp(20px, 6vw, 30px);
  letter-spacing: 0.04em;
}

.hud__value--gem {
  font-size: clamp(16px, 4.5vw, 22px);
  color: var(--hc-accent);
}

.hud__value--gem::before {
  content: '◆ ';
}

.taphint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(28px, env(safe-area-inset-bottom));
  margin: 0;
  text-align: center;
  font-size: clamp(13px, 3.6vw, 16px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--hc-text);
  text-shadow: 0 2px 0 rgb(0 0 0 / 85%);
  pointer-events: none;
  animation: taphint 1.4s ease-in-out infinite;
}

.taphint[hidden] {
  display: none;
}

@keyframes taphint {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

/* --- Einblendungen ------------------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: rgb(5 10 9 / 80%);
  backdrop-filter: blur(2px);
  /* Die Einblendung ist die EINZIGE Fläche der Seite, die scrollen darf – und
     nur senkrecht, damit ein Wisch nicht seitwärts ausbricht. */
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.overlay[hidden] {
  display: none;
}

/*
 * margin: auto statt align-items: center. Zentriert genauso, aber wenn die
 * Tafel höher ist als der Bildschirm – Handy im Querformat –, bleibt ihr oberer
 * Rand erreichbar. Mit align-items: center würde er nach oben aus dem
 * scrollbaren Bereich herauswandern.
 */
.panel {
  width: 100%;
  max-width: 340px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.panel[hidden] {
  display: none;
}

.brand {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand__name {
  font-size: clamp(26px, 9vw, 38px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--hc-accent);
  line-height: 1.1;
}

.brand__sub {
  font-size: clamp(11px, 3.2vw, 13px);
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--hc-muted);
}

.panel__title {
  margin: 0;
  font-size: clamp(22px, 7vw, 30px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel__tag {
  margin: 0;
  color: var(--hc-muted);
  font-size: 13px;
}

.panel__best {
  margin: 0;
  color: var(--hc-gold);
  font-size: 13px;
}

.panel__best[hidden] {
  display: none;
}

.panel__status {
  margin: 0;
  min-height: 1.4em;
  font-size: 12px;
  color: var(--hc-muted);
}

.panel__version {
  margin: 0;
  font-size: 10px;
  color: var(--hc-muted);
  opacity: 0.7;
}

/* --- Story --------------------------------------------------------------- */

.story {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  text-align: left;
}

.story__portrait {
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
  image-rendering: pixelated;
  image-rendering: -webkit-optimize-contrast;
  background: var(--hc-surface-2);
  border: 1px solid var(--hc-border);
  border-radius: var(--hc-radius);
}

.story__body {
  min-width: 0;
}

.story__who {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--hc-accent);
}

.story__text {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
}

/* --- Formular und Knöpfe ------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}

.field__label {
  font-size: 12px;
  color: var(--hc-muted);
}

.field input {
  font: inherit;
  padding: 10px 12px;
  color: var(--hc-text);
  background: var(--hc-surface);
  border: 1px solid var(--hc-border);
  border-radius: var(--hc-radius);
  /* Ausnahme zur globalen Regel: hier muss man markieren können. */
  user-select: text;
  -webkit-user-select: text;
  touch-action: auto;
}

.btn {
  font: inherit;
  padding: 12px 16px;
  border-radius: var(--hc-radius);
  border: 1px solid var(--hc-border);
  background: var(--hc-surface-2);
  color: var(--hc-text);
  cursor: pointer;
  /* Fingerfreundlich: nichts unter 44 px. */
  min-height: 44px;
}

.btn:hover {
  border-color: var(--hc-accent-strong);
}

.btn--primary {
  background: var(--hc-primary);
  border-color: var(--hc-primary);
}

.btn--primary:hover {
  background: var(--hc-primary-hover);
}

.btn--big {
  font-size: clamp(16px, 4.6vw, 20px);
  padding: 16px;
  letter-spacing: 0.06em;
}

.btn--ghost {
  background: transparent;
  color: var(--hc-muted);
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.langswitch {
  display: inline-flex;
  border: 1px solid var(--hc-border);
  border-radius: var(--hc-radius);
  overflow: hidden;
}

.langswitch__btn,
.iconbtn {
  font: inherit;
  font-size: 13px;
  color: var(--hc-muted);
  background: var(--hc-surface);
  border: 0;
  padding: 10px 14px;
  min-height: 40px;
  cursor: pointer;
}

.langswitch__btn + .langswitch__btn {
  border-left: 1px solid var(--hc-border);
}

.langswitch__btn[aria-pressed='true'] {
  background: var(--hc-primary);
  color: var(--hc-text);
}

.iconbtn {
  border: 1px solid var(--hc-border);
  border-radius: var(--hc-radius);
}

/* [hidden] allein reicht nicht gegen die Anzeigeart oben. */
.iconbtn[hidden],
.btn[hidden] {
  display: none;
}

.langswitch__btn:hover,
.iconbtn:hover {
  color: var(--hc-text);
}

/* Fokusrahmen bleiben sichtbar – Tastaturbedienung ist hier kein Nachgedanke. */
:focus-visible {
  outline: 2px solid var(--hc-accent);
  outline-offset: 2px;
}

/* --- Ergebnis ------------------------------------------------------------ */

.result {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
}

.result__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.result__row dt {
  color: var(--hc-muted);
}

.result__row dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.result__row--total {
  padding-top: 6px;
  border-top: 1px solid var(--hc-border);
  font-size: 17px;
  color: var(--hc-accent);
}

/* --- Bestenliste --------------------------------------------------------- */

.board {
  background: var(--hc-surface);
  border: 1px solid var(--hc-border);
  border-radius: var(--hc-radius);
  padding: 10px 12px;
  text-align: left;
}

.board__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--hc-muted);
}

.board__mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.board__dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hc-muted);
}

.board--server .board__dot {
  background: var(--hc-accent);
}

.board--local .board__dot {
  background: var(--hc-warn);
}

/*
 * Die Liste hat ihren eigenen Rollbereich. Sonst schiebt eine volle Top 25 den
 * Startknopf aus dem Bild – und der ist wichtiger als Platz 19.
 */
.board__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 13px;
  max-height: 34vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.board__list li {
  display: grid;
  grid-template-columns: 1.8em minmax(0, 1fr) auto;
  gap: 8px;
  padding: 3px 0;
}

.board__list li:nth-child(odd) {
  background: rgb(255 255 255 / 3%);
}

.board__rank {
  color: var(--hc-muted);
  font-variant-numeric: tabular-nums;
}

.board__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board__score {
  color: var(--hc-accent);
  font-variant-numeric: tabular-nums;
}

.board__list li.board__empty {
  display: block;
  background: none;
  color: var(--hc-muted);
  font-size: 12px;
}

.board__note {
  margin: 8px 0 0;
  font-size: 10px;
  line-height: 1.4;
  color: var(--hc-muted);
}

/* --- Meldungsstreifen ----------------------------------------------------
 *
 * Sichtbar nur, wenn beim Start etwas schiefgegangen ist. Er liegt über allem
 * und ist absichtlich laut: der Menübildschirm darunter ist statisches HTML
 * und sähe sonst völlig normal aus, obwohl kein Knopf verdrahtet wurde.
 *
 * Die erste Regel ist die wichtigste. `display` schlägt `[hidden]`, und die
 * gleiche Falle hat hier schon einmal zugeschlagen (die alten Tippflächen,
 * später die Anmeldekarte im Admin-Bereich): ohne sie wäre der Streifen immer
 * zu sehen.
 */

.crash[hidden] {
  display: none;
}

.crash {
  position: fixed;
  z-index: 100;
  top: 0;
  right: 0;
  left: 0;
  display: block;
  padding: calc(10px + env(safe-area-inset-top)) 12px 12px;
  border-bottom: 2px solid var(--hc-danger);
  background: #2a0b06;
  color: #ffe9e3;
  /* Auswählbar – der ganze Zweck ist, dass man den Text abschicken kann. */
  user-select: text;
  -webkit-user-select: text;
}

.crash__head {
  margin: 0 0 6px;
  color: var(--hc-danger);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.crash__line {
  margin: 0 0 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.crash__hint {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: #f0c3b7;
}

.crash__btn {
  margin-top: 8px;
  padding: 8px 14px;
  border: 1px solid var(--hc-danger);
  border-radius: var(--hc-radius);
  background: #4a1309;
  color: #ffe9e3;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

/* --- Levelliste im Menü -------------------------------------------------- */

.panel__title--levels {
  margin: 14px 0 6px;
}

.levels {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.level {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--hc-border);
  border-radius: var(--hc-radius);
  background: var(--hc-surface-2);
  color: var(--hc-text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}

.level:hover:not(:disabled) {
  border-color: var(--hc-accent-strong);
}

.level:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.level__name {
  font-weight: 700;
}

.level__time {
  color: var(--hc-accent);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.level__time--none {
  color: var(--hc-muted);
}

/* --- Touch-Steuerung ------------------------------------------------------
 *
 * Halbtransparent über dem Spielfeld. Nur auf Geräten mit grobem Zeiger –
 * am Rechner gibt es die Tastatur, und tote Knöpfe im Bild wären nur Deko.
 * `pointer-events` nur auf den Knöpfen selbst: die Fläche dazwischen bleibt
 * durchlässig.
 */

.pad[hidden] {
  display: none;
}

.pad {
  position: absolute;
  inset: auto 0 0 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 14px calc(14px + env(safe-area-inset-bottom));
  pointer-events: none;
  z-index: 4;
}

@media (pointer: coarse) {
  .pad {
    display: flex;
  }
}

.pad__group {
  display: flex;
  gap: 10px;
  pointer-events: none;
}

.pad__btn {
  width: 64px;
  height: 64px;
  border: 2px solid rgb(219 232 207 / 35%);
  border-radius: 50%;
  background: rgb(13 26 22 / 42%);
  color: rgb(219 232 207 / 80%);
  font-size: 26px;
  line-height: 1;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.pad__btn--jump {
  width: 78px;
  height: 78px;
  font-size: 32px;
  border-color: rgb(63 227 168 / 45%);
}

.pad__btn--down {
  background: rgb(63 227 168 / 30%);
  border-color: var(--hc-accent);
  color: #fff;
}

/* --- Rücksicht auf Bewegungsempfindlichkeit ------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .taphint {
    animation: none;
    opacity: 0.9;
  }
}
