/* Wierfel-Spill — optiméiert fir iPad (Touch) a normal Bildschirmer */

:root {
  /* 🌅 Sonneret — waarm Palette */
  --bg-top: #fff4e6;
  --bg-bottom: #ffe8cc;
  --ink: #2d2118;
  --ink-soft: #7d6552;
  --accent: #f76707;
  --accent-dark: #d9480f;
  --ok: #2f9e44;
  --ok-dark: #2b8a3e;
  --bad: #e03131;
  --bad-dark: #c92a2a;
  --card: #ffffff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
  overscroll-behavior: none;
  touch-action: manipulation; /* kee Double-Tap-Zoom, keng 300-ms-Delay */
  user-select: none;
  -webkit-user-select: none;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) 16px
    calc(14px + env(safe-area-inset-bottom));
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* ---------- Startscreen ---------- */

#screen-start {
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 4vh, 36px);
  text-align: center;
}

.title {
  font-size: clamp(36px, 8vmin, 64px);
  margin: 0;
}

.subtitle {
  font-size: clamp(17px, 3vmin, 24px);
  color: var(--ink-soft);
  margin: 0;
  max-width: 34ch;
}

.start-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(84vw, 380px);
}

/* All Knäppecher um Startscreen d'selwecht breed */
.mode-choice .btn,
.start-actions .btn {
  width: 100%;
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(84vw, 380px);
}

.mode-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.mode-choice small {
  color: var(--ink-soft);
  font-size: 13.5px;
}

/* ---------- Kaarten-Modus ---------- */

.card-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 4vh, 34px);
  text-align: center;
}

.card-answer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: pop 0.35s ease;
}

.card-solution-intro {
  margin: 0;
  font-weight: 700;
  font-size: clamp(16px, 2.6vmin, 21px);
}

.card-answer-die svg {
  width: clamp(150px, 34vmin, 240px);
  height: auto;
  display: block;
  filter: drop-shadow(0 8px 14px rgba(30, 38, 51, 0.35));
}

.card-answer-text {
  margin: 0;
  font-weight: 800;
  font-size: clamp(22px, 4.4vmin, 36px);
}

.card-answer-actions {
  display: flex;
  gap: 12px;
  width: min(100%, 360px);
}

.card-answer-actions .btn {
  flex: 1;
}

.btn.card-correct {
  background: var(--ok);
  color: #fff;
  box-shadow: 0 4px 0 var(--ok-dark), 0 8px 18px rgba(47, 158, 68, 0.35);
}

.btn.card-wrong {
  background: var(--bad);
  color: #fff;
  box-shadow: 0 4px 0 var(--bad-dark), 0 8px 18px rgba(224, 49, 49, 0.35);
}

.app-version {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  opacity: 0.75;
}

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: 16px;
  min-height: 58px;
  padding: 10px 22px;
  font-size: clamp(17px, 2.6vmin, 22px);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 0 var(--accent-dark), 0 8px 18px rgba(247, 103, 7, 0.35);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.75);
  color: var(--accent-dark);
  box-shadow: 0 2px 8px rgba(30, 38, 51, 0.12);
}

.btn.big {
  min-height: 72px;
  font-size: clamp(20px, 3.4vmin, 28px);
}

.btn.icon-only {
  min-width: 58px;
  padding: 10px;
}

.btn-icon {
  font: inherit;
  font-size: 22px;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 8px rgba(30, 38, 51, 0.14);
  cursor: pointer;
  touch-action: manipulation;
  display: grid;
  place-items: center;
}

.btn-icon:active {
  transform: scale(0.92);
}

/* ---------- Spillscherm ---------- */

.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0 8px;
}

.round-label {
  font-weight: 800;
  font-size: clamp(16px, 2.6vmin, 22px);
}

.score-label {
  margin-left: auto;
  font-weight: 700;
  font-size: clamp(15px, 2.4vmin, 20px);
  color: var(--ink-soft);
}

.controls {
  display: flex;
  gap: 12px;
  margin: 4px 0 clamp(12px, 3vh, 26px);
}

.controls .btn.primary {
  flex: 1;
}

/* D'Grid skaléiert souwuel am Portrait wéi Landscape (iPad). */
.dice-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(10px, 2.5vmin, 26px);
  width: min(100%, 74vh);
  margin: 0 auto;
  align-self: center;
}

.dice-grid.locked .die {
  pointer-events: none;
}

.die {
  border: none;
  background: none;
  padding: 0;
  aspect-ratio: 1 / 1;
  cursor: pointer;
  touch-action: manipulation;
  border-radius: 22%;
  transition: transform 0.12s ease;
}

.die svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 6px 8px rgba(30, 38, 51, 0.35));
}

