:root {
  --bg: #0f1420;
  --panel: #182033;
  --panel2: #1f2a42;
  --line: #2c3a58;
  --text: #e8edf7;
  --muted: #8d9bb8;
  --gold: #f5c542;
  --hp: #4cd964;
  --hp-enemy: #ff5a5f;
  --mana: #4aa3ff;
  --shield: #e9eef5;
  --c1: #9aa4b5;
  --c2: #2fbf71;
  --c3: #3a8dff;
  --c4: #b45cff;
  --c5: #ffb000;
  --bronze: #b0773f;
  --silver: #aab6c8;
  --goldt: #f5c542;
  --prism: #6ff0e4;
  --accent: #ffcb05;
  --danger: #ff5a5f;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.3 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
body { overscroll-behavior: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
#app { max-width: 540px; margin: 0 auto; padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; min-height: 100%; }

/* top bar */
#top { display: flex; align-items: center; gap: 8px; }
#top .round { font-weight: 700; font-size: 15px; }
#top .sub { color: var(--muted); font-size: 12px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top .stat { font-weight: 700; white-space: nowrap; }
#top .gold { color: var(--gold); }
#top .hpv { color: var(--hp); }
#menuBtn { background: var(--panel2); border-radius: 8px; width: 34px; height: 30px; font-size: 16px; }

/* players */
#players { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
#players::-webkit-scrollbar { display: none; }
.pchip { flex: 1 0 58px; background: var(--panel); border-radius: 7px; padding: 3px 5px; border: 1px solid transparent; text-align: left; }
.pchip .n { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip .b { height: 4px; background: #0008; border-radius: 2px; margin-top: 2px; overflow: hidden; }
.pchip .b i { display: block; height: 100%; background: var(--hp); }
.pchip .h { font-size: 11px; font-weight: 700; }
.pchip.me { border-color: var(--accent); }
.pchip.opp { border-color: var(--danger); }
.pchip.dead { opacity: .35; }

/* board */
#boardWrap { position: relative; background: var(--panel); border-radius: 12px; padding: 6px; }
#board { position: relative; margin: 0 auto; }
.hex { position: absolute; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); background: #243150; }
.hex.home { background: #2a3a5e; }
.hex.drop { background: #3f5a8f; }
.hex.hl { background: #4b6aa8; }
.divider { position: absolute; left: 0; right: 0; height: 2px; background: #ff5a5f33; }
.unit { position: absolute; display: flex; flex-direction: column; align-items: center; pointer-events: auto; transition: left .18s linear, top .18s linear; }
.unit.static { transition: none; }
.unit img { width: 135%; max-width: none; image-rendering: pixelated; margin: -24% 0 -20%; filter: drop-shadow(0 2px 2px #0008); pointer-events: none; }
.unit .bars { width: 86%; position: relative; z-index: 2; }
.unit .hpb { height: 5px; background: #000a; border-radius: 2px; overflow: hidden; position: relative; }
.unit .hpb i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--hp); }
.unit .hpb s { position: absolute; top: 0; bottom: 0; background: var(--shield); opacity: .85; }
.unit.enemy .hpb i { background: var(--hp-enemy); }
.unit .mpb { height: 3px; background: #000a; border-radius: 2px; margin-top: 1px; overflow: hidden; }
.unit .mpb i { display: block; height: 100%; background: var(--mana); }
.unit .stars { position: absolute; bottom: 12%; font-size: 9px; letter-spacing: -1px; color: var(--gold); text-shadow: 0 0 2px #000, 0 0 2px #000; z-index: 2; }
.unit .stars.s2 { color: #dfe6f2; }
.unit .stars.s3 { color: var(--gold); }
.unit .its { position: absolute; bottom: -2px; display: flex; gap: 1px; z-index: 3; }
.unit .ring { position: absolute; inset: 14% 12% 8%; border-radius: 50%; border: 2px solid var(--c1); opacity: .6; }
.unit.sel .ring { opacity: 1; box-shadow: 0 0 8px var(--accent); border-color: var(--accent) !important; }
.unit.dim { opacity: .55; }
.unit.dead { opacity: 0; transition: opacity .3s; pointer-events: none; }
.unit.stun img { filter: grayscale(.8) drop-shadow(0 2px 2px #0008); }
.unit.untarget img { opacity: .35; }
.cost1 { border-color: var(--c1) !important; } .cost2 { border-color: var(--c2) !important; } .cost3 { border-color: var(--c3) !important; } .cost4 { border-color: var(--c4) !important; } .cost5 { border-color: var(--c5) !important; }
.float { position: absolute; font-weight: 800; font-size: 11px; pointer-events: none; text-shadow: 0 1px 2px #000; animation: rise .7s ease-out forwards; z-index: 5; white-space: nowrap; }
.float.physical { color: #ff9f6b; } .float.magic { color: #c28cff; } .float.true { color: #fff; } .float.heal { color: var(--hp); } .float.crit { font-size: 13px; }
.float.cast { color: var(--mana); font-size: 10px; }
@keyframes rise { from { transform: translate(-50%, 0); opacity: 1; } to { transform: translate(-50%, -22px); opacity: 0; } }
#combatBar { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
#combatBar .time { font-weight: 700; flex: 1; }
.speed { background: var(--panel2); border-radius: 6px; padding: 5px 9px; font-weight: 700; }
.speed.on { background: var(--accent); color: #111; }
.boardLabel { position: absolute; left: 10px; font-size: 11px; color: var(--muted); z-index: 4; pointer-events: none; }

/* traits */
#traits { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; min-height: 26px; }
#traits::-webkit-scrollbar { display: none; }
.trait { flex: 0 0 auto; background: var(--panel); border-radius: 6px; padding: 4px 7px; font-size: 11px; border-left: 3px solid #3a4560; white-space: nowrap; }
.trait b { font-weight: 800; }
.trait.t0 { border-left-color: var(--bronze); } .trait.t1 { border-left-color: var(--silver); } .trait.t2 { border-left-color: var(--goldt); } .trait.t3 { border-left-color: var(--prism); }
.trait.off { opacity: .55; }
.trait .bp { color: var(--muted); }

/* bench */
#bench { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; }
.slot { position: relative; aspect-ratio: 1 / 1.1; background: var(--panel); border-radius: 7px; }
.slot.drop { background: #33466e; }
.slot .unit { position: absolute; inset: 0; width: 100% !important; transition: none; }

/* items */
#itemsBar { display: flex; gap: 4px; flex-wrap: wrap; min-height: 28px; align-items: center; }
#itemsBar .lbl { color: var(--muted); font-size: 11px; }
.ib { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 14px; padding: 0 2px; border-radius: 3px; font-size: 8px; font-weight: 800; color: #fff; background: #555; text-shadow: 0 1px 1px #0008; }
.itemBtn { min-width: 38px; height: 28px; font-size: 11px; border-radius: 6px; padding: 0 6px; }
.itemBtn.sel { outline: 2px solid var(--accent); }
.i-bf { background: #c0483b; } .i-bow { background: #d98a1f; } .i-rod { background: #7b4dd8; } .i-tear { background: #2f7de0; }
.i-vest { background: #6b7a8f; } .i-cloak { background: #6e3e9c; } .i-belt { background: #b8543a; } .i-glove { background: #c79a2c; } .i-spat { background: #d6b300; color: #222; }

/* shop */
#shop { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.card { background: var(--panel); border-radius: 8px; border: 2px solid var(--c1); padding: 3px 3px 4px; display: flex; flex-direction: column; align-items: center; min-height: 86px; position: relative; }
.card img { width: 48px; height: 48px; image-rendering: pixelated; margin: -4px 0 -4px; }
.card .nm { font-size: 11px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.card .tr { font-size: 9px; color: var(--muted); text-align: center; line-height: 1.15; }
.card .cost { position: absolute; top: 2px; right: 4px; font-weight: 800; color: var(--gold); font-size: 11px; }
.card.empty { opacity: .25; }
.card.owned { box-shadow: 0 0 0 2px var(--accent) inset; }
.card.poor { opacity: .5; }
.card.star2 { box-shadow: 0 0 10px var(--accent); }

/* actions */
#actions { display: grid; grid-template-columns: 1fr 1fr 44px 1.4fr; gap: 4px; }
.act { background: var(--panel2); border-radius: 9px; padding: 9px 4px; font-weight: 700; }
.act small { display: block; font-weight: 400; color: var(--muted); font-size: 10px; }
.act.fight { background: var(--accent); color: #111; font-size: 15px; }
.act.on { background: var(--accent); color: #111; }
.act:disabled { opacity: .4; }

/* sheet & modal */
#sheet { position: fixed; left: 0; right: 0; bottom: 0; max-width: 540px; margin: 0 auto; background: var(--panel2); border-radius: 14px 14px 0 0; padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px #000a; transform: translateY(105%); transition: transform .18s; z-index: 20; max-height: 70vh; overflow-y: auto; }
#sheet.open { transform: none; }
#sheet h3 { margin: 0 0 2px; font-size: 16px; }
#sheet .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#sheet .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 8px; margin: 8px 0; }
#sheet .stats div { background: var(--panel); border-radius: 6px; padding: 4px 6px; font-size: 11px; color: var(--muted); }
#sheet .stats b { display: block; color: var(--text); font-size: 13px; }
#sheet p { margin: 6px 0; color: #c9d3e6; }
.tag { background: var(--panel); border-radius: 5px; padding: 2px 6px; font-size: 11px; }
.btn { background: var(--accent); color: #111; border-radius: 8px; padding: 8px 14px; font-weight: 700; }
.btn.sec { background: var(--panel); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
#modal { position: fixed; inset: 0; background: #000b; display: none; align-items: center; justify-content: center; z-index: 30; padding: 12px; }
#modal.open { display: flex; }
#modal .box { background: var(--panel2); border-radius: 14px; padding: 14px; width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; }
#modal h2 { margin: 0 0 8px; font-size: 18px; }
.opts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.opt { background: var(--panel); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; align-items: center; border: 2px solid var(--c1); }
.opt img { width: 72px; height: 72px; image-rendering: pixelated; }
table.res { width: 100%; border-collapse: collapse; font-size: 12px; }
table.res td { padding: 4px 3px; border-bottom: 1px solid var(--line); }
.bar { height: 6px; border-radius: 3px; background: #ff9f6b; }
.bar.t { background: #8d9bb8; } .bar.h { background: var(--hp); }
.muted { color: var(--muted); }
.win { color: var(--hp); } .loss { color: var(--danger); }
#toast { position: fixed; left: 50%; top: 10px; transform: translateX(-50%); background: #000d; padding: 8px 14px; border-radius: 8px; z-index: 40; display: none; font-weight: 600; }
#update { position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); background: var(--accent); color: #111; padding: 9px 16px; border-radius: 20px; z-index: 40; display: none; font-weight: 700; box-shadow: 0 4px 16px #000a; }
.grid-items { display: grid; grid-template-columns: repeat(10, auto); gap: 3px; font-size: 10px; align-items: center; overflow-x: auto; }
.grid-items .ib { height: 18px; font-size: 9px; }
.ilist div { padding: 5px 0; border-bottom: 1px solid var(--line); }
.drag { position: fixed; pointer-events: none; z-index: 50; opacity: .85; }
.unit, .itemBtn { touch-action: none; }
.unit.dim { pointer-events: auto; }
