/* =============================================================================
   NUNU GAMES – gemeinsame Basis: Tokens, Vollbild ohne Scroll, Sticker-Knoepfe,
   Spiel-Menue (Plus oben rechts). Jedes Spiel bindet diese Datei ein.
   ============================================================================= */

:root {
  --sun: #ffe45c;      /* Hintergrund Uebersicht */
  --ink: #23194d;      /* Linien, Schrift, Schatten */
  --lila: #7b3cff;
  --orange: #ff6a13;
  --mint: #19c3a6;
  --pink: #ff5fa2;
  --paper: #ffffff;

  --font-display: "Baloo 2", "Arial Rounded MT Bold", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;

  --line: 4px;
  --lift: 6px;
  --radius: 22px;
  --tap: 64px;         /* Mindestgroesse Kinderfinger */

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
body {
  position: fixed;
  inset: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--sun);
}
button, input { font: inherit; color: inherit; }
input { user-select: text; -webkit-user-select: text; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* --- Sticker-Knopf: dicke Linie, harter Schatten, drueckt sich ein ------------ */
.nunu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: var(--tap);
  padding: 0 1em;
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 var(--lift) 0 var(--ink);
  transform: translateY(0);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.15s ease;
}
.nunu-btn:active,
.nunu-btn.is-pressed {
  transform: translateY(calc(var(--lift) - 2px));
  box-shadow: 0 2px 0 var(--ink);
}
.nunu-btn:focus-visible { outline: 4px solid var(--lila); outline-offset: 4px; }
.nunu-btn svg { width: 1.4em; height: 1.4em; flex: none; }

/* --- Plus oben rechts ------------------------------------------------------- */
.nunu-menu-toggle {
  position: fixed;
  z-index: 30;
  top: calc(10px + var(--safe-t));
  right: calc(10px + var(--safe-r));
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border-radius: 50%;
  background: var(--paper);   /* auf jedem Hintergrund lesbar */
  color: var(--ink);
}
.nunu-menu-toggle svg { width: 30px; height: 30px; transition: transform 0.25s cubic-bezier(0.34, 1.6, 0.64, 1); }
.nunu-menu-toggle[aria-expanded="true"] { background: var(--sun); }
.nunu-menu-toggle[aria-expanded="true"] svg { transform: rotate(45deg); }

/* --- Grid oben links: zu allen Spielen --------------------------------------- */
.nunu-home {
  position: fixed;
  z-index: 30;
  top: calc(10px + var(--safe-t));
  left: calc(10px + var(--safe-l));
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border-radius: 50%;
  background: var(--sun);
}
.nunu-home svg { width: 30px; height: 30px; }
.is-menu-open .nunu-home { display: none; }   /* im Menue steht «Alle Spiele» */

/* Level neu starten, unten links in der Ecke (Spiele, die das wollen) */
.nunu-restart {
  position: fixed;
  z-index: 30;
  bottom: calc(10px + var(--lift) + var(--safe-b));
  left: calc(10px + var(--safe-l));
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border-radius: 50%;
  background: #ffd9e6;
}
.nunu-restart svg { width: 30px; height: 30px; }
.is-menu-open .nunu-restart { display: none; }

/* --- Menue-Panel ------------------------------------------------------------ */
.nunu-menu {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  background: rgb(35 25 77 / 0.55);
  animation: nunu-fade 0.15s ease;
}
@keyframes nunu-fade { from { opacity: 0; } }
.nunu-menu-card {
  width: min(560px, 100%);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px;
  border: var(--line) solid var(--ink);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 0 var(--lift) 0 var(--ink);
  animation: nunu-pop 0.25s cubic-bezier(0.34, 1.6, 0.64, 1);
}
@keyframes nunu-pop { from { transform: scale(0.85); opacity: 0; } }
.nunu-menu-title {
  margin: 0 70px 14px 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.9rem;
  line-height: 1;
}
.nunu-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.nunu-tabs.is-2 { grid-template-columns: repeat(2, 1fr); }
.nunu-tabs.is-3 { grid-template-columns: repeat(3, 1fr); }
.nunu-tabs .nunu-btn { flex-direction: column; gap: 4px; min-height: 84px; padding: 8px 4px; font-size: 1rem; }
.nunu-tabs .nunu-btn[aria-selected="true"] { background: var(--sun); }
.nunu-panel {
  margin-top: 16px;
  padding: 16px;
  border-radius: 18px;
  background: #f4f1ff;
  font-size: 1.1rem;
  line-height: 1.35;
}
.nunu-panel p { margin: 0 0 0.6em; }
.nunu-panel p:last-child { margin-bottom: 0; }
.nunu-panel .nunu-btn { font-size: 1.1rem; }