.die:active {
  transform: scale(0.93);
}

.die.correct {
  animation: pop 0.5s ease;
  outline: 7px solid var(--ok);
  outline-offset: 3px;
}

.die.wrong {
  animation: shake 0.45s ease;
  outline: 7px solid var(--bad);
  outline-offset: 3px;
}

.die.reveal {
  outline: 7px solid var(--ok);
  outline-offset: 3px;
  animation: pulse 0.9s ease infinite;
}

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ---------- Feedback-Banner ---------- */

.feedback {
  position: fixed;
  left: 50%;
  top: calc(18px + env(safe-area-inset-top));
  transform: translateX(-50%);
  padding: 12px 26px;
  border-radius: 999px;
  font-size: clamp(18px, 3vmin, 26px);
  font-weight: 800;
  color: #fff;
  box-shadow: 0 8px 22px rgba(30, 38, 51, 0.3);
  z-index: 30;
  animation: slide-in 0.25s ease;
}

.feedback.ok {
  background: var(--ok);
}

.feedback.bad {
  background: var(--bad);
}

@keyframes slide-in {
  from { opacity: 0; transform: translate(-50%, -14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Statistiken-Overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 44, 0.55);
  display: flex;
  /* Op Touch: ass d'Panel méi héich wéi de Screen (z. B. Optiounen um
     Smartphone), muss de ganzen Overlay scrollen — soss ass de
     Zoumaachen-Knäppchen erreechbar keng. */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  z-index: 40;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.panel {
  /* margin: auto (ronderëm) zentréiert ouni iwwer de Rand ze clipping
     (place-items: center géif de Panel-Rand iwwer d'Viewport schaben). */
  margin: auto;
  background: var(--card);
  border-radius: 22px;
  padding: 24px 26px;
  width: min(100%, 420px);
  box-shadow: 0 18px 50px rgba(20, 28, 44, 0.4);
}

.panel h2 {
  margin: 0 0 14px;
  font-size: clamp(20px, 3.4vmin, 28px);
}

.stats-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
}

.stats-list li {
  display: flex;
  justify-content: space-between;
  padding: 11px 2px;
  border-bottom: 1px solid #ece1d3;
  font-size: clamp(16px, 2.6vmin, 19px);
}

.stats-list li.last {
  border-bottom: none;
}

.stats-list span {
  color: var(--ink-soft);
}

.panel-actions {
  display: flex;
  gap: 12px;
}

.panel-actions .btn {
  flex: 1;
}

/* ---------- Faarwen-Auswiel ---------- */

/* ---------- Optiounen ---------- */

.opt-label {
  font-weight: 700;
  font-size: 15.5px;
  margin: 14px 0 0;
}

.opt-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 0;
}

.opt-btn {
  flex: 1 1 auto;
  min-height: 52px;
  padding: 8px 14px;
  border-radius: 14px;
  border: 2px solid #e8dcc9;
  background: #fbf4ea;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.opt-btn.on {
  border-color: var(--accent);
  background: rgba(247, 103, 7, 0.12);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.colors-hint {
  color: var(--ink-soft);
  font-size: 14.5px;
  margin: 6px 0 0;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin: 14px 0 18px;
  /* Kee eegenen Scrollberäich: den ganzen Overlay scrollt (kuckt .overlay) —
     verschachtelt Scroll-Container funktionéieren op Touch schlecht. */
}

.color-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 2px solid #e8dcc9;
  background: #fbf4ea;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  min-height: 52px;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s ease, filter 0.15s ease;
}

.color-chip .swatch {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.color-chip .check {
  margin-left: auto;
  font-weight: 800;
  color: var(--ok);
}

.color-chip.off {
  opacity: 0.38;
  filter: grayscale(0.75);
}

/* ---------- Debug-Panel ---------- */

.panel.wide {
  width: min(100%, 480px);
}

.debug-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}

.debug-head h2 {
  margin: 0;
}

.debug-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
}

.debug-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fbf4ea;
  border-radius: 12px;
  padding: 5px 12px 5px 5px;
}

.dbg-play {
  min-height: 44px;
  min-width: 52px;
  padding: 6px 10px;
  font-size: 17px;
}

.dbg-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.dbg-text b {
  font-size: 16px;
}

.dbg-text small {
  color: var(--ink-soft);
  font-size: 12.5px;
}

.dbg-status {
  min-width: 92px;
  text-align: right;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

/* Landscape op iPad: Controls iwwer der Grid, méi kompakt */
@media (orientation: landscape) and (max-height: 560px) {
  #app {
    padding-top: calc(6px + env(safe-area-inset-top));
  }
  .controls {
    margin-bottom: 8px;
  }
  .btn,
  .btn-icon {
    min-height: 44px;
  }
}
