:root {
  --bg-top: #16224a;
  --bg-bottom: #0a0f26;
  --gold: #ffd966;
  --gold-dim: #b89a3e;
  --text: #f4f1e8;
  --muted: #a9b0c9;
  --panel: #1b2859;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-bottom);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-top), var(--bg-bottom));
  background-attachment: fixed;
}

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

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
  color: var(--gold);
  line-height: 1.2;
}

#subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.actions { display: flex; gap: 8px; flex-shrink: 0; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: rgba(255, 255, 255, 0.4); }
button:disabled { opacity: 0.5; cursor: default; }

button:focus-visible, input:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

button.primary {
  background: var(--gold);
  color: #2a2100;
  border-color: var(--gold);
  font-weight: 600;
}

button.ghost { background: transparent; }

#doors {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 2px 10px;
  scrollbar-width: none;
}
#doors::-webkit-scrollbar { display: none; }

.door {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 12px;
  font-weight: 700;
}

.door.locked {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border-style: dashed;
}

.door.available {
  background: linear-gradient(160deg, #ffe58a, #e0a82e);
  color: #2a2100;
  border-color: #ffe58a;
  box-shadow: 0 0 14px rgba(255, 217, 102, 0.45);
}

.door.opened {
  background: rgba(255, 217, 102, 0.14);
  color: var(--gold);
  border-color: var(--gold-dim);
}

.door.today { outline: 2px solid #fff; outline-offset: 2px; }

#stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 22px);
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  background: rgba(10, 15, 38, 0.95);
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 7, 20, 0.75);
  z-index: 10;
}

.card {
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.card h2 {
  margin: 0 0 10px;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--gold);
}

.card p { margin: 0 0 12px; line-height: 1.45; }
.muted { color: var(--muted); }
.door-text { font-size: 1.1rem; }
.message { color: #ff9a9a; min-height: 1.3em; }

.buttons { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

input[type="password"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  padding: 10px 12px;
}

.items {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 8px;
  padding: 0;
}
.items li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}
.items img { width: 40px; height: 40px; object-fit: contain; }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  cursor: pointer;
  line-height: 1.3;
}
.toggle input { width: 20px; height: 20px; accent-color: var(--gold); flex: none; }

.collection {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}
.collection figure {
  margin: 0;
  padding: 8px 4px;
  text-align: center;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 12px;
}
.collection img { width: 64px; height: 64px; object-fit: contain; }
.collection figcaption { margin-top: 4px; font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; }

.finale {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #060a1c;
  cursor: pointer;
}
.finale canvas { display: block; width: 100%; height: 100%; }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: #060a1c;
  cursor: pointer;
}
.viewer canvas { display: block; width: 100%; height: 100%; }

.collection figure { cursor: pointer; transition: transform 0.12s, background 0.12s; }
.collection figure:hover, .collection figure:focus-visible { background: rgba(255, 255, 255, 0.14); transform: translateY(-2px); outline: none; }

/* Label "Neues Bild" über dem neuen Item */
.newpop { position: fixed; inset: 0; z-index: 35; pointer-events: none; }
.newpop canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.newpop-label {
  position: absolute;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  font: bold 0.8rem Georgia, "Times New Roman", serif;
  letter-spacing: 0.03em;
  padding: 2px 9px;
  border-radius: 999px;
  color: #3b2a00;
  background: linear-gradient(100deg, #ffc247 10%, #fff2b3 45%, #ffc247 80%);
  background-size: 250% 100%;
  box-shadow: 0 0 10px rgba(255, 200, 80, 0.8), 0 2px 6px rgba(0, 0, 0, 0.4);
  animation: newpop-label 1.15s ease-out both, newpop-shimmer 0.9s linear infinite;
}
@keyframes newpop-label {
  0% { opacity: 0; transform: translate(-50%, -60%) scale(0.5); }
  18% { opacity: 1; transform: translate(-50%, -115%) scale(1.12); }
  32% { transform: translate(-50%, -110%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}
@keyframes newpop-shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
  .newpop-label { animation: newpop-fade 1.15s linear both; }
  @keyframes newpop-fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
}
