/* spsRPG — pixel UI. Mobile first. */
:root {
  --bg: #14142b;
  --bg2: #1f1d3d;
  --panel: #2a2850;
  --panel2: #353266;
  --edge: #0b0b18;
  --hi: #5a56a8;
  --text: #f1eee4;
  --muted: #a7a3c9;
  --gold: #ffcc33;
  --gold-d: #c28a00;
  --red: #e5484d;
  --green: #4cc38a;
  --blue: #4aa8ff;
  --purple: #b48cff;
  --orange: #ff9f43;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --body: 'VT323', ui-monospace, 'Courier New', monospace;
  --nav-h: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: var(--body); font-size: 21px; line-height: 1.2;
  min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  background-image: radial-gradient(#ffffff08 1px, transparent 1px); background-size: 6px 6px;
  -webkit-font-smoothing: none;
}
img, canvas, .px { image-rendering: pixelated; image-rendering: crisp-edges; }
a { color: var(--blue); }
h1, h2, h3 { font-family: var(--pixel); font-weight: normal; letter-spacing: 0; margin: 0 0 12px; line-height: 1.4; }
h1 { font-size: 16px; } h2 { font-size: 13px; color: var(--gold); } h3 { font-size: 11px; }
main { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; }
.loading { text-align: center; padding: 40px; font-family: var(--pixel); font-size: 12px; color: var(--muted); }

/* Pixel frame: hard double border without images */
.panel {
  background: var(--panel); margin: 0 0 14px; padding: 12px;
  box-shadow: 0 -4px 0 var(--edge), 0 4px 0 var(--edge), -4px 0 0 var(--edge), 4px 0 0 var(--edge),
              inset 0 3px 0 var(--hi), inset 0 -3px 0 #1a1838;
}
.panel.flat { box-shadow: 0 -3px 0 var(--edge), 0 3px 0 var(--edge), -3px 0 0 var(--edge), 3px 0 0 var(--edge); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 17px; }
.tiny { font-family: var(--pixel); font-size: 8px; }
.gold { color: var(--gold); } .red { color: var(--red); } .green { color: var(--green); } .blue { color: var(--blue); } .purple { color: var(--purple); }
.center { text-align: center; }
.list > * + * { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sep { height: 3px; background: var(--edge); margin: 10px 0; }

/* Buttons: big tap targets */
button, .btn {
  font-family: var(--pixel); font-size: 10px; color: var(--text); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 14px; border: 0; cursor: pointer; background: var(--hi);
  box-shadow: 0 -3px 0 var(--edge), 0 3px 0 var(--edge), -3px 0 0 var(--edge), 3px 0 0 var(--edge), inset 0 -4px 0 #00000055, inset 0 3px 0 #ffffff33;
}
button:active, .btn:active { transform: translateY(2px); box-shadow: 0 -3px 0 var(--edge), 0 3px 0 var(--edge), -3px 0 0 var(--edge), 3px 0 0 var(--edge), inset 0 3px 0 #00000055; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--gold-d); color: #fff8e0; }
button.danger { background: #a3262a; }
button.good { background: #23845a; }
button.ghost { background: var(--panel2); }
button.block, .btn.block { width: 100%; }
button.sm { min-height: 36px; padding: 6px 10px; font-size: 9px; }
input, select, textarea {
  font-family: var(--body); font-size: 22px; color: var(--text); background: var(--edge); border: 3px solid var(--hi);
  padding: 8px 10px; min-height: 44px; width: 100%; border-radius: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
label { display: block; margin-bottom: 10px; }
label > span { display: block; font-family: var(--pixel); font-size: 9px; color: var(--muted); margin-bottom: 6px; }

/* HUD */
#hud { position: sticky; top: 0; z-index: 20; background: var(--bg2); border-bottom: 4px solid var(--edge); padding: 8px 16px 10px; }
#hud .in { max-width: 720px; margin: 0 auto; }
.hud-top { display: flex; gap: 10px; align-items: center; }
.hud-top .portrait { width: 44px; height: 44px; flex: none; background: var(--edge); }
.hud-name { font-family: var(--pixel); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-sub { font-size: 17px; color: var(--muted); }
.hud-res { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; font-size: 19px; }
.hud-res .r { display: inline-flex; align-items: center; gap: 4px; }
.icon { width: 16px; height: 16px; vertical-align: middle; }
.icon.lg { width: 28px; height: 28px; }
.icon.xl { width: 48px; height: 48px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.badge { font-family: var(--pixel); font-size: 8px; padding: 5px 6px; background: var(--panel2); box-shadow: 0 0 0 2px var(--edge); }
.badge.red { background: #6b1d20; color: #ffd6d6; } .badge.green { background: #19523a; color: #d6ffe9; } .badge.gold { background: #6b5000; color: #fff2c2; }
.badge.bully { background: #5c1e22; color: #ffcccc; } .badge.programmer { background: #1a4260; color: #ccedff; } .badge.marketer { background: #543d1a; color: #ffebcc; }

/* Bars */
.bar { height: 12px; background: var(--edge); position: relative; box-shadow: 0 0 0 2px var(--edge); }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--green); display: block; transition: width .25s steps(6); }
.bar.xp > i { background: var(--purple); } .bar.en > i { background: var(--blue); } .bar.hp > i { background: var(--green); } .bar.hp.low > i { background: var(--red); }
.bar.tall { height: 18px; }
.barlabel { display: flex; justify-content: space-between; font-size: 16px; color: var(--muted); }

/* Nav */
#nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: grid; grid-template-columns: repeat(6, 1fr); background: var(--bg2); border-top: 4px solid var(--edge); padding-bottom: env(safe-area-inset-bottom); }
#nav a { color: var(--muted); text-decoration: none; font-family: var(--pixel); font-size: 7px; display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 0 9px; min-height: var(--nav-h); position: relative; }
#nav a.on { color: var(--gold); background: var(--panel); }
#nav .ni img { width: 24px; height: 24px; }
#nav .dot { position: absolute; top: 6px; right: calc(50% - 18px); width: 9px; height: 9px; background: var(--red); box-shadow: 0 0 0 2px var(--edge); }

/* Tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; padding: 4px; }
.tabs button { flex: 1 0 auto; background: var(--panel2); }
.tabs button.on { background: var(--gold-d); }

/* Cards / items */
.item { display: flex; gap: 10px; align-items: center; }
.item .ic { width: 40px; height: 40px; background: var(--edge); flex: none; display: grid; place-items: center; }
.item .ic img { width: 32px; height: 32px; }
.rar-common { color: #d6d3c4; } .rar-uncommon { color: var(--green); } .rar-rare { color: var(--blue); } .rar-epic { color: var(--purple); } .rar-legendary { color: var(--orange); }
.stat { font-size: 18px; color: var(--muted); }
.stat b { color: var(--text); font-weight: normal; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 19px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; }
table { width: 100%; border-collapse: collapse; font-size: 19px; }
td, th { padding: 6px 4px; text-align: left; border-bottom: 2px solid var(--edge); }
th { font-family: var(--pixel); font-size: 8px; color: var(--muted); font-weight: normal; }
tr.me td { color: var(--gold); }
.classcard { text-align: center; padding: 12px 6px; background: var(--panel2); cursor: pointer; border: 0; color: var(--text); display: block; width: 100%; min-height: 0; font-family: var(--body); font-size: 17px; flex-direction: column; }
.classcard.on { background: var(--gold-d); }
.classcard img { width: 64px; height: 64px; display: block; margin: 0 auto 6px; }
.classcard strong { font-family: var(--pixel); font-size: 9px; display: block; margin-bottom: 4px; }

/* Replay */
.arena { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; }
.fighter { text-align: center; }
.fighter img { width: 72px; height: 72px; }
.fighter.hit img { animation: shake .25s steps(3); }
.vs { font-family: var(--pixel); font-size: 12px; color: var(--red); }
.log { height: 220px; overflow-y: auto; background: var(--edge); padding: 8px; font-size: 19px; margin-top: 12px; }
.log p { margin: 0 0 4px; }
.log .crit { color: var(--orange); } .log .miss { color: var(--muted); }
.outcome { font-family: var(--pixel); font-size: 14px; text-align: center; padding: 14px 0; }
.dmg { font-family: var(--pixel); font-size: 10px; color: var(--red); height: 14px; }
@keyframes shake { 0% { transform: translateX(-3px); } 50% { transform: translateX(3px); } 100% { transform: none; } }

/* Minigames */
canvas.game { width: 100%; max-width: 420px; display: block; margin: 0 auto; background: var(--edge); touch-action: manipulation; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%); z-index: 50; max-width: calc(100% - 32px); width: max-content;
  background: var(--panel2); padding: 10px 14px; font-size: 19px; box-shadow: 0 0 0 3px var(--edge); display: none; }
#toast.show { display: block; }
#toast.err { background: #6b1d20; } #toast.ok { background: #19523a; }

.hero { text-align: center; padding: 28px 8px; }
.hero img { width: 96px; height: 96px; }
.hero h1 { font-size: 20px; color: var(--gold); margin-top: 14px; }
.note { font-size: 17px; color: var(--muted); }
.notif { border-left: 4px solid var(--gold); padding-left: 8px; }
.notif.seen { border-color: var(--hi); opacity: .75; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper b { min-width: 40px; text-align: center; font-family: var(--pixel); font-size: 11px; }
@media (min-width: 560px) { body { font-size: 22px; } #nav a { font-size: 8px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.icon.portrait-lg { width: 72px; height: 72px; }
/* Admin */
.admin pre { white-space: pre-wrap; word-break: break-word; font-size: 15px; background: var(--edge); padding: 8px; max-height: 420px; overflow: auto; }
.admin .scroll { overflow-x: auto; }
.admin table { font-size: 16px; }

[hidden] { display: none !important; }
.outcome .small { font-family: var(--body); font-size: 19px; color: var(--muted); }

/* ---------- v2: compact HUD, map, doll, drag & drop, progress, banners ---------- */
button, .btn { flex-wrap: wrap; white-space: normal; line-height: 1.5; min-width: 0; text-align: center; }
button.stack, .btn.stack { flex-direction: column; gap: 4px; }
button .sub, .btn .sub { font-family: var(--body); font-size: 17px; line-height: 1.1; display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }
.btn.sm { min-height: 36px; padding: 6px 10px; font-size: 9px; }

#hud { padding: 4px 12px 0; }
.hud-line { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: 20px; }
.hud-line .hud-id { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; }
.hud-line .hud-name { overflow: hidden; text-overflow: ellipsis; }
.hud-line .r { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.hud-line .badge { padding: 4px 5px; }
#hud .bar.xp { height: 5px; box-shadow: none; margin: 2px -12px 0; }

.resbar { display: inline-flex; gap: 10px; flex-wrap: wrap; font-size: 19px; align-items: center; }
.resbar span { display: inline-flex; gap: 4px; align-items: center; }
.hero-card { display: flex; gap: 12px; align-items: center; }
.doll { width: 108px; height: 120px; flex: none; }
.doll.big { width: 126px; height: 140px; }

/* Town minimap */
.map { position: relative; aspect-ratio: 4 / 3; background-size: 100% 100%; image-rendering: pixelated; box-shadow: 0 0 0 3px var(--edge); }
.spot { position: absolute; width: 24%; text-align: center; text-decoration: none; color: var(--text); }
.spot .spot-img { width: 62%; height: auto; aspect-ratio: 1; filter: drop-shadow(0 3px 0 #0008); }
.spot:active .spot-img { transform: translateY(2px); }
.spot-label { display: block; font-family: var(--pixel); font-size: 7px; line-height: 1.4; background: #0b0b18cc; padding: 3px 2px; margin-top: 2px; }
.spot-badge { position: absolute; top: -6px; right: 4%; font-family: var(--pixel); font-size: 7px; padding: 3px 4px; background: var(--gold-d); color: #fff8e0; box-shadow: 0 0 0 2px var(--edge); z-index: 1; }
.spot-badge.wait { background: var(--hi); }

/* Champion + drag & drop */
.doll-wrap { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px 0; }
.slots { display: flex; flex-direction: column; gap: 10px; }
.slot { text-align: center; }
.slot > span { display: block; margin-bottom: 4px; }
.tile { width: 64px; height: 64px; background: var(--edge); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative;
  box-shadow: 0 0 0 3px var(--hi); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; font-size: 16px; }
.tile img { pointer-events: none; }
.tile.empty { box-shadow: 0 0 0 3px #35326688; cursor: default; }
.tile.empty img { opacity: .25; }
.tile.rar-b-uncommon { box-shadow: 0 0 0 3px var(--green); } .tile.rar-b-rare { box-shadow: 0 0 0 3px var(--blue); }
.tile.rar-b-epic { box-shadow: 0 0 0 3px var(--purple); } .tile.rar-b-legendary { box-shadow: 0 0 0 3px var(--orange); }
.tile.locked { opacity: .5; } .tile.listed { opacity: .6; }
.tile.sel { outline: 3px solid var(--gold); outline-offset: 3px; }
.tile .rb { position: absolute; top: -6px; right: -6px; font-family: var(--pixel); font-size: 7px; background: var(--gold-d); color: #fff8e0; padding: 2px 3px; }
.tile .cmp { position: absolute; top: -6px; left: -6px; font-family: var(--pixel); font-size: 8px; line-height: 1; padding: 2px 3px; border-radius: 2px; z-index: 1; }
.tile .cmp.up { background: var(--green); color: #fff; }
.tile .cmp.down { background: var(--red); color: #fff; }
.tile .cmp.side { background: #355e88; color: #fff; }
.tile.dragging { opacity: .3; }
.tile.ghost { position: fixed; z-index: 100; pointer-events: none; transform: scale(1.15); box-shadow: 0 0 0 3px var(--gold), 0 8px 0 #0008; }
.inv { display: grid; grid-template-columns: repeat(auto-fill, 64px); gap: 14px; justify-content: center; min-height: 72px; padding: 6px 0; }
.drag-on [data-drop] { outline: 3px dashed #ffffff33; outline-offset: -3px; }
.drag-on .drop-hot { outline: 3px dashed var(--gold); background: #ffcc3318; }

/* Dungeon ladder */
.pips { display: flex; gap: 6px; margin: 8px 0; }
.pip { flex: 1; text-align: center; font-family: var(--pixel); font-size: 8px; padding: 6px 0; background: var(--edge); color: var(--muted); }
.pip.done { background: #19523a; color: #d6ffe9; } .pip.next { box-shadow: 0 0 0 2px var(--gold); color: var(--gold); } .pip.boss { color: var(--red); } .pip.boss.done { color: #d6ffe9; }

/* Level-up banner */
.overlay { position: fixed; inset: 0; z-index: 200; background: #0b0b18cc; display: grid; place-items: center; padding: 20px; }
.overlay .panel { max-width: 360px; width: 100%; text-align: center; animation: pop .3s steps(4); }
.overlay h1 { font-size: 22px; color: var(--gold); margin: 10px 0; }
@keyframes pop { from { transform: scale(.6); } to { transform: none; } }
.callout { background: #6b5000; box-shadow: 0 0 0 3px var(--edge); padding: 10px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; }

/* Active Event Banner & Seasonal Decorations */
.event-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(90deg, #3d2300, #5c3a00, #3d2300);
  border: 2px solid var(--gold);
  box-shadow: 0 0 8px #ffcc3340;
  padding: 6px 10px;
  margin-bottom: 10px;
  font-family: var(--pixel);
  font-size: 8px;
  color: #fff9e6;
  border-radius: 2px;
  animation: pulse-border 2s infinite ease-in-out;
}
.event-ribbon .ev-title { display: flex; align-items: center; gap: 6px; }
.event-ribbon .ev-mult { background: var(--gold); color: #1a1a24; padding: 2px 5px; font-weight: bold; border-radius: 2px; }
.event-ribbon .ev-timer { color: var(--gold); font-size: 8px; }

@keyframes pulse-border {
  0%, 100% { border-color: var(--gold); box-shadow: 0 0 4px #ffcc3340; }
  50% { border-color: #ffe680; box-shadow: 0 0 12px #ffcc3380; }
}

/* Season themes */
body[data-season="winter"] {
  --hi: #456289;
  --edge: #151b2e;
}
body[data-season="winter"] #hud {
  border-bottom: 2px solid #a8cceb;
}
body[data-season="spring"] {
  --hi: #3b6b55;
}
body[data-season="autumn"] {
  --hi: #734827;
}

#snow-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 150;
}

