/* ==================================================================
   LICHTWERK — Spiegel-Lichtstrahl-Puzzle ("Midnight Felt", 2026)
   ================================================================== */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg0: #0a0e0b;
  --felt: #0e1410;
  --card: rgba(255, 252, 240, 0.045);
  --card-hi: rgba(255, 252, 240, 0.09);
  --edge: rgba(232, 193, 90, 0.14);
  --edge-soft: rgba(255, 252, 240, 0.08);
  --ink: #f4efe2;
  --muted: #93a396;
  --gold: #e8c15a;
  --cyan: #5ec4c9;
  --gold-glow: rgba(232, 193, 90, 0.35);
  --foil: linear-gradient(115deg, #8a6a1c 0%, #e8c15a 25%, #fff3c4 50%, #e8c15a 75%, #8a6a1c 100%);
  --radius: 16px;
  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Outfit", system-ui, -apple-system, sans-serif;
  --ease-spring: cubic-bezier(0.34, 1.4, 0.5, 1);
}

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background: radial-gradient(120% 90% at 50% -10%, #1a2a1d 0%, var(--felt) 45%, var(--bg0) 100%);
  background-attachment: fixed;
  color: var(--ink);
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- Ambiente ---------- */
.ambience { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.aurora {
  position: absolute;
  width: 70vmax; height: 70vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.35;
  mix-blend-mode: screen;
}
.aurora-a {
  top: -35vmax; left: -20vmax;
  background: radial-gradient(circle, rgba(232,193,90,0.28), transparent 65%);
  animation: drift-a 26s ease-in-out infinite alternate;
}
.aurora-b {
  bottom: -40vmax; right: -25vmax;
  background: radial-gradient(circle, rgba(94,196,201,0.3), transparent 65%);
  animation: drift-b 32s ease-in-out infinite alternate;
}
@keyframes drift-a { to { transform: translate(10vmax, 8vmax) scale(1.15); } }
@keyframes drift-b { to { transform: translate(-8vmax, -10vmax) scale(1.1); } }
.grain {
  position: absolute; inset: -50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  opacity: 0.05;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: 14px 14px calc(24px + env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
#screen-game { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.topbar h1 {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 800;
  font-size: 1.6rem;
  line-height: 1.1;
}
#screen-select .topbar h1 { flex: 1; }
.lvl-title { flex: 1; min-width: 0; }
.lvl-title h1 { font-size: 1.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvl-sub { color: var(--muted); font-size: 0.78rem; }
.foil {
  background: var(--foil);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: foil-sheen 5.5s ease-in-out infinite;
}
@keyframes foil-sheen {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.btn-back {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  font-family: inherit;
  font-size: 1.15rem;
  box-shadow: 0 0 0 1px var(--edge-soft) inset;
  flex-shrink: 0;
  border: 0;
  cursor: pointer;
}
button {
  font-family: inherit;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.15s var(--ease-spring);
}
button:active { transform: scale(0.94); }
.btn-icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 1.05rem;
  box-shadow: 0 0 0 1px var(--edge-soft) inset;
  flex-shrink: 0;
}

/* ---------- Level-Auswahl ---------- */
.intro { color: var(--muted); font-size: 0.92rem; line-height: 1.55; margin-bottom: 12px; }
.intro b { color: var(--gold); font-weight: 600; }
.star-total {
  text-align: center;
  color: var(--gold);
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 14px;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.lvl-tile {
  aspect-ratio: 1;
  border-radius: 14px;
  background: linear-gradient(175deg, var(--card-hi), var(--card));
  box-shadow: 0 0 0 1px var(--edge-soft) inset;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--ink);
  animation: rise-in 0.4s var(--ease-spring) both;
  animation-delay: calc(var(--i, 0) * 35ms);
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.lvl-tile .n {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;
}
.lvl-tile .stars { font-size: 0.62rem; letter-spacing: 0.1em; color: var(--gold); }
.lvl-tile.done { box-shadow: 0 0 0 1px var(--edge) inset, 0 0 16px -6px var(--gold-glow); }
.lvl-tile.locked { opacity: 0.35; pointer-events: none; }
.lvl-tile.locked .n::after { content: " 🔒"; font-size: 0.7em; }

/* ---------- Spielbrett ---------- */
#board-holder {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}
#board {
  border-radius: 18px;
  background: rgba(8, 12, 9, 0.62);
  box-shadow: 0 0 0 1px var(--edge) inset, 0 14px 40px -18px rgba(0,0,0,0.8);
  touch-action: manipulation;
  max-width: 100%;
  max-height: 100%;
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 6, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 18px;
  animation: overlay-in 0.25s ease;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
.panel {
  background: linear-gradient(180deg, #17201a, #101611);
  border-radius: 22px;
  box-shadow: 0 0 0 1px var(--edge) inset, 0 24px 70px -24px rgba(0,0,0,0.9);
  padding: 26px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 420px;
  max-height: 86vh;
  overflow-y: auto;
  animation: panel-up 0.4s var(--ease-spring);
  text-align: center;
}
@keyframes panel-up {
  from { transform: translateY(46px) scale(0.96); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.panel h2 {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 800;
  font-size: 1.7rem;
  margin-bottom: 6px;
}
.panel .sub { color: var(--muted); font-size: 0.92rem; margin-bottom: 16px; line-height: 1.5; }
.win-stars {
  font-size: 2.4rem;
  letter-spacing: 0.15em;
  margin: 8px 0 4px;
  animation: stars-pop 0.6s var(--ease-spring);
}
@keyframes stars-pop {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.win-moves { color: var(--muted); font-size: 0.9rem; margin-bottom: 16px; }

.btn-primary {
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, #f0cd6e 0%, var(--gold) 40%, #c39a30 100%);
  color: #1a1508;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 15px;
  width: 100%;
  border-radius: 14px;
  box-shadow: 0 0 0 1px rgba(255, 230, 160, 0.35) inset, 0 10px 30px -10px var(--gold-glow);
  margin-bottom: 10px;
}
.btn-secondary {
  background: var(--card-hi);
  color: var(--ink);
  font-size: 1rem;
  padding: 13px;
  width: 100%;
  border-radius: 14px;
  box-shadow: 0 0 0 1px var(--edge-soft) inset;
}
.panel input[type="text"] {
  font-family: inherit;
  font-size: 1.15rem;
  text-align: center;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--edge-soft);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  margin-bottom: 14px;
}
.panel input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(232, 193, 90, 0.18);
}

.lb-list { list-style: none; text-align: left; margin: 6px 0 16px; }
.lb-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--edge-soft);
  font-size: 0.98rem;
}
.lb-list li:last-child { border-bottom: 0; }
.lb-rank { width: 34px; flex-shrink: 0; text-align: center; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-list li:nth-child(-n+3) .lb-rank { font-size: 1.15rem; }
.lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list li.me .lb-name { color: var(--gold); font-weight: 700; }
.lb-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-empty { color: var(--muted); padding: 18px 0; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti i {
  position: absolute;
  top: -4vh;
  width: 8px; height: 14px;
  border-radius: 2px;
  opacity: 0.9;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.7; }
}

.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
  .grain, .aurora { animation: none !important; }
}
