:root {
  --gold: #f0c04a; --mana: #6fe0cc; --ink: #eef3ff; --panel: rgba(10, 18, 34, 0.92); --edge: #c8aa6e;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; width: 100%; overflow: hidden; background: #0b1424; color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; position: fixed; inset: 0; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-text-size-adjust: 100%;
}
#app { position: fixed; inset: 0; overflow: hidden; }
#game { position: absolute; inset: 0; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; border: none; }

/* icons */
.ico { display: inline-block; width: 22px; height: 22px; flex: none; vertical-align: middle; }
.ico svg { width: 100%; height: 100%; display: block; }
.ico.sm { width: 16px; height: 16px; } .ico.lg { width: 30px; height: 30px; }

/* HUD */
.hud { position: absolute; left: 0; right: 0; margin: 0 auto; max-width: 560px; pointer-events: none; z-index: 5; }
.hud > * { pointer-events: auto; }
.hud.top { top: 0; padding: calc(var(--sat) + 8px) 10px 0; display: flex; gap: 8px; align-items: flex-start; }
.res-col { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.res { display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid rgba(200,170,110,0.45); border-radius: 12px; padding: 5px 8px; }
.res .ico { width: 26px; height: 26px; }
.res-main { flex: 1; min-width: 0; }
.res-val { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; }
.res-val small { opacity: 0.65; font-size: 11px; }
.bar { height: 6px; background: rgba(255,255,255,0.12); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar span { display: block; height: 100%; width: 0; border-radius: 3px; transition: width 0.25s; }
.gold .bar span { background: linear-gradient(90deg, #b8860b, var(--gold)); }
.mana .bar span { background: linear-gradient(90deg, #1f8a7e, var(--mana)); }
.chip-col { display: flex; flex-direction: column; gap: 4px; }
.chip { display: flex; align-items: center; gap: 5px; background: var(--panel); border: 1px solid rgba(200,170,110,0.35); border-radius: 10px; padding: 3px 8px; font-size: 13px; min-width: 76px; }
.chip .ico { width: 18px; height: 18px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; background: var(--panel); border: 1px solid rgba(200,170,110,0.45); display: grid; place-items: center; font-size: 26px; line-height: 1; }

.hud.bottom { bottom: 0; padding: 0 10px calc(var(--sab) + 10px); }
#hud-bottom { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 10px; }
.big { min-height: 72px; border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-weight: 800; font-size: 16px; letter-spacing: 0.3px;
  background: linear-gradient(#24324d, #141d30); border: 2px solid var(--edge); box-shadow: 0 4px 0 rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.15); text-shadow: 0 1px 2px #000; }
.big:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.45); }
.big.attack { background: linear-gradient(#d9482b, #8f2312); font-size: 19px; }
.big.train { background: linear-gradient(#3157a8, #1b2f63); }
.big.shop { background: linear-gradient(#2f8a4f, #17502c); }

.btn { min-height: 46px; min-width: 64px; padding: 0 16px; border-radius: 12px; font-weight: 700; background: linear-gradient(#34425f, #1d2638); border: 1px solid rgba(200,170,110,0.6); box-shadow: 0 3px 0 rgba(0,0,0,0.4); }
.btn:active { transform: translateY(2px); }
.btn.ok { background: linear-gradient(#3aa35f, #1f6a3a); }
.btn.danger { background: linear-gradient(#c0392b, #7d2016); }
.btn.gold { background: linear-gradient(#d9a520, #8c6410); color: #1b1300; text-shadow: none; }
.btn[disabled] { opacity: 0.45; }

/* info panel */
.panel { position: absolute; left: 10px; right: 10px; margin: 0 auto; max-width: 540px; bottom: calc(var(--sab) + 96px); z-index: 6;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 16px; padding: 10px 12px; box-shadow: 0 6px 24px rgba(0,0,0,0.5); }
.panel .p-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel h3 { margin: 0; font-size: 17px; }
.panel .lvl { color: var(--gold); font-weight: 700; font-size: 13px; }
.panel .stats { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; opacity: 0.9; margin: 6px 0 8px; }
.panel .p-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.panel .p-btns .btn { flex: 1; }
.panel .hint { font-size: 12px; opacity: 0.65; margin-top: 6px; }
.panel .close { width: 44px; height: 44px; font-size: 26px; background: transparent; }

#placebar { position: absolute; left: 10px; right: 10px; margin: 0 auto; max-width: 540px; bottom: calc(var(--sab) + 96px); z-index: 7; background: var(--panel); border: 1px solid var(--edge); border-radius: 16px; padding: 10px; }
.place-hint { text-align: center; font-size: 13px; opacity: 0.8; margin-bottom: 8px; }
.place-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.place-btns .btn { min-height: 54px; font-size: 17px; }

/* raid HUD */
.raid-info { flex: 1; background: var(--panel); border: 1px solid rgba(200,170,110,0.45); border-radius: 12px; padding: 6px 10px; font-size: 13px; }
.raid-name { font-weight: 800; font-size: 15px; color: #ffd9a0; }
.raid-avail { font-size: 11px; opacity: 0.7; margin-top: 2px; }
.raid-score { background: var(--panel); border: 1px solid rgba(200,170,110,0.45); border-radius: 12px; padding: 6px 10px; text-align: center; min-width: 106px; }
.timer { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stars { display: flex; justify-content: center; gap: 2px; margin: 2px 0; }
.stars .ico { width: 22px; height: 22px; }
.pct { font-weight: 700; color: #ffd34d; }
#raid-bottom { display: flex; flex-direction: column; gap: 8px; }
.raid-actions { display: flex; align-items: center; gap: 8px; }
.raid-tip { flex: 1; text-align: center; font-size: 12px; background: rgba(0,0,0,0.55); border-radius: 10px; padding: 6px; }
#troopBar { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 2px; touch-action: pan-x; scrollbar-width: none; }
#troopBar::-webkit-scrollbar { display: none; }
.tcard { flex: none; width: 74px; min-height: 92px; border-radius: 14px; background: linear-gradient(#26324c, #141c2e); border: 2px solid rgba(200,170,110,0.5); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px 2px; position: relative; }
.tcard.sel { border-color: #ffe27a; box-shadow: 0 0 0 2px #ffe27a, 0 0 18px rgba(255,226,122,0.5); transform: translateY(-4px); }
.tcard.empty { opacity: 0.35; }
.tcard .cnt { position: absolute; top: 3px; right: 6px; font-weight: 800; font-size: 14px; color: #fff; text-shadow: 0 1px 2px #000; }
.tcard .nm { font-size: 11px; font-weight: 700; text-align: center; line-height: 1.1; }
.pcan { width: 46px; height: 46px; display: block; flex: none; border-radius: 50%; }
.pcan.spell { border-radius: 10px; }
.qitem .pcan { width: 38px; height: 38px; }
.army-row .pcan { width: 28px; height: 28px; }
.tcard .pcan { width: 50px; height: 50px; }
.portrait { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.6); border: 3px solid; font-size: 17px; flex: none; }

/* bottom sheet */
.sheet { position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px; max-height: 78%; z-index: 20; display: flex; flex-direction: column;
  background: #0f1a2e; border-top: 2px solid var(--edge); border-radius: 20px 20px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,0.6); padding-bottom: var(--sab); animation: up 0.18s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 4px 16px; }
.sheet-head h2 { margin: 0; font-size: 20px; color: #ffe2a8; }
.sheet-sub { padding: 0 16px 6px; font-size: 13px; opacity: 0.85; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 6px 12px 16px; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); grid-auto-rows: max-content; align-content: start; gap: 10px; overscroll-behavior: contain; flex: 1 1 auto; min-height: 0; }
.card { background: linear-gradient(#1d2a44, #131c2f); border: 1px solid rgba(200,170,110,0.45); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; gap: 4px; min-height: 44px; height: auto; text-align: left; overflow: hidden; }
.card:active { transform: scale(0.98); }
.card.locked { opacity: 0.45; }
.card canvas[data-thumb] { width: 100%; height: auto; aspect-ratio: 456 / 200; display: block; }
.card .c-name { font-weight: 800; font-size: 14px; }
.card .c-meta { font-size: 11px; opacity: 0.75; line-height: 1.3; }
.card .c-cost { display: flex; align-items: center; gap: 4px; font-weight: 800; font-size: 14px; }
.card .c-row { display: flex; align-items: center; gap: 8px; }
.queue { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: nowrap; align-items: center; overflow-x: auto; min-height: 60px; overscroll-behavior: contain; }
.queue > * { flex-shrink: 0; }
.queue .btn.gold { position: sticky; right: 0; box-shadow: -8px 0 10px rgba(11,20,36,0.8); }
.qitem { position: relative; width: 52px; height: 58px; border-radius: 10px; background: #1a2540; border: 1px solid #3a4a6a; display: grid; place-items: center; overflow: hidden; }
.qitem .portrait { width: 36px; height: 36px; font-size: 13px; border-width: 2px; }
.qitem .qbar { position: absolute; left: 0; bottom: 0; height: 4px; background: #5cff6a; }
.qitem .x { position: absolute; top: 0; right: 3px; font-size: 12px; opacity: 0.8; }
.army-row { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; min-height: 36px; align-items: center; font-size: 13px; overscroll-behavior: contain; }
.army-row > * { flex-shrink: 0; }
.army-row .pill { background: #1a2540; border-radius: 999px; padding: 3px 8px 3px 3px; display: flex; align-items: center; gap: 5px; }
.army-row .portrait { width: 26px; height: 26px; font-size: 10px; border-width: 2px; }
.section { grid-column: 1 / -1; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; opacity: 0.6; margin-top: 4px; }

/* modals */
.modal { position: absolute; inset: 0; z-index: 30; background: rgba(0,0,0,0.6); display: grid; place-items: center; padding: 20px; }
.modal-card { width: 100%; max-width: 380px; background: #111c31; border: 2px solid var(--edge); border-radius: 20px; padding: 18px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,0.6); }
.modal-card h2 { margin: 0 0 8px; color: #ffe2a8; }
.modal-card .big-stars { display: flex; justify-content: center; gap: 6px; margin: 8px 0; }
.modal-card .big-stars .ico { width: 54px; height: 54px; }
.modal-card .res-line { display: flex; justify-content: center; gap: 16px; font-size: 18px; font-weight: 800; margin: 10px 0; align-items: center; }
.disclaimer { font-size: 13px; line-height: 1.45; background: rgba(255,255,255,0.05); border-radius: 10px; padding: 10px; text-align: left; }
.small { font-size: 12px; opacity: 0.8; text-align: left; line-height: 1.4; }
.menu-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

#toast { position: absolute; left: 50%; top: calc(var(--sat) + 120px); transform: translateX(-50%); z-index: 40; background: rgba(0,0,0,0.85); border: 1px solid var(--edge); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 86%; text-align: center; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
#toast.show { opacity: 1; }

.tabs { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #0a1222; border-radius: 12px; padding: 4px; }
.tab { min-height: 44px; border-radius: 9px; background: transparent; font-weight: 800; opacity: 0.65; }
.tab.on { background: linear-gradient(#34425f, #1d2638); opacity: 1; box-shadow: inset 0 0 0 1px rgba(200,170,110,0.6); }
.queue .btn.gold { min-height: 44px; font-size: 13px; }
.tcard.scard { background: linear-gradient(#3a2766, #1a1030); border-color: rgba(180,130,255,0.6); }
.tcard.scard.sel { border-color: #e2c8ff; box-shadow: 0 0 0 2px #c9a6ff, 0 0 18px rgba(180,120,255,0.6); }
#troopBar .divider { flex: none; width: 2px; margin: 8px 2px; background: linear-gradient(transparent, rgba(200,170,110,0.7), transparent); }
#flash { position: absolute; inset: 0; z-index: 15; pointer-events: none; opacity: 0; }
#flash.go { animation: flash 0.6s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---- v3: spell cancel zone, settings, lab ---- */
#cancelZone { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; border-radius: 16px 16px 0 0;
  background: rgba(60,10,16,0.82); border: 2px dashed rgba(255,120,120,0.7); color: #ffd0d0; font-weight: 800; font-size: 16px; pointer-events: none; z-index: 5; }
#cancelZone span { font-size: 30px; line-height: 1; }
#cancelZone.hot { background: rgba(190,30,40,0.92); border-style: solid; color: #fff; }
.modal-card.scroll { max-height: calc(100% - 40px); overflow-y: auto; }
.settings { text-align: left; background: rgba(255,255,255,0.06); border-radius: 12px; padding: 8px 12px; margin: 10px 0; }
.settings h3 { margin: 2px 0 6px; font-size: 16px; }
.set-row { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.set-row label { flex: 0 0 112px; font-weight: 700; }
.set-row input[type=range] { flex: 1; min-width: 0; height: 44px; accent-color: #4fd1c5; touch-action: none; }
.tgl { appearance: none; -webkit-appearance: none; width: 52px; height: 30px; border-radius: 15px; background: #3a4458; position: relative; flex: 0 0 52px; cursor: pointer; transition: background .15s; margin: 7px 0; }
.tgl::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #eef3ff; transition: left .15s; }
.tgl:checked { background: #2fb37a; }
.tgl:checked::after { left: 25px; }
.lab-now { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; background: rgba(79,209,197,0.12); border: 1px solid rgba(79,209,197,0.4); border-radius: 12px; padding: 8px 10px; margin-bottom: 6px; }
.lab-now .pcan { width: 48px; height: 48px; }
.lab-now .grow { flex: 1; min-width: 0; }
.lab-bar { height: 8px; background: rgba(0,0,0,0.4); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.lab-bar span { display: block; height: 100%; background: linear-gradient(90deg, #4fd1c5, #b8fff7); width: 0; }
.lvl-pips { color: #ffd34d; font-weight: 800; letter-spacing: 1px; }
.card.maxed { opacity: .75; }

/* v4: lab hints, recommended next, history, badges */
.card .c-lock { font-size: 12px; font-weight: 800; color: #ffb86b; background: rgba(255,140,60,0.14); border-radius: 8px; padding: 3px 6px; }
.card .c-lock.poor { color: #ff8a8a; background: rgba(255,80,80,0.12); }
.card .c-lock.busy { color: #9fe3dc; background: rgba(79,209,197,0.12); }
.card.locked { opacity: 0.62; }
.card.rec { border: 2px solid #ffd34d; box-shadow: 0 0 0 2px rgba(255,211,77,0.25), 0 0 16px rgba(255,211,77,0.35); position: relative; }
.card .rec-tag { font-size: 11px; font-weight: 900; color: #1b1424; background: linear-gradient(#ffe27a, #f0b429); border-radius: 8px; padding: 2px 6px; align-self: flex-start; }
.section.rec-line { grid-column: 1 / -1; color: #ffe27a; opacity: 1; }
.lab-hist { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; }
.lab-hist .h-row { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.05); border-radius: 10px; padding: 4px 8px; font-size: 13px; }
.lab-hist .h-row .pcan { width: 32px; height: 32px; }
.lab-hist .grow { flex: 1; }
.big .badge-dot { position: absolute; top: 4px; right: 8px; min-width: 20px; height: 20px; border-radius: 10px; background: #ff3b4f; border: 2px solid #fff; color: #fff; font: 900 12px/16px system-ui, sans-serif; text-align: center; }
.big { position: relative; }

/* v7: painted-art loading bar */
#artLoad { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; width: min(72vw, 320px);
  padding: 8px 12px 10px; border-radius: 12px; background: rgba(10,14,26,0.82); border: 1px solid rgba(201,163,107,0.6); color: #f0e6d2;
  font: 600 12px/1.3 system-ui, sans-serif; text-align: center; pointer-events: none; transition: opacity .4s; }
#artLoad.done { opacity: 0; }
#artLoad .al-b { margin-top: 6px; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.12); overflow: hidden; }
#artLoad .al-b i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #c9a36b, #ffe6a0); transition: width .15s; }
/* v7: painted thumbnails in the info panel (current level ▶ upgrade preview) */
.panel .ipics { display: flex; align-items: center; gap: 2px; flex: none; }
.panel .ithumb { width: 64px; height: 64px; flex: none; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); }
.panel .ithumb.inext { width: 52px; height: 52px; opacity: .95; }
.panel .iarrow { color: var(--gold); font-size: 11px; opacity: .8; }
.panel .ititle { flex: 1; min-width: 0; }
.panel .nextlv { color: #9fe3a0; font-weight: 700; }
/* v7: Lab upgrade preview — next research level portrait (silver/gold glow painted art) */
.card .pwrap { position: relative; flex: none; display: block; }
.card .pcan.nextp { position: absolute; right: -9px; bottom: -7px; width: 26px !important; height: 26px !important; box-shadow: 0 0 0 2px #141c30; }
/* v8 gems */
.chip.gems { position: relative; cursor: pointer; border-color: rgba(62,224,122,0.55); }
.chip.gems .plus { margin-left: auto; background: #2fb862; color: #fff; border-radius: 6px; width: 16px; height: 16px; font: 900 13px/16px system-ui; text-align: center; }
.chip .badge-dot { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; border-radius: 9px; background: #ff3b4f; border: 2px solid #fff; color: #fff; font: 900 11px/14px system-ui, sans-serif; text-align: center; }
.btn.gem { background: linear-gradient(#3ee07a, #17803f); color: #062312; text-shadow: none; white-space: nowrap; }
.btn.gem .ico.sm { width: 14px; height: 14px; vertical-align: -2px; }
.queue .btn.gem { position: sticky; right: 0; min-height: 44px; font-size: 13px; }
.proto-note { grid-column: 1 / -1; background: rgba(255,200,80,0.12); border: 1px dashed #ffcf5a; border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.gem-pack .gp-ico { position: relative; display: flex; justify-content: center; padding: 6px 0; }
.gem-pack .gp-ico .ico { width: 44px; height: 44px; }
.gem-pack .gp-n { position: absolute; right: 20%; bottom: 2px; font-weight: 900; font-size: 12px; opacity: .8; }
.gem-pack .btn[disabled] { opacity: .55; font-size: 12px; }
.gem-ways { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.gem-ways span { background: rgba(255,255,255,0.07); border-radius: 8px; padding: 4px 8px; font-size: 12px; }
.card.ach .lab-bar { height: 6px; }
/* v9.5 first-time tour */
#tour { position: absolute; left: 12px; right: 12px; bottom: calc(var(--sab, 0px) + 112px); z-index: 45; background: rgba(14,22,40,0.94); border: 1px solid #d9b45a; color: #f4ecd8; border-radius: 14px; padding: 12px 14px 10px; font-size: 15px; line-height: 1.35; box-shadow: 0 6px 24px rgba(0,0,0,0.5); opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; pointer-events: none; }
#tour.show { opacity: 1; transform: none; }
#tour.show .tour-b button { pointer-events: auto; }
#tour .tour-n { display: inline-block; background: #d9b45a; color: #1a1406; border-radius: 8px; padding: 0 6px; font-weight: 700; font-size: 12px; margin-right: 4px; }
#tour .tour-b { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
#tour button { border: 0; border-radius: 10px; padding: 7px 14px; font-weight: 700; font-size: 14px; }
#tour .tour-skip { background: transparent; color: #b9b2a0; }
#tour .tour-next { background: #d9b45a; color: #1a1406; }
/* v10 Duskamber (third resource, HL7+): compact row, dimmed until unlocked */
.dusk .bar span { background: linear-gradient(90deg, #7a3e0e, #e39a3b); }
.res.dusk { padding: 3px 8px; }
.res.dusk .ico { width: 22px; height: 22px; }
.res.dusk .res-val { font-size: 13px; }
.res.dusk.locked { opacity: 0.55; }

/* v10.33 payments: consent + legal links */
.pay-legal { font-size: 12px; opacity: .85; margin: 6px 0; text-align: center; }
.pay-legal a, .pay-consent a { color: var(--mana); }
.pay-consent { display: flex; gap: 8px; text-align: left; font-size: 13px; line-height: 1.4; margin: 10px 0; align-items: flex-start; }
.pay-consent input { width: 20px; height: 20px; flex: none; margin-top: 2px; }
#payConsent { z-index: 60; }

/* v10.46 entry page, online, story, defense */
.title-screen { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; transition: opacity .35s; }
.title-screen.out { opacity: 0; pointer-events: none; }
.title-bg { position: absolute; inset: 0; background: #0b1424 url(assets/ui/title_bg.webp) center 70% / cover no-repeat; }
.title-shade { position: absolute; inset: 0; background: linear-gradient(rgba(5,8,14,.55), rgba(5,8,14,0) 35%, rgba(5,8,14,0) 55%, rgba(5,8,14,.85)); }
.title-inner { position: relative; width: 100%; max-width: 440px; padding: 0 22px calc(var(--sab) + 26px); display: flex; flex-direction: column; min-height: 100%; }
.title-logo { margin-top: calc(var(--sat) + 9vh); text-align: center; font-family: Georgia, 'Times New Roman', serif; color: #f6dc9a; text-shadow: 0 3px 18px rgba(0,0,0,.9), 0 0 30px rgba(255,170,60,.35); }
.title-logo span { display: block; font-size: 56px; font-weight: 700; letter-spacing: 2px; line-height: 1; }
.title-logo small { display: block; font-size: 22px; letter-spacing: 12px; text-transform: uppercase; opacity: .9; margin-top: 6px; }
.title-sub { text-align: center; margin-top: 10px; opacity: .85; text-shadow: 0 1px 6px #000; }
.title-btns { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.btn.tbig { min-height: 54px; font-size: 18px; width: 100%; }
.title-foot { text-align: center; font-size: 12px; opacity: .7; margin-top: 12px; } .title-foot a { color: #f0d9a0; }
.side-btns { position: absolute; right: 8px; bottom: calc(var(--sab) + 92px); z-index: 5; display: flex; flex-direction: row; gap: 6px; }
#info:not(.hidden) ~ .side-btns, #sheet:not(.hidden) ~ .side-btns, #placebar:not(.hidden) ~ .side-btns { display: none; }
.sbtn { width: 56px; padding: 5px 0 3px; border-radius: 12px; background: var(--panel); border: 1px solid rgba(200,170,110,.5); display: flex; flex-direction: column; align-items: center; font-size: 10px; position: relative; }
.sbtn .ico svg { width: 26px; height: 26px; } .sbtn.alert::after { content: ''; position: absolute; top: 3px; right: 4px; width: 10px; height: 10px; border-radius: 50%; background: #ff5a3c; box-shadow: 0 0 6px #ff5a3c; }
.side-btns.hidden, .side-btns.busy { display: none; }
.ol-modal { position: fixed; inset: 0; z-index: 50; background: rgba(3,6,12,.6); display: flex; align-items: center; justify-content: center; padding: calc(var(--sat) + 10px) 10px calc(var(--sab) + 10px); }
.ol-card { width: 100%; max-width: 480px; max-height: 100%; background: var(--panel); border: 1px solid var(--edge); border-radius: 16px; padding: 12px 14px; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.ol-modal.story .ol-card { max-width: 520px; }
.ol-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; } .ol-head h2 { margin: 0; font-size: 20px; color: #f6dc9a; }
.ol-in { width: 100%; box-sizing: border-box; min-height: 48px; margin: 6px 0; padding: 0 12px; border-radius: 10px; border: 1px solid rgba(200,170,110,.5); background: #0d1626; color: var(--ink); font-size: 16px; }
.ol-err { color: #ff8a7a; min-height: 20px; font-size: 14px; margin: 4px 0; }
.ol-tabs { display: flex; gap: 8px; margin: 8px 0; } .ol-tabs .btn { flex: 1; } .ol-tabs .btn.on { background: linear-gradient(#d9a520, #8c6410); color: #1b1300; text-shadow: none; }
.ol-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(200,170,110,.15); }
.ol-entry { padding: 6px 0; border-bottom: 1px solid rgba(200,170,110,.15); } .replay { font-size: 13px; opacity: .85; margin-top: 4px; font-style: italic; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: #46536e; } .tag.real { background: #2f7d4a; } .tag.ai { background: #7d3a2f; }
.ol-card select { min-height: 40px; background: #0d1626; color: var(--ink); border: 1px solid rgba(200,170,110,.5); border-radius: 8px; }
.story-map { position: relative; margin: 8px 0; border-radius: 12px; overflow: hidden; } .story-map img { display: block; width: 100%; }
.snode { position: absolute; transform: translate(-50%, -50%); width: 44px; height: 44px; border-radius: 50%; background: radial-gradient(#ffe39a, #c8892a 70%); color: #2a1600; font-weight: 900; box-shadow: 0 0 14px rgba(255,200,90,.8), 0 3px 6px rgba(0,0,0,.6); border: none; }
.snode.locked { background: radial-gradient(#9aa3ad, #4d5560 70%); box-shadow: 0 3px 6px rgba(0,0,0,.6); color: #1b2027; }
.snode.done { background: radial-gradient(#d4ffb0, #4f9a3a 70%); } .snode i { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); font-style: normal; color: #ffd34d; font-size: 12px; text-shadow: 0 1px 3px #000; white-space: nowrap; }
.story-info { min-height: 60px; } .story-outro { font-style: italic; text-align: center; margin: 6px 0; opacity: .9; }

/* v10.46 layout audit: 44px tap targets */
.sbtn { min-height: 44px; }
#gemsChip, #spellsChip { position: relative; }
#gemsChip::before, #spellsChip::before { content: ''; position: absolute; left: -2px; right: -2px; top: -9px; bottom: -9px; }
.ol-row label { min-height: 44px; display: inline-flex; align-items: center; gap: 8px; }
.ol-row input[type=checkbox] { width: 22px; height: 22px; }
.ol-row select { min-height: 44px; }
/* v10.47 polish: transitions + feedback */
.ol-modal { animation: olFade .16s ease-out; }
.ol-modal .ol-card { animation: olPop .2s cubic-bezier(.2,.9,.3,1.2); }
@keyframes olFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes olPop { from { transform: scale(.94) translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.sbtn, .snode, .ol-card .btn { transition: transform .08s ease-out, filter .12s; }
.sbtn:active, .snode:active, .ol-card .btn:active { transform: scale(.94); filter: brightness(1.15); }
.snode:active { transform: translate(-50%, -50%) scale(.92); }
.snode:not(.locked):not(.done) { animation: sPulse 1.6s ease-in-out infinite; }
@keyframes sPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,211,77,.7), 0 3px 6px rgba(0,0,0,.6); } 50% { box-shadow: 0 0 0 10px rgba(255,211,77,0), 0 3px 6px rgba(0,0,0,.6); } }
.big-stars svg { animation: starPop .45s cubic-bezier(.2,1.4,.4,1) both; }
.big-stars > :nth-child(2) svg, .big-stars > svg:nth-child(2) { animation-delay: .18s; }
.big-stars > :nth-child(3) svg, .big-stars > svg:nth-child(3) { animation-delay: .36s; }
@keyframes starPop { from { transform: scale(0) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
#result:not(.hidden) #resultCard { animation: olPop .25s cubic-bezier(.2,.9,.3,1.2); }
@media (prefers-reduced-motion: reduce) { .ol-modal, .ol-modal .ol-card, .snode, .big-stars svg, #resultCard { animation: none !important; } }
/* v10.47 story sheet fit: card never exceeds the viewport minus safe areas; body scrolls; chapter info + Attack stay pinned */
/* v10.49 story sheet: fit the *small* visual viewport (Safari URL bar), flex column with scrolling body + pinned Attack footer (not sticky). */
.ol-card { max-height: calc(100vh - var(--sat) - var(--sab) - 20px); max-height: calc(100dvh - var(--sat) - var(--sab) - 20px); max-height: calc(100svh - var(--sat) - var(--sab) - 20px); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.ol-modal { max-height: 100vh; max-height: 100dvh; max-height: 100svh; }
.ol-modal.story { align-items: stretch; }
.ol-modal.story .ol-card {
  display: flex; flex-direction: column;
  width: 100%; max-width: 520px; margin: 0 auto;
  max-height: 100%; /* of the padded modal box pinned to visualViewport / svh */
  overflow: hidden; padding-bottom: 0;
}
.ol-modal.story .story-body { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.ol-modal.story .story-info {
  flex: 0 0 auto; position: relative; z-index: 2; margin: 0 -14px; padding: 8px 14px 10px;
  background: var(--panel); border-top: 1px solid var(--edge); box-shadow: 0 -6px 14px rgba(0,0,0,.35);
}
.ol-modal.story .story-info #sGo { min-height: 44px; width: 100%; }
@media (orientation: landscape) and (max-height: 500px) {
  .ol-modal.story .story-map img { max-height: 42svh; max-height: 42dvh; object-fit: cover; }
  .ol-modal.story .story-info { padding-top: 6px; padding-bottom: 6px; }
}

/* v10.48 collectors-full home indicator */
#fullPill { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab, 0px) + 150px); z-index: 46; display: flex; align-items: center; gap: 4px; background: #d8342c; color: #fff; border: 2px solid #ffd2c8; border-radius: 999px; padding: 6px 14px; font: 700 14px system-ui, sans-serif; min-height: 36px; box-shadow: 0 4px 12px rgba(0,0,0,.4); animation: fullPulse 1.6s ease-in-out infinite; }
#fullPill.hidden { display: none; }
@keyframes fullPulse { 50% { transform: translateX(-50%) scale(1.05); } }
@media (prefers-reduced-motion: reduce) { #fullPill { animation: none; } }
/* v10.48 tour steps aside: while a sheet / info panel is open the coach mark moves to the top; hidden behind modals */
#tour.aside { top: calc(var(--sat, 0px) + 96px); bottom: auto; font-size: 13px; padding: 8px 12px 6px; }
#tour.under { opacity: 0 !important; pointer-events: none; }
#tour.under .tour-b button { pointer-events: none !important; }
/* v10.48 raid hint floats near the top (where most drop lanes are), shakes on a blocked drop */
#raid-bottom .raid-tip { position: fixed; top: calc(var(--sat, 0px) + 128px); left: 50%; transform: translateX(-50%); width: max-content; max-width: 78vw; flex: none; pointer-events: none; z-index: 30; font-size: 13px; padding: 6px 12px; }
.raid-actions { justify-content: space-between; }
#raid-bottom .raid-tip.bad { background: rgba(200,30,30,.85); animation: tipShake .45s; }
@keyframes tipShake { 20%, 60% { transform: translateX(calc(-50% - 7px)); } 40%, 80% { transform: translateX(calc(-50% + 7px)); } }
#tour.aside.raidtop { top: calc(var(--sat, 0px) + 168px); }
.story-info .s-loot { margin-top: 6px; opacity: .9; }
.story-info .s-warn { margin-top: 6px; color: #ffb199; font-weight: 700; }
.snode .sst em { font-style: normal; color: rgba(255,255,255,.35); }
.snode .slock { position: absolute; right: -6px; bottom: -6px; font-size: 14px; line-height: 1; filter: drop-shadow(0 1px 2px #000); }
.snode .snext { position: absolute; left: 50%; bottom: calc(100% + 3px); transform: translateX(-50%); background: #ffd34d; color: #2a1600; font-size: 10px; font-weight: 900; letter-spacing: .5px; padding: 1px 6px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.6); white-space: nowrap; }
.snode.next { box-shadow: 0 0 0 3px #ffd34d, 0 0 18px rgba(255,210,90,.95), 0 3px 6px rgba(0,0,0,.6); }
.ol-note { background: rgba(255,211,77,.12); border: 1px solid rgba(255,211,77,.45); border-radius: 10px; padding: 8px 10px; margin: 6px 0 8px; font-size: 13px; line-height: 1.35; }
.card .c-eff { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.card .c-eff.full { white-space: normal; }
.card .c-desc.hidden { display: none; }
#sheet [data-brew] { position: relative; }
.card .c-more { position: absolute; bottom: 4px; right: 4px; display: inline-flex; align-items: center; justify-content: center; padding: 0 8px; min-width: 44px; min-height: 30px; background: rgba(0,0,0,.35); border-radius: 8px; text-decoration: none; color: #ffd34d; font-size: 12px; font-weight: 700; text-decoration: underline; cursor: pointer; }
@media (orientation: landscape) and (max-height: 500px) { /* v10.48: compact chapter info so the selected node stays visible above it */
  .ol-modal.story .story-info .s-intro { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ol-modal.story .story-info .s-loot { margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ol-modal.story .story-info .s-sep { display: none; }
  .ol-modal.story .story-info .s-warn { margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ol-modal.story .story-info #sGo { margin-top: 4px !important; }
  .ol-modal.story .story-info .s-loot:has(+ .s-warn) { display: none; }
}
.snode i, .snode .sst, .snode .snext, .snode .slock { pointer-events: none; }

/* v10.49: keep the story map from collapsing inside the flex scroll body before/while the image decodes */
.ol-modal.story .story-map { position: relative; min-height: 140px; }
.ol-modal.story .story-map img { width: 100%; height: auto; vertical-align: middle; }
