:root {
  --ink: #2b1d14; --paper: #f6ead2; --paper2: #ead6b0; --wood: #6b4429; --wood2: #4a2e1b;
  --ok: #3f9b4f; --bad: #c8473c; --gold: #f2c14e; --sky: #1b2a1e;
}
html, body { margin: 0; height: 100%; background: var(--sky); overflow: hidden; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; font: 600 16px Fredoka, system-ui, sans-serif; color: var(--ink); }
canvas#world { display: block; width: 100vw; height: 100vh; height: 100dvh; image-rendering: pixelated; }
button { font: inherit; cursor: pointer; color: inherit; }
[hidden] { display: none !important; }
.spr { image-rendering: pixelated; background-repeat: no-repeat; display: inline-block; }

/* —— HUD —— */
#hud { position: fixed; inset: 0 0 auto 0; padding: max(8px, env(safe-area-inset-top)) 10px 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; pointer-events: none; }
#hud .bars { display: flex; flex-direction: column; gap: 4px; pointer-events: auto; }
.bar { position: relative; width: 150px; height: 18px; border: 2px solid var(--wood2); border-radius: 6px; background: #2a1a10; overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 100%; transition: width .35s; }
.bar span { position: relative; display: block; text-align: center; font-size: 12px; line-height: 14px; color: #fff; text-shadow: 0 1px 0 #000; }
.bar.hp i { background: linear-gradient(#ef6a5c, #c8473c); }
.bar.xp { height: 14px; } .bar.xp span { font-size: 10px; line-height: 10px; }
.bar.xp i { background: linear-gradient(#7fd0ff, #3b8fd6); }
.coins { color: #fff; text-shadow: 0 1px 0 #000, 0 0 4px #000; font-size: 15px; }
#hud .btns { margin-left: auto; display: flex; gap: 6px; pointer-events: auto; }
#hud .btns button { width: 40px; height: 40px; border-radius: 10px; border: 2px solid var(--wood2); background: var(--paper); font-size: 19px; box-shadow: 0 3px 0 var(--wood2); padding: 0; }
#hud .btns button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood2); }
#goal { flex-basis: 100%; text-align: center; pointer-events: none; }
#goal:not(:empty) { justify-self: center; }
#goal span { display: inline-block; background: rgba(20, 14, 8, .72); color: #fff3d6; padding: 5px 12px; border-radius: 999px; font-size: 14px; max-width: 92vw; }

/* —— D-pad —— */
#pad { position: fixed; left: 14px; bottom: max(14px, env(safe-area-inset-bottom)); width: 150px; height: 150px; display: grid;
  grid-template: "a u b" 1fr "l c r" 1fr "d dd e" 1fr / 1fr 1fr 1fr; gap: 3px; opacity: .85; }
#pad button { border: 2px solid var(--wood2); background: rgba(246, 234, 210, .9); border-radius: 12px; font-size: 18px; padding: 0; touch-action: none; }
#pad [data-d=up] { grid-area: u; } #pad [data-d=left] { grid-area: l; } #pad [data-d=right] { grid-area: r; } #pad [data-d=down] { grid-area: dd; }
#pad button.on { background: var(--gold); }
@media (hover: hover) and (pointer: fine) { #pad { display: none; } }

/* —— dialog —— */
#dlg { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(10px, env(safe-area-inset-bottom)); width: min(760px, calc(100vw - 20px));
  display: flex; gap: 12px; padding: 12px; box-sizing: border-box; background: var(--paper); border: 3px solid var(--wood2); border-radius: 14px;
  box-shadow: 0 5px 0 var(--wood2), 0 10px 30px rgba(0, 0, 0, .45); }
#dlg .face { flex: none; width: 84px; height: 84px; overflow: hidden; border-radius: 10px; background: var(--paper2); border: 2px solid var(--wood); display: grid; place-items: center; }
#dlg .face.none { display: none; }
#dlg .body { flex: 1; min-width: 0; }
#dlg .who { font-size: 13px; color: var(--wood); text-transform: uppercase; letter-spacing: .04em; }
#dlg .en { font-size: 21px; line-height: 1.25; margin: 2px 0 4px; }
#dlg .ru { font-size: 14px; color: #7a6450; font-weight: 500; }
#dlg.notr .ru { display: none; }
#dlg .answers { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
#dlg .answers:empty { display: none; }
.ans { text-align: left; padding: 9px 12px; border-radius: 10px; border: 2px solid var(--wood); background: #fffaf0; font-size: 17px; }
.ans:hover { background: #fff3d6; }
.ans.bad { border-color: var(--bad); background: #fbe1dd; animation: shake .35s; }
.ans.good { border-color: var(--ok); background: #def3df; }
.ans small { display: block; color: #7a6450; font-weight: 500; font-size: 13px; }
#dlg .hint { color: var(--bad); font-size: 14px; margin-top: 6px; }
#dlg .hint:empty { display: none; }
#dlg .row { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
#dlg .row button { border: 2px solid var(--wood); background: var(--paper2); border-radius: 9px; padding: 5px 10px; font-size: 15px; }
#dlg .row .next { margin-left: auto; background: var(--wood); color: #fff; border-color: var(--wood2); }
#dlg.asking .row .next { display: none; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* —— battle —— */
#battle { position: fixed; inset: 0; display: flex; flex-direction: column; background: #3a5a28; }
#battle .arena { position: relative; flex: 1; min-height: 150px; }
#battle .arena canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
#battle .mon { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; color: #fff;
  background: rgba(30, 18, 10, .62); padding: 5px 12px 5px 6px; border-radius: 12px; border: 2px solid rgba(255, 220, 160, .35); white-space: nowrap; }
#battle .mface canvas { display: block; border-radius: 8px; background: #fff3; }
#battle .mface:empty { display: none; }
#battle .mname { font-size: 15px; text-shadow: 0 2px 0 #000; }
#battle .mhp { width: 170px; margin-top: 4px; }
#battle .mhp i { background: linear-gradient(#ef6a5c, #b0362c); }
.faceimg { display: block; }
#hudFace { pointer-events: none; }
#hudFace canvas { border-radius: 10px; border: 2px solid var(--wood2); background: var(--paper2); box-shadow: 0 3px 0 var(--wood2); }
#dlg .face canvas { width: 80px; height: 80px; border-radius: 8px; }
.heroes button canvas { border-radius: 8px; }
#battle .fx { position: absolute; inset: 0; pointer-events: none; }
.pop { position: absolute; font: 700 30px Fredoka, system-ui, sans-serif; color: #fff; text-shadow: 0 3px 0 #000; animation: pop 1s forwards; }
.pop.red { color: #ff8f84; } .pop.green { color: #9cf5a6; } .pop.blue { color: #a9ddff; }
@keyframes pop { from { transform: translateY(0) scale(.6); opacity: 1; } 30% { transform: translateY(-20px) scale(1.15); } to { transform: translateY(-60px); opacity: 0; } }
.flash { position: absolute; inset: 0; animation: flash .5s forwards; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }
#battle .panel { background: var(--paper); border-top: 3px solid var(--wood2); padding: 12px 14px max(12px, env(safe-area-inset-bottom)); max-height: 62vh; overflow: auto; }
#battle .panel > * { max-width: 760px; margin-left: auto; margin-right: auto; }
#battle .say { font-size: 13px; color: var(--wood); text-transform: uppercase; letter-spacing: .04em; }
#battle .sent { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px auto; font-size: 23px; }
.w { padding: 4px 9px; border-radius: 9px; border: 2px solid var(--wood); background: #fffaf0; }
.w:hover { background: #fff3d6; }
.w.bad { border-color: var(--bad); background: #fbe1dd; text-decoration: line-through; }
.w.fix { border-color: var(--ok); background: #def3df; }
.w.no { animation: shake .35s; border-color: var(--bad); }
#battle .sent.done .w { pointer-events: none; }
#battle .ru { color: #7a6450; font-size: 14px; font-weight: 500; min-height: 1em; }
#battle .opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
#battle .opts:empty { display: none; }
#battle .opts .ans { flex: 1 1 140px; text-align: center; }
#battle .msg { margin-top: 8px; font-size: 15px; }
#battle .msg:empty { display: none; }
#battle .msg.bad { color: var(--bad); } #battle .msg.ok { color: var(--ok); }
#battle .acts { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
#battle .acts button { flex: 1 1 110px; padding: 10px 8px; border-radius: 11px; border: 2px solid var(--wood2); background: var(--paper2); box-shadow: 0 3px 0 var(--wood2); font-size: 16px; }
#battle .acts button:disabled { opacity: .45; cursor: default; }
.big { display: block; width: 100%; padding: 12px; border-radius: 12px; border: 2px solid var(--wood2); background: var(--wood); color: #fff; font-size: 18px; box-shadow: 0 3px 0 var(--wood2); margin-top: 10px; }
.big.alt { background: var(--paper2); color: var(--ink); }
.cast { text-align: center; }
.cast .ic { font-size: 54px; }
.cast .q { font-size: 18px; margin: 4px 0 10px; }
.cast .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.cast input { font: 600 22px Fredoka, system-ui, sans-serif; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--wood); width: 180px; text-align: center; background: #fffaf0; }
.cast button { padding: 8px 14px; border-radius: 10px; border: 2px solid var(--wood2); background: var(--paper2); font-size: 18px; }
.cast button.mic { background: #ffe1a6; }
.cast button.mic.on { background: var(--bad); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* —— modal / title / toast —— */
#modal { position: fixed; inset: 0; background: rgba(10, 8, 5, .6); display: grid; place-items: center; padding: 14px; z-index: 5; }
#modal .box { position: relative; width: min(560px, 100%); max-height: 88vh; overflow: auto; box-sizing: border-box; background: var(--paper); border: 3px solid var(--wood2); border-radius: 16px; padding: 18px 18px 16px; box-shadow: 0 6px 0 var(--wood2); }
#modal .x { position: absolute; top: 8px; right: 8px; border: 0; background: none; font-size: 20px; }
#modal.lock .x { display: none; }
#modal h2 { margin: 0 0 10px; font-size: 22px; }
#modal p { margin: 6px 0; font-weight: 500; }
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.list .it { display: flex; gap: 10px; align-items: center; background: #fffaf0; border: 2px solid var(--paper2); border-radius: 10px; padding: 8px 10px; }
.list .it .ic { font-size: 26px; width: 34px; text-align: center; }
.list .it small { display: block; color: #7a6450; font-weight: 500; }
.list .it.done { opacity: .55; } .list .it.done b { text-decoration: line-through; }
.title { text-align: center; }
.title .logo { font: 26px "Press Start 2P", monospace; color: var(--wood); margin: 8px 0 4px; text-shadow: 3px 3px 0 var(--gold); }
.title .sub { color: #7a6450; margin-bottom: 8px; }
.heroes { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.heroes button { padding: 6px; border-radius: 12px; border: 3px solid var(--paper2); background: #fffaf0; }
.heroes button.on { border-color: var(--ok); background: #def3df; }
.title input { font: 600 20px Fredoka, system-ui, sans-serif; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--wood); width: 220px; text-align: center; }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; text-align: left; margin: 10px auto; max-width: 320px; }
#toast { position: fixed; left: 50%; top: 118px; transform: translateX(-50%); background: rgba(20, 14, 8, .85); color: #fff3d6; padding: 8px 16px; border-radius: 12px; font-size: 16px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 6; text-align: center; max-width: 90vw; }
#toast.on { opacity: 1; }
@media (max-width: 560px) {
  #dlg .face { width: 62px; height: 62px; } #dlg .face canvas { width: 58px; height: 58px; }
  #dlg .en { font-size: 18px; } .ans { font-size: 16px; }
  #battle .sent { font-size: 19px; }
  .bar { width: 120px; }
  #hud .btns button { width: 36px; height: 36px; font-size: 17px; }
}
#battle .opts > .cast { flex: 1 1 100%; }
body.inb #toast { top: auto; bottom: 66%; }
#battle .mface { flex: none; width: 40px; height: 40px; } #battle .mon > div { min-width: 170px; }
.title .cover { display: block; width: 100%; max-height: 38vh; object-fit: cover; border-radius: 12px; border: 3px solid var(--wood); margin: 0 0 6px; box-sizing: border-box; }
/* the map of lands (25.10) */
.list.lands .land { text-align: left; font: inherit; color: var(--ink); cursor: pointer; width: 100%; }
.list.lands .land.here { border-color: var(--wood); background: #fff3d6; }
.list.lands .land i { color: #7a6450; font-style: normal; font-weight: 500; }
.title select.landsel { width: 100%; padding: 10px; border-radius: 10px; border: 2px solid var(--paper2); font: inherit; font-size: 16px; background: #fffaf0; color: var(--ink); }
/* 26.10: language buttons (title, menu), words of «Мой словарик» among the spells */
.langs { display: flex; gap: 8px; justify-content: center; margin: 10px 0 2px; }
.title .langs button { font: 600 14px Fredoka, sans-serif; border: 2px solid #7a6450; background: #fff8e7; color: #3b2416; border-radius: 10px; padding: 5px 12px; cursor: pointer; }
.title .langs button.on { background: #3b2416; color: #fff8e7; }
.box > .in > .langs .big { flex: 1; margin: 0; }
.ans.dictw { border-color: #e0b100; background: #fff6cc; }
