:root {
  --bg: #1d3a2f;
  --bg-2: #142a22;
  --cream: #fbf5ea;
  --paper: #fffaf1;
  --ink: #2b211c;
  --muted: #7a6a5e;
  --red: #b8323a;
  --red-dark: #8e2229;
  --gold: #e3b45c;
  --path: #d9474f;
  --path-soft: #f7d9d6;
  --line: #e7dccb;
  --wall: #2b211c;
  --radius: 16px;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--cream);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #2c5444 0%, var(--bg) 45%, var(--bg-2) 100%) fixed;
  background-color: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px 40px;
}

/* ---------- Schnee ---------- */
#snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.flake {
  position: absolute; top: -10px; color: #fff; opacity: .7;
  animation: fall linear infinite;
}
@keyframes fall {
  to { transform: translateY(105vh) translateX(var(--drift, 20px)); }
}
@media (prefers-reduced-motion: reduce) { .flake { display: none; } }

/* ---------- Kalender ---------- */
.hero { text-align: center; margin: 12px 0 28px; }
.eyebrow { margin: 0; color: var(--gold); letter-spacing: .14em; text-transform: uppercase; font-size: 13px; font-weight: 600; }
h1 {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: clamp(32px, 7vw, 52px); line-height: 1.05; margin: 8px 0 10px; font-weight: 700;
}
.sub { margin: 0; color: #cfe0d6; font-size: 15px; }

.doors {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
}
@media (max-width: 640px) { .doors { grid-template-columns: repeat(4, 1fr); gap: 10px; } }

.door {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 0; padding: 0; cursor: pointer;
  border-radius: 14px;
  perspective: 600px;
  background: #0f2019;
  font: inherit;
  color: inherit;
}
.door .face {
  position: absolute; inset: 0;
  border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--red) 0%, var(--red-dark) 100%);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.12), 0 6px 14px rgba(0,0,0,.25);
  transform-origin: left center;
  transition: transform .5s cubic-bezier(.3,.7,.3,1);
}
.door:nth-child(3n) .face { background: linear-gradient(145deg, #2f6b52, #1f4c3a); }
.door:nth-child(4n+1) .face { background: linear-gradient(145deg, #c8913a, #9c6a22); }
.door .num {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: clamp(24px, 6vw, 34px); font-weight: 700;
  text-shadow: 0 2px 0 rgba(0,0,0,.2);
}
.door .face::after {
  content: ""; position: absolute; right: 10px; top: 50%; width: 5px; height: 5px;
  border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px rgba(0,0,0,.15);
}
.door.locked .face { filter: saturate(.35) brightness(.7); }
.door.locked .face::before { content: "🔒"; position: absolute; top: 6px; left: 8px; font-size: 11px; opacity: .8; }
.door.today .face { box-shadow: inset 0 0 0 2px var(--gold), 0 0 0 3px rgba(227,180,92,.35), 0 6px 14px rgba(0,0,0,.25); animation: glow 2.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: inset 0 0 0 2px var(--gold), 0 0 0 7px rgba(227,180,92,.15), 0 6px 14px rgba(0,0,0,.25); } }

.door .inside {
  position: absolute; inset: 0; border-radius: 14px;
  display: grid; place-items: center; align-content: center; gap: 2px;
  background: var(--paper); color: var(--ink); font-size: 13px;
}
.door .inside .heart { font-size: 26px; }
.door .inside small { color: var(--muted); }
.door.solved .face { transform: rotateY(-78deg); box-shadow: none; }
.door.opening .face { transform: rotateY(-100deg); }
.door:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.door.shake { animation: shake .4s; }
@keyframes shake { 20%,60% { transform: translateX(-5px); } 40%,80% { transform: translateX(5px); } }

.foot { text-align: center; color: #a9c2b5; font-size: 14px; margin-top: 28px; }

/* ---------- Spiel ---------- */
#game-view { max-width: 520px; margin: 0 auto; }
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.game-top h2 {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  margin: 0; font-size: 26px;
}
.back { color: var(--cream); text-decoration: none; font-weight: 600; padding: 8px 4px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--gold); min-width: 52px; text-align: right; }
.rules { color: #cfe0d6; font-size: 14px; line-height: 1.45; margin: 10px 0 16px; }

.board-wrap {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: 0 14px 40px rgba(0,0,0,.35);
}
#board { display: block; width: 100%; height: auto; touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer; }
#board .cell { fill: var(--paper); }
#board .cell.on { fill: var(--path-soft); }
#board .grid { stroke: var(--line); stroke-width: 2; }
#board .wall { stroke: var(--wall); stroke-width: 10; stroke-linecap: round; }
#board .path { fill: none; stroke: var(--path); stroke-width: 38; stroke-linecap: round; stroke-linejoin: round; }
#board .clue circle { fill: var(--ink); }
#board .clue.done circle { fill: var(--red-dark); }
#board .clue text { fill: #fff; font: 700 34px ui-rounded, system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; }
#board.won .path { stroke: #2f8a5f; }
#board.won .cell.on { fill: #d6efe0; }

.controls { display: flex; gap: 10px; margin-top: 16px; }
.controls button {
  flex: 1; font: inherit; font-weight: 600; font-size: 15px;
  padding: 12px 8px; border-radius: 12px; border: 0; cursor: pointer;
  background: rgba(255,255,255,.1); color: var(--cream);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.controls button:hover { background: rgba(255,255,255,.16); }
.controls button:active { transform: translateY(1px); }
.controls button:disabled { opacity: .4; cursor: default; }

.toast { min-height: 1.4em; text-align: center; color: var(--gold); font-size: 14px; margin: 14px 0 0; transition: opacity .3s; }

/* ---------- Gewonnen ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; padding: 16px;
  background: rgba(10, 20, 15, .6);
  backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.card {
  background: var(--paper); color: var(--ink);
  border-radius: 20px; padding: 28px 24px 24px;
  max-width: 400px; width: 100%; text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.4);
  animation: pop .45s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.card .big { font-size: 48px; }
.card h3 { font-family: "Iowan Old Style", Palatino, Georgia, serif; font-size: 28px; margin: 6px 0 4px; }
.win-stats { color: var(--muted); margin: 0 0 16px; font-size: 14px; }
.win-msg {
  font-size: 18px; line-height: 1.5; margin: 0 0 22px;
  padding: 16px; border-radius: 14px; background: #fbeee9;
}
.primary {
  display: inline-block; text-decoration: none; font-weight: 700;
  background: var(--red); color: #fff; padding: 12px 22px; border-radius: 12px;
}
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 11; }

/* ---------- Login ---------- */
#login-view { min-height: 80vh; display: grid; place-items: center; }
.login { display: grid; gap: 12px; }
.login h3 { margin: 0; }
.muted { color: var(--muted); margin: 0 0 4px; font-size: 15px; }
.login input {
  font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); width: 100%;
}
.login input:focus { outline: 2px solid var(--gold); border-color: transparent; }
.login button.primary { border: 0; font: inherit; font-weight: 700; cursor: pointer; font-size: 16px; }
.error { color: var(--red); min-height: 1.2em; margin: 0; font-size: 14px; }

.preview-bar {
  background: rgba(227,180,92,.15); color: var(--gold); border: 1px solid rgba(227,180,92,.35);
  border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-bottom: 12px; text-align: center;
}
.preview-bar a { color: var(--cream); font-weight: 600; }

.solved-note {
  margin-top: 16px; background: var(--paper); color: var(--ink);
  border-radius: 14px; padding: 16px; text-align: center; line-height: 1.5;
}
.solved-note small { display: block; color: var(--muted); margin-bottom: 6px; }

/* ---------- Tier fürs echte Türchen ---------- */
.door-reveal {
  display: grid; justify-items: center; gap: 2px;
  margin: 0 0 16px; padding: 14px; border-radius: 14px;
  border: 2px dashed var(--gold); background: #fff7e6;
}
.door-reveal .door-label { font-size: 14px; color: var(--muted); }
.door-reveal .door-emoji { font-size: 56px; line-height: 1.15; }
.door-reveal b { font-size: 20px; font-family: "Iowan Old Style", Palatino, Georgia, serif; }
.door-line { font-weight: 700; margin-bottom: 8px; }
.modal .card { max-height: calc(100vh - 32px); overflow-y: auto; }

/* ---------- Flüssigeres Spielgefühl ---------- */
#board .clue { transform-box: fill-box; transform-origin: center; }
#board .clue.pop { animation: clue-pop .35s cubic-bezier(.3,1.6,.5,1); }
@keyframes clue-pop { 40% { transform: scale(1.22); } }
#board.won .path, #board.won .cell { transition: stroke .5s, fill .5s; }
#board.won { animation: board-win .6s ease-out; }
@keyframes board-win { 50% { transform: scale(1.02); } }

/* ---------- Hinweis: als App speichern ---------- */
.install-hint {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14);
  border-radius: 14px; padding: 12px 14px; margin: -8px 0 20px; font-size: 14px;
}
.install-hint p { margin: 2px 0 0; color: #cfe0d6; line-height: 1.4; }
.install-icon { font-size: 26px; }
.install-hint > div { flex: 1; }
.install-btn { font: inherit; font-weight: 700; border: 0; border-radius: 10px; padding: 8px 12px; background: var(--gold); color: var(--ink); cursor: pointer; }
.install-close { font: inherit; font-size: 22px; line-height: 1; border: 0; background: none; color: #cfe0d6; cursor: pointer; padding: 4px 6px; }

/* ---------- Rückblick ---------- */
.win-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.primary.gold { background: var(--gold); color: var(--ink); }
.review-cta {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink);
  background: linear-gradient(135deg, #f3d48f, var(--gold)); border-radius: 14px;
  padding: 14px 16px; margin: -8px 0 20px; font-size: 16px; box-shadow: 0 8px 20px rgba(0,0,0,.25);
}
.review-cta b { flex: 1; }
#review-view { max-width: 560px; margin: 0 auto; }
.review-note { background: rgba(227,180,92,.15); color: var(--gold); border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.review-hero { text-align: center; margin: 18px 0 22px; }
.review-hero .big { font-size: 48px; }
.review-hero h1 { font-size: clamp(28px, 7vw, 40px); margin: 6px 0 8px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 520px) { .stats { grid-template-columns: repeat(3, 1fr); } }
.stat-tile {
  background: var(--paper); color: var(--ink); border-radius: 14px; padding: 14px;
  display: grid; gap: 2px; align-content: start;
}
.stat-tile b { font: 700 28px "Iowan Old Style", Palatino, Georgia, serif; font-variant-numeric: tabular-nums; }
.stat-tile span { font-size: 14px; }
.stat-tile small { color: var(--muted); font-size: 12px; }
.review-h { font-family: "Iowan Old Style", Palatino, Georgia, serif; font-size: 22px; margin: 28px 0 12px; }
.mini-doors { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.mini {
  aspect-ratio: 1; border-radius: 10px; background: rgba(255,255,255,.07);
  display: grid; place-items: center; align-content: center; gap: 0; position: relative;
}
.mini.done { background: var(--paper); color: var(--ink); }
.mini .e { font-size: 22px; line-height: 1.1; }
.mini .d { position: absolute; top: 3px; left: 6px; font-size: 10px; font-weight: 700; opacity: .55; }
.mini small { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.review-outro {
  margin: 24px 0 8px; padding: 20px; border-radius: 16px; text-align: center;
  background: #fbeee9; color: var(--ink); font-size: 18px; line-height: 1.5;
}
.logout { display: block; margin: 14px auto 0; font: inherit; font-size: 13px; color: #a9c2b5; background: none; border: 0; text-decoration: underline; cursor: pointer; padding: 6px; }

/* ---------- iPhone: Abstand zu Dynamic Island / Notch und Home-Balken ---------- */
/* Als App vom Home-Bildschirm läuft die Seite unter die Statusleiste. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
#app {
  padding: calc(var(--safe-top) + 20px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 40px) calc(var(--safe-left) + 16px);
}
/* Streifen hinter der Statusleiste, damit beim Scrollen nichts unter der Dynamic Island durchläuft */
body::before {
  content: ""; position: fixed; left: 0; right: 0; top: 0; z-index: 20;
  height: var(--safe-top); background: var(--bg-2); pointer-events: none;
}
.modal {
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 16px);
}
.modal .card {
  max-height: calc(100vh - var(--safe-top) - var(--safe-bottom) - 24px);
  max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 24px);
}
#login-view {
  min-height: calc(100vh - var(--safe-top) - var(--safe-bottom) - 60px);
  min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 60px);
}
