@font-face { font-family: "Friz Quadrata"; src: url(fonts/frizqt__.ttf); font-display: block; }
@font-face { font-family: Morpheus; src: url(fonts/morpheus.ttf); font-display: block; }
:root {
  --bg: #0b0d14; --surface: #141a2e; --edge: #3a4470; --ink: #f2efe6; --muted: #a8b0d0; --accent: #ffd200; --reward: #ffd200; --danger: #ff5040;
  --text-s: 13px; --text-m: 16px; --text-l: 22px; --text-xl: 48px; --space: 8px; --radius: 8px;
  --font-ui: "Friz Quadrata", Georgia, serif;
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--font-ui); overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
body.blocks { background: linear-gradient(#5d8fe0 0%, #8fb7f0 45%, #a8c8f0 62%); }
canvas.view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
canvas#c2d { image-rendering: pixelated; image-rendering: crisp-edges; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.kbd { display: inline-block; min-width: 1.6em; padding: 1px 6px; border: 1px solid var(--edge); border-bottom-width: 3px; border-radius: 5px; background: #20263e; font-size: var(--text-s); text-align: center; }

/* ---------------- screens */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: calc(var(--space) * 1.5); background: rgba(6, 8, 16, 0.78); z-index: 40; padding: calc(var(--space) * 3) calc(16px + var(--safe-r)) calc(var(--space) * 3) calc(16px + var(--safe-l)); text-align: center; overflow-y: auto; }
.screen[hidden] { display: none; }
#title { background: radial-gradient(ellipse at 50% 40%, rgba(30, 40, 80, 0.55), rgba(4, 6, 12, 0.92)), url(cover.jpg) center/cover; }
.logo { font: var(--text-xl) Morpheus, serif; color: var(--accent); text-shadow: 3px 3px 0 #3a2a00, 0 0 18px rgba(0, 0, 0, 0.7); margin: 0; }
.sub { color: var(--muted); max-width: 640px; font-size: var(--text-m); line-height: 1.45; margin: 0; }
.choices { display: flex; gap: calc(var(--space) * 2); flex-wrap: wrap; justify-content: center; }
.choice { width: 260px; min-height: 44px; padding: 14px 16px; border-radius: var(--radius); border: 2px solid var(--edge); background: var(--surface); cursor: pointer; text-align: left; }
.choice:hover, .choice:focus-visible { border-color: var(--accent); }
.choice b { display: block; font-size: var(--text-l); color: var(--accent); margin-bottom: 4px; }
.choice span { color: var(--muted); font-size: var(--text-s); line-height: 1.4; }
.choice.pixel b { font-family: var(--font-ui); letter-spacing: 1px; }
.btn { min-width: 220px; min-height: 44px; padding: 10px 18px; border-radius: var(--radius); border: 2px solid var(--edge); background: var(--surface); cursor: pointer; font-size: var(--text-m); }
.btn:hover, .btn:focus-visible { border-color: var(--accent); color: var(--accent); }
.btn.armed { border-color: var(--danger); color: var(--danger); }
.row { display: flex; gap: var(--space); flex-wrap: wrap; justify-content: center; }
.controls { color: var(--muted); font-size: var(--text-s); line-height: 2; max-width: 720px; }
a.back { color: var(--muted); font-size: var(--text-s); text-decoration: none; }
a.back:hover, a.back:focus-visible { color: var(--accent); }
.note { color: #7c84a8; font-size: 12px; max-width: 560px; }
#loading .bar { width: 320px; height: 12px; border: 2px solid var(--edge); border-radius: 6px; overflow: hidden; }
#loading .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
#settings label { display: grid; grid-template-columns: 150px 1fr 50px; align-items: center; gap: var(--space); width: min(420px, 90vw); text-align: left; min-height: 44px; }
#settings input[type=range] { width: 100%; accent-color: var(--accent); }
.toggle { justify-self: start; width: 54px; height: 30px; border-radius: 15px; border: 2px solid var(--edge); background: #20263e; position: relative; cursor: pointer; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: left 0.15s; }
.toggle[aria-pressed=true] { background: #4a3a10; border-color: var(--accent); }
.toggle[aria-pressed=true]::after { left: 27px; background: var(--accent); }
#dead h1 { font: 44px Morpheus, serif; color: var(--danger); margin: 0; }

/* ---------------- HUD (shared) */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud[hidden] { display: none; }
#hud .clickable, #hud button { pointer-events: auto; }
#plates, #floats { position: absolute; inset: 0; }
.plate { position: absolute; transform: translate(-50%, -100%); text-align: center; white-space: nowrap; font-size: 14px; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; }
.plate .n { color: #3fe23f; } .plate.neutral .n { color: #ffd200; } .plate.hostile .n { color: #ff4a3a; } .plate.dead .n { color: #999; }
.plate .mark { font: bold 30px Morpheus, serif; line-height: 26px; color: #ffd200; text-shadow: 2px 2px 0 #000; }
.plate .mark.gray { color: #aaa; }
.plate .hp { width: 80px; height: 6px; margin: 2px auto 0; border: 1px solid #000; background: #300; }
.plate .hp i { display: block; height: 100%; background: #d42; }
.plate.sel .n { text-decoration: underline; }
.float { position: absolute; transform: translate(-50%, -50%); font-size: 24px; color: #fff; text-shadow: 2px 2px 0 #000, -1px -1px 0 #000; white-space: nowrap; animation: rise 1.1s ease-out forwards; }
.float.crit { font-size: 36px; color: #ffe040; } .float.hurt { color: #ff4a3a; } .float.miss { color: #ccc; font-size: 18px; }
html.rm .float { animation: none; }
@keyframes rise { to { transform: translate(-50%, -160%); opacity: 0; } }
#err { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); color: #ff3a2a; font-size: 18px; text-shadow: 1px 1px 0 #000; transition: opacity 0.4s; }
#zone { position: absolute; left: 50%; top: 16%; transform: translateX(-50%); font: 54px Morpheus, serif; color: #ffd200; text-shadow: 3px 3px 0 #3a2a00; opacity: 0; transition: opacity 1.2s; white-space: nowrap; }
#zone.on { opacity: 1; }
.frame { position: absolute; top: calc(12px + var(--safe-t)); display: flex; gap: 10px; align-items: center; padding: 8px 12px; width: 320px; }
#pframe { left: calc(12px + var(--safe-l)); }
#tframe { left: calc(344px + var(--safe-l)); }
.frame .face { width: 54px; height: 54px; flex: none; border-radius: 50%; border: 2px solid #000; background: #d9a77e; background-image: linear-gradient(#6a3a1a 0 26%, transparent 26%), radial-gradient(circle at 34% 55%, #222244 0 3px, transparent 4px), radial-gradient(circle at 66% 55%, #222244 0 3px, transparent 4px), linear-gradient(transparent 80%, #24489c 80%); }
.frame .face.beast { background: #6e6a66; background-image: radial-gradient(circle at 34% 45%, #ffd200 0 3px, transparent 4px), radial-gradient(circle at 66% 45%, #ffd200 0 3px, transparent 4px); }
.frame .nm { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .frame .nm small { color: var(--muted); font-size: 12px; margin-left: 4px; }
.bar { position: relative; height: 16px; margin-top: 4px; background: #111; border: 1px solid #000; }
.bar i { display: block; height: 100%; background: #2ab02a; } .bar.rage i { background: #c02020; }
.bar span { position: absolute; inset: 0; font-size: 11px; line-height: 16px; text-align: center; text-shadow: 1px 1px 0 #000; font-variant-numeric: tabular-nums; }
.frame .bars { flex: 1; min-width: 0; }
#tframe.hostile .nm { color: #ff5a4a; } #tframe.neutral .nm { color: #ffd200; } #tframe.friendly .nm { color: #3fe23f; }
#mm { position: absolute; right: calc(12px + var(--safe-r)); top: calc(12px + var(--safe-t)); width: 176px; text-align: center; padding: 6px; }
#mm canvas { width: 160px; height: 160px; display: block; margin: 0 auto; image-rendering: pixelated; }
#mm .zn { font-size: 13px; color: #ffd200; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tracker { position: absolute; right: calc(12px + var(--safe-r)); top: calc(232px + var(--safe-t)); width: 240px; font-size: 13px; padding: 8px 10px; }
#tracker .qt { color: #ffd200; font-size: 15px; } #tracker .q { margin-top: 6px; } #tracker .q.done { color: #ffd200; } #tracker .o { color: #ccd; font-size: 12px; margin-left: 8px; }
#tracker:empty { display: none; }
#chat { position: absolute; left: calc(12px + var(--safe-l)); bottom: calc(150px + var(--safe-b)); width: min(480px, 44vw); font-size: 14px; line-height: 1.35; text-shadow: 1px 1px 0 #000; }
#chat p { margin: 1px 0; } #chat .quest { color: #ffd200; } #chat .loot { color: #3fe23f; } #chat .xp { color: #a8a8ff; } #chat .level { color: #ffd200; font-size: 16px; } #chat .bad { color: #ff5a4a; } #chat .say { color: #fff; } #chat .buff { color: #9ad8ff; }
#bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(26px + var(--safe-b)); display: flex; gap: 6px; padding: 6px; }
.slot { position: relative; width: 52px; height: 52px; border: 2px solid #000; background: #111 center/cover; cursor: pointer; padding: 0; }
.slot img { width: 100%; height: 100%; display: block; pointer-events: none; }
.slot em { position: absolute; right: 3px; top: 1px; font-style: normal; font-size: 12px; color: #ddd; text-shadow: 1px 1px 0 #000; }
.slot .cd { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); transform-origin: bottom; }
.slot.off img { filter: grayscale(0.8) brightness(0.6); }
.slot.on { box-shadow: 0 0 0 3px #ffd200; }
#xp { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(8px + var(--safe-b)); width: min(640px, 80vw); height: 12px; background: #111; border: 1px solid #000; }
#xp i { display: block; height: 100%; background: #8a3ad8; } #xp span { position: absolute; inset: 0; font-size: 10px; line-height: 12px; text-align: center; text-shadow: 1px 1px 0 #000; font-variant-numeric: tabular-nums; }
#cast { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(110px + var(--safe-b)); width: 260px; }
#cast[hidden] { display: none; }
#viewbtn { position: absolute; right: calc(12px + var(--safe-r)); bottom: calc(26px + var(--safe-b)); min-width: 44px; min-height: 44px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
#pausebtn { position: absolute; right: calc(200px + var(--safe-r)); top: calc(12px + var(--safe-t)); min-width: 44px; min-height: 44px; cursor: pointer; font-size: 18px; }

/* the NPC window and quest log */
.win { position: absolute; z-index: 20; pointer-events: auto; }
#dialog { left: calc(16px + var(--safe-l)); top: calc(100px + var(--safe-t)); width: min(400px, 92vw); max-height: 70vh; overflow-y: auto; padding: 14px 16px; font-size: 15px; line-height: 1.45; }
#dialog h2, #log h2 { margin: 0 0 8px; font-size: 19px; color: #ffd200; font-weight: normal; }
#dialog p { margin: 6px 0; } #dialog .obj { color: #ccd; }
#dialog .qlink { display: block; width: 100%; text-align: left; background: none; border: none; color: #ffd200; padding: 8px 4px; min-height: 40px; cursor: pointer; font-size: 15px; }
#dialog .qlink:hover, #dialog .qlink:focus-visible { color: #fff; }
#dialog .qlink.gray { color: #aaa; }
#dialog .acts { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
#dialog .acts button, #log button { min-height: 44px; padding: 6px 14px; cursor: pointer; }
#dialog .close, #log .close { position: absolute; right: 8px; top: 6px; min-width: 40px; min-height: 40px; background: none; border: none; color: #ccc; font-size: 20px; cursor: pointer; }
#log { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, 94vw); max-height: 76vh; overflow-y: auto; padding: 16px 18px; font-size: 15px; line-height: 1.45; }
#log .entry { border-top: 1px solid rgba(255, 255, 255, 0.15); padding: 8px 0; }
#log .entry b { color: #ffd200; font-weight: normal; }
.win[hidden] { display: none; }

/* ---------------- touch */
#touch { position: absolute; inset: 0; pointer-events: none; }
#touch[hidden] { display: none; }
#stick { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.35); background: rgba(0, 0, 0, 0.15); transform: translate(-50%, -50%); display: none; }
#stick i { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); }
.tbtn { position: absolute; width: 64px; height: 64px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.5); background: rgba(10, 14, 30, 0.55); color: #fff; font-size: 13px; pointer-events: auto; }
#tjump { right: calc(24px + var(--safe-r)); bottom: calc(110px + var(--safe-b)); }
#ttalk { right: calc(100px + var(--safe-r)); bottom: calc(150px + var(--safe-b)); }
#ttab { right: calc(24px + var(--safe-r)); bottom: calc(186px + var(--safe-b)); }
body.touch #chat { display: none; }
body.touch #tracker { top: calc(220px + var(--safe-t)); width: 200px; }
@media (max-width: 900px) {
  #tframe { left: auto; right: calc(12px + var(--safe-r)); top: calc(196px + var(--safe-t)); width: 220px; }
  #tracker { display: none; }
  .frame { width: 230px; }
  .slot { width: 46px; height: 46px; }
  #mm { width: 136px; } #mm canvas { width: 120px; height: 120px; }
  #pausebtn { right: calc(156px + var(--safe-r)); }
}
@media (orientation: portrait) and (max-width: 900px) {
  #bar { bottom: calc(26px + var(--safe-b)); flex-wrap: wrap; width: 320px; justify-content: center; }
  #tframe { top: calc(176px + var(--safe-t)); }
}

/* ---------------- 2D: 16-bit RPG windows */
body.pixel .panel { background: linear-gradient(#24307a, #121a4a); border: 3px solid #e8e8f0; box-shadow: 0 0 0 3px #1a1a2a, inset 0 0 0 2px #6a78c8, 4px 4px 0 3px rgba(0, 0, 0, 0.35); border-radius: 6px; }
body.pixel .bar { border: 2px solid #000; box-shadow: 0 0 0 1px #888; }
body.pixel .bar i { background: repeating-linear-gradient(90deg, #3ad83a 0 8px, #2ab02a 8px 10px); }
body.pixel .bar.rage i { background: repeating-linear-gradient(90deg, #e03030 0 8px, #b02020 8px 10px); }
body.pixel .slot { box-shadow: 0 0 0 2px #8890c8; image-rendering: pixelated; }
body.pixel .slot img { image-rendering: pixelated; }
body.pixel #xp { border: 2px solid #e8e8f0; } body.pixel #xp i { background: repeating-linear-gradient(90deg, #a050e0 0 12px, #7a30b8 12px 14px); }
body.pixel .frame .face { border-radius: 4px; }
body.pixel #mm canvas { border: 2px solid #000; }

/* ---------------- blocks: Minecraft-ish */
body.blocks .panel { background: rgba(20, 20, 20, 0.45); border: 3px solid #1a1a1a; box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.25), inset -2px -2px 0 rgba(0, 0, 0, 0.4); }
body.blocks #bar { background: rgba(40, 40, 40, 0.6); border: 4px solid #1a1a1a; box-shadow: inset 0 0 0 3px #8b8b8b; gap: 4px; }
body.blocks .slot { border: none; box-shadow: inset 0 0 0 3px #555; padding: 4px; background: transparent; }
body.blocks .slot img { image-rendering: pixelated; }
body.blocks .slot.on { box-shadow: 0 0 0 3px #fff, inset 0 0 0 3px #000; }
body.blocks #xp { height: 10px; background: #1a1a1a; border: 2px solid #000; } body.blocks #xp i { background: #7cf03c; }
body.blocks #mm { background: #c6c6c6; border: 3px solid #000; box-shadow: inset 3px 3px 0 #fff, inset -3px -3px 0 #555; }
body.blocks #mm .zn { color: #222; }
body.blocks #mm canvas { border: 3px solid #555; }
body.blocks .frame .face { border-radius: 0; }
body.blocks #chat { background: rgba(0, 0, 0, 0.35); padding: 4px 8px; }
body.blocks .plate .n { background: rgba(0, 0, 0, 0.3); padding: 0 5px 1px; }
body.blocks #cross { position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; transform: translate(-50%, -50%); background: linear-gradient(#fff, #fff) center/2px 100% no-repeat, linear-gradient(#fff, #fff) center/100% 2px no-repeat; opacity: 0.6; }
body.pixel #cross { display: none; }
