* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #cfe6f2;
  font-family: 'Nunito', system-ui, sans-serif;
  color: #fff;
  user-select: none;
}

#game { display: block; width: 100vw; height: 100vh; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }

#hearts {
  position: absolute;
  top: 22px;
  left: 26px;
  display: flex;
  gap: 4px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}
#hearts svg { width: 30px; height: 30px; }

#stamina {
  position: absolute;
  left: 0;
  top: 0;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  opacity: 0;
  transition: opacity 0.35s;
  transform-origin: center;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}
#stamina circle { fill: none; stroke-width: 5; }
#stamina .bg { stroke: rgba(20, 30, 20, 0.45); }
#stamina .fg {
  stroke: #7ee05a;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 20px 20px;
  transition: stroke 0.2s;
}
#stamina.low .fg { stroke: #f2c94c; }
#stamina.tired .fg { stroke: #e2533f; }

#help {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(10, 20, 30, 0.45);
  font-size: 14px;
  white-space: nowrap;
  transition: opacity 0.4s;
}
#help b { color: #ffe9a8; font-weight: 700; }
#help.hidden { opacity: 0; }

/* ---------- Aloitusruutu ---------- */
#start {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, rgba(10, 25, 40, 0.25), rgba(10, 25, 40, 0.65));
  transition: opacity 0.6s;
  z-index: 10;
}
#start.hidden { opacity: 0; pointer-events: none; }

#start .panel { text-align: center; padding: 16px; max-width: 520px; }

#start h1 {
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 700;
  font-size: clamp(34px, 7vw, 64px);
  letter-spacing: 0.04em;
  margin: 0;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
#start .sub { margin: 6px 0 28px; font-size: 18px; opacity: 0.9; }

#play {
  font-family: 'Cinzel', Georgia, serif;
  font-size: 22px;
  letter-spacing: 0.1em;
  color: #2b2210;
  background: linear-gradient(#ffe9a8, #e8c46a);
  border: 2px solid #fff6d8;
  border-radius: 6px;
  padding: 10px 42px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}
#play:hover, #new-game:hover { filter: brightness(1.06); }
#start .buttons { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#new-game {
  font-family: 'Cinzel', Georgia, serif;
  font-size: 16px;
  letter-spacing: 0.08em;
  color: #ffe9a8;
  background: rgba(12, 16, 22, 0.5);
  border: 1px solid rgba(255, 233, 168, 0.6);
  border-radius: 6px;
  padding: 7px 28px;
  cursor: pointer;
}
#new-game.confirm { background: #a8322a; color: #fff; border-color: #fff; }
.save-info { margin: 10px 0 0; font-size: 14px; opacity: 0.75; min-height: 1em; }

#saved {
  position: absolute;
  right: 22px;
  bottom: 60px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(12, 16, 22, 0.55);
  color: #ffe9a8;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.5s;
}
#saved.visible { opacity: 1; }

#start .controls {
  list-style: none;
  padding: 0;
  margin: 28px 0 0;
  font-size: 15px;
  line-height: 1.9;
  opacity: 0.9;
}
#start .controls b { color: #ffe9a8; }

/* ---------- Puhekehote ---------- */
#talk-prompt {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 5px;
  border-radius: 999px;
  background: rgba(10, 20, 30, 0.6);
  font-size: 16px;
  font-weight: 700;
  transform: translate(-50%, -100%);
  transition: opacity 0.2s;
}
#talk-prompt .key {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #ffe9a8;
  color: #2b2210;
  font-size: 14px;
}
#talk-prompt.hidden { opacity: 0; }

/* ---------- Keskusteluikkuna ---------- */
#dialogue {
  position: absolute;
  left: 50%;
  bottom: 56px;
  width: min(760px, calc(100vw - 32px));
  min-height: 118px;
  transform: translateX(-50%);
  padding: 26px 30px 22px;
  border-radius: 18px;
  background: rgba(12, 16, 22, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  transition: opacity 0.2s, transform 0.2s;
}
#dialogue.hidden { opacity: 0; transform: translateX(-50%) translateY(12px); }
#dialogue .name {
  position: absolute;
  top: -15px;
  left: 24px;
  padding: 4px 16px;
  border-radius: 999px;
  background: #ffe9a8;
  color: #2b2210;
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.04em;
}
#dialogue .text { font-size: 20px; line-height: 1.5; min-height: 60px; }
#dialogue .text.narration { font-style: italic; color: #d8d0b8; }
#dialogue .next {
  position: absolute;
  right: 24px;
  bottom: 12px;
  color: #ffe9a8;
  font-size: 14px;
  animation: bob 0.9s ease-in-out infinite;
}
#dialogue .next.hidden { display: none; }
@keyframes bob { 50% { transform: translateY(4px); } }

