:root {
  --bg: #0f1b2d;
  --bg-deep: #0a1220;
  --surface: #f7f1e3;
  --text: #f4efe6;
  --text-dark: #2a2320;
  --muted: #a9b4c4;
  --accent: #c8423a;
  --accent-dark: #9e2f29;
  --gold: #e6b64c;
  --green: #3d7a5a;
  --door: #1d3150;
  --door-border: #36507a;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at top, var(--bg) 0%, var(--bg-deep) 100%) fixed;
  padding: 0 16px 48px;
}

main { max-width: 720px; margin: 0 auto; position: relative; }

/* ---------- Header ---------- */

.header { max-width: 720px; margin: 0 auto; padding: 32px 0 24px; text-align: center; position: relative; }
.header h1 { font-family: Georgia, serif; font-size: clamp(1.8rem, 6vw, 2.6rem); margin: 0 0 12px; color: var(--gold); }
.header p { color: var(--muted); line-height: 1.5; margin: 0; white-space: pre-line; }

/* ---------- Login ---------- */

.login {
  max-width: 320px; margin: 24px auto; position: relative;
  display: grid; gap: 10px;
}
.login label { color: var(--muted); font-weight: 600; }
.login input {
  padding: 12px 14px; border-radius: 8px; border: 2px solid var(--door-border);
  background: var(--door); color: var(--text); font-size: 1rem;
}
.login input:focus { outline: none; border-color: var(--gold); }
.login-error { color: #ff9b94; min-height: 1.2em; margin: 0; }

/* ---------- Doors ---------- */

.door-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
@media (min-width: 560px) { .door-grid { grid-template-columns: repeat(6, 1fr); } }

.door {
  aspect-ratio: 1;
  border-radius: var(--radius);
  border: 2px solid var(--door-border);
  background: var(--door);
  color: var(--text);
  font: 700 1.4rem Georgia, serif;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, background 0.15s ease;
}
.door:hover:not(:disabled) { transform: translateY(-2px); }
.door:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.door[data-state="open"]   { background: var(--accent); border-color: var(--gold); }
.door[data-state="solved"] { background: var(--green); border-color: var(--green); }
.door[data-state="locked"] { color: var(--muted); }
.door[data-state="empty"]  { opacity: 0.35; cursor: default; }

.door[data-state="solved"]::after,
.door[data-state="locked"]::after {
  position: absolute; right: 6px; bottom: 4px; font-size: 0.75rem;
}
.door[data-state="solved"]::after { content: "✓"; }
.door[data-state="locked"]::after { content: "🔒"; }

/* ---------- Fragments ---------- */

.fragments { margin-top: 32px; text-align: center; }
.fragments h2 { font-size: 1rem; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
.fragment-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-height: 44px; }
.fragment-empty { color: var(--muted); font-style: italic; }

/* ---------- Tiles (fragments + scramble) ---------- */

.tile {
  min-width: 40px; height: 44px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  font: 700 1.25rem Georgia, serif;
  background: var(--gold); color: var(--text-dark);
  border: none;
}
button.tile { cursor: pointer; }
button.tile:disabled { opacity: 0.25; cursor: default; }
.tile-empty { background: transparent; border: 2px dashed #c9bfa9; }

/* ---------- Dialog ---------- */

dialog {
  width: min(560px, 100%);
  max-height: 90vh;
  border: none;
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  background: var(--surface);
  color: var(--text-dark);
}
dialog::backdrop { background: rgba(5, 10, 20, 0.7); }

.dialog-close {
  position: absolute; top: 8px; right: 12px;
  background: none; border: none; font-size: 1.8rem; cursor: pointer; color: var(--text-dark);
}

.door-date { margin: 0; color: var(--accent); font-weight: 600; font-size: 0.9rem; }
#door-content h2 { font-family: Georgia, serif; margin: 4px 0 16px; }
#door-content p { line-height: 1.6; }

.puzzle { margin-top: 24px; padding-top: 20px; border-top: 1px solid #ddd2bb; }
.puzzle-question { font-weight: 600; }
.puzzle-hint { color: #6b5f55; font-style: italic; }

.reward {
  margin-top: 24px; padding: 16px 18px;
  background: #eef5ef; border-left: 4px solid var(--green); border-radius: 8px;
}
.reward-fragment { margin-top: 12px; display: flex; align-items: center; gap: 10px; }

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

.button {
  padding: 12px 18px; border-radius: 8px; border: none;
  background: var(--accent); color: white; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.button:hover:not(:disabled) { background: var(--accent-dark); }
.button:disabled { opacity: 0.4; cursor: default; }
.button-secondary { background: #d9cfbb; color: var(--text-dark); }
.button-secondary:hover:not(:disabled) { background: #c9bfa9; }

.quiz-options { display: grid; gap: 8px; }
.quiz-options .button.wrong { background: #b8aea0; text-decoration: line-through; }

.scramble-answer, .scramble-tiles { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.scramble-actions { display: flex; gap: 8px; margin-top: 16px; }

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

.shake { animation: shake 0.4s; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  padding: 10px 18px; border-radius: 999px;
  background: var(--surface); color: var(--text-dark); font-weight: 600;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* ---------- Snow ---------- */

#snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.flake {
  position: absolute; top: -10px;
  width: var(--size); height: var(--size);
  left: var(--x);
  border-radius: 50%; background: white; opacity: 0.7;
  animation: fall var(--duration) linear var(--delay) infinite;
}
@keyframes fall { to { transform: translate(20px, 105vh); } }
@media (prefers-reduced-motion: reduce) { #snow { display: none; } }
