/* GIANT'S VAULT. Phone first: everything fits 360 px wide. */
:root {
    --bg: #0b0a10;
    --panel: rgba(18, 14, 22, 0.95);
    --panel2: rgba(34, 26, 34, 0.9);
    --line: rgba(214, 170, 102, 0.28);
    --text: #f1e6d2;
    --dim: #a69a88;
    --gold: #e0b45c;
    --red: #e0533c;
    --life: #c8263a;
    --rage: #e0623a;
    --mana: #3d8fe0;
    --essence: #9a68f0;
    --common: #d8d8d8; --magic: #5b8cff; --rare: #ffd84a; --set: #3fe07a; --legendary: #ff8a1e; --mythic: #ff3b5c;
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --serif: 'Cinzel', Georgia, 'Times New Roman', serif;
    --sans: 'Alegreya Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    margin: 0; padding: 0; height: 100%;
    background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 16px;
    overflow: hidden; overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
[hidden] { display: none !important; }

/* The view sizes the canvases in px from JS. Never 100vw/100vh (phones). */
#view, #overlay { position: fixed; left: 0; top: 0; display: block; touch-action: none; }
#overlay { pointer-events: none; z-index: 5; }

#back-link {
    position: fixed; top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); z-index: 99999;
    font: 13px Arial, Helvetica, sans-serif; color: #fff; text-decoration: none;
    background: rgba(0, 0, 0, 0.55); padding: 6px 12px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, 0.25);
}
#back-link:hover { background: rgba(0, 0, 0, 0.8); }