#dialogue .choices {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
#dialogue .choice {
  min-width: 200px;
  padding: 9px 20px;
  border-radius: 999px;
  background: rgba(12, 16, 22, 0.78);
  border: 2px solid transparent;
  font-size: 18px;
}
#dialogue .choice.selected { border-color: #ffe9a8; color: #ffe9a8; }
#dialogue .choice.selected::before { content: '▶ '; font-size: 13px; }

body.talking #help, body.talking #stamina { opacity: 0 !important; }

/* ---------- Huudahdukset ---------- */
.bark {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -100%);
  padding: 6px 14px;
  border-radius: 14px;
  background: rgba(255, 252, 240, 0.95);
  color: #2b2210;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  transition: opacity 0.2s;
}
.bark::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -7px;
  margin-left: -7px;
  border: 7px solid transparent;
  border-bottom: 0;
  border-top-color: rgba(255, 252, 240, 0.95);
}
.bark.hidden { opacity: 0; }

/* ---------- Vahinko ja kaatuminen ---------- */
#hurt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(220, 30, 20, 0.55));
  opacity: 0;
}
#hurt.flash { animation: hurt 0.6s ease-out; }
@keyframes hurt { 0% { opacity: 1; } 100% { opacity: 0; } }

#hearts.shake { animation: heartshake 0.4s; }
@keyframes heartshake {
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

#death {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: rgba(10, 5, 15, 0.75);
  opacity: 0;
  transition: opacity 0.8s;
  z-index: 5;
}
#death.visible { opacity: 1; }
#death span {
  font-family: 'Cinzel', Georgia, serif;
  font-size: clamp(32px, 6vw, 56px);
  color: #e8c4c4;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.6);
}

/* Vihollisen huomaaminen ja terveyspalkki */
.bark.alert {
  padding: 0 12px;
  background: #ffcf3a;
  color: #3a1a00;
  font-family: 'Cinzel', Georgia, serif;
  font-size: 26px;
  font-weight: 700;
  border-radius: 10px;
}
.bark.alert::after { border-top-color: #ffcf3a; }

.hpbar {
  position: absolute;
  left: 0;
  top: 0;
  width: 56px;
  height: 7px;
  transform: translate(-50%, -100%);
  border-radius: 4px;
  background: rgba(20, 10, 10, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.6);
  overflow: hidden;
  transition: opacity 0.3s;
}
.hpbar .fill { height: 100%; background: linear-gradient(#ff7a5a, #d8342a); transition: width 0.15s; }
.hpbar.hidden { opacity: 0; }

/* ---------- Kartta ---------- */
#minimap {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.4s;
}
body.playing #minimap { opacity: 1; }
body.talking #minimap { opacity: 0.35; }

#map-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 15, 20, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 8;
}
#map-overlay.visible { opacity: 1; }
.map-panel { text-align: center; }
.map-panel h2 {
  margin: 0 0 10px;
  font-family: 'Cinzel', Georgia, serif;
  font-size: 28px;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
#bigmap {
  display: block;
  border-radius: 10px;
  border: 3px solid rgba(255, 248, 230, 0.9);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin-top: 12px;
  font-size: 14px;
}
.legend b { color: #ffe9a8; }
.legend .dot {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 4px;
  border-radius: 50%;
  border: 2px solid #fff;
  font-style: normal;
  font-weight: 900;
  font-size: 12px;
  vertical-align: middle;
}
.legend .unknown { background: #ffcf3a; color: #3a2a00; }
.legend .found { background: #d8443a; }
.legend .cleared { background: #4caf50; }

#toast {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translate(-50%, -10px);
  padding: 10px 26px;
  border-radius: 999px;
  background: rgba(12, 16, 22, 0.75);
  border: 1px solid rgba(255, 233, 168, 0.6);
  color: #ffe9a8;
  font-family: 'Cinzel', Georgia, serif;
  font-size: 20px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.4s, transform 0.4s;
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Pomon terveyspalkki ---------- */
#bossbar {
  position: absolute;
  left: 50%;
  bottom: 64px;
  width: min(560px, calc(100vw - 40px));
  transform: translate(-50%, 12px);
  opacity: 0;
  transition: opacity 0.4s, transform 0.4s;
  text-align: center;
}
#bossbar.visible { opacity: 1; transform: translate(-50%, 0); }
#bossbar .name {
  font-family: 'Cinzel', Georgia, serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
}
#bossbar .bar {
  height: 12px;
  border-radius: 6px;
  background: rgba(20, 10, 10, 0.65);
  border: 2px solid rgba(255, 248, 230, 0.85);
  overflow: hidden;
}
#bossbar .fill { height: 100%; width: 100%; background: linear-gradient(#ffb04a, #d8642a); transition: width 0.2s; }
#bossbar.enraged .fill { background: linear-gradient(#ff5a4a, #b8142a); }
body.playing:has(#bossbar.visible) #help { opacity: 0; }

/* ---------- Jousi: tähtäin ja aseet ---------- */
#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  opacity: 0;
  transition: opacity 0.15s;
  --charge: 0;
}
#crosshair.visible { opacity: 1; }
#crosshair .ring {
  position: absolute;
  left: 0;
  top: 0;
  width: 44px;
  height: 44px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(calc(1.6 - var(--charge) * 0.9));
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}
#crosshair .dot {
  position: absolute;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.7);
}
#crosshair.full .ring { border-color: #ffd04a; box-shadow: 0 0 10px rgba(255, 200, 60, 0.9); }
#crosshair.full .dot { background: #ffd04a; }

