:root {
  --bg: #0b0f14; --panel: #131a22; --panel2: #1a2430; --line: #243040; --text: #eef3f8; --muted: #8a98a8;
  --accent: #6d5efc; --gold: #fbbf24; --good: #34d399; --warn: #fb923c; --bad: #f87171; --xp: #60a5fa;
  --nav: 62px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; max-width: 520px; margin: 0 auto; padding-bottom: calc(var(--nav) + 28px + env(safe-area-inset-bottom)); }
button, select { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
a { color: inherit; }

.top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.top h1 { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { color: var(--muted); font-size: 12px; text-decoration: none; }
.badge { background: var(--accent); border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700; }
.chip { background: var(--panel2); border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700; }

.stage { position: relative; padding: 10px 12px 0; }
.stage[hidden] { display: none; }
#scene { display: block; width: 100%; aspect-ratio: 160 / 144; image-rendering: pixelated; border-radius: 14px; border: 1px solid var(--line); background: #0b0f14; }
.stage-btn[hidden] { display: none; }
.stage-btn { position: absolute; right: 20px; bottom: 10px; font-size: 11px; padding: 5px 9px; background: rgba(0, 0, 0, .55); }
.stage-btn.stage-left { right: auto; left: 20px; }
#display-ui { position: fixed; top: 10px; right: 10px; display: flex; gap: 8px; z-index: 40; transition: opacity .3s; }
#display-ui[hidden] { display: none; }
#display-ui.faded { opacity: 0; pointer-events: none; }

main { padding: 10px 12px; display: grid; gap: 10px; }
.note { color: var(--muted); text-align: center; padding: 30px 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.card h2 { margin: 0 0 8px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.gold { color: var(--gold); font-weight: 700; }
.big { font-size: 24px; font-weight: 800; }

.bar { height: 8px; border-radius: 6px; background: var(--panel2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--xp); width: 0; transition: width .4s; }
.bar.hp > i { background: var(--good); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.stat { background: var(--panel2); border-radius: 10px; padding: 6px 4px; text-align: center; }
.stat b { display: block; font-size: 16px; }
.stat span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.btn { padding: 7px 11px; border-radius: 10px; background: var(--panel2); font-weight: 700; font-size: 13px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.buy { background: #14532d; color: #bbf7d0; }
.btn.sell { background: #3b2a12; color: #fde68a; }
.btn.wide { width: 100%; padding: 11px; font-size: 14px; margin-top: 10px; }
.btn[disabled] { opacity: .35; pointer-events: none; }

.tag { display: inline-block; font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 999px; }
.tag.safe { background: #064e3b; color: var(--good); }
.tag.fair { background: #12344d; color: #7dd3fc; }
.tag.risky { background: #4a2a0a; color: var(--warn); }
.tag.deadly { background: #4c1d1d; color: var(--bad); }
.tag.lock { background: var(--panel2); color: var(--muted); }
.tag.here { background: var(--accent); color: #fff; }
.tag.rar { background: var(--panel2); vertical-align: middle; }

.seg { display: flex; flex-wrap: wrap; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { flex: 1 1 auto; min-width: 0; padding: 7px 8px; border-radius: 9px; color: var(--muted); font-weight: 700; font-size: 13px; }
.seg button.on { background: var(--panel2); color: var(--text); }

/* sprite icons cut from the art sheets */
.ico { display: inline-block; flex: none; width: calc(16px * var(--z, 2)); height: calc(16px * var(--z, 2)); background-image: var(--sheet); background-repeat: no-repeat;
  background-size: calc(var(--cols) * 16px * var(--z, 2)) auto; background-position: calc(-16px * var(--z, 2) * var(--c)) calc(-16px * var(--z, 2) * var(--r)); image-rendering: pixelated; }
.gicon { display: inline-block; flex: none; width: calc(18px * var(--z, 2)); height: calc(18px * var(--z, 2)); object-fit: contain; }
.frame { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 10px; background: var(--panel2); border: 2px solid var(--line); }
.frame.r-common { border-color: #556070; }
.frame.r-uncommon { border-color: #34d399; }
.frame.r-rare { border-color: #60a5fa; }
.frame.r-epic { border-color: #c084fc; }
.frame.r-legendary { border-color: #fb923c; box-shadow: 0 0 8px rgba(251, 146, 60, .5); }
.monsters { display: flex; gap: 2px; margin: 4px 0 2px; }

.slot { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.slot:first-of-type { border-top: 0; }
.slot .name { flex: 1; min-width: 0; }

.rates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; font-size: 11px; }
.rates.two { grid-template-columns: repeat(2, 1fr); }
.rates div { background: var(--panel2); border-radius: 8px; padding: 5px; text-align: center; }
.rates b { display: block; font-size: 14px; color: var(--text); }

.zone.locked { opacity: .55; }
.zone.current { border-color: var(--accent); }

.item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .nm { font-weight: 700; }
.item .qty { color: var(--muted); font-weight: 400; }
.item .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.item.stack { flex-wrap: wrap; }
.item.stack .acts { width: 100%; justify-content: flex-start; }

.pipsrow { display: flex; gap: 3px; margin: 3px 0; }
.pipsm { width: 9px; height: 9px; border-radius: 3px; background: var(--panel2); border: 1px solid var(--line); }
.pipsm.on { background: var(--gold); border-color: var(--gold); }
.pips { display: flex; gap: 8px; }
.pip { width: 22px; height: 22px; border-radius: 6px; background: var(--panel2); border: 2px solid var(--line); }
.pip.on { background: var(--gold); border-color: var(--gold); }

.r-common { color: #aab6c4; }
.r-uncommon { color: #34d399; }
.r-rare { color: #60a5fa; }
.r-epic { color: #c084fc; }
.r-legendary { color: #fb923c; }
.up { color: var(--good); }
.down { color: var(--bad); }
select { font: inherit; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; display: flex; background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px 5px; color: var(--muted); font-size: 11px; font-weight: 700; position: relative; }
.tabbar button.on { color: var(--text); }
.tabbar button.on::before { content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.tabbar .dot { position: absolute; top: 5px; right: 24%; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); border: 2px solid #0d131a; }

.credit { padding: 6px 14px 0; font-size: 10px; color: #5c6b7c; text-align: center; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal[hidden] { display: none; }
.sheet { width: 100%; max-width: 420px; max-height: 88vh; overflow: auto; }
.sheet h2 { text-transform: none; letter-spacing: 0; font-size: 18px; color: var(--text); }
.sheet h3 { margin: 12px 0 4px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sum { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.sum div { background: var(--panel2); border-radius: 10px; padding: 8px 10px; }
.sum b { display: block; font-size: 18px; }
.loot { margin: 8px 0 0; padding: 0; list-style: none; font-size: 14px; }
.loot li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.loot li .grow { flex: 1; }
.callout { background: #1e2a3a; border-radius: 10px; padding: 8px 10px; font-size: 13px; color: #c7d2e0; margin-top: 8px; }
.lucky { background: #3b2a12; color: #fde68a; border-radius: 10px; padding: 8px 10px; font-size: 14px; margin: 8px 0; }
.fightline { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 4px 0; font-size: 14px; }
.fightline .bar { grid-column: 1 / -1; height: 6px; }
.runlog { margin-top: 6px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav) + 14px); transform: translateX(-50%); background: #7f1d1d; color: #fee2e2; font-weight: 700; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90%; z-index: 30; }
#toast.show { opacity: 1; }
#toast.good { background: #14532d; color: #bbf7d0; }
.mats { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; }
.mats span, .item .small span { display: inline-flex; align-items: center; gap: 3px; }

/* display mode: the scene alone, filling the whole portrait screen */
body.display { background: #000; overflow: hidden; max-width: none; padding: 0; }
body.display .top, body.display main, body.display .credit, body.display .tabbar, body.display .stage-btn { display: none; }
body.display .stage { position: fixed; inset: 0; padding: 0; z-index: 30; background: #000; }
body.display #scene { width: 100vw; height: 100vh; height: 100dvh; aspect-ratio: auto; border: 0; border-radius: 0; }
#hud { display: none; position: fixed; left: 0; top: 0; pointer-events: none; z-index: 31; }
body.display #hud { display: block; }
#safe { position: fixed; left: 0; top: 0; width: 0; height: 0; visibility: hidden; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) 0; }

.pick { z-index: 26; background: rgba(5, 8, 12, .92); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.choice { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px 10px; border-radius: 14px; background: var(--panel2); border: 2px solid var(--line); font-weight: 700; }
.choice.on { border-color: var(--accent); background: #232a45; box-shadow: 0 0 14px rgba(109, 94, 252, .45); }
.choice .ico { margin: 6px 0; }

.r-set { color: #22d3ee; }
.frame.r-set { border-color: #22d3ee; box-shadow: 0 0 8px rgba(34, 211, 238, .45); }
.tag.set { background: #083344; color: #67e8f9; }
.effects { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 2px; color: #9fe6c0; }
.effects .uniq { color: #fb923c; font-weight: 700; }
.grouphead { margin: 14px 0 2px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.setpieces { display: flex; gap: 6px; margin: 8px 0; }
.setpiece { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 46px; height: 54px; border-radius: 10px; background: var(--panel2); border: 2px solid var(--line); opacity: .4; filter: grayscale(1); }
.setpiece.owned { opacity: .85; filter: none; border-color: #556070; }
.setpiece.worn { opacity: 1; filter: none; border-color: #22d3ee; box-shadow: 0 0 8px rgba(34, 211, 238, .45); }
.setbonus { font-size: 13px; padding: 4px 8px; margin-top: 4px; border-radius: 8px; background: var(--panel2); color: var(--muted); }
.setbonus.on { background: #083344; color: #67e8f9; }

.setpiece small { font-size: 9px; color: var(--muted); font-weight: 700; }
.hardbox { margin-top: 10px; padding: 10px; border-radius: 12px; border: 1px solid #5b2a14; background: #1d130c; }
.hardbox.locked { opacity: .7; }
.hardbox .wide { margin-top: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 5px 9px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); font-size: 12px; font-weight: 700; }
.filters { margin: 4px 0 8px; }
.filters .chips { margin-top: 6px; }
.chip.gem { background: #2a2350; color: #c4b5fd; }
.chip[hidden] { display: none; }
.formgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field input { width: 100%; box-sizing: border-box; background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 8px; font-size: 14px; min-width: 0; }
.field select { width: 100%; box-sizing: border-box; background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 8px; font-size: 14px; min-width: 0; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
/* looks of the page: the gem shop sells these, each one only changes the colours */
body[data-theme="forest"] { --bg: #0b140e; --panel: #12201a; --panel2: #19291f; --line: #24402f; --text: #eef8f0; --muted: #8aa898; --accent: #3fbf6b; }
body[data-theme="ocean"] { --bg: #08121c; --panel: #0f1f30; --panel2: #162a40; --line: #214260; --text: #eaf4ff; --muted: #86a4c4; --accent: #38bdf8; }
body[data-theme="paper"] { --bg: #f4efe6; --panel: #fffaf0; --panel2: #efe6d6; --line: #d9ccb4; --text: #2b2418; --muted: #7a6e58; --accent: #b45309; --gold: #b7791f; }
body[data-theme="sakura"] { --bg: #150d14; --panel: #221520; --panel2: #2e1c2b; --line: #4a2a45; --text: #fdeef6; --muted: #c49ab4; --accent: #f472b6; }
body[data-theme="sunset"] { --bg: #140c0a; --panel: #22140f; --panel2: #301c14; --line: #4e2c1c; --text: #fff1e6; --muted: #c9a088; --accent: #fb923c; }
body[data-theme="gold"] { --bg: #07070c; --panel: #11101a; --panel2: #1a1826; --line: #3a3320; --text: #fff8e1; --muted: #b3a77c; --accent: #fbbf24; }
.swatch { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 32px; border-radius: 8px; border: 1px solid var(--line); font-weight: 800; font-size: 13px; color: #111; }
.swatch.text { width: auto; min-width: 44px; padding: 0 6px; font-size: 11px; color: var(--text); background: var(--panel2); }
.swatch[data-theme-preview="forest"] { background: #19291f; color: #3fbf6b; }
.swatch[data-theme-preview="ocean"] { background: #162a40; color: #38bdf8; }
.swatch[data-theme-preview="paper"] { background: #fffaf0; color: #b45309; }
.swatch[data-theme-preview="sakura"] { background: #2e1c2b; color: #f472b6; }
.swatch[data-theme-preview="sunset"] { background: #301c14; color: #fb923c; }
.swatch[data-theme-preview="gold"] { background: #1a1826; color: #fbbf24; }
.lookpic { display: inline-flex; align-items: center; justify-content: center; min-width: 52px; }
.rainbow { background: linear-gradient(90deg, #f87171, #fbbf24, #34d399, #60a5fa, #c084fc, #f87171); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: rainbow 4s linear infinite; font-weight: 800; }
@keyframes rainbow { to { background-position: 200% 0; } }
.chip.on { border-color: var(--accent); background: #232a45; }
.chip[disabled] { opacity: .4; pointer-events: none; }
.tabbar button { font-size: 10px; }

.frame.pet { border-color: var(--pc); }
.frame.pet.glow { animation: petglow 2.2s ease-in-out infinite; }
@keyframes petglow { 0%, 100% { box-shadow: 0 0 6px var(--pc); } 50% { box-shadow: 0 0 18px 3px var(--pc); } }
.starpips { display: inline-flex; gap: 3px; }
.starpip { width: 9px; height: 9px; transform: rotate(45deg); background: var(--panel2); border: 1px solid var(--line); }
.starpip.on { background: var(--gold); border-color: var(--gold); }
.oddsrow { display: flex; flex-wrap: wrap; gap: 2px 10px; margin: 2px 0; font-weight: 700; }
.hatch { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 6px 0; }
.hatch .frame { width: 110px; height: 110px; border-radius: 18px; }

input[type="number"], input[type="search"] { font: inherit; width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.sellform label { display: block; margin: 8px 0; font-size: 13px; color: var(--muted); }
.sellform label.chip { display: inline-flex; margin: 0; color: var(--text); }
.sellform input[type="radio"] { width: auto; margin-right: 4px; }
.notice { padding: 6px 0; border-top: 1px solid var(--line); color: var(--muted); }
.notice.new { color: var(--text); font-weight: 700; }
.notice:first-of-type { border-top: 0; }

/* messages between players */
.chip.mail { border: 1px solid var(--line); color: var(--text); cursor: pointer; }
.chip.mail.new { background: #3b2f12; border-color: #fbbf24; color: #fde68a; }
#mailbox { z-index: 27; }
.field textarea { width: 100%; box-sizing: border-box; min-height: 110px; resize: vertical; background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 8px; font-size: 14px; font-family: inherit; }
.mailrow { display: flex; gap: 8px; align-items: baseline; width: 100%; text-align: left; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.mailrow .grow { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailrow.unread .nm { color: #fde68a; }
.mailbody { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0; }
#mute-name, #mailbox select, #mailbox input[type=number] { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 8px; font-size: 14px; min-width: 0; box-sizing: border-box; }
#duo-name, #duo-answer, .formgrid > input { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 8px; font-size: 14px; min-width: 0; width: 100%; box-sizing: border-box; }
