:root {
  --papier: #f4efe4;
  --tinte: #241f1b;
  --akzent: #c8452f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #17141a;
  color: var(--papier);
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#buehne {
  position: relative;
  width: 100vw;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Canvas fuellt so viel Flaeche wie moeglich, behaelt aber 16:9 */
#spiel {
  width: 100%;
  height: auto;
  max-width: calc(100dvh * 16 / 9);
  max-height: 100dvh;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  background: #9fd0e8;
  display: block;
  touch-action: none;   /* kein Scrollen/Zoomen beim Spielen */
}

/* ---------------------------------------------------------- Dreh-Hinweis --- */

.drehhinweis {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  background: rgba(20, 16, 22, 0.97);
  border: 0;
  padding: 24px;
  text-align: center;
  font-size: 18px;
  pointer-events: auto;
  z-index: 20;
}

.drehhinweis span:last-child { opacity: 0.75; font-size: 13px; }
.dreh-icon { font-size: 34px; animation: kippen 1.8s ease-in-out infinite; }

@keyframes kippen {
  0%, 45%, 100% { transform: rotate(0deg); }
  60%, 85% { transform: rotate(90deg); }
}

.versteckt { display: none !important; }

/* -------------------------------------------------------------- Overlays --- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 13, 18, 0.86);
  padding: 12px;
  overflow-y: auto;
  z-index: 10;
}

.karte {
  background: var(--papier);
  color: var(--tinte);
  max-width: 420px;
  width: 100%;
  padding: clamp(16px, 3vw, 28px) clamp(18px, 3.5vw, 32px);
  border: 3px solid var(--tinte);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.45);
  margin: auto;
  text-align: center;
}

.karte h1 {
  margin: 0 0 4px;
  font-size: clamp(26px, 6vw, 36px);
  letter-spacing: 1px;
}

.bilanz {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  font-size: clamp(12px, 2.7vw, 15px);
  text-align: left;
}

.bilanz li {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(36, 31, 27, 0.25);
}

.bilanz li strong { font-variant-numeric: tabular-nums; }

button {
  font: inherit;
  font-weight: 700;
  font-size: clamp(16px, 3.4vw, 18px);
  padding: 13px 28px;
  width: 100%;
  background: var(--akzent);
  color: var(--papier);
  border: 3px solid var(--tinte);
  cursor: pointer;
  touch-action: manipulation;
}

button:hover { background: #a8331f; }
button:active { transform: translateY(2px); }
button:focus-visible {
  outline: 4px solid #ffd23a;
  outline-offset: 3px;
}

.nebenknopf {
  margin-top: 8px;
  background: var(--papier);
  color: var(--tinte);
  font-size: clamp(13px, 2.8vw, 15px);
  padding: 9px 20px;
}

.nebenknopf:hover { background: #e7dfcd; }

/* ------------------------------------------------------------ Rangliste --- */

.rangliste { margin: 0 0 12px; }

.score-form {
  display: flex;
  gap: 8px;
  margin: 0 0 8px;
}

.score-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: clamp(14px, 3vw, 16px);
  padding: 10px 12px;
  border: 2px solid var(--tinte);
  background: #fff;
  color: var(--tinte);
}

.score-form input:focus-visible {
  outline: 3px solid #ffd23a;
  outline-offset: 1px;
}

.score-form button {
  width: auto;
  flex: 0 0 auto;
  font-size: clamp(14px, 3vw, 16px);
  padding: 10px 16px;
}

.rangliste-status {
  margin: 0 0 8px !important;
  font-size: clamp(12px, 2.6vw, 14px) !important;
  min-height: 1.2em;
}

.rangliste-liste {
  margin: 0;
  padding: 0 0 0 26px;
  font-size: clamp(12px, 2.7vw, 14px);
  max-height: 32vh;
  overflow-y: auto;
}

.rangliste-liste li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
  border-bottom: 1px dashed rgba(36, 31, 27, 0.2);
}

.rangliste-liste li strong { font-variant-numeric: tabular-nums; }

.rangliste-liste li.du {
  background: #ffe9a8;
  margin: 0 -6px;
  padding: 3px 6px;
}

/* Fiktionshinweis + Pflicht-Links am Startbildschirm */
.fusszeile {
  margin: 12px 0 0;
  font-size: 11px;
  line-height: 1.5;
  opacity: 0.65;
  text-align: center;
}

.fusszeile a { color: var(--tinte); }

/* Handy im Querformat: die Karte MUSS ohne Scrollen passen, sonst liegt der
   Startknopf unter der Falz und das Spiel wirkt kaputt. */
@media (max-height: 470px) {
  .overlay { padding: 5px; }
  .karte {
    padding: 12px 18px;
    max-width: 420px;
  }
  .karte h1 { font-size: 24px; }
  .bilanz { font-size: 12px; }
  .bilanz li { padding: 2px 0; }
  button { padding: 9px 20px; font-size: 15px; }
  .fusszeile { margin-top: 8px; font-size: 10px; }

  /* Mit Rangliste wird die Endkarte zu hoch fuers Querformat (gemessen:
     435 px bei 390 px Bildschirm, Knoepfe unter der Falz). Breite ist hier
     reichlich da, also Bilanz+Knoepfe links, Rangliste rechts daneben. */
  #ende .karte {
    max-width: 720px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 18px;
    align-items: start;
  }
  #ende .karte h1 { grid-column: 1; margin-bottom: 6px; }
  #ende .bilanz { grid-column: 1; }
  #ende #neustartknopf,
  #ende #hauptmenueknopf { grid-column: 1; }
  #ende .rangliste {
    grid-column: 2;
    grid-row: 1 / span 4;
    margin: 0;
  }
  #ende .rangliste-liste { max-height: 20vh; font-size: 12px; }
  #ende .score-form input,
  #ende .score-form button { padding: 8px 12px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .dreh-icon { animation: none; }
  button:active { transform: none; }
}
