@font-face { font-family: Andika; src: url(../munch/fonts/andika-bold.woff2) format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: Andika; src: url(../munch/fonts/andika-regular.woff2) format('woff2'); font-weight: 400; font-display: swap; }
:root {
  --bg: #0e1118; --panel: #161b26; --line: #2a3242; --ink: #dfe6f0; --dim: #7d8aa0; --faint: #4a5468;
  --fire: #ffb04a; --rune: #ffcf6a; --good: #7fe0a0; --bad: #ff6a6a; --say: #9ad0ff; --npc: #f0c8ff; --fight: #ffa07a;
  --z: 1; /* the page zoom (set by game.js to fit big screens); viewport sizes are divided by it */
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --lp: #c78bff; --lr: #6aa8ff; --lm: #4fd1c5; --li: #7fe07f; --ri: #ffd34f; --rm: #ffa04f; --rr: #ff7a8a; --rp: #ff8ad8; --th: #9aa4b8;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 400 16px/1.45 Andika, system-ui, sans-serif; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#app { display: grid; grid-template-columns: minmax(0, 1fr) 300px; height: calc(100vh / var(--z)); height: calc(100dvh / var(--z)); }
#main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* the room scene */
#scene { position: relative; flex: none; aspect-ratio: 21 / 9; max-height: calc(40vh / var(--z)); width: 100%; overflow: hidden; background: #000; }
#art { position: absolute; inset: 0; background: center bottom / cover no-repeat; image-rendering: pixelated; transition: opacity .35s; }
#art.fade { opacity: 0; }
#scene::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(to bottom, transparent 70%, rgba(14, 17, 24, .85)); }
#place { position: absolute; left: 14px; top: 10px; z-index: 3; font-weight: 700; font-size: 20px; text-shadow: 0 2px 0 #000, 0 0 8px #000; }
#stage { position: absolute; inset: 0; z-index: 2; }
.fig { position: absolute; bottom: 6%; display: flex; flex-direction: column; align-items: center; transform: translateX(-50%); transition: left .4s; }
.fig canvas, .fig img { image-rendering: pixelated; display: block; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .45)); }
.fig .nm { font-size: 12px; font-weight: 700; padding: 0 6px; border-radius: 6px; background: rgba(0, 0, 0, .55); white-space: nowrap; margin-top: 2px; }
.fig.me .nm { color: var(--rune); }
.fig.mob img { transform: scaleX(-1); }
.fig.mob.noflip img { transform: none; }
.fig.mob.dead { opacity: 0; transform: translateX(-50%) translateY(20px); transition: opacity .6s, transform .6s; }
.fig.shake { animation: shake .3s; }
@keyframes shake { 0%, 100% { translate: 0; } 25% { translate: -6px; } 75% { translate: 6px; } }
.mobhp { width: 90px; height: 7px; border-radius: 4px; background: rgba(0, 0, 0, .6); overflow: hidden; margin-bottom: 4px; border: 1px solid rgba(255, 255, 255, .25); }
.mobhp i { display: block; height: 100%; background: linear-gradient(#ff8a6a, #d83a3a); transition: width .25s; }
.word { font: 700 24px var(--mono); letter-spacing: .04em; padding: 2px 10px 4px; border-radius: 8px; background: rgba(10, 12, 20, .82); border: 2px solid var(--fire); margin-bottom: 6px; white-space: pre; box-shadow: 0 0 18px rgba(255, 176, 74, .35); }
.word .ok { color: var(--good); } .word .no { color: var(--bad); text-decoration: underline; } .word .todo { color: #fff; }
.word .at { color: #fff; border-bottom: 3px solid var(--fire); }
.dmg { position: absolute; font: 700 26px var(--mono); color: var(--rune); text-shadow: 0 2px 0 #000; pointer-events: none; animation: rise .9s forwards; z-index: 5; }
@keyframes rise { to { transform: translateY(-50px); opacity: 0; } }
.hurt #scene { animation: hurt .35s; }
@keyframes hurt { 0% { box-shadow: inset 0 0 0 0 rgba(255, 0, 0, 0); } 30% { box-shadow: inset 0 0 80px 20px rgba(255, 40, 40, .55); } 100% { box-shadow: inset 0 0 0 0 rgba(255, 0, 0, 0); } }
.provebtn { position: absolute; right: 12px; top: 10px; z-index: 4; background: rgba(0, 0, 0, .6); color: var(--rune); border: 1px solid var(--rune); border-radius: 8px; padding: 4px 10px; font-size: 14px; }

/* the dark: tutorial runes over the scene */
.drillbox { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: rgba(0, 0, 0, .68); text-align: center; padding: 10px 16px; pointer-events: none; }
.drillbox .wall { display: flex; gap: 10px; }
.drillbox .wall b { width: 40px; height: 44px; display: flex; align-items: center; justify-content: center; font: 700 22px var(--mono); color: #3a3428; background: rgba(20, 16, 12, .8); border: 2px solid #3a3428; border-radius: 6px; transition: all .4s; }
.drillbox .wall b.next { color: #a08a60; border-color: #a08a60; animation: breathe 1.4s infinite; }
.drillbox .wall b.on { color: #fff3c8; background: #5a3a10; border-color: var(--rune); box-shadow: 0 0 16px var(--fire), inset 0 0 10px rgba(255, 200, 90, .6); text-shadow: 0 0 8px var(--fire); }
@keyframes breathe { 50% { box-shadow: 0 0 10px rgba(255, 176, 74, .45); } }
.drillbox .tip { max-width: 560px; font-size: 18px; text-shadow: 0 2px 0 #000; }
.drill { font: 700 34px var(--mono); letter-spacing: .08em; white-space: pre-wrap; }
.drill .ok { color: var(--rune); text-shadow: 0 0 12px var(--fire); } .drill .no { color: var(--bad); text-decoration: underline; } .drill .todo { color: #7d8aa0; }
.drill .at { color: #fff; border-bottom: 3px solid var(--fire); }
.drillbox .count { color: var(--dim); font-size: 14px; }

#runes-fx { position: absolute; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center; gap: 24px; background: radial-gradient(rgba(255, 176, 74, .35), rgba(0, 0, 0, .6)); pointer-events: none; }
#runes-fx b { font: 700 120px var(--mono); color: var(--rune); text-shadow: 0 0 30px var(--fire), 0 0 60px var(--fire); animation: runein 2.4s forwards; }
@keyframes runein { 0% { transform: scale(.2); opacity: 0; } 20% { transform: scale(1.15); opacity: 1; } 80% { opacity: 1; } 100% { transform: scale(1); opacity: 0; } }

/* the log */
#log { flex: 1; min-height: 80px; overflow-y: auto; padding: 10px 16px; font-size: 17px; scroll-behavior: smooth; }
#log p { margin: 0 0 6px; max-width: 80ch; }
#log .room h2 { margin: 6px 0 2px; font-size: 18px; color: var(--fire); }
#log .room { margin-bottom: 8px; }
#log .exits { color: var(--dim); font-size: 15px; }
#log .echo { color: var(--faint); font-family: var(--mono); font-size: 14px; }
#log .sys { color: var(--dim); font-style: italic; }
#log .say b { color: var(--say); } #log .say.me b { color: var(--rune); }
#log .npc b { color: var(--npc); }
#log .fight { color: var(--fight); } #log .ouch { color: var(--bad); } #log .miss { color: var(--fight); }
#log .good { color: var(--good); } #log .win { color: var(--rune); font-weight: 700; }
#log .rune { color: var(--rune); font-weight: 700; font-size: 19px; }
#log .jail { color: #ffb0b0; } #log .move { color: var(--dim); }
.kw { font-family: var(--mono); font-weight: 700; color: var(--rune); background: rgba(255, 207, 106, .1); border-radius: 4px; padding: 0 3px; white-space: nowrap; }
.kw .dk { color: var(--faint); }
.kw.locked { color: var(--dim); background: rgba(255, 255, 255, .04); }

/* the input bar */
#bar { flex: none; padding: 6px 16px 4px; border-top: 1px solid var(--line); background: var(--panel); }
#target { font: 700 22px var(--mono); letter-spacing: .04em; padding: 2px 0 4px; white-space: pre-wrap; }
#target .ok { color: var(--good); } #target .no { color: var(--bad); text-decoration: underline; } #target .todo { color: var(--dim); }
#target .at { color: #fff; border-bottom: 3px solid var(--fire); }
#target small { font: 400 13px Andika, sans-serif; color: var(--dim); margin-left: 10px; letter-spacing: 0; }
#row { display: flex; align-items: center; gap: 8px; }
#caret { color: var(--fire); font: 700 22px var(--mono); }
#cmd { flex: 1; min-width: 0; background: #0b0e14; color: #fff; border: 2px solid var(--line); border-radius: 8px; padding: 8px 12px; font: 700 22px var(--mono); outline: none; }
#cmd:focus { border-color: var(--fire); }
#cmd.dud { animation: dud .25s; border-color: var(--bad); }
@keyframes dud { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
#hint { min-height: 20px; font-size: 13px; color: var(--dim); padding: 2px 0; }
#hint b { color: var(--ink); }

/* the on-screen keyboard */
#kbd { flex: none; padding: 6px 10px 10px; display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--panel); transition: opacity .4s; }
#kbd.fade { opacity: .12; } #kbd.fade.show { opacity: 1; }
#kbd.hide { display: none; }
.krow { display: flex; gap: 4px; }
.krow.r1 { margin-left: 18px; } .krow.r2 { margin-left: 40px; }
.key { position: relative; width: 38px; height: 34px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font: 700 14px var(--mono);
  background: #1d222c; color: #3a4252; border: 1px solid #262c38; border-bottom: 3px solid var(--fc); --fc: #333; }
.key.lit { background: #262d3b; color: #fff; box-shadow: 0 0 10px -2px var(--fc); }
.key.bump b { border-bottom: 2px solid currentColor; }
.key i { position: absolute; right: 3px; top: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--bad); opacity: 0; }
.key.next { background: var(--fc); color: #111; transform: translateY(-2px); box-shadow: 0 0 16px var(--fc); }
.key.press { animation: press .15s; }
@keyframes press { 50% { transform: translateY(2px); filter: brightness(1.5); } }
.key.dark-hit { animation: darkhit .4s; }
@keyframes darkhit { 30% { background: #4a1a1a; } }
.key.won { animation: won 2.4s; }
@keyframes won { 0% { box-shadow: 0 0 0 0 var(--rune); background: var(--rune); color: #000; } 100% { box-shadow: 0 0 10px -2px var(--fc); } }
.r3 .key { width: 260px; }
.f-lp { --fc: var(--lp); } .f-lr { --fc: var(--lr); } .f-lm { --fc: var(--lm); } .f-li { --fc: var(--li); }
.f-ri { --fc: var(--ri); } .f-rm { --fc: var(--rm); } .f-rr { --fc: var(--rr); } .f-rp { --fc: var(--rp); } .f-th { --fc: var(--th); }

/* the side panel */
#side { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 10px 14px 20px; }
#side header { display: flex; justify-content: space-between; align-items: center; }
#side header b { font-size: 20px; color: var(--rune); }
.tools button { background: none; border: 1px solid var(--line); color: var(--dim); border-radius: 6px; padding: 1px 8px; margin-left: 4px; font-size: 12px; }
.tools button.off { opacity: .4; }
#doll-wrap { display: flex; justify-content: center; padding: 8px 0 4px; background: radial-gradient(ellipse at 50% 60%, #2a3242, transparent 70%); }
#doll { width: 170px; height: 250px; image-rendering: pixelated; }
#doll.shake { animation: shake .3s; }
#hp { display: flex; align-items: center; gap: 8px; }
#hp-bar { flex: 1; height: 10px; border-radius: 5px; background: #0b0e14; overflow: hidden; border: 1px solid var(--line); }
#hp-bar i { display: block; height: 100%; background: linear-gradient(#7fe0a0, #2a9a5a); transition: width .3s; }
#hp-bar.low i { background: linear-gradient(#ff8a6a, #c83a3a); }
#hp-n { color: var(--dim); min-width: 40px; text-align: right; }
#speed { color: var(--dim); font-size: 13px; margin-top: 4px; }
#side h3 { margin: 14px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); }
#side h3 small { text-transform: none; letter-spacing: 0; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.slot { background: #0f131b; border: 1px solid var(--line); border-radius: 8px; padding: 4px; display: flex; flex-direction: column; align-items: center; min-height: 74px; justify-content: center; }
.slot img { width: 44px; height: 44px; object-fit: contain; image-rendering: pixelated; }
.slot .kw { font-size: 13px; margin-top: 2px; }
.slot.empty { color: var(--faint); font-size: 12px; }
#runes { font: 700 14px var(--mono); display: flex; flex-wrap: wrap; gap: 3px; }
#runes span { width: 22px; height: 24px; display: inline-flex; align-items: center; justify-content: center; border-radius: 4px; background: #0f131b; color: var(--faint); }
#runes span.on { background: #2a2416; color: var(--rune); box-shadow: inset 0 0 0 1px #6a5420; }
#here, #who { font-size: 14px; }
#here div, #who div { padding: 1px 0; }
#who small { color: var(--dim); }

/* overlays: character maker and proving stone */
#create, #prove { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 30%, rgba(60, 40, 20, .7), rgba(5, 6, 10, .96)), url(rooms/fjall.webp) center / cover; }
.card { background: rgba(18, 22, 32, .94); border: 1px solid var(--line); border-radius: 14px; padding: 22px 26px; max-width: 640px; width: 100%; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
.card h1 { margin: 0; font-size: 44px; color: var(--rune); letter-spacing: .06em; text-shadow: 0 0 20px rgba(255, 176, 74, .4); }
.card h2 { margin: 0 0 6px; color: var(--rune); }
.lead { color: var(--ink); margin: 6px 0 14px; }
.maker { display: flex; gap: 20px; align-items: flex-start; }
#c-doll { width: 136px; height: 200px; image-rendering: pixelated; flex: none; background: radial-gradient(ellipse at 50% 60%, #2a3242, transparent 70%); }
.opts { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.opts label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--dim); }
.opts label.tick { flex-direction: row; align-items: center; gap: 6px; }
#c-name { font: 700 22px var(--mono); padding: 6px 10px; background: #0b0e14; color: #fff; border: 2px solid var(--line); border-radius: 8px; }
.pick { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.pick span { font-size: 12px; color: var(--dim); width: 44px; }
.pick button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #3a4252; padding: 0; }
.pick button.text { width: auto; border-radius: 6px; padding: 0 8px; background: #0b0e14; color: var(--ink); border-color: var(--line); font-size: 13px; }
.pick button.on { border-color: #fff; box-shadow: 0 0 0 2px var(--fire); }
#c-err, #p-score { color: var(--bad); min-height: 20px; margin: 8px 0 0; }
#p-score.good { color: var(--good); }
.card > button { margin-top: 10px; font-size: 20px; font-weight: 700; padding: 10px 26px; border-radius: 10px; border: 0; background: var(--fire); color: #1a1008; }
.small { color: var(--dim); font-size: 13px; margin-bottom: 0; }
#prove .drill { font-size: 22px; line-height: 1.6; margin: 14px 0; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; height: auto; }
  #main { height: calc(100vh / var(--z)); height: calc(100dvh / var(--z)); }
  #side { border-left: 0; border-top: 1px solid var(--line); }
  .key { width: 28px; height: 30px; font-size: 12px; } .r3 .key { width: 180px; }
  .krow.r1 { margin-left: 12px; } .krow.r2 { margin-left: 26px; }
  .maker { flex-direction: column; align-items: center; }
}

/* new gear: a card that pops up in the scene, and the doll glows */
.loot { position: absolute; left: 50%; top: 42%; z-index: 6; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 14px 8px; background: rgba(20, 14, 10, .9); border: 2px solid var(--rune, #f0b040); border-radius: 10px; animation: lootin 2.6s forwards; pointer-events: none; }
.loot img { width: 84px; height: 84px; object-fit: contain; image-rendering: pixelated; }
.loot span { font-weight: 700; color: var(--rune, #f0b040); letter-spacing: .05em; }
@keyframes lootin { 0% { transform: translate(-50%, -50%) scale(.3); opacity: 0; } 12% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; } 20% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { transform: translate(-50%, -90%) scale(.9); opacity: 0; } }
#doll.glow { animation: dollglow 1.6s; }
@keyframes dollglow { 0%, 100% { filter: none; } 30% { filter: drop-shadow(0 0 10px var(--rune, #f0b040)) brightness(1.25); } }
/* the end of a stage */
.stage-done { position: absolute; inset: 0; z-index: 7; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; background: radial-gradient(rgba(255, 190, 90, .45), rgba(0, 0, 0, .7)); pointer-events: none; animation: stagein 7s forwards; }
.stage-done b { font-size: 64px; color: var(--rune); text-shadow: 0 0 30px var(--fire), 0 4px 0 #000; letter-spacing: .03em; }
.stage-done span { font-size: 22px; text-shadow: 0 2px 0 #000; }
@keyframes stagein { 0% { opacity: 0; transform: scale(.7); } 8% { opacity: 1; transform: scale(1.05); } 12% { transform: scale(1); } 85% { opacity: 1; } 100% { opacity: 0; } }
