/* Ashenvault — char-dark stone, one warm source (the gold), one cold (the gems). */
:root {
  --bg: #151220;
  --bg2: #1d1a2b;
  --panel: #221e33;
  --card: #2a2540;
  --line: #3a3452;
  --text: #f1ecff;
  --muted: #a49bc2;
  --gold: #ffd23f;
  --gold2: #ffb347;
  --gem: #7ff5e6;
  --ember: #ff8a3a;
  --good: #6ccf6c;
  --bad: #ff6b6b;
  --font: "Rubik", "Segoe UI", system-ui, -apple-system, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; overflow: hidden; }
body { -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
small { color: var(--muted); font-size: 11px; }
h2, h3, h4 { margin: 8px 0 6px; font-weight: 800; letter-spacing: .01em; }
h3 { font-size: 15px; display: flex; align-items: baseline; gap: 8px; }
h4 { font-size: 13px; color: var(--muted); }
a { color: var(--gem); }
pre { white-space: pre-wrap; font-size: 10px; color: var(--muted); }

#app { display: flex; flex-direction: column; height: 100%; max-width: 520px; margin: 0 auto; padding-top: var(--safe-top); }
#app[hidden], #create[hidden], #modal[hidden] { display: none !important; }

/* ---- top bar */
#top { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.res { display: flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 999px; background: #0e0c17; font-weight: 800; font-size: 13px; font-variant-numeric: tabular-nums; }
.res.gold { color: var(--gold); }
.res.gems { color: var(--gem); }
.res.embers { color: var(--ember); }
#top .gear { margin-left: auto; font-size: 18px; padding: 4px; }

/* ---- battle */
#battle { position: relative; height: 44vh; min-height: 220px; max-height: 420px; background: #000; flex: 0 0 auto; }
#scene { display: block; width: 100%; height: 100%; }
#battleUi { position: absolute; inset: 0; pointer-events: none; }
#battleUi > * { pointer-events: auto; }
#stageNav { position: absolute; left: 6px; bottom: 6px; display: flex; align-items: center; gap: 4px; background: rgba(0,0,0,.5); border-radius: 8px; padding: 3px; }
#stageNav .stg { font-size: 11px; font-weight: 700; padding: 0 4px; color: #ffe9b0; }
#stageNav .stg i { color: var(--muted); font-style: normal; font-weight: 600; }
.nb { width: 26px; height: 24px; border-radius: 6px; background: #2a2540; font-weight: 800; font-size: 12px; }
.nb.auto { width: auto; padding: 0 8px; font-size: 10px; color: var(--muted); }
.nb.auto.on { background: #4a3f18; color: var(--gold); }
#heroInfo { position: absolute; left: 8px; bottom: 36px; font-size: 11px; display: flex; flex-direction: column; gap: 2px; text-shadow: 0 1px 2px #000; }
#heroInfo .lv { color: var(--gem); font-weight: 800; }
#heroInfo .xp { display: block; width: 70px; height: 3px; background: rgba(0,0,0,.6); border-radius: 2px; overflow: hidden; }
#heroInfo .xp b { display: block; height: 100%; background: var(--gem); }
#bossBtn { position: absolute; right: 8px; bottom: 44px; padding: 8px 12px; background: linear-gradient(#ff5a5a, #c62828); border-radius: 10px; font-weight: 900; box-shadow: 0 3px 0 #7a1414, 0 0 18px rgba(255,90,90,.4); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
#skillbar { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 5px; }
.sk { position: relative; width: 42px; height: 42px; border-radius: 10px; background: #2a2540; border: 2px solid var(--line); font-size: 20px; overflow: hidden; display: grid; place-items: center; }
.sk.ready { border-color: var(--gold); box-shadow: 0 0 10px rgba(255,210,63,.35); }
.sk.cd { filter: saturate(.4); }
.sk .cdm { position: absolute; inset: 0; background: rgba(0,0,0,.55); transform-origin: bottom; transform: scaleY(var(--f)); pointer-events: none; }
.sk .cdt { position: absolute; bottom: 1px; right: 3px; font-size: 10px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px #000; }
.sk.tiny { width: 34px; font-size: 9px; font-weight: 900; color: var(--muted); }
.sk.tiny.on { color: var(--gold); border-color: var(--gold); }

/* ---- tabs */
#tabs { display: flex; background: var(--bg2); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
#tabs button { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px 5px; font-size: 10px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; }
#tabs button .ic { font-size: 17px; }
#tabs button.on { color: var(--gold); border-bottom-color: var(--gold); background: linear-gradient(rgba(255,210,63,.08), transparent); }
#tabs button.locked { opacity: .5; }
#tabs button small { font-size: 8px; }
.badge { position: absolute; top: 5px; right: 18%; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 6px var(--bad); }

/* ---- panel */
#panel { flex: 1; overflow-y: auto; padding: 8px 8px calc(12px + var(--safe-bottom)); -webkit-overflow-scrolling: touch; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.card.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; padding: 8px 12px; }
.card.stats div { display: flex; flex-direction: column; }
.card.stats b { font-size: 13px; font-variant-numeric: tabular-nums; }
.card.head, .card.summon, .card.item, .card.dungeon, .card.wb { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); margin-bottom: 6px; }
.row.acts { background: none; border: 0; padding: 0; }
.row.acts .btn { flex: 1; }
.row.wrap { flex-wrap: wrap; }
.row .ic { font-size: 20px; width: 28px; text-align: center; }
.row .ic.big { font-size: 26px; width: 34px; }
.row b { font-size: 13px; }
.row b small { font-weight: 600; margin-left: 4px; }
.row.poor .buy { opacity: .5; }
.row.locked { opacity: .55; }
.row.skill.on { border-color: var(--gold); }
.row.done { opacity: .6; }
.row.rank { padding: 6px 10px; }
.row.rank.me { border-color: var(--gem); }
.row.rank .grow small { margin-left: 4px; }
.seg { display: flex; gap: 4px; margin-bottom: 8px; background: var(--bg2); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; padding: 7px; border-radius: 8px; font-weight: 800; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--gold); }
.seg.wrap { flex-wrap: wrap; }
.btn { padding: 8px 12px; border-radius: 10px; background: #3a3452; font-weight: 800; font-size: 12px; white-space: nowrap; box-shadow: 0 2px 0 rgba(0,0,0,.4); }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn.primary { background: linear-gradient(#ffd23f, #e0a52a); color: #2a1e00; }
.btn.gem { background: linear-gradient(#5ad8c9, #2a9d90); color: #04231f; }
.btn.buy { min-width: 84px; text-align: center; display: flex; flex-direction: column; align-items: center; line-height: 1.1; color: var(--gold); background: #3f3520; }
.btn.buy small { color: var(--muted); font-size: 9px; }
.btn.big { width: 100%; padding: 12px; font-size: 14px; margin: 8px 0; }
.btn.sm { padding: 6px 8px; font-size: 11px; }
.btn.back { margin-bottom: 8px; }
.btn.glow { box-shadow: 0 0 12px rgba(255,210,63,.5); border: 1px solid var(--gold); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 2px; }
.tag { padding: 4px 8px; border-radius: 999px; background: #1e3a2a; color: var(--good); font-size: 11px; font-weight: 800; }
.kv { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.card.rekindle p { margin: 4px 0 8px; font-size: 12px; color: var(--muted); }
.bar { display: block; height: 5px; border-radius: 3px; background: rgba(0,0,0,.5); overflow: hidden; margin: 3px 0; }
.bar b { display: block; height: 100%; background: linear-gradient(90deg, var(--gold2), var(--gold)); }

/* gear */
.card.equipped { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.slot, .cell { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; aspect-ratio: 1; border-radius: 10px; background: #1a1727; border: 2px solid var(--rc, #555); }
.slot .ic, .cell .ic { font-size: 20px; }
.slot.empty { opacity: .5; border-style: dashed; }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.grid.mobs { grid-template-columns: repeat(4, 1fr); margin-bottom: 8px; }
.cell.eq::after { content: "✓"; position: absolute; top: -4px; right: -2px; font-size: 10px; background: var(--good); color: #000; border-radius: 50%; width: 14px; height: 14px; display: grid; place-items: center; font-weight: 900; }
.cell.sel { box-shadow: 0 0 0 2px #fff; }
.cell.unknown { opacity: .4; }
.cell .mob, .mob { width: 44px; height: 50px; background-repeat: no-repeat; background-size: auto 100%; background-position: 0 0; transform: scaleX(-1); }
.mob.big { width: 60px; height: 68px; }
.card.item .statl { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 11px; margin-top: 3px; }
.card.item .sub { color: var(--muted); }
.orb { width: 22px; height: 22px; border-radius: 50%; box-shadow: 0 0 10px currentColor; flex: 0 0 auto; }
.lore { font-style: italic; }

/* more */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tile { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); text-align: left; }
.tile .ic { font-size: 22px; }
.tile b { font-size: 13px; }
.tile.locked { opacity: .5; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 8px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); font-size: 11px; }
.day.past { opacity: .5; }
.day.now { border-color: var(--gold); box-shadow: 0 0 8px rgba(255,210,63,.4); }
.feed { padding: 4px 8px; font-size: 12px; color: var(--muted); }
.feed span { color: var(--text); font-weight: 700; }

/* toasts */
#toasts { position: fixed; top: calc(52px + var(--safe-top)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; z-index: 30; }
.toast { padding: 7px 12px; border-radius: 999px; background: rgba(20,16,32,.94); border: 1px solid var(--line); font-size: 12px; font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,.5); animation: tin .25s ease-out; max-width: 92vw; text-align: center; }
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }
.toast.gem { border-color: var(--gem); color: var(--gem); }
.toast.out { opacity: 0; transition: opacity .4s; }
@keyframes tin { from { transform: translateY(-10px); opacity: 0; } }

/* modal */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 40; padding: 16px; }
#modal .box { width: min(92vw, 400px); max-height: 88vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; text-align: center; animation: pop .22s ease-out; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
#modal h2 { margin: 0 0 8px; font-size: 20px; }
#modal p { margin: 6px 0; color: var(--muted); font-size: 13px; }
#modal .big { font-size: 24px; font-weight: 900; color: var(--text); }
#modal .big.gold { color: var(--gold); }
#modal .code { letter-spacing: .2em; font-family: ui-monospace, monospace; }
#modal .row { background: none; border: 0; justify-content: center; }
#modal .btn { margin: 4px; }
#modal label { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; }
#modal input[type=range] { flex: 1; accent-color: var(--gold); }
.input { width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: #0e0c17; color: var(--text); font: inherit; text-align: center; font-weight: 700; margin: 6px 0; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.lootgrid { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 10px 0; }
.loot { width: 108px; padding: 8px 4px; border-radius: 10px; background: #1a1727; border: 2px solid var(--rc); display: flex; flex-direction: column; gap: 2px; animation: lootin .4s both; }
.loot b { font-size: 12px; color: var(--rc); }
.loot.r3, .loot.r4, .loot.r5, .loot.r6 { box-shadow: 0 0 16px var(--rc); }
@keyframes lootin { from { transform: translateY(14px) scale(.8); opacity: 0; } }

/* creator */
#create { height: 100%; overflow-y: auto; display: grid; place-items: start center; padding: 16px 12px; background: radial-gradient(circle at 50% 0%, #2d2444, var(--bg) 60%); }
.cbox { width: min(94vw, 420px); text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.cbox h1 { margin: 6px 0 0; font-size: 34px; letter-spacing: .04em; color: var(--gold); text-shadow: 0 0 24px rgba(255,210,63,.35); font-weight: 900; }
.cbox .tag { background: none; color: var(--muted); font-size: 12px; margin: 0 8px; font-weight: 500; }
#preview { width: 220px; height: 200px; background: radial-gradient(circle at 50% 80%, #3a3452, transparent 70%); }
.classes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; width: 100%; }
.cls { display: flex; flex-direction: column; gap: 3px; padding: 8px 6px; border-radius: 12px; background: var(--card); border: 2px solid var(--line); text-align: center; }
.cls.on { border-color: var(--gold); background: #3a3020; }
.cls small { font-size: 10px; line-height: 1.2; }
.opts { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.opts .seg { margin: 0; }
.opts .seg button { padding: 6px 4px; font-size: 11px; text-transform: capitalize; }
.sw { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.sw button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; }
.sw button.on { border-color: #fff; box-shadow: 0 0 8px #fff; }

/* mini mode (desktop corner window): battle only */
body.mini #top, body.mini #tabs, body.mini #panel { display: none; }
body.mini #battle { height: 100%; max-height: none; }
body.mini #app { max-width: none; }
body.mini .unmini { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; padding: 0; font-size: 16px; line-height: 28px; opacity: 0.7; pointer-events: auto; }
.unmini { display: none; }
body.mini .unmini { display: block; }

@media (min-width: 700px) {
  #battle { height: 46vh; max-height: 460px; }
  body { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  #bossBtn { animation: none; }
}
