:root {
  --ink: #e9dcc0;
  --ink-dim: #b3a585;
  --gold: #d4a64a;
  --gold-dim: #8a6a30;
  --panel: rgba(22, 17, 12, 0.92);
  --panel-edge: #6a4f2a;
  --slot: rgba(48, 38, 26, 0.85);
  --hp: #b8322a;
  --st: #4f8a3a;
  --rs: #6a5ab8;
  --title: 'Cinzel', 'Trajan Pro', Georgia, serif;
  --body: 'EB Garamond', Georgia, 'Times New Roman', serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0c0a08; color: var(--ink); font-family: var(--body); font-size: 16px; user-select: none; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; }
.hidden { display: none !important; }
button { font-family: var(--title); background: linear-gradient(#3b2d1c, #241a10); color: var(--ink); border: 1px solid var(--gold-dim); padding: 8px 18px; cursor: pointer; letter-spacing: 0.06em; font-size: 14px; }
button:hover:not(:disabled) { border-color: var(--gold); color: #fff3d0; box-shadow: 0 0 10px rgba(212, 166, 74, 0.35); }
button:disabled { opacity: 0.4; cursor: default; }

/* ---------- title ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 50;
  background: radial-gradient(ellipse at 50% 60%, rgba(60, 38, 20, 0.55), rgba(5, 4, 3, 0.96) 70%); }
.title-inner { text-align: center; width: min(520px, 90vw); }
.sigil { font-size: 42px; color: var(--gold); opacity: 0.8; }
h1 { font-family: var(--title); font-size: clamp(42px, 8vw, 78px); letter-spacing: 0.22em; margin: 8px 0 4px; color: #f0dfb4; text-shadow: 0 0 30px rgba(212, 120, 40, 0.35); }
.subtitle { font-style: italic; color: var(--ink-dim); font-size: 19px; margin-bottom: 36px; letter-spacing: 0.08em; }
#menu { display: flex; flex-direction: column; gap: 10px; align-items: center; }
#menu button { width: 260px; font-size: 16px; padding: 11px; }
#loading .bar { height: 4px; background: #2a2016; margin: 0 auto 10px; width: 300px; }
#loadbar { height: 100%; width: 0; background: var(--gold); transition: width 0.2s; }
#loadtext { color: var(--ink-dim); font-style: italic; }

/* ---------- hud ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#vignette { position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.85) 100%); opacity: 0; transition: opacity 1s; }
#hurt { position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 40%, rgba(150, 0, 0, 0.75) 100%); opacity: 0; }
#compass { position: absolute; top: 14px; left: 50%; width: min(520px, 70vw); height: 30px; transform: translateX(-50%); overflow: hidden;
  background: linear-gradient(90deg, transparent, rgba(15, 11, 7, 0.75) 15%, rgba(15, 11, 7, 0.75) 85%, transparent); border-top: 1px solid rgba(212, 166, 74, 0.35); border-bottom: 1px solid rgba(212, 166, 74, 0.35); }
#compass-strip { position: absolute; top: 0; height: 100%; }
.ctick { position: absolute; top: 5px; transform: translateX(-50%); font-family: var(--title); font-size: 15px; color: var(--ink); }
.ctick.minor { font-size: 10px; top: 9px; color: var(--ink-dim); }
.ctick.quest { color: #ffcf50; font-size: 16px; top: 4px; text-shadow: 0 0 6px #c08020; }
.ctick.place { color: #9ab8c8; font-size: 12px; top: 7px; }
#compass-needle { position: absolute; left: 50%; top: 0; width: 1px; height: 6px; background: var(--gold); }
#target-info { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); text-align: center; }
#target-name { font-family: var(--title); font-size: 14px; text-shadow: 0 1px 3px #000; }
.tbar { width: 220px; height: 6px; background: rgba(0, 0, 0, 0.6); border: 1px solid #5a3a2a; margin-top: 3px; }
#target-hp { height: 100%; background: var(--hp); width: 100%; transition: width 0.15s; }
#clock { position: absolute; top: 18px; right: 22px; font-family: var(--title); font-size: 14px; text-align: right; text-shadow: 0 1px 3px #000; color: var(--ink); }
#clock small { display: block; font-family: var(--body); font-style: italic; color: var(--ink-dim); font-size: 13px; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: rgba(255, 240, 210, 0.85); box-shadow: 0 0 3px #000; }
#crosshair.active { width: 8px; height: 8px; margin: -4px; background: transparent; border: 1.5px solid #ffd780; }
#prompt { position: absolute; left: 50%; top: calc(50% + 26px); transform: translateX(-50%); text-align: center; text-shadow: 0 1px 3px #000, 0 0 8px #000; font-size: 17px; line-height: 1.45; white-space: nowrap; }
#prompt .key { display: inline-block; min-width: 22px; padding: 0 5px; border: 1px solid var(--gold-dim); background: rgba(20, 14, 8, 0.8); font-family: var(--title); font-size: 12px; margin-right: 6px; color: var(--gold); }
#prompt .lvl { color: #e07050; }
#action { position: absolute; left: 50%; top: calc(50% + 90px); transform: translateX(-50%); width: 240px; text-align: center; }
#action-label { font-style: italic; text-shadow: 0 1px 3px #000; }
.abar { height: 5px; background: rgba(0, 0, 0, 0.6); border: 1px solid var(--gold-dim); margin-top: 4px; }
#action-fill { height: 100%; width: 0; background: var(--gold); }
#vitals { position: absolute; left: 22px; bottom: 22px; width: 250px; }
.vbar { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.vbar span { width: 62px; font-family: var(--title); font-size: 11px; color: var(--ink-dim); text-shadow: 0 1px 2px #000; letter-spacing: 0.05em; }
.track { flex: 1; height: 10px; background: rgba(0, 0, 0, 0.55); border: 1px solid rgba(140, 110, 60, 0.6); }
.fill { height: 100%; transition: width 0.2s; }
.fill.hp { background: linear-gradient(#d8483a, #8a1f18); }
.fill.st { background: linear-gradient(#6aac4a, #2f5a22); }
.fill.rs { background: linear-gradient(#8a7ae0, #3f308a); }
.fill.mn { background: linear-gradient(#5ab0e8, #1f4a8a); }
#plevel { font-family: var(--title); font-size: 13px; color: var(--gold); text-shadow: 0 1px 3px #000; margin-bottom: 4px; letter-spacing: 0.06em; }
.menutabs { display: flex; gap: 2px; margin: -6px 30px 14px 0; border-bottom: 1px solid var(--panel-edge); flex-wrap: wrap; }
.menutab { background: none; border: none; border-bottom: 2px solid transparent; padding: 6px 12px; font-size: 13px; color: var(--ink-dim); }
.menutab:hover:not(:disabled) { box-shadow: none; color: #fff0c8; }
.menutab.on { color: #fff0c8; border-bottom-color: var(--gold); }
.menutab small { font-family: var(--body); font-size: 11px; opacity: 0.6; margin-left: 4px; }
.loadbar { height: 6px; background: rgba(0, 0, 0, 0.5); border: 1px solid #4a3a22; margin: 4px 0 2px; }
.loadbar div { height: 100%; }
.craftjob { margin-top: 12px; padding: 8px 10px; border: 1px solid var(--gold-dim); background: rgba(60, 45, 25, 0.4); }
.craftjob .abar { margin: 6px 0; }
.incs { display: grid; grid-template-columns: repeat(2, 300px); gap: 6px; }
.inc { background: var(--slot); border: 1px solid #4a3a22; padding: 8px 12px; }
.inc.locked { opacity: 0.45; }
.inc.quick { border-color: var(--gold); }
.inc h4 { margin: 0; font-family: var(--title); font-size: 14px; color: #f0e0b0; }
.inc .words { font-style: italic; color: var(--ink-dim); font-size: 14px; margin: 3px 0; }
.inc .meta { font-size: 13px; color: #8ab8e0; }
.inc button { padding: 3px 10px; font-size: 12px; margin: 6px 6px 0 0; }
#buffs { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.buff { font-size: 13px; padding: 2px 7px; background: rgba(20, 15, 10, 0.8); border: 1px solid #5a7a3a; border-radius: 2px; text-shadow: none; }
.buff.bad { border-color: #a03a2a; color: #ffb0a0; }
#needs { position: absolute; right: 22px; bottom: 22px; display: flex; gap: 10px; }
.need { width: 52px; text-align: center; font-size: 11px; color: var(--ink-dim); font-family: var(--title); text-shadow: 0 1px 2px #000; }
.need svg { width: 46px; height: 46px; display: block; margin: 0 auto 2px; }
.need .ico { font-size: 17px; }
.need.low { color: #ff8a70; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }
#belt { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; }
#belt-name { position: absolute; bottom: 90px; left: 50%; transform: translateX(-50%); font-family: var(--title); font-size: 14px; text-shadow: 0 1px 3px #000; transition: opacity 0.5s; }
.slot { width: 58px; height: 58px; background: var(--slot); border: 1px solid #4a3a22; position: relative; pointer-events: auto; }
.slot img { width: 100%; height: 100%; display: block; pointer-events: none; }
.slot .n { position: absolute; right: 3px; bottom: 1px; font-size: 13px; font-weight: 600; text-shadow: 0 0 3px #000, 0 0 2px #000; }
.slot .k { position: absolute; left: 3px; top: 1px; font-size: 10px; color: var(--ink-dim); font-family: var(--title); }
.slot .dur { position: absolute; left: 4px; right: 4px; bottom: 3px; height: 3px; background: rgba(0, 0, 0, 0.6); }
.slot .dur div { height: 100%; background: #7ac04a; }
.slot.sel { border-color: var(--gold); box-shadow: 0 0 10px rgba(212, 166, 74, 0.6), inset 0 0 12px rgba(212, 166, 74, 0.25); }
.slot.legend { background: radial-gradient(rgba(150, 110, 30, 0.45), var(--slot)); }
#xpdrops { position: absolute; right: 28px; top: 90px; width: 200px; height: 220px; }
.xpdrop { position: absolute; right: 0; bottom: 0; font-family: var(--title); font-size: 14px; text-shadow: 0 1px 3px #000; animation: xprise 1.8s ease-out forwards; white-space: nowrap; }
@keyframes xprise { from { transform: translateY(0); opacity: 1; } 80% { opacity: 1; } to { transform: translateY(-170px); opacity: 0; } }
#toasts { position: absolute; left: 24px; top: 40%; width: 420px; display: flex; flex-direction: column; gap: 4px; }
.toast { background: linear-gradient(90deg, rgba(15, 11, 7, 0.82), transparent); padding: 4px 12px; border-left: 2px solid var(--gold-dim); font-size: 16px; animation: tin 0.3s, tout 0.6s 4.4s forwards; }
@keyframes tin { from { opacity: 0; transform: translateX(-10px); } }
@keyframes tout { to { opacity: 0; } }
#banner { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); text-align: center; animation: banner 4.5s forwards; }
#banner-top { font-family: var(--title); letter-spacing: 0.3em; font-size: 14px; color: var(--gold); }
#banner-main { font-family: var(--title); font-size: 34px; color: #f6e6c0; text-shadow: 0 0 18px rgba(212, 140, 40, 0.6), 0 2px 4px #000; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, 8px); } 12% { opacity: 1; transform: translate(-50%, 0); } 80% { opacity: 1; } 100% { opacity: 0; } }
#hint { position: absolute; bottom: 92px; left: 50%; transform: translateX(-50%); font-size: 15px; text-shadow: 0 1px 3px #000; }
#hint b { color: var(--gold); font-family: var(--title); font-size: 12px; }
#lockhint { position: absolute; top: 46%; width: 100%; text-align: center; font-family: var(--title); letter-spacing: 0.15em; font-size: 18px; text-shadow: 0 0 10px #000; }

/* ---------- panels ---------- */
#panel { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: rgba(5, 4, 2, 0.55); }
#panel-inner { background: var(--panel); border: 1px solid var(--panel-edge); box-shadow: 0 0 0 1px #000, 0 10px 60px rgba(0, 0, 0, 0.8), inset 0 0 60px rgba(0, 0, 0, 0.5); padding: 20px 24px; max-height: 92vh; overflow: auto; min-width: 360px; max-width: 96vw; position: relative; }
.ptitle { font-family: var(--title); font-size: 22px; letter-spacing: 0.12em; color: #f0dfb4; margin: 0 0 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 20px; }
.ptitle small { font-family: var(--body); font-size: 14px; color: var(--ink-dim); letter-spacing: 0; font-style: italic; }
.close { position: absolute; right: 10px; top: 8px; background: none; border: none; font-size: 20px; color: var(--ink-dim); padding: 4px 8px; }
.tabs { display: flex; gap: 2px; margin-bottom: 12px; flex-wrap: wrap; }
.tab { padding: 6px 12px; font-size: 13px; background: #1e170f; border-color: #3a2c18; }
.tab.on { background: #3e2e1a; border-color: var(--gold); color: #fff0c8; }
.tab.near { box-shadow: inset 0 -2px 0 #7ac04a; }
.grid { display: grid; grid-template-columns: repeat(8, 58px); gap: 4px; }
.grid .slot { cursor: pointer; }
.grid .slot:hover { border-color: var(--gold-dim); }
.grid .slot.beltslot { border-color: #6a5430; }
.sec { font-family: var(--title); font-size: 12px; color: var(--ink-dim); letter-spacing: 0.12em; margin: 12px 0 6px; }
.row { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.equip { display: grid; grid-template-columns: 58px 1fr; gap: 6px 10px; align-items: center; font-size: 14px; }
.equip .lbl { color: var(--ink-dim); }
.stats { font-size: 15px; line-height: 1.6; margin-top: 10px; }
.stats b { color: var(--gold); font-weight: 600; }
.recipes { width: 300px; max-height: 420px; overflow-y: auto; border: 1px solid #3a2c18; }
.recipe { display: flex; align-items: center; gap: 8px; padding: 4px 8px; cursor: pointer; border-bottom: 1px solid rgba(80, 60, 30, 0.25); }
.recipe img { width: 36px; height: 36px; }
.recipe:hover { background: rgba(80, 60, 30, 0.3); }
.recipe.on { background: rgba(120, 90, 40, 0.35); }
.recipe.locked { opacity: 0.45; }
.recipe.ready .rn::after { content: ' ●'; color: #7ac04a; font-size: 10px; }
.rdetail { width: 320px; }
.rdetail h3 { font-family: var(--title); margin: 0 0 4px; font-size: 18px; }
.rdetail .desc { font-style: italic; color: var(--ink-dim); margin-bottom: 10px; }
.req { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.req img { width: 30px; height: 30px; }
.req.ok { color: #a8d88a; } .req.no { color: #e08a7a; }
.skillgrid { display: grid; grid-template-columns: repeat(3, 190px); gap: 6px; }
.skill { background: var(--slot); border: 1px solid #4a3a22; padding: 7px 10px; display: flex; align-items: center; gap: 10px; }
.skill .si { font-size: 22px; width: 28px; text-align: center; }
.skill .sn { font-size: 14px; }
.skill .sl { margin-left: auto; font-family: var(--title); font-size: 18px; color: var(--gold); }
.skill .sb { height: 3px; background: #2a2016; margin-top: 3px; } .skill .sb div { height: 100%; }
.book { width: min(620px, 90vw); background: linear-gradient(#e8d9b5, #d9c597); color: #2a1e10; padding: 34px 44px; font-size: 19px; line-height: 1.55; white-space: pre-wrap; box-shadow: inset 0 0 70px rgba(110, 70, 20, 0.45); font-family: var(--body); max-height: 80vh; overflow-y: auto; }
.book h2 { font-family: var(--title); text-align: center; font-size: 22px; margin: 0 0 18px; letter-spacing: 0.08em; white-space: normal; }
.quest { margin-bottom: 14px; }
.quest h3 { font-family: var(--title); font-size: 16px; margin: 0; color: var(--gold); }
.quest h4 { margin: 2px 0; font-size: 16px; }
.quest p { margin: 4px 0 6px; font-style: italic; color: var(--ink-dim); }
.goal { font-size: 15px; } .goal.done { color: #8ab870; text-decoration: line-through; }
.trade-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; width: 460px; }
.ware { display: flex; align-items: center; gap: 8px; background: var(--slot); padding: 4px 8px; border: 1px solid #3a2c18; cursor: pointer; font-size: 14px; }
.ware:hover { border-color: var(--gold); }
.ware img { width: 34px; height: 34px; }
.ware .price { margin-left: auto; color: var(--gold); }
.speech { font-style: italic; font-size: 18px; margin-bottom: 12px; color: #f0e0b0; max-width: 520px; }
.mapwrap { position: relative; }
.mapwrap canvas { display: block; image-rendering: auto; border: 1px solid var(--panel-edge); }
.choice { display: flex; gap: 16px; margin-top: 14px; }
.choice button { flex: 1; padding: 16px; text-align: left; font-family: var(--body); font-size: 16px; letter-spacing: 0; line-height: 1.4; }
.choice button b { font-family: var(--title); display: block; font-size: 16px; color: var(--gold); margin-bottom: 4px; }
.settings label { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin: 8px 0; }
.controls { columns: 2; column-gap: 30px; font-size: 15px; line-height: 1.7; }
.controls b { font-family: var(--title); font-size: 12px; color: var(--gold); display: inline-block; min-width: 70px; }
.ctx { position: fixed; z-index: 40; background: #1c150d; border: 1px solid var(--gold-dim); min-width: 120px; }
.ctx div { padding: 5px 12px; cursor: pointer; font-size: 15px; }
.ctx div:hover { background: #3a2c18; }

#tooltip { position: fixed; z-index: 45; pointer-events: none; background: rgba(12, 9, 6, 0.96); border: 1px solid var(--gold-dim); padding: 8px 12px; max-width: 300px; font-size: 14px; line-height: 1.4; }
#tooltip h4 { margin: 0 0 3px; font-family: var(--title); font-size: 14px; color: #f6e2b0; }
#tooltip .legendary { color: #ffb840; }
#tooltip i { color: var(--ink-dim); }
#tooltip .st { color: #a8c8e0; }

#fade { position: fixed; inset: 0; z-index: 60; background: #000; opacity: 0; pointer-events: none; transition: opacity 1.2s; display: flex; align-items: center; justify-content: center; }
#fade.on { opacity: 1; pointer-events: auto; }
#fade-text { font-family: var(--body); font-style: italic; font-size: 22px; color: var(--ink); text-align: center; max-width: 640px; line-height: 1.6; padding: 20px; }
.story p { opacity: 0; animation: storyin 1.6s forwards; margin: 0 0 14px; }
@keyframes storyin { to { opacity: 1; } }
.death h1 { color: #b8322a; font-size: 48px; letter-spacing: 0.15em; }

@media (max-width: 1250px) {
  #needs { bottom: 96px; }
  #belt-name { bottom: 150px; }
}
@media (max-width: 760px) {
  .slot { width: 44px; height: 44px; }
  #belt .slot { width: 40px; height: 40px; }
  #vitals { width: 180px; }
}

#dialogue { position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%); width: min(620px, 92vw); background: rgba(16, 12, 8, 0.9); border: 1px solid var(--panel-edge); box-shadow: 0 0 0 1px #000, 0 6px 30px rgba(0, 0, 0, 0.6); padding: 12px 18px 10px; pointer-events: auto; }
#dialogue .dname { font-family: var(--title); font-size: 14px; letter-spacing: 0.08em; margin-bottom: 4px; }
#dialogue .dtext { font-size: 18px; line-height: 1.45; }
#dialogue .dmore { text-align: right; font-family: var(--title); font-size: 11px; color: var(--ink-dim); margin-top: 6px; }
#tutorial { position: absolute; left: 22px; top: 18px; width: 270px; background: linear-gradient(90deg, rgba(15, 11, 7, 0.8), rgba(15, 11, 7, 0.4)); border-left: 2px solid var(--gold-dim); padding: 8px 12px; text-shadow: 0 1px 2px #000; }
#tutorial .ttop { font-family: var(--title); font-size: 11px; letter-spacing: 0.15em; color: var(--gold); }
#tutorial .tbar2 { height: 3px; background: rgba(0, 0, 0, 0.5); margin: 4px 0 6px; }
#tutorial .tbar2 div { height: 100%; background: var(--gold); }
#tutorial .ttitle { font-family: var(--title); font-size: 15px; margin-bottom: 3px; }
#tutorial .tgoal { font-size: 14px; color: var(--ink); }
#tutorial .tgoal.done { color: #8ab870; }
