@font-face { font-family: 'Pixelify'; src: url('../fonts/pixelify-sans-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: block; }
@font-face { font-family: 'Pixelify'; src: url('../fonts/pixelify-sans-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: block; }
@font-face { font-family: 'Pixelify'; src: url('../fonts/pixelify-sans-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: block; }
@font-face { font-family: 'Bastarda'; src: url('../fonts/jacquarda-bastarda-9-latin-400-normal.woff2') format('woff2'); font-display: block; }

:root {
  --ink: #2b1d14;
  --ink-soft: #5a4232;
  --parch: #f3e3c3;
  --parch-2: #e6cf9f;
  --wood: #3b2416;
  --wood-2: #573620;
  --wood-3: #7a4d2c;
  --gold: #f2c45a;
  --gold-2: #c98f2a;
  --cream: #fff4dc;
  --hp: #e0504a;
  --hp-2: #a3302d;
  --mp: #4f8fe6;
  --mp-2: #2c5aa8;
  --xp: #8fd16a;
  --shadow: rgba(10, 5, 2, .55);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #120b07; overflow: hidden; }
body { font-family: 'Pixelify', system-ui, sans-serif; color: var(--cream); -webkit-font-smoothing: none; user-select: none; touch-action: none; font-variant-ligatures: none; font-feature-settings: 'liga' 0, 'clig' 0; }

#stage { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; }
#game canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
#ui { position: absolute; left: 0; top: 0; width: 960px; height: 540px; transform-origin: 0 0; pointer-events: none; font-size: 16px; }
#ui > * { pointer-events: auto; }
#ui .passthru { pointer-events: none; }
.hidden { display: none !important; }

/* ---------- panels ---------- */
.panel {
  background: linear-gradient(180deg, var(--wood-2), var(--wood));
  border: 3px solid #1b0f08;
  box-shadow: inset 0 0 0 2px var(--gold-2), inset 0 0 0 4px #1b0f08, inset 0 0 0 6px var(--wood-3), 0 6px 0 var(--shadow);
  border-radius: 6px;
  padding: 14px 16px;
}
.parch {
  background: radial-gradient(ellipse at 50% 40%, var(--parch), var(--parch-2));
  color: var(--ink);
  border: 3px solid #1b0f08;
  box-shadow: inset 0 0 0 2px #b88a4a, inset 0 0 18px rgba(120, 70, 20, .35), 0 6px 0 var(--shadow);
  border-radius: 6px;
}
.title-font { font-family: 'Bastarda', 'Pixelify', serif; letter-spacing: .5px; }
h2.pt { font-family: 'Bastarda', serif; font-weight: 400; font-size: 34px; margin: 0 0 8px; color: var(--gold); text-shadow: 2px 2px 0 #1b0f08; }
.parch h2.pt { color: #6b2f12; text-shadow: none; }

.btn {
  font: inherit; font-weight: 600; font-size: 16px;
  color: var(--cream);
  background: linear-gradient(180deg, #8a5a33, #5e3a1f);
  border: 2px solid #1b0f08;
  box-shadow: inset 0 2px 0 rgba(255, 230, 180, .25), inset 0 -3px 0 rgba(0, 0, 0, .3), 0 3px 0 #1b0f08;
  border-radius: 5px;
  padding: 7px 14px;
  cursor: pointer;
  text-align: left;
  outline: none;
  transition: transform .05s;
}
.btn:hover, .btn.focus { background: linear-gradient(180deg, #b77b40, #7d4b22); color: #fff; }
.btn.focus { box-shadow: inset 0 2px 0 rgba(255, 230, 180, .35), inset 0 -3px 0 rgba(0, 0, 0, .3), 0 3px 0 #1b0f08, 0 0 0 2px var(--gold); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 2px 0 rgba(0, 0, 0, .3), 0 1px 0 #1b0f08; }
.btn[disabled] { opacity: .45; cursor: default; filter: grayscale(.6); }
.btn.gold { background: linear-gradient(180deg, #f6cf6a, #c98f2a); color: var(--ink); }
.btn.gold:hover, .btn.gold.focus { background: linear-gradient(180deg, #ffe08e, #dca23a); }
.btn small { font-weight: 400; opacity: .8; }
.parch .btn { color: var(--cream); }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 10px; top: 10px; display: flex; gap: 10px; align-items: flex-start; pointer-events: none; }
#hud .card { display: flex; gap: 10px; align-items: center; padding: 8px 12px 8px 8px; }
#hud .portrait { width: 52px; height: 52px; border-radius: 4px; background: #1b0f08 center/cover no-repeat; border: 2px solid var(--gold-2); image-rendering: pixelated; overflow: hidden; position: relative; }
#hud .portrait canvas, #hud .portrait img { width: 100%; height: 100%; image-rendering: pixelated; }
#hud .nm { font-weight: 700; font-size: 15px; color: var(--gold); text-shadow: 1px 1px 0 #000; }
#hud .nm span { color: var(--cream); font-weight: 400; font-size: 13px; }
.bar { position: relative; width: 150px; height: 13px; background: #1b0f08; border: 1px solid #000; border-radius: 3px; margin-top: 3px; overflow: hidden; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(180deg, var(--hp), var(--hp-2)); transition: width .3s; }
.bar.mp > i { background: linear-gradient(180deg, var(--mp), var(--mp-2)); }
.bar.xp { height: 6px; } .bar.xp > i { background: linear-gradient(180deg, #b6ef8a, #5f9d3c); }
.bar > b { position: absolute; inset: 0; font-size: 11px; line-height: 12px; text-align: center; font-weight: 600; text-shadow: 1px 1px 0 #000; }
#hud .gold { position: absolute; right: -0px; }
#hudRight { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
#hudRight .loc { padding: 6px 14px; font-family: 'Bastarda', serif; font-size: 24px; color: var(--gold); text-shadow: 2px 2px 0 #000; }
#hudRight .money { padding: 4px 12px; font-weight: 700; color: var(--gold); }
#tracker { max-width: 290px; padding: 8px 12px; font-size: 13px; line-height: 1.35; }
#tracker .qt { color: var(--gold); font-weight: 700; }
#tracker .qo { color: var(--cream); }
#tracker .qo.done { color: var(--xp); }
#tracker .qg { color: var(--gold); font-size: 12px; margin: 1px 0 4px; opacity: .9; }
.wayarrow { position: absolute; top: 300px; font-size: 15px; font-weight: 700; color: var(--gold); text-shadow: 2px 2px 0 #000, -1px -1px 0 #000; pointer-events: none; animation: nudge 1s ease-in-out infinite alternate; white-space: nowrap; }
.wayarrow.l { left: 14px; } .wayarrow.r { right: 14px; }
@keyframes nudge { from { transform: translateX(0); } to { transform: translateX(var(--nx, 6px)); } }
.wayarrow.l { --nx: -6px; }

/* prompt bubble that floats over interactables */
.prompt { position: absolute; transform: translate(-50%, -100%); background: rgba(27, 15, 8, .88); border: 2px solid var(--gold-2); border-radius: 6px; padding: 3px 9px; font-size: 13px; font-weight: 600; white-space: nowrap; pointer-events: none; color: var(--cream); }
.prompt kbd { background: var(--gold); color: var(--ink); border-radius: 3px; padding: 0 5px; margin-right: 5px; font-family: inherit; font-weight: 700; }
.nameplate { position: absolute; transform: translate(-50%, -100%); font-size: 12px; font-weight: 600; color: #fff; text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, -1px -1px 0 #000; pointer-events: none; white-space: nowrap; }
.nameplate.sign { color: var(--gold); font-size: 13px; }
.nameplate.quest::before { content: '! '; color: var(--gold); font-weight: 700; }
.nameplate.turnin::before { content: '? '; color: var(--xp); font-weight: 700; }

/* ---------- dialogue ---------- */
#dialogue { position: absolute; left: 70px; right: 70px; bottom: 16px; min-height: 128px; display: flex; gap: 14px; padding: 14px 18px 14px 14px; cursor: pointer; }
#dialogue .face { flex: 0 0 104px; height: 104px; border: 3px solid #6b4423; border-radius: 4px; background: #2a1a10 center bottom / contain no-repeat; image-rendering: pixelated; }
#dialogue .face.none { display: none; }
#dialogue .face canvas { width: 100%; height: 100%; image-rendering: pixelated; }
#dialogue .who { font-family: 'Bastarda', serif; font-size: 26px; color: #6b2f12; line-height: 1; margin-bottom: 4px; }
#dialogue .txt { font-size: 18px; line-height: 1.4; color: var(--ink); }
#dialogue .more { position: absolute; right: 16px; bottom: 8px; color: #6b2f12; animation: bob 0.8s infinite; font-size: 14px; }
@keyframes bob { 50% { transform: translateY(3px); } }

/* ---------- modal ---------- */
.veil { position: absolute; inset: 0; background: rgba(10, 6, 3, .55); display: flex; align-items: center; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { animation: pop .18s ease-out; max-height: 510px; display: flex; flex-direction: column; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.row { display: flex; gap: 10px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 6px; }
.grow { flex: 1; }
.muted { opacity: .75; }
.scroll { position: relative; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--gold-2) transparent; }
.close-x { position: absolute; right: 10px; top: 8px; }

/* event card */
.event { width: 560px; padding: 18px 22px; }
.event h2.pt { font-size: 30px; line-height: 1.05; }
.event .art { height: 150px; margin: -4px -6px 12px; border-radius: 4px; border: 2px solid #6b4423; background: #2a1a10 center / cover no-repeat; image-rendering: pixelated; position: relative; overflow: hidden; }
.event .art canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.event p { font-size: 17px; line-height: 1.45; margin: 0 0 14px; white-space: pre-line; }
.event .choices { display: flex; flex-direction: column; gap: 7px; }

/* menu */
.menu { width: 860px; height: 486px; padding: 0; display: flex; overflow: hidden; }
.menu .tabs { width: 170px; padding: 18px 12px; display: flex; flex-direction: column; gap: 6px; background: rgba(0, 0, 0, .2); border-right: 2px solid #1b0f08; }
.menu .tabs .btn { width: 100%; }
.menu .body { flex: 1; padding: 18px 22px; overflow: hidden; display: flex; flex-direction: column; position: relative; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 22px; font-size: 16px; }
.stat-grid div { display: flex; justify-content: space-between; border-bottom: 1px dashed rgba(242, 196, 90, .25); padding: 2px 0; }
.stat-grid b { color: var(--gold); }
.up { color: #9ff07a; } .down { color: #ff8a7a; }
.item-list { display: flex; flex-direction: column; gap: 5px; padding-right: 6px; }
.item-row { display: flex; align-items: center; gap: 10px; width: 100%; }
.item-row .ic { width: 32px; height: 32px; flex: 0 0 32px; image-rendering: pixelated; background: rgba(0, 0, 0, .3) center / 28px no-repeat; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .5); }
.item-row .nm { flex: 1; }
.item-row .qty { opacity: .8; min-width: 34px; text-align: right; }
.item-row .price { color: var(--gold); min-width: 64px; text-align: right; font-weight: 700; }
.rare { color: #ffcf6e; }
.desc-box { min-height: 62px; margin-top: 10px; padding: 8px 10px; font-size: 14px; line-height: 1.35; background: rgba(0, 0, 0, .25); border-radius: 4px; }
.slot { display: flex; gap: 10px; align-items: center; padding: 6px 8px; background: rgba(0, 0, 0, .22); border-radius: 4px; margin-bottom: 6px; }
.slot .lbl { width: 92px; color: var(--gold); font-weight: 700; }

.quest { padding: 8px 10px; background: rgba(0, 0, 0, .22); border-radius: 4px; margin-bottom: 8px; }
.quest .t { color: var(--gold); font-weight: 700; font-size: 17px; }
.quest .s { font-size: 14px; line-height: 1.35; opacity: .9; margin: 3px 0; }
.quest li { font-size: 14px; } .quest li.done { color: var(--xp); text-decoration: line-through; }

/* shop */
.shop { width: 760px; height: 470px; }
.shop .cols { display: flex; gap: 16px; flex: 1; min-height: 0; }
.shop .cols > .scroll { flex: 1.3; }

/* toast */
#toasts { position: absolute; left: 50%; top: 92px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: rgba(27, 15, 8, .92); border: 2px solid var(--gold-2); border-radius: 6px; padding: 6px 16px; font-weight: 600; animation: toast 2.8s forwards; text-shadow: 1px 1px 0 #000; }
.toast.big { font-family: 'Bastarda', serif; font-weight: 400; font-size: 30px; color: var(--gold); padding: 6px 26px; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- title & creation ---------- */
#title { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; pointer-events: none; }
#title .logo { margin-top: 56px; font-family: 'Bastarda', serif; font-size: 92px; color: var(--gold); text-shadow: 4px 4px 0 #1b0f08, 0 0 24px rgba(255, 200, 90, .35); line-height: 1; }
#title .sub { font-size: 20px; color: var(--cream); text-shadow: 2px 2px 0 #000; letter-spacing: 3px; margin-top: 6px; }
#title .opts { margin-top: 44px; display: flex; flex-direction: column; gap: 10px; width: 280px; pointer-events: auto; }
#title .opts .btn { text-align: center; font-size: 19px; padding: 10px; }
#title .save { font-size: 13px; text-align: center; color: var(--parch); text-shadow: 1px 1px 0 #000; }
#title .foot { position: absolute; bottom: 10px; font-size: 12px; opacity: .8; text-shadow: 1px 1px 0 #000; }

.create { width: 900px; padding: 14px 22px; }
.create h2.pt { font-size: 30px; margin-bottom: 2px; }
.classes { display: flex; gap: 14px; margin: 8px 0 12px; }
.cls { flex: 1; padding: 10px; border-radius: 6px; background: rgba(0, 0, 0, .25); border: 2px solid transparent; cursor: pointer; text-align: center; }
.cls.sel { border-color: var(--gold); background: rgba(242, 196, 90, .12); }
.cls .sprite { height: 112px; display: flex; align-items: flex-end; justify-content: center; }
.cls .sprite canvas { image-rendering: pixelated; }
.cls h3 { margin: 2px 0 0; font-family: 'Bastarda', serif; font-weight: 400; font-size: 28px; color: #7a2e12; }
.cls .tt { font-size: 13px; opacity: .8; }
.cls p { font-size: 13.5px; line-height: 1.3; text-align: left; margin: 6px 0 0; min-height: 70px; }
.cls .mini { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px 8px; font-size: 12px; text-align: left; margin-top: 6px; }
.cls .mini b { color: #7a2e12; }
input.name { font: inherit; font-size: 18px; padding: 7px 10px; border-radius: 4px; border: 2px solid #1b0f08; background: var(--parch); color: var(--ink); width: 240px; outline: none; }
input.name:focus { box-shadow: 0 0 0 2px var(--gold); }

/* ---------- battle ---------- */
#battleUi { position: absolute; inset: 0; pointer-events: none; }
#battleUi > * { pointer-events: auto; }
#bCmd { position: absolute; left: 318px; top: 58px; width: 300px; padding: 12px; }
#bCmd .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
#bCmd .btn { text-align: center; }
#bCmd .list { display: flex; flex-direction: column; gap: 5px; max-height: 190px; }
#bCmd .list .btn { text-align: left; display: flex; justify-content: space-between; gap: 8px; }
#bCmd .hint { font-size: 13px; opacity: .85; margin-bottom: 8px; min-height: 18px; }
#bHero { position: absolute; left: 14px; top: 58px; width: 290px; padding: 10px 14px; }
#bHero .bar { width: 100%; height: 16px; } #bHero .bar > b { font-size: 12px; line-height: 15px; }
#bHero .st { font-size: 12px; margin-top: 5px; min-height: 16px; }
#bLog { position: absolute; left: 50%; transform: translateX(-50%); top: 200px; padding: 6px 18px; font-size: 16px; font-weight: 600; text-shadow: 1px 1px 0 #000; white-space: nowrap; }
#bOrder { position: absolute; left: 12px; top: 12px; display: flex; gap: 4px; align-items: center; padding: 6px 8px; font-size: 12px; }
#bOrder .o { padding: 2px 7px; border-radius: 3px; background: rgba(0, 0, 0, .35); }
#bOrder .o.h { background: rgba(242, 196, 90, .3); color: var(--gold); }
#bOrder .o:first-of-type { outline: 2px solid var(--gold); }
.chip { display: inline-block; padding: 0 6px; border-radius: 3px; margin-right: 4px; font-size: 11px; font-weight: 700; }
.chip.poison { background: #6b3a8f; } .chip.burn { background: #b5541f; } .chip.slow { background: #2f6aa0; } .chip.stun { background: #8a7d22; }
.chip.guard { background: #5e6f80; } .chip.atk_up { background: #a03030; } .chip.def_down { background: #555; }

.result { width: 470px; padding: 18px 24px; text-align: center; }
.result .lv { color: var(--xp); font-weight: 700; font-size: 18px; margin: 8px 0 2px; }
.result ul { list-style: none; padding: 0; margin: 8px 0 14px; font-size: 16px; line-height: 1.6; }

/* ---------- touch ---------- */
#touch { position: fixed; inset: auto 0 0 0; height: 0; z-index: 20; }
#touch button { position: fixed; bottom: 18px; width: 64px; height: 64px; border-radius: 50%; font-size: 26px; color: #fff; background: rgba(27, 15, 8, .55); border: 2px solid rgba(242, 196, 90, .6); font-family: inherit; }
#touch [data-k=left] { left: 18px; } #touch [data-k=right] { left: 96px; }
#touch .act { right: 18px; background: rgba(201, 143, 42, .6); }
#touch .menu { right: 96px; bottom: 30px; width: 52px; height: 52px; font-size: 22px; }

/* fade overlay for scene transitions */
#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .35s; }
#fade.on { opacity: 1; }
