/* 심연의 계단 — iron-bound dungeon UI.
   Pixel art is drawn at 3x (frames, banners) or 2x (icons) so every art pixel stays square. */
@font-face { font-family: "Galmuri11"; src: url(assets/fonts/Galmuri11.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Galmuri11"; src: url(assets/fonts/Galmuri11-Bold.woff2) format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Galmuri14"; src: url(assets/fonts/Galmuri14.woff2) format("woff2"); font-weight: 400; font-display: swap; }

:root {
  --ink: #120d16; --stone: #211a28; --stone-2: #2b2333; --stone-3: #372d41;
  --outline: #0b0810; --iron: #8a7f99; --iron-dk: #4d4458;
  --amber: #f2b14a; --amber-hi: #ffd88a; --brass: #d9a441; --ember: #c8641e;
  --parch: #ecdcbc; --dim: #a395ae; --blood: #ef6b78; --arcane: #6fd8ea; --verdant: #8ee06a; --violet: #c58cff;
  --f-body: "Galmuri14", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  --f-pix: "Galmuri11", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--ink); color: var(--parch);
  font-family: var(--f-body); font-size: 14px; line-height: 1.5; user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }
#ui { position: fixed; inset: 0; pointer-events: none; display: flex; align-items: center; justify-content: center; }
#ui > * { pointer-events: auto; }
#ui.dim { background: radial-gradient(ellipse at center, rgba(12,8,16,.4), rgba(12,8,16,.82)); }
#ui.dim ~ #toasts { visibility: hidden; }
img, .px { image-rendering: pixelated; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--amber-hi); outline-offset: 3px; }