/* Sound-Schalter: ganze Zeile tippbar */
.nunu-switch { width: 100%; justify-content: space-between; margin-bottom: 12px; }
.nunu-switch:last-child { margin-bottom: 0; }
.nunu-switch .nunu-switch-state {
  min-width: 3.2em;
  padding: 6px 10px;
  border-radius: 999px;
  background: #ddd;
  font-size: 0.95rem;
}
.nunu-switch[aria-pressed="true"] .nunu-switch-state { background: var(--mint); color: var(--paper); }

/* Farbe: Klötze fuer den Hintergrund */
.nunu-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 10px; }
.nunu-swatch {
  aspect-ratio: 1;
  min-height: 56px;
  padding: 0;
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  background: var(--c);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.nunu-swatch:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.nunu-swatch:focus-visible { outline: 4px solid var(--lila); outline-offset: 3px; }
.nunu-swatch[aria-pressed="true"] { outline: 4px solid var(--ink); outline-offset: 3px; }

/* High Score */
.nunu-scores { list-style: none; margin: 0; padding: 0; counter-reset: rank; font-variant-numeric: tabular-nums; }
.nunu-scores li {
  display: flex;
  gap: 0.6em;
  padding: 4px 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  counter-increment: rank;
}
.nunu-scores li::before { content: counter(rank) "."; min-width: 1.8em; opacity: 0.5; }
.nunu-scores li span:last-child { margin-left: auto; }
.nunu-scores li.is-new { color: var(--lila); }
.nunu-scores li.is-empty { counter-increment: none; font-family: var(--font-body); font-weight: 600; font-size: 1.05rem; }
.nunu-scores li.is-empty::before { content: none; }

/* Code-Zeile unter den Reitern */
.nunu-code {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-top: 16px;
  font-weight: 700;
  font-size: 1.1rem;
}
.nunu-code-current b {
  display: inline-block;
  margin-left: 0.3em;
  padding: 4px 10px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  letter-spacing: 0.12em;
}
.nunu-code label { display: inline-flex; align-items: center; gap: 0.5em; margin-left: auto; }
.nunu-code input {
  width: 5.6em;
  height: 52px;
  padding: 0 10px;
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;   /* >= 16px: iOS zoomt beim Tippen nicht */
  letter-spacing: 0.15em;
  text-align: center;
  text-transform: uppercase;
}
.nunu-code input:focus { outline: none; border-color: var(--lila); }
.nunu-code input.is-wrong { border-color: var(--orange); animation: nunu-shake 0.3s; }
@keyframes nunu-shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* immer sichtbar unten im Menue: Level neu starten + Alle Spiele */
.nunu-menu-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.nunu-menu-actions .nunu-btn { width: 100%; padding: 0 10px; font-size: 1.1rem; white-space: nowrap; }
.nunu-menu-restart { background: #ffd9e6; }
.nunu-menu-home { background: var(--sun); }

/* Kleine Querformat-Hoehen (iPhone quer): Menue kompakter */
/* zwei Spalten: links Reiter + «Alle Spiele», rechts Inhalt + Code-Zeile */
@media (max-height: 480px) and (orientation: landscape) {
  .nunu-menu { padding-right: calc(var(--tap) + 20px + var(--safe-r)); }   /* Platz fuers Kreuz */
  .nunu-menu-card {
    width: min(760px, 100%);
    height: 100%;
    padding: 12px;
    display: grid;
    grid-template-columns: 190px 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "title panel" "tabs panel" "home code";
    gap: 10px 14px;
    overflow: hidden;
  }
  .nunu-menu-title { grid-area: title; margin: 0; font-size: 1.5rem; }
  .nunu-tabs { grid-area: tabs; grid-template-columns: 1fr; align-content: start; gap: 8px; }
  .nunu-tabs .nunu-btn { flex-direction: row; justify-content: flex-start; min-height: 48px; padding: 0 12px; }
  .nunu-panel { grid-area: panel; margin: 0; padding: 12px; overflow-y: auto; font-size: 1rem; }
  .nunu-code { grid-area: code; margin: 0; font-size: 1rem; }
  .nunu-code input { height: 46px; }
  .nunu-menu-actions { grid-area: home; margin: 0; gap: 8px; }
  .nunu-menu-actions .nunu-btn { min-height: 50px; padding: 0; }
  .nunu-menu-actions .nunu-btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