/* ---------------------------------------------------------------- buttons */
.btn, .ibtn, .tbtn {
    font: inherit; color: var(--text); cursor: pointer; min-height: 44px; min-width: 44px;
    border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 240, 210, 0.07);
}
.btn { padding: 10px 18px; font-size: 16px; font-family: var(--serif); letter-spacing: 0.04em; }
.btn.primary { background: linear-gradient(180deg, #e7bf6a, #a8792e); color: #1c1206; border-color: #f3d38d; font-weight: 800; }
.btn.danger { border-color: #ff6b6b; color: #ffb3b3; }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, .ibtn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.ibtn { position: relative; font-size: 18px; padding: 0; display: grid; place-items: center; }
.ibtn b { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--gold); color: #000; font-size: 12px; line-height: 18px; padding: 0 4px; }

/* icons cut from the fal 4x4 sheets (set in JS with background-position) */
.ic { display: inline-block; width: 100%; height: 100%; background-size: 400% 400%; border-radius: 6px; }
.ibtn .ic { width: 32px; height: 32px; }

/* ---------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud-top { position: absolute; top: calc(8px + var(--safe-t)); left: calc(104px + var(--safe-l)); right: 250px; text-shadow: 0 2px 4px #000; }
#area-name { font-family: var(--serif); font-weight: 800; color: var(--gold); font-size: 17px; }
#quest { font-size: 13px; color: var(--dim); }
#hud-btns { position: absolute; top: calc(8px + var(--safe-t)); right: calc(8px + var(--safe-r)); display: flex; gap: 6px; pointer-events: auto; }
#boss, #rift { position: absolute; top: calc(58px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(560px, 80vw); text-align: center; text-shadow: 0 2px 4px #000; }
#rift { top: calc(58px + var(--safe-t)); }
#boss-name, #rift-name { font-family: var(--serif); font-weight: 800; color: #ffcfa8; font-size: 14px; margin-bottom: 3px; }
.bar { position: relative; height: 12px; border-radius: 6px; background: rgba(0, 0, 0, 0.6); border: 1px solid var(--line); overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #8a1020, #e0453c); }
#rift-fill { background: linear-gradient(90deg, #5a2a9a, #c890ff); }
.bar .tick { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255, 255, 255, 0.6); }
/* just under the hero (the camera keeps the hero at the middle of the screen), clear of the stick, the skill
   buttons and the dock in both orientations */
#prompt { position: fixed; z-index: 25; left: 50%; top: calc(50% + 34px); transform: translateX(-50%); background: var(--panel); color: inherit; font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
#prompt[hidden] { display: none; }
@media (pointer: coarse) { #prompt { min-height: 44px; padding: 8px 18px; font-size: 16px; } }

#dock { position: absolute; left: 50%; bottom: calc(8px + var(--safe-b)); transform: translateX(-50%); display: flex; align-items: flex-end; gap: 10px; }
.orb { position: relative; width: 86px; height: 86px; border-radius: 50%; overflow: hidden; background: radial-gradient(circle at 40% 35%, #2a2028, #0c080c); border: 2px solid #8a6a3a; box-shadow: 0 0 12px #000, inset 0 0 14px #000; }
.orb.small { width: 58px; height: 58px; }
.orb i { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; }
.orb.life i { background: radial-gradient(circle at 40% 30%, #ff7a7a, var(--life) 50%, #4a0610); }
.orb.res i { background: radial-gradient(circle at 40% 30%, #9ad0ff, var(--mana) 50%, #0a1a4a); }
.orb.res.rage i { background: radial-gradient(circle at 40% 30%, #ffc08a, var(--rage) 50%, #4a1406); }
.orb.res.essence i { background: radial-gradient(circle at 40% 30%, #e2c8ff, var(--essence) 50%, #24083e); }
.orb span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 13px; text-shadow: 0 1px 3px #000; }
.orbs-r { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#bar { display: flex; flex-direction: column; gap: 4px; pointer-events: auto; }
#xp { height: 6px; border-radius: 3px; background: rgba(0, 0, 0, 0.6); overflow: hidden; border: 1px solid var(--line); }
#xp i { display: block; height: 100%; background: linear-gradient(90deg, #a8792e, #f3d38d); }
#slots { display: flex; gap: 5px; }
.slot { position: relative; width: 50px; height: 50px; border-radius: 8px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.6); padding: 0; cursor: pointer; overflow: hidden; color: var(--text); }
.slot .ic { position: absolute; inset: 0; border-radius: 0; }
.slot .key { position: absolute; left: 3px; top: 1px; font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.slot .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.7); }
.slot .n { position: absolute; right: 3px; bottom: 1px; font-size: 12px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.slot.nores .ic { filter: grayscale(0.8) brightness(0.6); }
.slot.on { border-color: var(--gold); box-shadow: 0 0 8px var(--gold); }
#pet-chip { position: absolute; left: calc(10px + var(--safe-l)); bottom: calc(14px + var(--safe-b)); width: 150px; height: 36px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); overflow: hidden; pointer-events: auto; cursor: pointer; }
#pet-chip .face { position: absolute; left: 0; top: 0; width: 36px; height: 36px; background: url(art/portrait-pet.webp) center 22% / cover; border-radius: 50%; }
#pet-chip i { position: absolute; left: 36px; bottom: 0; height: 4px; background: var(--set); }
#pet-state { position: absolute; left: 42px; top: 8px; font-size: 13px; white-space: nowrap; }

/* ---------------------------------------------------------------- touch deck */
#touch { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#stick-zone { position: absolute; left: 0; bottom: 0; width: 45%; height: 55%; pointer-events: auto; touch-action: none; }
#stick { position: absolute; width: 0; height: 0; opacity: 0.35; left: 90px; bottom: 140px; }
#stick.on { opacity: 0.9; }
#stick .ring { position: absolute; width: 120px; height: 120px; left: -60px; top: -60px; border-radius: 50%; border: 2px solid rgba(255, 230, 190, 0.5); }
#stick .knob { position: absolute; width: 54px; height: 54px; left: -27px; top: -27px; border-radius: 50%; background: rgba(255, 230, 190, 0.5); }
#tbtns { position: absolute; right: calc(10px + var(--safe-r)); bottom: calc(110px + var(--safe-b)); width: 190px; height: 190px; pointer-events: none; }
.tbtn { position: absolute; pointer-events: auto; touch-action: none; width: 56px; height: 56px; border-radius: 50%; padding: 0; overflow: hidden; background: rgba(0, 0, 0, 0.55); }
.tbtn .ic { position: absolute; inset: 0; border-radius: 50%; }
.tbtn .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.7); }
.tbtn.big { width: 76px; height: 76px; }

/* ---------------------------------------------------------------- screens and panels */
.screen {
    position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
    padding: calc(52px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
    background: rgba(5, 4, 8, 0.6); overflow-y: auto;
}
.sheet {
    width: min(460px, 100%); max-height: 100%; overflow-y: auto; touch-action: pan-y;
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px;
    box-shadow: 0 10px 40px #000; --sheet-pt: 16px; --sheet-px: 16px; --sheet-pb: 16px;
}
.sheet.wide { width: min(900px, 100%); }
.sheet::-webkit-scrollbar { width: 10px; }
.sheet::-webkit-scrollbar-track { background: transparent; margin: 12px; }
.sheet::-webkit-scrollbar-thumb { background: rgba(214, 170, 102, 0.35); border-radius: 5px; }
.sheet h1, .sheet h2 { margin: 0 0 10px; font-family: var(--serif); color: var(--gold); }
.title-screen { background: #000 url(art/title.webp) center / cover; align-items: flex-end; padding-bottom: calc(6vh + var(--safe-b)); }
.title-screen .sheet { background: rgba(10, 8, 12, 0.72); text-align: center; }
.logo { font-size: clamp(34px, 9vw, 60px); letter-spacing: 0.06em; text-shadow: 0 0 18px rgba(255, 160, 60, 0.5), 0 3px 0 #3a2208; }
.tagline { color: var(--dim); margin: -4px 0 14px; font-style: italic; }
.menu { display: flex; flex-direction: column; gap: 8px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 44px; }
.version { color: var(--dim); font-size: 12px; margin-top: 10px; }
.dim { color: var(--dim); font-size: 14px; }
.red { color: var(--red) !important; }
table { border-collapse: collapse; width: 100%; }
td { padding: 5px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
td:first-child { color: var(--gold); white-space: nowrap; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { margin: 0; }
#panel .sheet { padding-top: 10px; --sheet-pt: 10px; }

.story { width: min(760px, 100%); padding: 0; overflow: hidden; }
.story img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #120c10; }
.story h2, .story p, .story .sheet-foot { padding: 0 18px; }
.story h2 { margin-top: 14px; }
.story p { line-height: 1.5; font-size: 17px; }
.story .sheet-foot { padding-bottom: 14px; }

/* class cards */
#class-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.class-card { text-align: left; padding: 0; overflow: hidden; display: flex; flex-direction: column; border-radius: 10px; }
.class-card img { width: 100%; aspect-ratio: 3 / 3.2; object-fit: cover; object-position: center 15%; display: block; }
.class-card div { padding: 8px 10px 10px; }
.class-card h3 { margin: 0 0 4px; font-family: var(--serif); color: var(--gold); }
.class-card p { margin: 0; font-size: 14px; color: var(--dim); line-height: 1.35; }
.class-card .m { font-size: 13px; font-weight: 700; }

/* inventory */
.inv { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 14px; }
.equip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.grid.pet { grid-template-columns: repeat(8, 1fr); }
.cell { position: relative; display: block; width: 100%; aspect-ratio: 1; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 6px; background: rgba(0, 0, 0, 0.45); padding: 0; cursor: pointer; overflow: hidden; color: var(--text); min-height: 0; min-width: 0; }
.cell .ic { position: absolute; inset: 2px; width: auto; height: auto; }
.cell .lbl { position: absolute; left: 3px; bottom: 1px; font-size: 10px; color: var(--dim); }
.cell.sel { outline: 2px solid var(--gold); }
.cell.r-magic { border-color: var(--magic); } .cell.r-rare { border-color: var(--rare); } .cell.r-set { border-color: var(--set); }
.cell.r-legendary { border-color: var(--legendary); box-shadow: inset 0 0 10px rgba(255, 138, 30, 0.5); } .cell.r-mythic { border-color: var(--mythic); box-shadow: inset 0 0 12px rgba(255, 59, 92, 0.6); }
.cell .sock { position: absolute; right: 2px; top: 2px; font-size: 9px; }
.slotname { font-size: 11px; color: var(--dim); text-align: center; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sub { font-family: var(--serif); color: var(--gold); font-size: 14px; margin: 10px 0 4px; }

#tip { position: fixed; z-index: 70; pointer-events: none; max-width: 300px; background: rgba(8, 6, 10, 0.97); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; line-height: 1.35; box-shadow: 0 6px 20px #000; }
#tip .n { font-family: var(--serif); font-weight: 800; font-size: 15px; }
#tip .b { color: var(--dim); }
#tip .pw { color: var(--legendary); margin-top: 4px; }
#tip .st { color: var(--set); }
#tip .q { display: inline-block; width: 28px; height: 4px; background: #333; margin-left: 6px; vertical-align: middle; border-radius: 2px; overflow: hidden; }
#tip .q i { display: block; height: 100%; background: var(--gold); }
#tip .up { color: #7ae07a; } #tip .down { color: #ff7a7a; }

/* skills */
.trees { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.tree { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.tree h3 { margin: 0; font-family: var(--serif); }
.tree .barrow { display: flex; align-items: center; gap: 8px; margin: 6px 0 8px; }
.tree .barrow .bar { flex: 1; height: 10px; }
.tree .barrow .bar i { background: linear-gradient(90deg, #a8792e, #f3d38d); }
.tier { display: flex; gap: 6px; align-items: center; margin: 4px 0; }
.tier .t { width: 18px; font-size: 11px; color: var(--dim); }
.sk { position: relative; width: 54px; height: 54px; padding: 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #000; cursor: pointer; }
.sk .ic { position: absolute; inset: 0; border-radius: 0; }
.sk .r { position: absolute; right: 2px; bottom: 0; font-size: 12px; font-weight: 800; text-shadow: 0 1px 2px #000; }
.sk.locked .ic { filter: grayscale(1) brightness(0.35); }
.sk.zero .ic { filter: grayscale(0.7) brightness(0.6); }
.sk.passive { border-radius: 50%; }
.skinfo { margin-top: 10px; min-height: 70px; font-size: 14px; background: rgba(0, 0, 0, 0.3); border-radius: 8px; padding: 8px; }
.synergy { margin-top: 10px; padding: 8px; border-radius: 8px; border: 1px solid var(--set); font-size: 14px; }

/* character */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; font-size: 14px; }
.stats div { display: flex; justify-content: space-between; border-bottom: 1px solid rgba(255, 255, 255, 0.06); padding: 3px 0; }
.stats b { color: var(--gold); }
.attrs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 8px 0; }
.attrs .row { background: var(--panel2); border-radius: 8px; padding: 0 8px; }

.list { display: flex; flex-direction: column; gap: 6px; }
.list .btn { text-align: left; }
.npc { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.npc img { width: 88px; height: 110px; object-fit: cover; object-position: center 15%; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.npc p { margin: 4px 0; font-style: italic; }

#toasts { position: fixed; left: 50%; top: calc(96px + var(--safe-t)); transform: translateX(-50%); z-index: 60; pointer-events: none; display: flex; flex-direction: column; gap: 6px; align-items: center; width: min(520px, 92vw); }
.toast { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; animation: toast 3s forwards; text-align: center; font-size: 15px; }
.toast.legendary { border-color: var(--legendary); color: var(--legendary); font-family: var(--serif); font-weight: 800; }
.toast.big { font-family: var(--serif); font-size: 20px; color: var(--gold); }
@keyframes toast { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; }

/* ---------------------------------------------------------------- phones */
@media (max-width: 700px) {
    #hud-top { left: calc(96px + var(--safe-l)); right: 8px; top: calc(56px + var(--safe-t)); }
    #area-name { font-size: 14px; } #quest { font-size: 12px; }
    #boss, #rift { top: calc(100px + var(--safe-t)); }
    .orb { width: 64px; height: 64px; } .orb.small { width: 44px; height: 44px; }
    .slot { width: 44px; height: 44px; }
    #dock { gap: 6px; }
    .inv { grid-template-columns: 1fr; }
    #pet-chip { bottom: calc(86px + var(--safe-b)); width: 120px; }
}
@media (max-width: 700px) and (pointer: coarse), (max-height: 500px) and (pointer: coarse) {
    #slots { display: none; }
    #dock { left: 50%; }
}
@media (max-height: 500px) {
    .orb { width: 56px; height: 56px; } .orb.small { width: 40px; height: 40px; }
    #hud-top { top: calc(8px + var(--safe-t)); right: 240px; }
    #tbtns { bottom: calc(60px + var(--safe-b)); }
}

/* A long sheet scrolls, but its foot (Done, Close, Continue) and its tab bar don't: they are pinned to the
   sheet's bottom and top edges over an opaque strip of the sheet's own colour, so nothing shows through.
   A foot inside a wrapper is pinned too, without the bleed. --sheet-p* are set wherever a .sheet's padding is. */
.sheet > .sheet-foot { position: sticky; bottom: calc(-1 * var(--sheet-pb)); z-index: 5; margin-inline: calc(-1 * var(--sheet-px)); margin-bottom: calc(-1 * var(--sheet-pb)); padding: 10px var(--sheet-px) var(--sheet-pb); background: #110d15; border-top: 1px solid rgba(214, 170, 102, 0.28); }
.sheet * > .sheet-foot { position: sticky; bottom: calc(-1 * var(--sheet-pb)); z-index: 5; padding-bottom: var(--sheet-pb); background: #110d15; }
.sheet > .tabs { position: sticky; top: calc(-1 * var(--sheet-pt)); z-index: 5; margin-inline: calc(-1 * var(--sheet-px)); padding: 8px var(--sheet-px); background: #110d15; }
.sheet > .panel-head { position: sticky; top: calc(-1 * var(--sheet-pt)); z-index: 5; margin: calc(-1 * var(--sheet-pt)) calc(-1 * var(--sheet-px)) 8px; padding: var(--sheet-pt) var(--sheet-px) 8px; background: #110d15; }
/* the story card had overflow: hidden, so a long card on a landscape phone cut Continue off: it scrolls now, Continue pinned */
.story { overflow-y: auto; }
.story > .sheet-foot { bottom: 0; margin: 0; padding: 10px 18px 14px; background: #110d15; }