/* ---------- frames ---------- */
.frame {
  position: relative;
  border: 12px solid transparent;
  border-image: url(assets/ui/frame.png) 4 / 12px stretch;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(242,177,74,.08), transparent 60%),
    repeating-conic-gradient(rgba(255,255,255,.02) 0 25%, transparent 0 50%) 0 0 / 6px 6px,
    var(--stone);
  background-clip: padding-box;
  padding: 16px 20px 18px;
  max-width: 94vw; max-height: 94vh; overflow: auto;
  display: flex; flex-direction: column;
  filter: drop-shadow(0 16px 30px rgba(0,0,0,.7));
  animation: frame-in .2s steps(3) both;
}
.frame.wide { width: min(980px, 94vw); }
.frame.sheet { width: min(780px, 94vw); }
.frame.narrow { width: min(470px, 92vw); }
.frame.levelup { width: min(620px, 94vw); }
.frame.center { text-align: center; }
@keyframes frame-in { from { transform: translateY(10px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.frame::-webkit-scrollbar { width: 9px; }
.frame::-webkit-scrollbar-thumb { background: var(--iron-dk); border: 2px solid var(--outline); }

/* banner header: crimson cloth with gold trim */
.plaque { display: flex; justify-content: center; margin: -2px auto 8px; }
.plaque h2 {
  font-family: var(--f-pix); font-weight: 700; font-size: 22px; line-height: 22px; letter-spacing: 1px;
  color: var(--amber-hi); text-shadow: 0 3px 0 rgba(20,4,8,.9);
  min-width: 200px; height: 48px; padding: 12px 10px 0; text-align: center; white-space: nowrap;
  border-style: solid; border-color: transparent; border-width: 0 48px;
  border-image: url(assets/ui/banner.png) 0 16 fill / 0 48px stretch;
}
.plaque.gold h2 { border-image-source: url(assets/ui/banner-gold.png); }
.plaque.arcane h2 { border-image-source: url(assets/ui/banner-arcane.png); color: #d8f6ff; }
.plaque.blood h2 { border-image-source: url(assets/ui/banner-blood.png); color: #ffe2e5; }
.plaque .torch { display: none; }
.lede { text-align: center; color: var(--dim); margin: 0 auto 14px; max-width: 62ch; }
.lede.small { margin-bottom: 8px; }
.row { display: flex; justify-content: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; flex: none; }
.row:empty { display: none; }
/* long lists scroll inside the panel; header and buttons stay put */
.heroes, .wares, .quests, .entries, .creditbox { overflow-y: auto; min-height: 0; flex: 0 1 auto; padding-right: 4px; }
.heroes::-webkit-scrollbar, .wares::-webkit-scrollbar, .quests::-webkit-scrollbar, .entries::-webkit-scrollbar, .creditbox::-webkit-scrollbar { width: 9px; }
.heroes::-webkit-scrollbar-thumb, .wares::-webkit-scrollbar-thumb, .quests::-webkit-scrollbar-thumb, .entries::-webkit-scrollbar-thumb, .creditbox::-webkit-scrollbar-thumb { background: var(--iron-dk); border: 2px solid var(--outline); }
.duo { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 0 20px; }
.rule { display: flex; align-items: center; gap: 10px; margin: 10px 0 6px; color: var(--brass); }
.rule::before, .rule::after { content: ""; flex: 1; height: 3px; background: repeating-linear-gradient(90deg, var(--iron-dk) 0 6px, transparent 6px 9px); }
.dim { color: var(--dim); }
.good { color: var(--arcane); } .bad { color: var(--blood); } .zero { color: #6f6479; }
.arcane { color: var(--arcane); }

/* ---------- buttons ---------- */
.pbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 12px; cursor: pointer; color: #fff3dc; background: none;
  border: 9px solid transparent; border-image: url(assets/ui/btn-ember.png) 3 fill / 9px stretch;
  text-shadow: 0 2px 0 rgba(0,0,0,.55);
}
.pbtn.iron { border-image-source: url(assets/ui/btn-iron.png); color: var(--parch); }
.pbtn.danger { border-image-source: url(assets/ui/btn-blood.png); color: #ffe6e8; }
.pbtn b { color: var(--amber-hi); font-weight: 400; }
.pbtn:hover:not(:disabled) { filter: brightness(1.14); }
.pbtn:active:not(:disabled) { transform: translateY(2px); }
.pbtn:disabled { filter: grayscale(.85) brightness(.6); cursor: default; }
kbd { font-family: var(--f-pix); font-size: 11px; line-height: 14px; color: var(--parch); background: #19131f;
  border: 2px solid var(--iron-dk); border-bottom-width: 4px; padding: 0 5px; margin: 0 2px; text-shadow: none; }

/* sockets for icons */
.sock { position: relative; flex: none; width: 54px; height: 54px; display: flex; align-items: center; justify-content: center;
  border: 9px solid transparent; border-image: url(assets/ui/socket.png) 3 fill / 9px stretch; }
.sock img { width: 32px; height: 32px; }
.arc-icon { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px var(--outline); }
.arc-icon img { width: 70%; height: 70%; }

/* ---------- title ---------- */
.title-screen { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 20px; }
.logo { display: flex; gap: 22px; font-family: var(--f-pix); font-weight: 700; font-size: 66px; line-height: 1.1; letter-spacing: 4px; color: var(--amber);
  text-shadow: 0 6px 0 #6a2a0c, 0 12px 0 #160904, 0 0 48px rgba(255,140,40,.35); animation: frame-in .5s steps(5) both; }
.tagline { margin: 22px 0 26px; color: var(--parch); text-shadow: 0 2px 0 #000; }
.menu { display: flex; flex-direction: column; gap: 6px; width: 300px; }
.mitem { display: flex; align-items: center; gap: 12px; padding: 0 12px 0 8px; min-height: 50px; cursor: pointer; text-align: left;
  border: 9px solid transparent; border-image: url(assets/ui/btn-iron.png) 3 fill / 9px stretch; background: none; color: var(--parch); text-shadow: 0 2px 0 #000; }
.mitem img { width: 32px; height: 32px; }
.mitem em { margin-left: auto; font-style: normal; color: var(--amber); }
.mitem.primary { border-image-source: url(assets/ui/btn-ember.png); min-height: 58px; font-family: var(--f-pix); font-weight: 700; font-size: 22px; color: #fff3dc; }
.mitem:hover, .mitem:focus-visible { filter: brightness(1.15); }
.mitem:active { transform: translateY(2px); }
.purse { display: inline-flex; align-items: center; gap: 8px; margin-top: 18px; font-family: var(--f-pix); font-weight: 700; font-size: 22px; color: var(--amber); text-shadow: 0 3px 0 #000; }
.purse img { width: 22px; height: 22px; }
.purse.inline { display: flex; justify-content: center; margin: 0 auto 12px; }
.controls { margin-top: 18px; color: var(--dim); text-shadow: 0 2px 0 #000; }
.controls .touch { display: block; margin-top: 4px; opacity: .7; }

/* ---------- heroes ---------- */
.heroes { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 10px 10px; text-align: center; cursor: pointer;
  background: var(--stone-2); border: 3px solid var(--outline); }
.hero:hover:not(:disabled) { background: var(--stone-3); }
.hero.sel { border-color: var(--amber); box-shadow: inset 0 0 28px rgba(242,177,74,.18), 0 0 0 2px var(--outline); }
.hero.locked { cursor: default; opacity: .8; }
.niche { flex: none; width: 84px; height: 84px; display: flex; align-items: center; justify-content: center;
  border: 12px solid transparent; border-image: url(assets/ui/frame.png) 4 / 12px stretch;
  background: radial-gradient(circle at 50% 70%, rgba(242,177,74,.22), #0d0a11 72%); background-clip: padding-box; }
.niche img { width: 48px; height: 48px; }
.hero .niche { width: 80px; height: 80px; margin-bottom: 2px; }
.hero .niche img { width: 48px; height: 48px; }
.select .hname { font-size: 14px; font-family: var(--f-body); font-weight: 400; color: var(--amber-hi); }
.select .hdesc { font-size: 14px; line-height: 1.4; }
.niche.big { width: 128px; height: 128px; margin: 6px auto 10px; }
.niche.big img { width: 96px; height: 96px; }
.hname { font-family: var(--f-pix); font-weight: 700; font-size: 22px; line-height: 1.2; color: var(--parch); }
.htitle { color: var(--dim); }
.hstats { display: flex; justify-content: center; gap: 10px; margin-top: 4px; font-family: var(--f-pix); font-size: 11px; color: var(--parch); }
.hstats span { display: inline-flex; align-items: center; gap: 3px; }
.hstats img { width: 16px; height: 16px; }
.hdesc { margin: 6px 0 0; color: var(--dim); }
.hdesc.how { color: var(--brass); }
.frame.center .hdesc { margin: 8px auto 0; max-width: 40ch; }
.toggle { display: flex; align-items: center; gap: 8px; color: var(--blood); cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--blood); }

/* ---------- character sheet (pause) ---------- */
.sheet-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 20px; align-items: start; }
.herostrip { display: flex; gap: 12px; align-items: center; }
.htext { min-width: 0; flex: 1; }
.hpbar { position: relative; height: 20px; margin-top: 8px; background: #1a0a0e; border: 3px solid var(--outline); box-shadow: inset 0 0 0 2px #3a1218; }
.hpbar i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(#ff7a82 0 33%, #d4384a 33%); }
.hpbar span { position: relative; display: block; text-align: center; font-family: var(--f-pix); font-size: 11px; line-height: 14px; color: #fff; text-shadow: 0 1px 0 #000; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 0 8px 0 3px; background: var(--stone-3); border: 2px solid var(--outline); }
.chip img { width: 16px; height: 16px; }
.lvchip { color: var(--amber); padding-left: 8px; }
.ledger { display: grid; grid-template-columns: 1fr 1fr; column-gap: 16px; }
.lrow { display: flex; align-items: center; gap: 6px; padding: 3px 0; border-bottom: 2px dotted rgba(138,127,153,.22); }
.licon { width: 16px; height: 16px; }
.lname { color: var(--dim); white-space: nowrap; }
.lval { margin-left: auto; font-weight: 400; }
.shelf { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.wslot { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.wslot .sock { width: 54px; height: 54px; }
.wslot .lv { position: absolute; right: -9px; bottom: -11px; font-family: var(--f-pix); font-size: 11px; line-height: 13px; background: var(--outline); color: var(--amber); padding: 1px 3px; }
.wslot .lv em { font-style: normal; color: var(--blood); margin-left: 2px; }
.wslot.evolved .sock, .wslot.union .sock { border-image-source: url(assets/ui/socket-gold.png); }
.wslot.empty .sock { opacity: .35; }
.wname { max-width: 100%; font-family: var(--f-pix); font-size: 11px; color: var(--parch); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 6px; }
.dbar { width: 100%; height: 8px; background: #120d16; border: 2px solid var(--outline); }
.dbar i { display: block; height: 100%; background: linear-gradient(var(--amber) 0 50%, var(--ember) 50%); }
.dnum { font-family: var(--f-pix); font-size: 11px; color: var(--dim); }
.prow { display: flex; gap: 6px; flex-wrap: wrap; }
.pslot { position: relative; width: 46px; height: 46px; display: flex; align-items: center; justify-content: center;
  border: 9px solid transparent; border-image: url(assets/ui/socket.png) 3 fill / 9px stretch; }
.pslot img { width: 24px; height: 24px; }
.pslot span { position: absolute; right: -9px; bottom: -11px; font-family: var(--f-pix); font-size: 11px; line-height: 13px; background: var(--outline); color: var(--arcane); padding: 1px 3px; }
.pslot.empty { opacity: .3; }
.charms { display: flex; flex-wrap: wrap; gap: 6px; }
.charm { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 3px; background: var(--stone-3); border: 2px solid var(--outline); }
.charm img { width: 22px; height: 22px; }
.charm.arc { box-shadow: inset 0 0 0 1px rgba(197,140,255,.4); }
.charm.rel { box-shadow: inset 0 0 0 1px rgba(111,216,234,.35); }
.explore { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 12px; color: var(--dim); }
.explore b { color: var(--arcane); font-weight: 400; }
.segbar { display: flex; gap: 3px; }
.segbar i { width: 14px; height: 10px; background: #19131f; border: 2px solid var(--outline); }
.segbar i.on { background: var(--arcane); }

/* ---------- level up ---------- */
.opts { display: flex; flex-direction: column; gap: 8px; }
.offer { --k: var(--iron); position: relative; display: flex; align-items: center; gap: 12px; padding: 6px 12px 6px 30px; text-align: left; cursor: pointer;
  background: var(--stone-2); border: 3px solid var(--outline); box-shadow: inset 5px 0 0 var(--k); }
.offer.weapon { --k: var(--ember); } .offer.passive { --k: var(--arcane); } .offer.limit { --k: var(--blood); }
.offer.gold { --k: var(--brass); } .offer.heal { --k: var(--verdant); }
.offer:hover, .offer:focus-visible { background: var(--stone-3); border-color: var(--amber); outline: none; }
.key { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-family: var(--f-pix); font-size: 11px; line-height: 16px; width: 16px; text-align: center; background: var(--outline); color: var(--amber); }
.otext { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.oname { font-family: var(--f-pix); font-weight: 700; font-size: 22px; line-height: 1.15; color: var(--parch); }
.oname em { font-style: normal; font-weight: 400; font-size: 11px; color: var(--amber); margin-left: 8px; vertical-align: 4px; }
.oname em.new { color: #1a0b05; background: var(--amber); padding: 0 4px; }
.lvpips { display: flex; gap: 2px; }
.lvpips i { width: 10px; height: 6px; background: #19131f; border: 1px solid var(--outline); }
.lvpips i.on { background: var(--amber); }
.lvpips i.new { background: var(--amber-hi); animation: blink .6s steps(2) infinite; }
.odesc { color: var(--parch); }
.oevo { color: var(--violet); }
.banish-mode .offer { --k: var(--blood); border-color: var(--blood); }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- arcana: tarot cards painted at 64x96 art px ---------- */
.tart { --s: 3; position: relative; display: block; flex: none; width: calc(64px * var(--s)); height: calc(96px * var(--s));
  filter: drop-shadow(0 10px 12px rgba(0,0,0,.65)); transition: transform .12s steps(2), filter .12s steps(2); }
.tart img { display: block; width: 100%; height: 100%; }
.tart .tname { position: absolute; left: 0; right: 0; top: calc(75px * var(--s)); height: calc(8px * var(--s)); display: flex; align-items: center; justify-content: center;
  font-family: var(--f-pix); font-weight: 700; font-size: 22px; line-height: 1; color: #fff3dc; text-shadow: 0 2px 0 #000; white-space: nowrap; }
.tarot { display: flex; justify-content: center; align-items: flex-start; gap: 22px; flex-wrap: wrap; }
.tcard { --c: var(--violet); position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 4px; width: calc(64px * 3 + 12px);
  background: none; border: 0; cursor: pointer; text-align: center; animation: deal .45s steps(5) both; animation-delay: calc(var(--i, 0) * 110ms); }
.tcard:hover .tart, .tcard:focus-visible .tart { transform: translateY(-8px); filter: drop-shadow(0 0 8px var(--c)) drop-shadow(0 14px 12px rgba(0,0,0,.65)); }
.tcard:focus-visible { outline: none; }
.tcard:focus-visible .tart { outline: 3px solid var(--amber-hi); outline-offset: 4px; }
.tcard .key { top: 14px; left: 14px; transform: none; z-index: 2; }
.tdesc { color: var(--parch); max-width: 26ch; min-height: 3em; }
@keyframes deal { from { transform: translateY(60px) rotate(-6deg); opacity: 0; } to { transform: none; opacity: 1; } }
.tome-glyph { display: flex; justify-content: center; margin: 4px 0 10px; }
.tart.reveal { animation: reveal .6s steps(6) both; }
@keyframes reveal { from { transform: rotateY(90deg) scale(.8); filter: brightness(3); } to { transform: none; } }
.entries.gallery { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.gcard { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px 4px; text-align: center; }
.gcard .tart { --s: 2; }
.gcard .tart .tname { font-size: 11px; }
.gcard:focus-visible { outline: 3px solid var(--amber-hi); outline-offset: 2px; }
.gcard.locked .gdesc { color: var(--brass); }
.gdesc { color: var(--parch); max-width: 22ch; }
@media (max-width: 760px), (max-height: 620px) {
  .tcard { width: calc(64px * 2 + 12px); }
  .tcard .tart, .tome-glyph .tart { --s: 2; }
  .tcard .tart .tname, .tome-glyph .tart .tname { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) { .tcard, .tart.reveal { animation: none; } }

/* ---------- three doors ---------- */
.doors { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.door { --g: rgba(242,177,74,.4); position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0 14px 16px; text-align: center; cursor: pointer;
  background: var(--stone-2); border: 3px solid var(--outline); }
.door .arch { width: 100%; height: 118px; margin-bottom: 6px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 14px;
  background: radial-gradient(ellipse at 50% 100%, var(--g), #07050a 72%);
  clip-path: polygon(0 100%, 0 38%, 6% 22%, 16% 10%, 30% 3%, 50% 0, 70% 3%, 84% 10%, 94% 22%, 100% 38%, 100% 100%); }
.door .arch img { width: 48px; height: 48px; }
.door.cursed { --g: rgba(239,107,120,.5); } .door.spring { --g: rgba(142,224,106,.45); } .door.chest { --g: rgba(255,207,74,.55); }
.door.merchant { --g: rgba(197,140,255,.45); } .door.none { --g: rgba(160,150,180,.35); }
.door .key { top: 10px; left: 10px; transform: none; z-index: 1; }
.dname { font-family: var(--f-pix); font-weight: 700; font-size: 22px; color: var(--parch); }
.ddesc { color: var(--dim); }
.door:hover, .door:focus-visible { border-color: var(--amber); background: var(--stone-3); outline: none; }

/* ---------- wares (shop, merchant) ---------- */
.wares { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 8px; }
.ware { display: flex; align-items: center; gap: 10px; padding: 5px 12px 5px 5px; text-align: left; cursor: pointer; background: var(--stone-2); border: 3px solid var(--outline); }
.ware:hover:not(:disabled), .ware:focus-visible { border-color: var(--amber); background: var(--stone-3); outline: none; }
.ware:disabled { cursor: default; }
.wtext { flex: 1; min-width: 0; }
.wname { color: var(--amber-hi); }
.wdesc { color: var(--dim); }
.ware .price { display: flex; align-items: center; gap: 4px; font-family: var(--f-pix); font-weight: 700; color: var(--amber); white-space: nowrap; }
.ware .price img { width: 16px; height: 16px; }
.ware.poor .price { color: var(--blood); }
.ware.maxed { opacity: .7; } .ware.maxed .price { color: var(--verdant); }
.ware.locked { opacity: .55; }
.pips { display: flex; gap: 3px; margin-top: 4px; }
.pips i { width: 14px; height: 6px; background: #19131f; border: 1px solid var(--outline); }
.pips i.on { background: var(--amber); }

/* ---------- quests ---------- */
.quests { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 8px; }
.quest { position: relative; padding: 8px 12px; background: var(--stone-2); border: 3px solid var(--outline); }
.qhead { display: flex; justify-content: space-between; align-items: center; }
.qn { color: var(--amber-hi); }
.stamp { font-family: var(--f-pix); font-weight: 700; font-size: 11px; color: var(--verdant); border: 2px solid var(--verdant); padding: 0 5px; transform: rotate(-6deg); }
.qdesc { color: var(--dim); }
.qfoot { display: flex; align-items: center; gap: 8px; margin: 6px 0 4px; }
.qnum { font-family: var(--f-pix); font-size: 11px; color: var(--dim); }
.qreward { color: var(--brass); }
.quest.done { opacity: .62; }
.quest.done .segbar i.on { background: var(--verdant); }

/* ---------- codex ---------- */
.tabs { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.tab { padding: 4px 12px; cursor: pointer; color: var(--dim); background: var(--stone-2); border: 3px solid var(--outline); }
.tab:hover { color: var(--parch); }
.tab.on { color: #1a0b05; background: var(--amber); }
.entries { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 8px; }
.entry { display: flex; gap: 10px; padding: 5px; background: var(--stone-2); border: 3px solid var(--outline); }
.entry.locked { opacity: .55; }
.etext { min-width: 0; }
.ename { color: var(--amber-hi); }
.emeta { color: var(--dim); font-family: var(--f-pix); font-size: 11px; }
.edesc { margin-top: 2px; color: var(--parch); }

/* ---------- loot ---------- */
.loot { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.lootrow { display: flex; align-items: center; gap: 10px; padding: 5px 10px 5px 5px; background: var(--stone-2); border: 3px solid var(--outline); animation: loot-in .3s steps(3) both; text-align: left; }
.lootrow .lname { color: var(--amber-hi); }
.lootrow .lname em { font-style: normal; color: var(--amber); font-family: var(--f-pix); font-size: 11px; }
.lootrow .ldesc { color: var(--dim); }
.lootrow.evolve { border-color: #9a4ac0; background: linear-gradient(90deg, rgba(154,74,192,.28), var(--stone-2) 70%); }
.lootrow.evolve .lname { color: var(--violet); }
.lootrow.union { border-color: #3a9ab0; background: linear-gradient(90deg, rgba(111,216,234,.22), var(--stone-2) 70%); }
.lootrow.union .lname { color: var(--arcane); }
@keyframes loot-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- results ---------- */
.tally { display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; margin-top: 12px; }
.trow { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 2px dotted rgba(138,127,153,.22); }
.trow span { color: var(--dim); }
.trow b { color: var(--amber); font-weight: 400; }
.note { margin-top: 10px; padding: 5px 10px; border: 2px solid currentColor; text-align: left; }
.frame.center .note { text-align: center; }
.note.good { color: var(--verdant); background: rgba(142,224,106,.07); }
.note.gold { color: var(--amber-hi); background: rgba(242,177,74,.07); }
.note.arcane { color: var(--arcane); background: rgba(111,216,234,.07); }

/* ---------- settings ---------- */
.slider { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 10px 0; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 240px; height: 14px; background: #19131f; border: 3px solid var(--outline); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 16px; height: 24px; background: var(--amber); border: 3px solid var(--outline); cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 12px; height: 20px; background: var(--amber); border: 3px solid var(--outline); border-radius: 0; }
.creditbox { white-space: pre-wrap; font-family: var(--f-pix); font-size: 11px; line-height: 16px; color: var(--dim); max-height: 34vh; overflow: auto; background: #0f0b13; padding: 10px; border: 3px solid var(--outline); text-align: left; }

/* ---------- in-run overlays ---------- */
#toasts { position: fixed; top: 17%; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { padding: 5px 14px; color: var(--parch); background: rgba(18,13,22,.9); border: 3px solid var(--outline); box-shadow: inset 0 0 0 2px var(--iron-dk); text-shadow: 0 2px 0 #000; animation: toast 2.6s both; }
.toast.floor { font-family: var(--f-pix); font-weight: 700; font-size: 22px; color: var(--amber-hi); }
.toast.boss { font-family: var(--f-pix); font-weight: 700; font-size: 22px; color: #ff9ee6; box-shadow: inset 0 0 0 2px #6a2a5a; }
.toast.bad { color: #ffaca4; box-shadow: inset 0 0 0 2px #6a2228; }
.toast.good { color: #b8f59c; box-shadow: inset 0 0 0 2px #2f5a24; }
.toast.event { color: var(--amber-hi); box-shadow: inset 0 0 0 2px #6a4a12; }
.toast.relic { color: var(--arcane); box-shadow: inset 0 0 0 2px #1f5664; }
.toast.quest { color: var(--amber-hi); }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.pausebtn { position: fixed; right: 12px; bottom: 12px; width: 50px; height: 50px; display: flex; gap: 5px; align-items: center; justify-content: center; cursor: pointer; opacity: .85;
  border: 9px solid transparent; border-image: url(assets/ui/btn-iron.png) 3 fill / 9px stretch; background: none; }
.pausebtn i { width: 6px; height: 16px; background: var(--parch); box-shadow: 0 2px 0 #000; }
.pausebtn:hover { opacity: 1; filter: brightness(1.15); }

.bossintro { display: flex; align-items: center; justify-content: center; gap: 22px; width: 100vw; padding: 18px 40px;
  background: linear-gradient(90deg, transparent, rgba(40,0,30,.92) 15%, rgba(40,0,30,.92) 85%, transparent); animation: bossin 2.2s both; }
.bossintro img { width: 128px; height: 128px; filter: drop-shadow(0 0 16px #ff40ff); }
.bossintro .btitle { color: #ff9ee6; letter-spacing: 4px; text-shadow: 0 2px 0 #000; }
.bossintro .bname { font-family: var(--f-pix); font-weight: 700; font-size: 66px; line-height: 1.1; color: #fff; text-shadow: 0 5px 0 #400030, 0 0 30px #ff40ff; }
@keyframes bossin { 0% { opacity: 0; transform: scaleY(.2); } 12% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }

#stick { position: fixed; width: 110px; height: 110px; border-radius: 50%; background: rgba(255,255,255,.08); border: 2px solid rgba(255,255,255,.2); display: none; pointer-events: none; transform: translate(-50%, -50%); }
#knob { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px; border-radius: 50%; background: rgba(255,220,150,.35); }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .logo { font-size: 44px; gap: 12px; }
  .sheet-top { grid-template-columns: 1fr; }
  .shelf { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bossintro .bname { font-size: 44px; }
  .bossintro img { width: 96px; height: 96px; }
  .plaque h2 { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .frame, .logo, .lootrow, .toast, .bossintro { animation: none; }
  .lvpips i.new { animation: none; }
}

/* keyboard cursor */
.mitem { position: relative; }
.mitem:focus-visible { outline: none; filter: brightness(1.2); }
.mitem:focus-visible::before { content: ""; position: absolute; left: -30px; top: 50%; margin-top: -9px; border: 9px solid transparent; border-left: 12px solid var(--amber-hi); filter: drop-shadow(0 2px 0 #000); animation: nudge .6s steps(2) infinite; }
@keyframes nudge { 50% { transform: translateX(4px); } }
.quest:focus-visible, .entry:focus-visible, .hero:focus-visible, .tab:focus-visible { outline: 3px solid var(--amber-hi); outline-offset: 1px; }
.offer:focus-visible, .door:focus-visible, .ware:focus-visible { box-shadow: inset 5px 0 0 var(--k, transparent), 0 0 0 3px var(--amber-hi); }
.controls kbd + kbd { margin-left: 0; }
@media (prefers-reduced-motion: reduce) { .mitem:focus-visible::before { animation: none; } }

/* ---------- first-time tips: a small card bottom left, out of the fight's way ---------- */
#tip { position: fixed; left: 14px; bottom: 14px; max-width: min(430px, 70vw); display: flex; align-items: flex-start; gap: 10px; padding: 8px 12px 8px 8px;
  background: rgba(18,13,22,.94); border: 3px solid var(--outline); box-shadow: inset 0 0 0 2px #6a4a12, 0 8px 18px rgba(0,0,0,.6);
  color: var(--parch); text-shadow: 0 2px 0 #000; pointer-events: none; visibility: hidden; transform: translateX(-24px); opacity: 0; transition: transform .18s steps(3), opacity .18s steps(3); }
#tip.on { visibility: visible; transform: none; opacity: 1; }
#tip b { flex: none; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; font-family: var(--f-pix); font-weight: 700; color: #1a0b05; background: var(--amber); box-shadow: 0 0 0 2px var(--outline); }
#ui.dim ~ #tip { visibility: hidden; }

/* ---------- town ---------- */
.townhud { position: fixed; inset: 0; pointer-events: none !important; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding: 10px 12px 12px; gap: 6px; }
.townhud > * { pointer-events: auto; }
.purse.corner { position: absolute; top: 12px; left: 14px; margin: 0; }
.townbar { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.townbar .pbtn { min-height: 40px; }
.townbar .pbtn img { width: 24px; height: 24px; }
.townhint { color: var(--dim); text-shadow: 0 2px 0 #000; pointer-events: none !important; }

/* ---------- modes at the dungeon gate ---------- */
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.mode { --g: rgba(242,177,74,.4); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0 14px 14px; text-align: center; cursor: pointer;
  background: var(--stone-2); border: 3px solid var(--outline); }
.mode .arch { width: 100%; height: 112px; margin-bottom: 4px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 12px;
  background: radial-gradient(ellipse at 50% 100%, var(--g), #07050a 72%);
  clip-path: polygon(0 100%, 0 38%, 6% 22%, 16% 10%, 30% 3%, 50% 0, 70% 3%, 84% 10%, 94% 22%, 100% 38%, 100% 100%); }
.mode .arch img { width: 48px; height: 48px; }
.mode.endless { --g: rgba(197,140,255,.5); }
.mode.daily { --g: rgba(111,216,234,.45); }
.mode.locked { cursor: default; opacity: .7; }
.mode .ddesc b { color: var(--amber-hi); font-weight: 400; }
.mode .rules { list-style: none; display: flex; flex-direction: column; gap: 2px; color: var(--parch); }
.mode .rules li::before { content: "◆ "; color: var(--brass); }
.mfoot { margin-top: auto; padding-top: 6px; font-family: var(--f-pix); font-size: 11px; color: var(--amber); }
.mode:hover:not(:disabled), .mode:focus-visible { border-color: var(--amber); background: var(--stone-3); outline: none; }
.mode:focus-visible { box-shadow: 0 0 0 3px var(--amber-hi); }

/* hero traits, mode chip, records */
.htrait { margin-top: 6px; color: var(--parch); font-size: 13px; line-height: 1.4; }
.htrait b { color: var(--amber-hi); font-weight: 400; margin-right: 4px; }
.herostrip .htrait { margin-top: 6px; }
.chip.mchip { color: var(--violet); padding: 0 8px; }
.tally.one { grid-template-columns: 1fr; margin-top: 4px; }
.ranks { list-style: none; counter-reset: rk; display: flex; flex-direction: column; gap: 4px; }
.ranks li { counter-increment: rk; display: flex; align-items: center; gap: 8px; padding: 3px 8px; background: var(--stone-2); border: 2px solid var(--outline); }
.ranks li::before { content: counter(rk); width: 18px; font-family: var(--f-pix); font-weight: 700; color: var(--amber); }
.ranks li img { width: 24px; height: 24px; }
.ranks li b { margin-left: auto; color: var(--amber-hi); font-weight: 400; }
.ranks li em { font-style: normal; color: var(--dim); }
.toggle.calm { color: var(--parch); margin-top: 8px; }
.toggle.calm input { accent-color: var(--amber); }
.row.tight { margin-top: 8px; }
.entries.help { grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
.entries.help .edesc { color: var(--parch); }
.select .htrait { font-size: 13px; }
@media (max-width: 720px) {
  .townhint { display: none; }
  .townbar .pbtn { min-height: 36px; padding: 0 6px; }
  #tip { max-width: 86vw; }
}
@media (prefers-reduced-motion: reduce) { #tip { transition: none; } }
@media (max-height: 620px) { .mode .arch { height: 64px; padding-bottom: 6px; } .mode .arch img { width: 32px; height: 32px; } .modes { gap: 8px; } }
.levelup.five .opts { gap: 5px; }
.levelup.five .offer { padding-top: 2px; padding-bottom: 2px; }
.levelup.five .offer .sock { width: 44px; height: 44px; }
.levelup.five .offer .sock img { width: 26px; height: 26px; }
@media (max-height: 760px) { .levelup .lede { margin-bottom: 8px; } .levelup.five .oevo { display: none; } }

/* ---------- recipes: pause tab, level-up button, C key ---------- */
.ptabs { margin: -2px 0 10px; }
.ptabs .tab kbd { font-size: 10px; padding: 0 3px; }
.recipes { display: flex; flex-direction: column; }
.recipes .rhow { color: var(--dim); font-size: 13px; margin: -2px 0 6px; text-align: center; }
.recipes .center { text-align: center; }
.rgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 6px; }
.rcp { display: flex; align-items: center; gap: 4px; padding: 4px 8px; background: var(--stone-2); border: 2px solid var(--outline); min-width: 0; }
.rcp .ri { flex: none; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; background: #120d16; box-shadow: inset 0 0 0 2px var(--iron-dk); }
.rcp .ri img { width: 24px; height: 24px; opacity: .4; filter: grayscale(.7); }
.rcp .ri.have img, .rcp .ri.res img { opacity: 1; filter: none; }
.rcp .ri.have { box-shadow: inset 0 0 0 2px var(--amber); }
.rcp .ri.res { box-shadow: inset 0 0 0 2px var(--violet); background: radial-gradient(circle, rgba(197,140,255,.28), #120d16 70%); }
.rcp > i { font-style: normal; font-family: var(--f-pix); font-weight: 700; color: var(--brass); }
.rcp .rt { display: flex; flex-direction: column; min-width: 0; margin-left: 6px; line-height: 1.3; }
.rcp .rn { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rcp .rn b { font-weight: 400; color: var(--parch); }
.rcp .rn u { text-decoration: none; font-size: 11px; line-height: 12px; padding: 0 3px; color: var(--violet); border: 1px solid rgba(197,140,255,.55); }
.rcp .rn u.tag { color: #10262a; background: var(--arcane); border-color: var(--arcane); }
.rcp .rt small { color: var(--dim); font-size: 12px; }
.rcp .rt em { font-style: normal; font-size: 12px; color: var(--blood); }
.rcp.ready { border-color: var(--amber); box-shadow: 0 0 14px rgba(242,177,74,.35); }
.rcp.ready .rt em { color: var(--amber-hi); }
.rcp.hint { border-style: dashed; border-color: var(--iron-dk); }
.rcp.hint .rt em { color: var(--arcane); }
@media (max-width: 720px) { .rgrid { grid-template-columns: 1fr; } }
