/* Begrepshvelvet – hvelvets verden. Skallet (stiglet.css) lastes først.
   Fakkelbelyst steinhvelv: plommefarget stein, tre, messing og pergament. */
:root {
  --hv-night: #2f2236;
  --hv-stone: #54405c;
  --hv-stone-light: #8a7591;
  --hv-wood: #b97a3e;
  --hv-parchment: #fbefd5;
  --hv-ember: #fb923c;
  --hv-ink: var(--ink, #2b2118);
  --hv-coral: var(--coral, #fa5c66);
  --hv-yellow: var(--yellow, #facc15);
  --hv-cream: var(--cream, #fff9f0);
  --hv-shadow: 0 4px 0 var(--hv-ink);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--hv-night) url("bilder/vegg.svg") 0 0 / 240px 120px;
  color: var(--hv-ink);
  font-family: "Nunito", sans-serif;
  font-weight: 600;
}

#hv-app {
  min-height: calc(100dvh - var(--stiglet-hode-hoyde, 0px));
  display: flex;
  flex-direction: column;
  /* Mørkere mot kantene, som lys fra faklene i midten */
  background: radial-gradient(ellipse at 50% 30%, transparent 35%, rgba(27, 18, 32, .6) 100%);
}

:focus-visible { outline: 4px solid var(--hv-yellow); outline-offset: 3px; }

/* ---------- Knapper ---------- */
.hv-btn {
  font: 800 1.05rem "Nunito", sans-serif;
  color: #fff;
  background: var(--hv-coral);
  border: 3px solid var(--hv-ink);
  border-radius: 12px;
  box-shadow: var(--hv-shadow);
  padding: 10px 20px;
  cursor: pointer;
}
.hv-btn:active:not(:disabled) { box-shadow: none; transform: translateY(4px); }
.hv-btn:disabled { opacity: .55; cursor: default; }
.hv-btn--big { font-size: 1.25rem; padding: 13px 26px; width: 100%; }
.hv-btn--small { font-size: .9rem; padding: 6px 14px; }
.hv-btn--white { background: #fff; color: var(--hv-ink); }

.hv-link {
  display: inline-block; margin-top: 12px;
  color: var(--hv-ink); font-weight: 800;
  text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px;
}
.hv-link:hover { color: var(--hv-coral); }
.hv-link[hidden] { display: none; }

/* ---------- Fakler ---------- */
.hv-torch {
  width: 46px; height: auto; flex: none;
  filter: drop-shadow(0 0 18px rgba(251, 146, 60, .75));
  animation: hv-flicker 1.7s ease-in-out infinite alternate;
  transform-origin: 50% 60%;
}
.hv-torch:last-of-type { animation-delay: -.8s; }
.hv-torch--small { width: 34px; }
@keyframes hv-flicker {
  0% { filter: drop-shadow(0 0 12px rgba(251, 146, 60, .55)); transform: scale(1); }
  45% { filter: drop-shadow(0 0 22px rgba(251, 146, 60, .9)); transform: scale(1.03, .98); }
  100% { filter: drop-shadow(0 0 16px rgba(250, 204, 21, .7)); transform: scale(.98, 1.03); }
}

/* ---------- Start: velg tema ---------- */
.hv-start {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 20px 16px 32px;
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 24px;
  align-items: start;
}
.hv-start[hidden], .hv-game[hidden] { display: none; }

.hv-intro { position: sticky; top: 12px; display: grid; gap: 14px; }
.hv-logo { display: flex; align-items: center; justify-content: center; gap: 10px; }
.hv-title {
  font: 400 2.9rem/1 "Chewy", cursive; margin: 0; text-align: center;
  color: var(--hv-yellow);
  text-shadow: 0 4px 0 var(--hv-ink), 3px 0 0 var(--hv-ink), -3px 0 0 var(--hv-ink), 0 -3px 0 var(--hv-ink),
    2px 2px 0 var(--hv-ink), -2px 2px 0 var(--hv-ink), 2px -2px 0 var(--hv-ink), -2px -2px 0 var(--hv-ink);
  letter-spacing: .01em;
}
.hv-rules {
  margin: 0; padding: 12px 16px 12px 36px; line-height: 1.4; font-size: .95rem;
  background: var(--hv-parchment);
  border: 3px solid var(--hv-ink); border-radius: 20px;
}
.hv-rules li + li { margin-top: 5px; }
.hv-chosen {
  background: var(--hv-cream);
  border: 3px solid var(--hv-ink); border-radius: 20px; box-shadow: var(--hv-shadow);
  padding: 14px 18px 16px; text-align: center;
}
.hv-chosen-label { margin: 0; font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.hv-chosen-title { font: 400 1.9rem/1.05 "Chewy", cursive; margin: 2px 0 2px; overflow-wrap: anywhere; }
.hv-chosen-meta { margin: 0 0 12px; font-size: .9rem; }
.hv-records { margin-top: 14px; text-align: left; }
.hv-records[hidden] { display: none; }
.hv-records h3 { font: 800 .7rem "Nunito", sans-serif; text-transform: uppercase; letter-spacing: .06em; margin: 0 0 4px; text-align: center; }
.hv-records ol { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.hv-records li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 10px; border-radius: 8px; }
.hv-records li:nth-child(odd) { background: #fff; }
.hv-records li:first-child { background: var(--hv-yellow); font-weight: 800; }
.hv-rec-score { font-weight: 800; }

.hv-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.hv-chip {
  font: 800 .95rem/1 "Nunito", sans-serif; color: var(--hv-ink); background: #fff;
  border: 3px solid var(--hv-ink); border-radius: 999px; padding: 8px 15px; cursor: pointer;
}
.hv-chip[aria-pressed="true"] { background: var(--hv-yellow); }

.hv-themes {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px;
}
.hv-loading { color: var(--hv-cream); font-size: 1.1rem; }
.hv-theme {
  width: 100%; height: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  font: inherit; color: var(--hv-ink); cursor: pointer;
  background: var(--hv-cream);
  border: 3px solid var(--hv-ink); border-radius: 20px; box-shadow: var(--hv-shadow);
  padding: 10px 12px;
}
.hv-theme:active { box-shadow: none; transform: translateY(4px); }
.hv-theme[aria-pressed="true"] { background: var(--hv-yellow); }
.hv-theme-img {
  flex: none; width: 64px; height: 64px; object-fit: cover;
  border: 3px solid var(--hv-ink); border-radius: 14px; background: var(--subject, #a78bfa);
}
.hv-theme-img--none { display: grid; place-items: center; font: 400 1.8rem "Chewy", cursive; }
.hv-theme-text { min-width: 0; display: grid; gap: 3px; }
.hv-theme-name { font: 400 1.3rem/1.05 "Chewy", cursive; overflow-wrap: anywhere; }
.hv-theme-meta { font-size: .78rem; font-weight: 800; display: flex; align-items: baseline; gap: 6px; }
.hv-dot { width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--hv-ink); background: var(--subject, #a78bfa); flex: none; }
.hv-theme-best { font-size: .78rem; font-weight: 800; }

/* ---------- Spill ---------- */
.hv-game {
  flex: 1;
  display: flex; flex-direction: column; gap: 10px;
  padding: 10px 16px 14px;
  width: min(1240px, 100%);
  margin: 0 auto;
}

.hv-hud {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: var(--hv-cream);
  border: 3px solid var(--hv-ink); border-radius: 18px; box-shadow: var(--hv-shadow);
  padding: 7px 14px;
}
.hv-hud-item { display: flex; flex-direction: column; gap: 3px; }
.hv-hud-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 800; }
.hv-hud-score { min-width: 76px; align-items: flex-end; }
.hv-score { font: 400 1.7rem/1 "Chewy", cursive; color: var(--hv-coral); display: inline-block; }
.hv-score.hv-bump { animation: hv-bump .35s ease-out; }
@keyframes hv-bump { 40% { transform: scale(1.35); } }

.hv-rooms { list-style: none; margin: 0; padding: 0; display: flex; gap: 5px; }
.hv-rooms li {
  width: 17px; height: 23px; border: 3px solid var(--hv-ink);
  border-radius: 9px 9px 3px 3px; background: #fff;
}
.hv-rooms li.hv-done { background: var(--hv-yellow); }
.hv-rooms li.hv-now { background: var(--hv-coral); }

.hv-lives { display: flex; gap: 3px; min-height: 25px; }
.hv-lives img { width: 26px; height: 25px; }
.hv-lives img.hv-lost { animation: hv-pop .4s ease-out; }
@keyframes hv-pop { 0% { transform: scale(1.5); } }

.hv-fuse { flex: 1; min-width: 170px; position: relative; height: 30px; }
.hv-fuse-rope {
  position: absolute; inset: 4px 0; overflow: hidden;
  border: 3px solid var(--hv-ink); border-radius: 999px; background: #fff;
}
.hv-fuse-bar {
  height: 100%; width: 100%; transform-origin: left;
  background: repeating-linear-gradient(115deg, var(--hv-wood) 0 9px, #d39552 9px 18px);
}
.hv-fuse-spark {
  position: absolute; top: 50%; left: 100%; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%; border: 3px solid var(--hv-ink);
  background: radial-gradient(circle, #fff 0 25%, var(--hv-yellow) 30% 55%, var(--hv-ember) 60%);
  box-shadow: 0 0 14px 4px rgba(251, 146, 60, .8);
  animation: hv-spark .25s steps(2) infinite;
}
@keyframes hv-spark { 50% { transform: scale(1.18) rotate(20deg); } }
.hv-fuse-time {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 800; font-size: .9rem; pointer-events: none;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
}
.hv-fuse.hv-low .hv-fuse-bar { background: repeating-linear-gradient(115deg, var(--hv-coral) 0 9px, #fc8a91 9px 18px); }
.hv-fuse.hv-low .hv-fuse-time { animation: hv-bump .5s ease-in-out infinite; }

.hv-main { flex: 1; display: grid; grid-template-columns: 270px 1fr; gap: 14px; min-height: 0; align-items: start; }

/* Døra med begrepslåsen */
.hv-lock { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hv-plaque {
  margin: 0; padding: 4px 16px; max-width: 100%;
  font: 400 1.25rem/1.1 "Chewy", cursive; text-align: center; overflow-wrap: anywhere;
  background: var(--hv-yellow); border: 3px solid var(--hv-ink); border-radius: 12px; box-shadow: var(--hv-shadow);
}
.hv-door { position: relative; width: 100%; max-width: 270px; aspect-ratio: 300 / 440; perspective: 900px; }
.hv-door-light {
  position: absolute; inset: 8.5% 11.5% 1% 11.5%; border-radius: 50% 50% 0 0 / 33% 33% 0 0;
  background: radial-gradient(ellipse at 50% 70%, #fff 0, var(--hv-yellow) 45%, var(--hv-ember) 100%);
  opacity: 0; transition: opacity .5s;
}
.hv-door-frame { position: absolute; inset: 0; width: 100%; height: 100%; }
.hv-door-leaf { position: absolute; inset: 0; transform-origin: 11% 50%; transition: transform .7s cubic-bezier(.3, 1.3, .5, 1); }
.hv-door-leaf img { width: 100%; height: 100%; display: block; }
.hv-door.hv-open .hv-door-leaf { transform: rotateY(-68deg); }
.hv-door.hv-open .hv-door-light { opacity: 1; }
.hv-slots {
  list-style: none; margin: 0; padding: 0;
  position: absolute; left: 17%; right: 17%; top: 37.5%; bottom: 12.5%;
  display: flex; flex-direction: column; justify-content: center; gap: 5px;
}
.hv-slots li {
  flex: 0 1 36px; min-height: 0; padding: 2px 8px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: .82rem; font-weight: 800; line-height: 1.05; overflow: hidden;
  border: 3px dashed rgba(43, 33, 24, .65); border-radius: 10px;
  background: rgba(43, 33, 24, .22);
}
.hv-slots li.hv-filled {
  border-style: solid; border-color: var(--hv-ink); background: var(--hv-yellow);
  box-shadow: 0 3px 0 var(--hv-ink);
  animation: hv-drop .35s cubic-bezier(.3, 1.6, .5, 1);
}
.hv-slots li span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
@keyframes hv-drop { 0% { transform: scale(1.4) rotate(-4deg); } }
.hv-bonus {
  margin: 0; padding: 4px 12px; font-weight: 800; font-size: .85rem; text-align: center;
  color: #fff; background: var(--hv-coral); border: 3px solid var(--hv-ink); border-radius: 999px;
}
.hv-bonus[hidden] { display: none; }

/* Arenaen */
.hv-arena { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.hv-prompt-row { display: flex; align-items: center; gap: 10px; }
.hv-prompt {
  flex: 1; margin: 0; min-height: 3.5em;
  background: var(--hv-parchment);
  border: 3px solid var(--hv-ink); border-radius: 16px; box-shadow: var(--hv-shadow);
  padding: 8px 16px; font-weight: 800; font-size: 1.08rem; line-height: 1.25;
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.hv-stage {
  position: relative;
  border: 3px solid var(--hv-ink); border-radius: 20px; box-shadow: var(--hv-shadow);
  background: var(--hv-stone); overflow: hidden;
  aspect-ratio: 2 / 1;
  /* Fyller bredden, men aldri høyere enn skjermen: da smalner den i stedet */
  width: min(100%, max(600px, (100dvh - var(--stiglet-hode-hoyde, 0px) - 196px) * 2));
  align-self: center;
}
.hv-stage.hv-shake { animation: hv-shake .35s; }
@keyframes hv-shake {
  20% { transform: translateX(-9px); } 40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); } 80% { transform: translateX(4px); }
}
#hv-canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; outline: none; }
#hv-canvas[hidden] { display: none; }

.hv-panel {
  position: absolute; inset: 0; overflow: auto;
  background: var(--hv-parchment);
  background-image: radial-gradient(ellipse at 50% 40%, transparent 55%, rgba(185, 122, 62, .28) 100%);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 12px; padding: 14px 20px; text-align: center;
}
.hv-panel[hidden] { display: none; }
.hv-panel h3 { font: 400 2.1rem/1.05 "Chewy", cursive; margin: 0; }
.hv-panel p { margin: 0; max-width: 58ch; font-size: 1.05rem; }
.hv-piece {
  display: inline-block; background: var(--hv-yellow);
  border: 3px solid var(--hv-ink); border-radius: 12px; box-shadow: var(--hv-shadow);
  padding: 4px 16px; font: 400 1.7rem/1.15 "Chewy", cursive; overflow-wrap: anywhere;
  animation: hv-drop .35s cubic-bezier(.3, 1.6, .5, 1);
}
.hv-options { display: grid; gap: 10px; width: min(680px, 100%); }
.hv-option {
  font: 600 1.02rem/1.3 "Nunito", sans-serif; text-align: left;
  background: #fff; color: var(--hv-ink);
  border: 3px solid var(--hv-ink); border-radius: 12px; box-shadow: var(--hv-shadow);
  padding: 9px 14px; cursor: pointer;
}
.hv-option:hover:not(:disabled) { background: var(--hv-cream); }
.hv-option:active:not(:disabled) { box-shadow: none; transform: translateY(4px); }
.hv-option:disabled { cursor: default; color: var(--hv-ink); }
.hv-option.hv-right { background: var(--subj-science, #4ade80); }
.hv-option.hv-wrong { background: var(--hv-coral); color: #fff; }
.hv-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.hv-chest { width: 130px; height: auto; }
.hv-chest--closed { animation: hv-wobble 1.6s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes hv-wobble { 0%, 70%, 100% { transform: rotate(0); } 78% { transform: rotate(-5deg); } 86% { transform: rotate(5deg); } 94% { transform: rotate(-3deg); } }

/* ---------- Smalere skjermer ---------- */
@media (max-width: 900px) {
  .hv-start { grid-template-columns: 1fr; }
  .hv-intro { position: static; }
  .hv-main { grid-template-columns: 1fr; align-content: start; }
  .hv-lock { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .hv-plaque { display: none; }
  /* Døra blir en liggende lås: brikkene på rad */
  .hv-door { aspect-ratio: auto; max-width: none; perspective: none; }
  .hv-door-light, .hv-door-frame, .hv-door-leaf img { display: none; }
  .hv-door-leaf { position: static; transform: none !important; }
  .hv-slots {
    position: static; flex-direction: row; flex-wrap: wrap;
    background: var(--hv-wood); border: 3px solid var(--hv-ink); border-radius: 16px; padding: 8px;
  }
  .hv-slots li { flex: 1 1 110px; min-height: 36px; }
  .hv-stage { aspect-ratio: auto; width: 100%; }
  #hv-canvas { aspect-ratio: 2 / 1; height: auto; }
  .hv-panel { position: static; min-height: 340px; }
  .hv-title { font-size: 2.3rem; }
  .hv-torch--small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .hv-torch, .hv-fuse-spark, .hv-chest--closed, .hv-fuse.hv-low .hv-fuse-time { animation: none; }
  .hv-door-leaf, .hv-door-light { transition: none; }
  .hv-stage.hv-shake { animation: none; }
}
