:root {
  --bg: #1E1B19;
  --bg-mid: #2B2622;
  --plate: #171412;
  --cell-light: #37322E;
  --cell-dark: #302B28;
  --text: #F6F1E7;
  --muted: #B8AEA2;
  --accent: #F4B81E;
  --btn: #4A433D;
  --btn-down: #5C544C;
  --warn: #E0452B;
  --ok: #12A07A;
  --cell: 48px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 35%, var(--bg-mid), var(--bg) 70%) fixed, var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.screen {
  position: fixed; inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex; flex-direction: column;
}

/* ---------------------------------------------------------------- Übersicht */
.map-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 8px;
}
.logo { margin: 0; font-size: clamp(28px, 7vmin, 42px); font-weight: 800; letter-spacing: .5px; }
.logo span { color: var(--accent); }
.total { display: flex; align-items: center; gap: 8px; font-size: 22px; font-weight: 700; }
.total .star { width: 28px; height: 28px; }
.map-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 16px 40px; }
.map-path {
  display: flex; flex-direction: column-reverse; align-items: center; gap: 18px;
  max-width: 520px; margin: 0 auto; padding: 20px 0;
}
.map-node {
  width: 84px; height: 84px; border-radius: 50%;
  border: 4px solid #6B625A; background: var(--btn);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transform: translateX(var(--x));
  box-shadow: 0 6px 0 #120f0d;
}
.map-node .num { font-size: 28px; font-weight: 800; line-height: 1; }
.map-node .stars { display: flex; gap: 1px; }
.map-node .star { width: 18px; height: 18px; }
.map-node.locked { opacity: .45; cursor: default; }
.map-node.current { border-color: var(--accent); background: #5a4a2a; animation: beckon 1.6s ease-in-out infinite; }
.map-node:not(.locked):active { background: var(--btn-down); }
@keyframes beckon { 50% { box-shadow: 0 6px 0 #120f0d, 0 0 0 10px rgba(244,184,30,.18); } }

/* ---------------------------------------------------------------- Spielkopf */
.hud {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px;
  padding: 10px 12px 6px; min-height: 84px;
}
.hud-box {
  background: rgba(0,0,0,.28); border-radius: 14px; padding: 6px 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.hud-box small { font-size: 15px; color: var(--muted); }
.moves-box span { font-size: clamp(30px, 7vmin, 52px); font-weight: 800; line-height: 1; color: var(--accent); }
.moves-box.low span { color: var(--warn); }
.moves-box.pulse { animation: pulse .5s ease-out; }
@keyframes pulse { 40% { transform: scale(1.15); } }
.goals { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; }
.goal { display: flex; align-items: center; gap: 6px; font-size: 24px; font-weight: 800; }
.goal-icon { width: 34px; height: 34px; }
.goal .check { width: 26px; height: 26px; fill: none; stroke: var(--ok); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.goal.done .goal-icon { opacity: .6; }
.score { font-size: 22px; font-weight: 800; }
.score-bar { position: relative; width: 92px; height: 8px; border-radius: 4px; background: #3b342e; margin-top: 4px; }
.score-fill { height: 100%; border-radius: 4px; background: var(--accent); width: 0; transition: width .4s ease; }
.score-bar .mark { position: absolute; top: -3px; width: 3px; height: 14px; margin-left: -1.5px; background: #6B625A; border-radius: 2px; }
.score-bar .mark.reached { background: #fff; }

/* ---------------------------------------------------------------- Brett */
.board-wrap {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px;
}
.board {
  position: relative; border-radius: 18px; background: var(--plate);
  box-shadow: 0 0 0 6px var(--plate), 0 12px 30px rgba(0,0,0,.5);
  touch-action: none; overflow: hidden;
}
.layer { position: absolute; inset: 0; pointer-events: none; }
.cell, .over, .tile, .cell-flash {
  position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell);
}
.cell.light { background: var(--cell-light); }
.cell.dark { background: var(--cell-dark); }
.cell svg, .over svg { width: 100%; height: 100%; display: block; }
.over.cage { z-index: 1; }

.tile { will-change: transform; }
.tile-in { position: absolute; inset: 9%; transform-origin: 50% 100%; transition: transform .15s ease, filter .15s ease; }
.tile-in > svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.tile.lifted { z-index: 3; }
.tile.lifted .tile-in { transform: scale(1.08); }
.tile.selected .tile-in { transform: scale(1.12); }
.tile.selected::after {
  content: ""; position: absolute; inset: 2px; border-radius: 12px;
  border: 4px solid var(--accent); animation: ring .9s ease-in-out infinite;
}
@keyframes ring { 50% { opacity: .6; } }
.tile.flash .tile-in { transform: scale(1.12); filter: brightness(1.35); }
.tile.vanish .tile-in { transition: transform var(--vanish, 200ms) cubic-bezier(.5,0,.9,.4), opacity var(--vanish, 200ms); transform: scale(0); opacity: 0; }
.tile-in.land { animation: land .26s linear; }
@keyframes land {
  0% { transform: scale(1, 1); }
  27% { transform: scale(1.10, .86); }
  69% { transform: scale(.97, 1.04); }
  100% { transform: scale(1, 1); }
}
.tile-in.born { animation: born .32s cubic-bezier(.34,1.56,.64,1); }
@keyframes born { 0% { transform: scale(0); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
.tile-in.pop { animation: pop .25s ease-out; }
@keyframes pop { 50% { transform: scale(1.2); } }
.tile-in.nope, .over.nope { animation: nope .16s ease-in-out 2; }
@keyframes nope { 25% { translate: -5% 0; } 75% { translate: 5% 0; } }
.tile.shrink .tile-in { transform: scale(.6); }
.tile.hint .tile-in { filter: brightness(1.25); transform: scale(1.08); }
.tile.hint-move .tile-in { animation: hint .7s ease-in-out 2; }
@keyframes hint { 50% { translate: var(--hx) var(--hy); } }

.tile .mark.pulse { animation: markpulse 1.6s ease-in-out infinite; }
@keyframes markpulse { 50% { opacity: .65; } }
.tile.k-b .mark { animation: breathe 1.2s ease-in-out infinite; transform-origin: 50% 50%; }
@keyframes breathe { 50% { transform: scale(1.06); } }
.tile .spin { animation: spin 10s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- Effekte */
.fx-canvas { z-index: 4; }
.fx { z-index: 5; }
.beam {
  position: absolute; left: 0; top: 0; right: 0; bottom: 0;
  background: #fff; border-radius: 999px;
  box-shadow: 0 0 14px 4px rgba(255,255,255,.55);
}
.beam-h { bottom: auto; animation: beamh var(--dur) ease-out forwards; }
.beam-v { right: auto; animation: beamv var(--dur) ease-out forwards; }
@keyframes beamh { 0% { transform: scaleX(0); } 43% { transform: scaleX(1); } 62% { transform: scaleX(1) scaleY(1); } 100% { transform: scaleX(1) scaleY(0); } }
@keyframes beamv { 0% { transform: scaleY(0); } 43% { transform: scaleY(1); } 62% { transform: scaleY(1) scaleX(1); } 100% { transform: scaleY(1) scaleX(0); } }
.blast {
  position: absolute; width: var(--size); height: var(--size); margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
  border-radius: 50%; border: calc(var(--cell) * .2) solid rgba(255,255,255,.9);
  animation: blast var(--dur) cubic-bezier(.2,.8,.3,1) forwards;
}
@keyframes blast { 0% { transform: scale(.18); opacity: .9; } 100% { transform: scale(1); opacity: 0; border-width: 0; } }
.cell-flash { background: rgba(255,255,255,.5); animation: fade .3s ease-out forwards; }
@keyframes fade { to { opacity: 0; } }
.prism-line { position: absolute; height: 3px; margin-top: -1.5px; transform-origin: 0 50%; border-radius: 2px; animation: fade var(--dur) ease-in forwards; box-shadow: 0 0 6px currentColor; }
.float {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
  font-weight: 800; font-size: calc(var(--cell) * .42); color: #fff;
  -webkit-text-stroke: 3px var(--bg); paint-order: stroke fill;
  animation: rise .7s cubic-bezier(.2,.8,.3,1) forwards;
}
.float.big { font-size: calc(var(--cell) * .52); }
.float.hot, .float.gold { color: var(--accent); }
@keyframes rise { 0% { translate: 0 0; opacity: 1; } 64% { opacity: 1; } 100% { translate: 0 calc(var(--cell) * -.5); opacity: 0; } }
.praise {
  position: absolute; left: 50%; top: 22%; transform: translate(-50%, -50%);
  font-size: calc(var(--cell) * .9); font-weight: 900; white-space: nowrap;
  color: var(--text); -webkit-text-stroke: 4px var(--bg); paint-order: stroke fill;
  border-bottom: 5px solid var(--accent); padding: 0 6px;
  animation: praise .95s ease-out forwards;
}
.praise.small { font-size: calc(var(--cell) * .6); }
@keyframes praise {
  0% { scale: .6; opacity: 0; } 26% { scale: 1.1; opacity: 1; } 34% { scale: 1; }
  79% { opacity: 1; } 100% { opacity: 0; }
}

/* ---------------------------------------------------------------- Fußleiste */
.foot { display: flex; justify-content: center; gap: 12px; padding: 6px 12px 12px; }
.foot-btn {
  min-width: 96px; height: 60px; border: 0; border-radius: 14px; background: var(--btn);
  display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 18px; font-weight: 600;
}
.foot-btn:active { background: var(--btn-down); }
.foot-btn svg { width: 26px; height: 26px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.foot-btn svg .fill { fill: var(--text); }
.foot-btn svg .cross { display: none; stroke: var(--warn); }
.foot-btn.off svg .wave { display: none; }
.foot-btn.off svg .cross { display: inline; }

/* ---------------------------------------------------------------- Einblendung */
.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(10,8,7,.72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.overlay-box {
  width: min(400px, 100%); background: #2B2622; border-radius: 22px; padding: 26px 22px 20px;
  display: flex; flex-direction: column; align-items: stretch; gap: 12px; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.6); animation: popin .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popin { from { transform: scale(.85); opacity: 0; } }
.overlay-box h2 { margin: 0 0 4px; font-size: 32px; }
.ov-goals { display: flex; justify-content: center; gap: 22px; flex-wrap: wrap; margin: 6px 0; }
.ov-goal { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 26px; font-weight: 800; }
.ov-goal .goal-icon { width: 56px; height: 56px; }
.ov-moves { margin: 0; font-size: 22px; color: var(--muted); }
.ov-moves b { color: var(--accent); font-size: 28px; }
.ov-moves .bonus { color: var(--ok); font-weight: 700; }
.ov-stars { display: flex; justify-content: center; gap: 10px; margin: 4px 0; }
.star { display: inline-block; }
.star.big { width: 64px; height: 64px; }
.star.appear { animation: born .35s cubic-bezier(.34,1.56,.64,1); }
.ov-score { margin: 0; font-size: 24px; font-weight: 700; }
.ov-done { margin: 0; font-size: 20px; color: var(--accent); font-weight: 700; }
.btn {
  height: 58px; border: 0; border-radius: 14px; background: var(--btn); font-size: 20px; font-weight: 700;
}
.btn:active { background: var(--btn-down); }
.btn.primary { background: var(--accent); color: #241b05; height: 64px; font-size: 24px; }
.btn.primary:active { background: #d9a110; }
.btn.ghost { background: transparent; color: var(--muted); height: 48px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; }
.segs { display: flex; background: #1E1B19; border-radius: 12px; padding: 4px; gap: 4px; }
.seg { border: 0; background: transparent; border-radius: 9px; padding: 0 12px; height: 44px; font-size: 16px; color: var(--muted); }
.seg.on { background: var(--btn); color: var(--text); font-weight: 700; }

/* Querformat: Anzeige links, Brett rechts */
@media (orientation: landscape) and (max-height: 600px), (orientation: landscape) and (min-aspect-ratio: 4/3) {
  .screen.game { display: grid; grid-template-columns: minmax(200px, 28%) 1fr; grid-template-rows: 1fr auto; }
  .hud { grid-column: 1; grid-row: 1; grid-template-columns: 1fr; align-content: center; }
  .board-wrap { grid-column: 2; grid-row: 1 / 3; }
  .foot { grid-column: 1; grid-row: 2; flex-wrap: wrap; }
  .foot-btn { min-width: 0; flex: 1; flex-direction: column; gap: 2px; font-size: 15px; height: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile .spin, .tile .mark.pulse, .tile.k-b .mark, .map-node.current { animation: none; }
}