#weapons {
  position: absolute;
  right: 22px;
  bottom: 100px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  opacity: 0;
  transition: opacity 0.4s;
}
body.playing #weapons { opacity: 1; }
#weapons .slot {
  position: relative;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(12, 16, 22, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.25);
  transition: transform 0.15s, border-color 0.15s;
}
#weapons .slot svg { width: 34px; height: 34px; }
#weapons .slot.active { border-color: #ffe9a8; background: rgba(12, 16, 22, 0.75); transform: scale(1.1); }
#weapons .key {
  position: absolute;
  left: 4px;
  top: 2px;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.7;
}
#arrow-count {
  position: absolute;
  right: 4px;
  bottom: 1px;
  font-size: 13px;
  font-weight: 700;
  color: #ffe9a8;
  text-shadow: 0 1px 2px #000;
}
#arrow-count.empty { color: #ff7a6a; }
#weapons .hint { font-size: 11px; opacity: 0.7; align-self: center; writing-mode: vertical-rl; transform: rotate(180deg); }

/* ---------- Loitsupalkki (Ctrl pohjassa) ---------- */
#spellbar {
  position: absolute;
  left: 50%;
  bottom: 70px;
  transform: translateX(-50%) translateY(12px);
  padding: 10px 14px 12px;
  border-radius: 14px;
  background: rgba(16, 12, 10, 0.72);
  border: 1px solid rgba(255, 190, 90, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
#spellbar.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
#spellbar .title { font-family: 'Cinzel', serif; font-size: 12px; letter-spacing: 0.12em; color: #e8c88a; text-transform: uppercase; margin-bottom: 6px; text-align: center; }
#spellbar .spell { display: grid; grid-template-columns: auto auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; }
#spellbar .key { grid-row: span 2; width: 26px; height: 26px; border-radius: 6px; background: #f4eedc; color: #2a1c12; font-weight: 700; display: grid; place-items: center; }
#spellbar .icon { grid-row: span 2; width: 34px; height: 34px; filter: drop-shadow(0 0 6px rgba(255, 140, 40, 0.8)); }
#spellbar .name { font-weight: 700; color: #ffe9a8; }
#spellbar .cost { font-size: 12px; color: #c8b8a0; }
#spellbar .spell + .spell { margin-top: 8px; }
#spellbar .spell:not(.ready) { opacity: 0.45; filter: grayscale(0.7); }
#spellbar .spell:not(.ready) .cost::after { content: ' · ei tarpeeksi loitsuvoimaa'; color: #f08a6a; }
#spellbar .icon.dash { filter: drop-shadow(0 0 6px rgba(120, 190, 255, 0.85)); }
#spellbar.denied { animation: spell-denied 0.35s; }
@keyframes spell-denied { 25%, 75% { transform: translateX(calc(-50% - 6px)); } 50% { transform: translateX(calc(-50% + 6px)); } }
body:not(.playing) #spellbar { display: none; }

/* ---------- Loitsuvoimapalkki ---------- */
#mana {
  position: absolute;
  top: 60px;
  left: 28px;
  display: flex;
  align-items: center;
  gap: 6px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}
#mana .icon { width: 18px; height: 18px; opacity: 0.55; transition: opacity 0.3s, filter 0.3s; }
#mana .bar {
  width: 150px;
  height: 10px;
  border-radius: 999px;
  background: rgba(20, 16, 30, 0.55);
  border: 1.5px solid rgba(255, 236, 200, 0.75);
  overflow: hidden;
}
#mana .fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #e2401a, #ff8a2a 55%, #ffd36a);
}
#mana.full .icon { opacity: 1; filter: drop-shadow(0 0 5px rgba(255, 150, 40, 0.9)); }
#mana.full .bar { border-color: #ffd36a; box-shadow: 0 0 8px rgba(255, 160, 50, 0.6); }
#mana.ready-flash .bar { animation: mana-ready 0.6s; }
@keyframes mana-ready { 0% { box-shadow: 0 0 0 rgba(255, 200, 80, 0); } 40% { box-shadow: 0 0 16px rgba(255, 200, 80, 1); } 100% { box-shadow: 0 0 8px rgba(255, 160, 50, 0.6); } }
body:not(.playing) #mana { display: none; }
