/* Kingsward */
:root {
  --bg: #070b17;
  --ink: #0b1020;
  --surface: #121a31;
  --surface-2: #1a2444;
  --surface-3: #243058;
  --line: #2c3964;
  --line-soft: rgba(140, 160, 230, 0.16);
  --text: #eef1fb;
  --muted: #a3aed1;
  --faint: #7480a8;
  --gold: #f2c14e;
  --gold-deep: #c8922a;
  --essence: #b49bff;
  --income: #7fe0a4;
  --hp: #5fd38a;
  --danger: #ff6b78;
  --you: #6db6ff;
  --rival: #ffb454;
  --font-display: 'Gambetta', 'Iowan Old Style', Georgia, serif;
  --font-ui: 'Satoshi', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.35;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
h1, h2, p, ol, dl, dd { margin: 0; padding: 0; }
a { color: var(--gold); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

svg.ic { width: 1em; height: 1em; fill: currentColor; flex: none; display: block; }
.ic-slot { display: inline-flex; }

#app { position: fixed; inset: 0; display: flex; justify-content: center; background: var(--bg); }
.screen { display: none; }
#app[data-screen='title'] #title { display: block; }
#app[data-screen='game'] #game { display: grid; }
#app[data-screen='online'] #online { display: block; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: var(--r-md);
  background: var(--surface-3);
  border: 1px solid var(--line);
  font-weight: 700; font-size: 15px; letter-spacing: 0.01em;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(180deg, #f8d373, #e3a93a);
  border-color: #ffe6a3;
  color: #2a1a00;
  box-shadow: 0 6px 18px rgba(242, 193, 78, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.btn.ghost { background: rgba(18, 26, 49, 0.6); }
.btn.big { min-height: 54px; font-size: 18px; border-radius: 14px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
@media (hover: hover) {
  .btn:hover { background: #2c3a6a; }
  .btn.primary:hover { background: linear-gradient(180deg, #ffdc85, #eab445); }
}

.icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 19px; color: var(--muted); flex: none;
}
.icon-btn:active { transform: scale(0.94); }

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: rgba(10, 15, 31, 0.78); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 3px; gap: 3px;
}
.seg button {
  min-height: 40px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--muted);
  padding: 0 12px; transition: background 0.15s ease, color 0.15s ease;
}
.seg button[aria-checked='true'], .seg button[aria-selected='true'] { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px rgba(160, 180, 255, 0.25); }
.seg.small button { min-height: 34px; font-size: 13px; padding: 0 10px; }

/* ------------------------------------------------------------ title */
#title { position: relative; width: 100%; height: 100%; overflow: hidden; background: var(--bg); }
#title::before {
  content: ''; position: absolute; inset: -60px;
  background: url('assets/splash2.jpg') center 30% / cover no-repeat;
  filter: blur(30px) brightness(0.45) saturate(1.1);
}
.title-art {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: min(100%, 640px); height: 100%; object-fit: cover; object-position: 50% 0%;
}
@media (min-width: 700px) {
  .title-art { -webkit-mask-image: linear-gradient(90deg, transparent, #000 14%, #000 86%, transparent); mask-image: linear-gradient(90deg, transparent, #000 14%, #000 86%, transparent); }
}
.title-shade {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(7, 11, 23, 0.55) 0%, rgba(7, 11, 23, 0.05) 22%, rgba(7, 11, 23, 0.35) 44%, rgba(7, 11, 23, 0.94) 70%, var(--bg) 100%);
}
.title-body {
  position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(var(--safe-t) + clamp(18px, 5vh, 56px)) 16px calc(var(--safe-b) + 16px);
}
.brand { text-align: center; }
.brand h1 {
  font-family: var(--font-display); font-weight: 700; font-size: clamp(46px, 13vw, 72px); line-height: 1; letter-spacing: 0.01em;
  background: linear-gradient(180deg, #fff3cf 10%, #f2c14e 55%, #b97a1c 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 rgba(40, 18, 0, 0.75)) drop-shadow(0 10px 24px rgba(0, 0, 0, 0.7));
}
.tagline { margin-top: 8px; font-size: 15px; font-weight: 500; color: #e6e9f8; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95), 0 2px 12px rgba(0, 0, 0, 0.9), 0 0 26px rgba(7, 11, 23, 0.85); }
.setup {
  width: min(100%, 460px);
  background: rgba(11, 16, 32, 0.84); border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  padding: 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}
.setup h2 { font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 2px 2px 8px; }
.faction-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.faction {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; text-align: center;
  padding: 7px 2px 6px; border-radius: var(--r-md); min-width: 0;
  background: var(--surface); border: 1.5px solid var(--line);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}
.faction:active { transform: scale(0.97); }
.faction .pic { width: 100%; height: 50px; }
.faction b { display: none; font-size: 12px; font-weight: 700; line-height: 1.1; }
@media (min-width: 470px) { .faction b { display: block; } }
.faction[aria-checked='false'] .pic img { filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.45)) saturate(0.75) brightness(0.82); }
.faction[aria-checked='true'] { border-color: var(--fc); background: color-mix(in srgb, var(--fc) 14%, var(--surface)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fc) 22%, transparent); }
.faction-blurb { min-height: 36px; margin: 8px 2px 10px; font-size: 13px; color: #cfd6f0; }
.opts { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 8px; }
.opts .seg button { padding: 0 4px; }
.mode-blurb { margin: 7px 2px 0; font-size: 12px; color: var(--muted); min-height: 16px; }
.title-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 54px; gap: 8px; margin-top: 14px; }
.title-actions .btn { width: 100%; padding: 0 6px; white-space: nowrap; }
.title-actions .btn.big { font-size: 17px; }
.title-actions .btn.ghost { min-height: 54px; font-size: 24px; color: var(--muted); }
.btn.online { background: linear-gradient(180deg, #3a63c9, #27469a); border-color: #86a8ff; color: #fff; box-shadow: 0 6px 18px rgba(60, 100, 220, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.25); }
@media (hover: hover) { .btn.online:hover { background: linear-gradient(180deg, #4470dc, #2d50ad); } }
@media (max-width: 359px) { .title-actions { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 46px; gap: 6px; } .title-actions .btn.big { font-size: 15px; } }
.fine { margin-top: 12px; font-size: 12px; color: var(--faint); text-align: center; line-height: 1.35; }

/* ------------------------------------------------------------ online lobby */
#online { position: relative; width: 100%; height: 100%; overflow: hidden; background: var(--bg); }
#online::before {
  content: ''; position: absolute; inset: -60px;
  background: url('assets/splash2.jpg') center 30% / cover no-repeat;
  filter: blur(26px) brightness(0.36) saturate(1.1);
}
.on-body {
  position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--safe-t) + 14px) 14px calc(var(--safe-b) + 14px);
}
.on-card { margin: auto 0; }
.on-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.on-head h1 { flex: 1; min-width: 0; font-family: var(--font-display); font-weight: 700; font-size: 26px; line-height: 1.1; color: var(--gold); }
.on-head .icon-btn { width: 44px; height: 44px; font-size: 22px; color: var(--text); }
.on-link { font-size: 12px; font-weight: 700; color: var(--rival); text-align: right; }
.on-lead { font-size: 14px; color: #cfd6f0; margin: 0 2px 14px; }
.fld { display: grid; gap: 6px; margin-bottom: 12px; }
.fld > span { font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-left: 2px; }
.fld input {
  width: 100%; min-width: 0; height: 50px; padding: 0 14px; border-radius: var(--r-md);
  background: rgba(7, 11, 23, 0.8); border: 1.5px solid var(--line); color: var(--text);
  font: inherit; font-size: 17px; font-weight: 700; -webkit-user-select: text; user-select: text; -webkit-appearance: none; appearance: none;
}
.fld input::placeholder { color: var(--faint); font-weight: 500; opacity: 1; }
.fld input:focus-visible { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(242, 193, 78, 0.22); }
#onCode { text-transform: uppercase; letter-spacing: 0.3em; font-size: 20px; text-align: center; padding: 0 8px 0 14px; font-variant-numeric: tabular-nums; }
#onCode::placeholder { letter-spacing: 0.3em; }
#onCreate { width: 100%; }
.on-note { margin: 8px 2px 0; font-size: 13px; color: var(--muted); text-align: center; }
.on-or { display: flex; align-items: center; gap: 10px; margin: 16px 0 12px; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); }
.on-or::before, .on-or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.on-join { display: grid; grid-template-columns: minmax(0, 1fr) minmax(96px, 0.6fr); gap: 8px; align-items: end; }
.on-join .fld { margin: 0; }
.on-join .btn { min-height: 50px; }
.on-msg { min-height: 18px; margin: 10px 2px 0; font-size: 13px; font-weight: 700; color: var(--muted); text-align: center; }
.on-msg.bad { color: #ff9aa3; }
.on-msg.good { color: var(--income); }

.room-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 8px 8px 14px; margin-bottom: 12px; border-radius: var(--r-md); background: rgba(7, 11, 23, 0.7); border: 1px dashed rgba(242, 193, 78, 0.5); }
.room-code { display: grid; line-height: 1.1; -webkit-user-select: text; user-select: text; }
.room-code small { font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.room-code b { font-size: 30px; font-weight: 900; letter-spacing: 0.16em; color: var(--gold); }
.teams { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-bottom: 12px; }
.team { display: grid; gap: 6px; align-content: start; padding: 8px; border-radius: var(--r-md); background: rgba(7, 11, 23, 0.55); border: 1px solid var(--line-soft); }
.team h3 { margin: 0 2px 2px; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.team.t0 h3 { color: var(--you); }
.team.t1 h3 { color: var(--rival); }
.seat {
  display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: center; gap: 8px; width: 100%; min-height: 50px; padding: 5px 8px 5px 6px; text-align: left;
  border-radius: 10px; background: var(--surface); border: 1.5px solid var(--line);
}
.seat .pic { width: 34px; height: 38px; }
.seat .s-ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-size: 19px; background: rgba(140, 160, 230, 0.1); color: var(--faint); }
.seat .s-txt { display: grid; min-width: 0; line-height: 1.2; }
.seat .s-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .s-tag { font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat.me { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 9%, var(--surface)); }
.seat.me .s-tag { color: var(--gold); }
.seat.off { opacity: 0.6; }
.seat.empty { border-style: dashed; background: transparent; }
.seat.empty .s-name { color: var(--muted); }
button.seat.empty .s-tag { color: var(--you); font-weight: 700; }
button.seat:active { transform: scale(0.98); }
#roomFaction .faction { padding: 5px 2px 4px; }
#roomFaction .faction .pic { height: 40px; }
#roomFaction { margin-bottom: 12px; }
#roomOpts.locked .seg { opacity: 0.55; pointer-events: none; }
.room-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 12px; }
.room-actions .btn { padding: 0 14px; white-space: nowrap; }
.room-actions .btn.ghost { min-height: 54px; }
@media (max-width: 359px) {
  .room-code b { font-size: 26px; }
  .seat { grid-template-columns: 28px minmax(0, 1fr); gap: 6px; padding-left: 5px; padding-right: 5px; }
  .seat .pic { width: 28px; height: 32px; }
  .seat.empty { grid-template-columns: minmax(0, 1fr); padding-left: 10px; }
  .seat.empty .s-ic { display: none; }
  .team { padding: 6px; }
  .room-actions .btn.big { font-size: 16px; }
}
@media (min-aspect-ratio: 1/1) and (min-width: 640px) and (max-height: 560px) {
  .on-body { padding-top: calc(var(--safe-t) + 8px); padding-bottom: calc(var(--safe-b) + 8px); }
  .on-card { width: min(100%, 640px); }
  .on-head { margin-bottom: 8px; }
  .on-lead { margin-bottom: 10px; }
  #onEntry { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 16px; align-items: end; }
  #onEntry .on-lead, #onEntry .on-msg { grid-column: 1 / -1; }
  #onEntry .on-or { display: none; }
  #onEntry .on-note { grid-column: 1; grid-row: 4; }
  #onEntry #onCreate { grid-column: 2; grid-row: 2; margin-bottom: 12px; min-height: 50px; }
  #onEntry .on-join { grid-column: 1 / -1; grid-row: 3; }
  #onEntry .on-note { display: none; }
  .teams { margin-bottom: 8px; }
  #roomFaction { margin-bottom: 8px; }
  #roomFaction .faction .pic { height: 34px; }
  .room-top { margin-bottom: 8px; padding-top: 4px; padding-bottom: 4px; }
  .room-actions { margin-top: 8px; }
  .room-actions .btn.big, .room-actions .btn.ghost { min-height: 46px; }
}

/* character portrait */
.pic {
  --tc: var(--you);
  position: relative; flex: none; width: 38px; height: 38px;
  display: inline-flex; align-items: flex-end; justify-content: center;
}
.pic::before {
  content: ''; position: absolute; left: 4%; right: 4%; bottom: -3px; height: 36%; border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--tc) 75%, transparent), transparent);
}
.pic img {
  position: relative; display: block; width: auto; height: auto; max-width: 130%; max-height: 100%;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.45)); pointer-events: none; -webkit-user-drag: none;
}
.pic.merc { --tc: #b889ff; }
.pic.creep { --tc: #ff6b78; }
.pic.ess { --tc: var(--essence); }
.pic.king { --tc: var(--gold); }

/* token (round badge for the non-character icons) */
.tok {
  --tc: var(--you);
  position: relative; flex: none; width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 23px; color: #f4f7ff;
  background: radial-gradient(circle at 35% 28%, color-mix(in srgb, var(--tc) 55%, #fff 6%), color-mix(in srgb, var(--tc) 38%, #0a0f20) 58%, color-mix(in srgb, var(--tc) 18%, #060912));
  box-shadow: 0 0 0 2px var(--tc), 0 3px 8px rgba(0, 0, 0, 0.5);
}
.tok.merc { --tc: #b889ff; }
.tok.creep { --tc: #ff6b78; }
.tok.goldtok { --tc: var(--gold); }
.tok.esstok { --tc: var(--essence); }

/* ------------------------------------------------------------ game layout */
#game {
  width: min(100vw, 560px); height: 100%;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--ink);
}
#hud {
  padding: calc(var(--safe-t) + 8px) 10px 8px;
  background: linear-gradient(180deg, #131b36, #0e1529);
  border-bottom: 1px solid var(--line-soft);
  display: grid; gap: 8px; z-index: 3;
}
.kings { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; }
.king .k-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; margin-bottom: 4px; }
.k-name { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; }
.king.you .k-name { color: var(--you); }
.king.rival .k-name { color: var(--rival); }
.k-hp { font-size: 14px; font-weight: 700; }
.bar { height: 9px; border-radius: 6px; background: #070b17; box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; border-radius: 6px; background: linear-gradient(180deg, #7de8a3, #3fb56c); transition: width 0.25s ease, background 0.25s ease; }
.king.rival .bar i { margin-left: auto; }
.bar i.mid { background: linear-gradient(180deg, #ffd66e, #e0a12e); }
.bar i.low { background: linear-gradient(180deg, #ff8f99, #e04556); }
.king.hurt .bar { animation: hurt 0.35s ease; }
@keyframes hurt { 0%, 100% { box-shadow: inset 0 0 0 1px var(--line); } 40% { box-shadow: inset 0 0 0 1px var(--danger), 0 0 12px rgba(255, 107, 120, 0.8); } }
.wavebox { text-align: center; min-width: 78px; }
.w-num { font-family: var(--font-display); font-weight: 700; font-size: 18px; line-height: 1; color: var(--gold); white-space: nowrap; }
.w-timer { font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 3px; white-space: nowrap; }
.w-timer.soon { color: var(--danger); }
.w-timer.fight { color: var(--rival); }

.res { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; }
.res.tight .pill.inc small, .res.tighter .pill small { display: none; }
.res.tighter .pill { padding: 0 7px; }
.res-gap { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 38px; padding: 0 9px;
  border-radius: 10px; background: var(--surface); border: 1px solid var(--line-soft);
  font-size: 17px; white-space: nowrap; flex: none;
}
.pill b { font-size: 15px; font-weight: 700; }
.pill small { font-size: 12px; color: var(--muted); font-weight: 500; }
.pill.gold { color: var(--gold); }
.pill.ess { color: var(--essence); }
.pill.inc { color: var(--income); }
.pill b { color: var(--text); }
.pill.bump { animation: bump 0.3s ease; }
@keyframes bump { 40% { transform: scale(1.08); } }

/* ------------------------------------------------------------ stage */
#stage { position: relative; overflow: hidden; background: var(--bg); min-height: 0; }
#lane { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#overlay { position: absolute; inset: 0; pointer-events: none; }
#overlay > * , .ov-top > *, .ov-bottom > * { pointer-events: auto; }
.ov-top, .ov-bottom { position: absolute; left: 8px; right: 8px; display: flex; justify-content: space-between; gap: 8px; pointer-events: none !important; }
.ov-top { top: 8px; align-items: flex-start; }
.ov-bottom { bottom: 8px; align-items: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 4px 10px 4px 6px;
  border-radius: var(--r-md); background: rgba(10, 15, 31, 0.82); border: 1px solid var(--line);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  font-size: 13px; text-align: left; min-width: 0; flex: 0 1 auto;
}
.wave-chip .pic { width: 32px; height: 32px; }
#app[data-mode='2v2'] #viewSeg button { padding: 0 8px; }
/* 2v2 on tall phones: four lane buttons share the row, so the wave chip goes compact */
#app[data-mode='2v2'] #stage:not(.gutters) .wave-chip .lg { display: none; }
#app[data-mode='2v2'] #stage:not(.gutters) .wave-chip .sm { display: inline; }
#app[data-mode='2v2'] #stage:not(.gutters) .wave-chip { flex: none; gap: 4px; padding: 4px 7px 4px 4px; }
#app[data-mode='2v2'] #stage:not(.gutters) #viewSeg button { padding: 0 6px; }
#app[data-mode='2v2'] #stage:not(.gutters) .wave-chip .wc-text small { white-space: nowrap; }
.wave-chip .sm { display: none; }
/* short screens: the lane is narrower than the stage, so the chips move into the side gutters */
#stage.gutters .ov-top { left: 5px; right: 5px; top: 6px; }
#stage.gutters #viewSeg { grid-auto-flow: row; width: min(calc(var(--gut) - 10px), 84px); }
#stage.gutters #viewSeg button, #app[data-mode='2v2'] #stage.gutters #viewSeg button { padding: 0; white-space: nowrap; }
#stage.gutters .wave-chip { flex-direction: column; justify-content: flex-start; gap: 2px; width: min(calc(var(--gut) - 10px), 84px); padding: 5px 2px 6px; text-align: center; }
#stage.gutters .wave-chip .pic { display: inline-flex; width: 40px; height: 40px; }
#stage.gutters .wave-chip .wc-text { justify-items: center; }
#stage.gutters .wave-chip .lg { display: none; }
#stage.gutters .wave-chip .sm { display: inline; }
#stage.gutters .wave-chip .wc-text b { font-size: 14px; }
#stage.gutters .wave-chip .types { display: inline-flex !important; }
#stage.gutters #toast { top: 8px; max-width: calc(100% - 2 * var(--gut) - 10px); white-space: normal; border-radius: 14px; padding: 6px 12px; line-height: 1.25; }
#stage.gutters .pop { top: 6px; left: 5px; right: calc(var(--gut) + 4px); width: auto; }
#viewSeg { flex: none; }
.wave-chip .wc-text { display: grid; line-height: 1.15; min-width: 0; }
.wave-chip .wc-text small { font-size: 12px; color: var(--muted); font-weight: 500; }
.wave-chip .wc-text b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wave-chip .types { display: inline-flex; gap: 4px; font-size: 16px; }
.lane-chip { display: grid; gap: 1px; padding: 5px 10px; min-height: 40px; line-height: 1.15; pointer-events: none !important; }
.lane-chip small { font-size: 12px; color: var(--muted); font-weight: 500; }
.lane-chip b { font-size: 14px; }
.lane-chip b.good { color: var(--hp); }
.lane-chip b.warn { color: var(--gold); }
.lane-chip b.bad { color: var(--danger); }
.action { min-width: 108px; min-height: 46px; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5); }
.action.speed { background: rgba(10, 15, 31, 0.86); border-color: var(--line); color: var(--text); box-shadow: none; }

.pop {
  position: absolute; top: 56px; right: 8px; width: min(300px, calc(100% - 16px)); z-index: 4;
  background: rgba(13, 19, 39, 0.96); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 12px; font-size: 13px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}
.pop h3 { margin: 0 0 6px; font-size: 15px; font-weight: 700; }
.pop p { margin: 0 0 6px; color: #d5dbf2; }
.pop p:last-child { margin: 0; }
.pop .row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.pop .row svg { font-size: 16px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.tag svg { font-size: 14px; }

#toast {
  position: absolute; left: 50%; top: 58px; transform: translate(-50%, -6px); opacity: 0;
  max-width: calc(100% - 24px); padding: 8px 14px; border-radius: 999px;
  background: rgba(13, 19, 39, 0.94); border: 1px solid var(--line); font-size: 13px; font-weight: 700; text-align: center;
  transition: opacity 0.18s ease, transform 0.18s ease; pointer-events: none !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: rgba(255, 107, 120, 0.7); color: #ffd0d5; }
#netStatus {
  position: absolute; left: 50%; bottom: 62px; transform: translateX(-50%); z-index: 3;
  padding: 7px 14px; border-radius: 999px; background: rgba(60, 20, 26, 0.94); border: 1px solid rgba(255, 107, 120, 0.7);
  color: #ffd0d5; font-size: 13px; font-weight: 700; white-space: nowrap; pointer-events: none !important;
}
#viewSeg button { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#app[data-mode='2v2'] #stage:not(.gutters) #viewSeg { flex: 0 1 auto; min-width: 0; grid-auto-columns: minmax(0, auto); }
#app[data-mode='2v2'] #stage:not(.gutters) #viewSeg button { max-width: 72px; min-width: 0; }
.action.wait { background: rgba(10, 15, 31, 0.86); border-color: var(--line); color: var(--muted); box-shadow: none; }

#banner {
  position: absolute; left: 50%; top: 24%; transform: translateX(-50%);
  width: min(300px, calc(100% - 32px)); padding: 12px 14px 12px; text-align: center;
  background: rgba(11, 16, 32, 0.93); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  animation: bannerIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes bannerIn { from { opacity: 0; transform: translateX(-50%) translateY(10px) scale(0.96); } }
#banner .b-kicker { font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
#banner h3 { margin: 2px 0 6px; font-family: var(--font-display); font-weight: 700; font-size: 24px; line-height: 1.1; color: var(--gold); }
#banner h3.bad { color: var(--danger); }
#banner .b-line { font-size: 13px; color: #d5dbf2; margin-top: 3px; }
#banner .b-line.warn { color: #ffc0c6; font-weight: 700; }
#banner .b-rows { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; text-align: left; font-size: 13px; margin-top: 6px; }
#banner .b-rows span:nth-child(even) { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--gold); }
#banner .b-rows .tot { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 2px; font-weight: 700; color: var(--text); }

/* ------------------------------------------------------------ panel */
#panel {
  background: linear-gradient(180deg, #10172e, #0c1224);
  border-top: 1px solid var(--line-soft);
  padding: 8px 8px calc(var(--safe-b) + 6px);
  display: grid; gap: 8px; z-index: 3; min-width: 0;
}
#detail {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center;
  height: 98px; padding: 6px 10px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line-soft); overflow: hidden;
}
.d-main { display: flex; gap: 10px; align-items: center; min-width: 0; }
.d-main > .pic { width: 54px; height: 62px; }
.d-main.act > .tok, .d-main.act > .pic { display: none; }
.d-text { flex: 1; min-width: 0; }
.d-title { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
.d-title .tier { font-size: 12px; color: var(--gold); font-weight: 700; }
.d-title .rng { font-size: 12px; color: var(--muted); font-weight: 500; }
.d-title .inc { font-size: 12px; color: var(--income); font-weight: 700; }
.d-desc .q { color: var(--gold); }
.d-meta { display: flex; flex-wrap: wrap; gap: 0 8px; height: 17px; font-size: 12px; line-height: 17px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; }
.d-meta > span { display: inline-flex; align-items: center; gap: 3px; height: 17px; }
.d-meta .tag { color: var(--text); }
.d-desc { font-size: 12px; color: #cdd4ee; margin-top: 2px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.d-hint { font-size: 13px; color: #d5dbf2; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.d-hint b { color: var(--gold); }
.d-actions { display: grid; gap: 5px; }
.d-actions .btn { min-height: 30px; padding: 0 10px; font-size: 14px; border-radius: 9px; gap: 5px; white-space: nowrap; }
.d-actions.one .btn { min-height: 52px; min-width: 68px; padding: 3px 10px; flex-direction: column; gap: 0; line-height: 1.15; }
.d-actions.one .btn .c { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.d-actions .btn svg { font-size: 14px; }
.d-actions .btn.sell { color: #ffd0d5; }

#cards { display: grid; gap: 6px; height: 96px; grid-auto-rows: minmax(0, 1fr); }
#cards.build { grid-template-columns: repeat(5, minmax(0, 1fr)); }
#cards.send { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: 1fr 1fr; }
#cards.realm { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 5px 1px; border-radius: var(--r-md); min-width: 0; min-height: 0; overflow: hidden;
  background: var(--surface-2); border: 1.5px solid var(--line);
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.1s ease, opacity 0.15s ease;
}
.card:active { transform: scale(0.96); }
.card[aria-pressed='true'] { border-color: var(--gold); background: #2a3157; box-shadow: 0 0 0 2px rgba(242, 193, 78, 0.22), 0 6px 16px rgba(0, 0, 0, 0.4); }
.card .nm { font-size: 12px; font-weight: 700; line-height: 1.12; letter-spacing: -0.01em; text-align: center; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .cost { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card .cost svg { font-size: 13px; }
.card .cost.g { color: var(--gold); }
.card .cost.e { color: var(--essence); }
.card .cost.i { color: var(--income); }
.card.cant { opacity: 0.5; }
.card.cant .cost.g, .card.cant .cost.e { color: var(--danger); }
.card.locked { opacity: 0.38; }
.card .tok { width: 34px; height: 34px; font-size: 21px; }
.card .pic { width: 100%; height: 38px; }
#cards.build .card { padding-top: 3px; padding-bottom: 3px; }
#cards.build .card .pic { height: 35px; }
.card .ctr { position: absolute; top: 4px; right: 4px; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; }
.card .ctr svg { width: 9px; height: 9px; }
.card .ctr.up { background: rgba(95, 211, 138, 0.22); color: var(--hp); }
.card .ctr.down { background: rgba(255, 107, 120, 0.2); color: var(--danger); }
.card .lvl { position: absolute; top: 4px; right: 6px; font-size: 12px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
#cards.send .card { flex-direction: row; justify-content: flex-start; gap: 7px; padding: 3px 7px; }
#cards.send .card .pic { width: 34px; height: 36px; }
#cards.send .card .col { display: grid; min-width: 0; text-align: left; gap: 1px; }
#cards.send .card .nm { text-align: left; -webkit-line-clamp: 1; white-space: nowrap; text-overflow: ellipsis; display: block; }
#cards.send .card .costs { display: flex; gap: 8px; }
#cards.send .card .nm { font-size: 13px; }
#cards.realm .card { gap: 4px; }
#cards.realm .card .tok { width: 36px; height: 36px; }
#cards.realm .card .pic { height: 40px; }

#tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#tabs button {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 44px; border-radius: var(--r-md); font-weight: 700; font-size: 14px; color: var(--muted);
  background: transparent; border: 1px solid transparent;
}
#tabs button svg { font-size: 18px; }
#tabs button[aria-selected='true'] { color: var(--text); background: var(--surface-2); border-color: var(--line); }
#tabs button[aria-selected='true'] svg { color: var(--gold); }
.badge { position: absolute; top: 5px; right: 10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--essence); color: #1a0f3a; font-size: 12px; font-weight: 700; font-style: normal; display: grid; place-items: center; }

/* ------------------------------------------------------------ dialogs */
.dlg {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(4, 7, 16, 0.74); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } }
.dlg-card {
  width: min(100%, 420px); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: linear-gradient(180deg, #17203f, #10172e); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 20px 18px 18px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  animation: rise 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
@keyframes rise { from { transform: translateY(14px) scale(0.97); opacity: 0; } }
.dlg-card h2 { font-family: var(--font-display); font-weight: 700; font-size: 28px; line-height: 1.1; color: var(--gold); margin-bottom: 12px; text-align: center; }
.how { list-style: none; display: grid; gap: 11px; }
.how li { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: start; font-size: 14px; color: #d5dbf2; }
.how li .ic-slot { width: 34px; height: 34px; border-radius: 10px; background: var(--surface-3); align-items: center; justify-content: center; font-size: 20px; color: var(--gold); }
.how li b { color: var(--text); }
.how-win { margin: 14px 0; font-size: 14px; font-weight: 700; text-align: center; color: var(--text); }
.dlg-card > .btn { width: 100%; }
.menu-list { display: grid; gap: 8px; }
.menu-list .btn { width: 100%; }
.credits { margin-top: 14px; font-size: 12px; color: var(--faint); line-height: 1.4; text-align: center; -webkit-user-select: text; user-select: text; }
.result .dlg-card { text-align: center; }
.result-icon { width: 64px; height: 64px; margin: 0 auto 8px; border-radius: 50%; display: grid; place-items: center; font-size: 36px; background: rgba(242, 193, 78, 0.14); color: var(--gold); box-shadow: 0 0 0 2px rgba(242, 193, 78, 0.4); }
.result-icon.char { width: 96px; height: 104px; border-radius: 0; background: none; box-shadow: none; }
.result-icon.char .pic { width: 96px; height: 104px; }
.result.lost .result-icon:not(.char) { background: rgba(255, 107, 120, 0.12); color: var(--danger); box-shadow: 0 0 0 2px rgba(255, 107, 120, 0.4); }
.result.lost h2 { color: var(--danger); }
.result h2 { margin-bottom: 4px; }
#resultSub { color: #d5dbf2; font-size: 14px; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.stats div { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 9px 4px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* tall phones have room for bigger portraits on the cards */
@media (min-height: 760px) and (max-aspect-ratio: 1/1) {
  #cards { height: 110px; }
  #cards.build .card .pic { height: 44px; }
  #cards.realm .card .pic { height: 48px; }
  #cards.send .card .pic { width: 38px; height: 42px; }
}
/* ------------------------------------------------------------ short phones */
@media (max-height: 700px) and (max-aspect-ratio: 1/1) {
  #hud { gap: 5px; padding-top: calc(var(--safe-t) + 5px); padding-bottom: 5px; }
  .king .k-top { margin-bottom: 2px; }
  .bar { height: 7px; }
  .w-timer { margin-top: 1px; }
  .pill, .icon-btn { height: 32px; }
  .icon-btn { width: 36px; }
  #panel { gap: 6px; padding-top: 6px; }
  .ov-top { top: 4px; }
  .ov-bottom { bottom: 6px; }
  .seg.small button { min-height: 30px; }
  .chip { min-height: 36px; padding-top: 2px; padding-bottom: 2px; }
  #detail { height: 82px; }
  .d-desc { -webkit-line-clamp: 2; }
  #cards { height: 86px; }
  #tabs button { min-height: 38px; }
  .card { gap: 2px; padding-top: 3px; padding-bottom: 3px; }
  .card .tok { width: 28px; height: 28px; font-size: 18px; }
  .card .pic { height: 29px; }
  #cards.build .card { padding-top: 2px; padding-bottom: 2px; }
  #cards.build .card .pic { height: 28px; }
  #cards.send .card .pic { height: 34px; }
  #cards.realm .card .tok { width: 32px; height: 32px; }
  #cards.realm .card .pic { height: 34px; }
  .d-main > .pic { width: 48px; height: 56px; }
  .setup { padding: 12px; }
  .faction .pic { height: 44px; }
  .faction-blurb { margin-bottom: 8px; }
  .result-icon.char, .result-icon.char .pic { width: 80px; height: 84px; }
}
@media (max-width: 384px), (min-aspect-ratio: 1/1) and (min-width: 640px) and (max-width: 840px) {
  #detail { gap: 8px; padding-left: 8px; padding-right: 8px; }
  .d-meta { gap: 0 6px; }
  .d-actions .btn { padding: 0 8px; }
  .card .nm { letter-spacing: -0.03em; }
  #cards.send .card { gap: 5px; padding: 3px 5px; }
  #cards.send .card .pic { width: 30px; }
  #cards.send .card .costs { gap: 5px; }
  #app[data-mode='2v2'] #viewSeg button { padding: 0 7px; }
  #app[data-mode='2v2'] #stage:not(.gutters) .wave-chip .types { display: none; }
}
@media (max-width: 359px) {
  .pill small { display: none; }
  .k-name { letter-spacing: 0; }
  .k-name .kx { display: none; }
  #detail { gap: 6px; }
  .d-meta .tag svg { display: none; }
  .d-actions .btn { padding: 0 6px; }
  #cards { gap: 4px; }
  #cards.send .card .pic { display: none; }
}

/* ------------------------------------------------------------ wide / landscape */
@media (min-aspect-ratio: 1/1) and (min-width: 640px) {
  #game {
    width: min(100vw, 1240px);
    grid-template-columns: minmax(0, 1fr) clamp(360px, 46vw, 430px);
    grid-template-rows: auto minmax(0, 1fr);
  }
  #stage { grid-column: 1; grid-row: 1 / span 2; }
  #hud { grid-column: 2; grid-row: 1; border-left: 1px solid var(--line-soft); }
  #panel { grid-column: 2; grid-row: 2; border-left: 1px solid var(--line-soft); border-top: 0; align-content: start; overflow-y: auto; }
  #tabs { order: -1; }
  .title-body { justify-content: flex-start; gap: 28px; }
  .brand { margin-top: 0; }
  .setup { margin-top: auto; margin-bottom: auto; }
}
@media (min-aspect-ratio: 1/1) and (min-width: 640px) and (min-height: 620px) {
  #panel { gap: 12px; padding: 14px; }
  #detail { height: 96px; padding: 10px 12px; }
  .d-desc { -webkit-line-clamp: 3; }
  #cards { height: auto; }
  #cards.build { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 104px; }
  #cards.send { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: none; grid-auto-rows: 58px; }
  #cards.realm { grid-auto-rows: 116px; }
  .card .tok { width: 40px; height: 40px; font-size: 25px; }
  .card .pic { height: 50px; }
  #cards.send .card .pic { width: 40px; height: 44px; }
  #cards.realm .card .pic { height: 52px; }
}

/* narrow battlefield: very small phones and small landscape phones */
@media (max-width: 359px), (min-aspect-ratio: 1/1) and (min-width: 640px) and (max-width: 760px) {
  .seg.small button { padding-left: 8px; padding-right: 8px; }
  .wave-chip { padding-left: 10px; }
  .wave-chip .pic { display: none; }
  .wave-chip .wc-text small { white-space: nowrap; }
  .action { min-width: 0; padding-left: 12px; padding-right: 12px; }
  .action svg { display: none; }
  .lane-chip { padding-left: 8px; padding-right: 8px; }
}

/* landscape phones: title beside the setup card instead of above it */
@media (min-aspect-ratio: 1/1) and (min-width: 640px) and (max-height: 560px) {
  .title-body { flex-direction: row; align-items: flex-start; justify-content: center; gap: 24px; padding-top: calc(var(--safe-t) + 10px); padding-bottom: calc(var(--safe-b) + 10px); }
  .brand { flex: 0 1 300px; margin: auto 0; }
  .brand h1 { font-size: clamp(40px, 7vw, 60px); }
  .setup { margin: auto 0; padding: 10px 12px; }
  .setup h2 { margin-bottom: 5px; }
  .faction { padding-top: 5px; padding-bottom: 4px; }
  .faction .pic { height: 40px; }
  .faction-blurb { min-height: 0; margin: 6px 2px 8px; }
  .mode-blurb { margin-top: 5px; }
  .title-actions { margin-top: 10px; }
  .title-actions .btn.big, .title-actions .btn.ghost { min-height: 46px; }
  .fine { margin-top: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
