:root {
  --bg-deep: #120d09;
  --bg-panel: #241a12;
  --leather: #2e2015;
  --parchment: #ecdfc0;
  --parchment-dark: #d9c79f;
  --gold: #c9a24b;
  --gold-bright: #f4d35e;
  --shadow-purple: #7a4fb0;
  --danger: #a13d3d;
  --text-light: #f0e6d2;
  --text-dark: #2b2118;
  --font-display: 'Cinzel Decorative', 'Cinzel', serif;
  --font-body: 'EB Garamond', Georgia, serif;
  --font-pixel: 'Press Start 2P', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at 50% 0%, #241a12 0%, var(--bg-deep) 65%);
  color: var(--text-light);
  font-family: var(--font-body);
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 24px 12px;
}

#app {
  width: 100%;
  max-width: 1000px;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: fadeIn 0.4s ease;
}
.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; margin: 0; }

/* ---------------- Start-skærm ---------------- */
#screen-start {
  width: 100%;
  padding: 32px 16px 48px;
  text-align: center;
  background:
    linear-gradient(rgba(18,13,9,0.72), rgba(18,13,9,0.88)),
    url('../assets/cover.png') center 18% / 340px auto no-repeat;
  border-radius: 18px;
  border: 1px solid #3a2b1c;
}

.game-title {
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  color: var(--gold-bright);
  text-shadow: 0 0 18px rgba(244, 211, 94, 0.35), 0 2px 0 #000;
  letter-spacing: 1px;
}
.game-subtitle {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--parchment-dark);
  margin-top: 6px;
  font-size: 1.1rem;
}

.start-form {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
#username-input {
  font-family: var(--font-body);
  font-size: 1.1rem;
  padding: 10px 16px;
  border-radius: 8px;
  border: 2px solid var(--gold);
  background: var(--parchment);
  color: var(--text-dark);
  width: min(320px, 80vw);
  text-align: center;
}
#username-input:focus-visible { outline: 3px solid var(--gold-bright); outline-offset: 2px; }

.start-error { color: #ff8a8a; min-height: 1.2em; font-size: 0.9rem; }
.continue-hint { color: var(--parchment-dark); font-size: 0.9rem; min-height: 1.2em; }

.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

/* ---------------- Knapper ---------------- */
button {
  font-family: var(--font-body);
  font-size: 1.05rem;
  cursor: pointer;
  border: 2px solid var(--gold);
  background: linear-gradient(180deg, #3a2b1c, #241a12);
  color: var(--text-light);
  padding: 10px 22px;
  border-radius: 999px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
button:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(201, 162, 75, 0.35); background: linear-gradient(180deg, #4a3728, #2e2015); }
button:active { transform: translateY(0); }
button:focus-visible { outline: 3px solid var(--gold-bright); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: default; transform: none; box-shadow: none; }

.btn-primary { border-color: var(--gold-bright); background: linear-gradient(180deg, #6b4a1e, #402c10); font-weight: 600; }

/* ---------------- Parkament-panel (historie / epilog) ---------------- */
.parchment-panel {
  position: relative;
  width: min(720px, 94vw);
  background: var(--parchment);
  color: var(--text-dark);
  padding: 40px 44px 32px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  clip-path: polygon(
    0% 3%, 4% 0%, 9% 2%, 14% 0%, 19% 2%, 24% 0%, 29% 2%, 34% 0%, 39% 2%, 44% 0%,
    49% 2%, 54% 0%, 59% 2%, 64% 0%, 69% 2%, 74% 0%, 79% 2%, 84% 0%, 89% 2%, 94% 0%, 100% 3%,
    100% 97%, 96% 100%, 91% 98%, 86% 100%, 81% 98%, 76% 100%, 71% 98%, 66% 100%, 61% 98%, 56% 100%,
    51% 98%, 46% 100%, 41% 98%, 36% 100%, 31% 98%, 26% 100%, 21% 98%, 16% 100%, 11% 98%, 6% 100%, 0% 97%
  );
}
.parchment-panel h2 { font-size: 1.5rem; color: var(--text-dark); border-bottom: 2px solid var(--gold); padding-bottom: 10px; margin-bottom: 14px; }
.parchment-panel p { font-size: 1.12rem; line-height: 1.55; margin: 0 0 14px; }
.story-result { font-style: italic; color: #5a4324; min-height: 1.4em; margin: 6px 0 16px; }

.choices { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.choice-btn {
  text-align: left;
  border: 2px solid #8a6a34;
  background: #f4ecd6;
  color: var(--text-dark);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 1.02rem;
}
.choice-btn:hover { background: #fff6de; }

.level-intro {
  margin-top: 18px;
  font-family: var(--font-pixel);
  font-size: 0.7rem;
  color: #5a4324;
  border-top: 1px dashed var(--gold);
  padding-top: 14px;
  line-height: 1.8;
}

.hidden { display: none !important; }

/* ---------------- Highscores ---------------- */
#screen-highscores .parchment-panel ul { list-style: none; margin: 0; padding: 0; }
#screen-highscores .parchment-panel li {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 8px 4px; border-bottom: 1px solid #c9b98a; font-family: var(--font-pixel); font-size: 0.65rem;
}
.hs-rank { color: #7a5a1e; width: 3em; }
.hs-name { flex: 1; text-align: left; }
.hs-score { color: #5a4324; }

/* ---------------- Spil-skærm ---------------- */
#screen-game { width: 100%; }
.game-frame {
  position: relative;
  width: min(960px, 100%);
  margin: 0 auto;
  border: 6px solid var(--gold);
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 0 2px #4a3728, 0 12px 40px rgba(0,0,0,0.6);
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: linear-gradient(180deg, #241a12, #1a1109);
  border-bottom: 2px solid var(--gold);
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  color: var(--gold-bright);
  gap: 10px;
}
#hud-world { color: var(--parchment); flex: 1; }
#hud-status { white-space: nowrap; }

#game-canvas { display: block; width: 100%; height: auto; aspect-ratio: 960 / 540; background: #000; }

.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(10, 6, 4, 0.82);
  text-align: center;
  padding: 20px;
}
.overlay h3 { font-size: 1.4rem; color: var(--gold-bright); }
.overlay-buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ---------------- Mobil-kontroller ---------------- */
#mobile-controls {
  display: none;
  justify-content: space-between;
  padding: 14px 10px;
  gap: 10px;
}
#mobile-controls .pad-left,
#mobile-controls .pad-right { display: flex; gap: 10px; }
#mobile-controls button {
  width: 58px; height: 58px; border-radius: 50%;
  font-family: var(--font-pixel); font-size: 0.8rem; padding: 0;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
@media (pointer: coarse) {
  #mobile-controls { display: flex; }
}

/* ---------------- Epilog ---------------- */
#epilogue-score { font-family: var(--font-pixel); font-size: 0.8rem; color: #5a4324; margin: 16px 0; }

@media (max-width: 640px) {
  .parchment-panel { padding: 30px 20px 24px; }
  .parchment-panel p { font-size: 1rem; }
}
