/* Pocket Brawlers — UI shell (Platform/UI). Retro arcade styling. */
@font-face { font-family: 'PB Display'; src: url(../fonts/pb-display.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'PB Pixel'; src: url(../fonts/pb-pixel-400.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'PB Pixel'; src: url(../fonts/pb-pixel-700.woff2) format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --bg: #0b0716;
  --ink: #fff7ec;
  --muted: #c9bfe3;
  --hot: #ff3d5a;
  --gold: #ffcc33;
  --orange: #ff8a1f;
  --cool: #22d3ee;
  --lime: #a6ff3d;
  --violet: #8b5cf6;
  --panel: #1a1030;
  --panel2: #251846;
  --edge: #000;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --display: 'PB Display', Impact, 'Arial Black', system-ui, sans-serif;
  --pixel: 'PB Pixel', ui-monospace, Menlo, Consolas, monospace;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: var(--pixel);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: none;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; }
[hidden] { display: none !important; }
#app { position: fixed; inset: 0; overflow: hidden; background: var(--bg); }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
canvas.px { image-rendering: pixelated; }

/* ------------------------------------------------------------- screens */
.screen {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 16px) calc(var(--sab) + 12px) calc(var(--sal) + 16px);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(139, 92, 246, 0.38), transparent 60%),
    radial-gradient(90% 80% at 50% 110%, rgba(255, 61, 90, 0.3), transparent 60%),
    linear-gradient(rgba(11, 7, 22, 0.74), rgba(11, 7, 22, 0.9));
  overflow-y: auto; touch-action: pan-y;
  animation: fade-in .18s ease-out;
}
.screen:not(#scr-title):not(.dim):not(.vs-screen) { background-color: rgba(11, 7, 22, 0.6); }
/* subtle CRT scanlines over menus */
.screen::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: repeating-linear-gradient(rgba(0, 0, 0, .22) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}
.screen > * { position: relative; z-index: 1; }
.screen.dim { background: rgba(8, 5, 18, 0.72); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: min(820px, 100%);
  max-height: 100%;
  margin: auto;
  display: flex; flex-direction: column; gap: 10px;
}
.panel.modal {
  width: min(460px, 100%);
  padding: 20px 22px 22px;
  background: var(--panel);
  border: 4px solid var(--edge);
  border-radius: 8px;
  box-shadow: 8px 8px 0 var(--edge), inset 0 0 0 3px var(--violet);
  text-align: center; align-items: center;
  animation: pop .22s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(.88); opacity: 0; } to { transform: none; opacity: 1; } }

h2 {
  margin: 0; font: 400 clamp(24px, 6vmin, 38px)/1 var(--display); letter-spacing: .02em; text-transform: uppercase;
  color: var(--gold); text-shadow: 3px 3px 0 var(--edge), -1px -1px 0 var(--edge), 1px -1px 0 var(--edge), -1px 1px 0 var(--edge);
}
h3 { margin: 8px 0 4px; font: 700 16px var(--pixel); letter-spacing: .08em; text-transform: uppercase; color: var(--gold); text-shadow: 2px 2px 0 var(--edge); }
.hint { margin: 0; color: var(--muted); font: 700 16px/1.35 var(--pixel); }
.small { margin: 0; color: var(--muted); font: 400 14px/1.35 var(--pixel); }
.small b { color: var(--ink); }

.bar { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.bar h2 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 2px 4px 4px 2px; }
.back-btn {
  width: 52px; height: 48px; flex: none; border-radius: 6px;
  border: 4px solid var(--edge); background: var(--panel2); color: var(--ink);
  font: 900 34px/1 var(--font); padding-bottom: 4px; cursor: pointer;
  box-shadow: 0 4px 0 var(--edge);
}
.back-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }

/* ------------------------------------------------------------- buttons */
.menu { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
.menu.col { flex-direction: column; align-items: stretch; width: 100%; }
.btn {
  --c1: #ffffff; --c2: #cfc6ea; --txt: #160c2a;
  position: relative; min-height: 60px; min-width: 150px; padding: 0 24px;
  border: 4px solid var(--edge); border-radius: 8px; cursor: pointer;
  background: linear-gradient(180deg, var(--c1) 0 50%, var(--c2) 50% 100%);
  color: var(--txt);
  box-shadow: 0 6px 0 var(--edge), inset 0 -5px 0 rgba(0,0,0,.22), inset 0 4px 0 rgba(255,255,255,.55);
  font: 700 24px/1 var(--pixel); letter-spacing: .04em; text-transform: uppercase;
  transition: transform .05s, box-shadow .05s, filter .1s;
}
.btn > span { display: inline-block; }
.btn:active, .btn.pressed { transform: translateY(5px); box-shadow: 0 1px 0 var(--edge), inset 0 -3px 0 rgba(0,0,0,.22), inset 0 4px 0 rgba(255,255,255,.45); }
.btn:focus-visible { outline: 4px solid var(--gold); outline-offset: 4px; }
.btn:disabled { filter: grayscale(.8) brightness(.7); }
.btn-hot  { --c1: #ffd84d; --c2: #ff9a1f; --txt: #2a0a00; }
.btn-cool { --c1: #8af5ff; --c2: #34b6ff; --txt: #04122a; }
.btn-lime { --c1: #dcff6b; --c2: #6fe03a; --txt: #0e2200; }
.btn-dark { --c1: #3d2f66; --c2: #2a1f4a; --txt: var(--ink); }
.btn-sm { min-height: 48px; min-width: 0; font-size: 18px; padding: 0 16px; }
.link-btn {
  background: none; border: 0; color: var(--muted); font: 700 15px var(--pixel);
  text-decoration: underline; text-underline-offset: 5px; text-decoration-thickness: 2px;
  padding: 12px 10px; min-height: 44px; cursor: pointer;
}
.link-btn:active { color: var(--gold); }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 6px;
  border: 3px solid var(--edge); background: rgba(26, 16, 48, .7); color: var(--ink); cursor: pointer;
  box-shadow: 0 3px 0 var(--edge);
}
.icon-btn svg { fill: currentColor; }

/* ------------------------------------------------------------- title */
.title-wrap { display: flex; align-items: center; justify-content: center; gap: clamp(16px, 5vw, 56px); margin: auto; width: 100%; }
.title-side { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.main-menu { width: clamp(250px, 34vw, 340px); gap: 12px; }
.main-menu .btn { min-height: 62px; font-size: clamp(24px, 3.4vw, 30px); }
.links { display: flex; flex-wrap: wrap; justify-content: center; }
.logo { margin: 0; display: flex; flex-direction: column; align-items: center; line-height: .9; transform: rotate(-5deg); }
.logo-top {
  font: 700 clamp(20px, 4.4vw, 34px) var(--pixel); letter-spacing: .45em; padding-left: .45em;
  color: var(--cool); text-shadow: 3px 3px 0 var(--edge), 0 0 18px rgba(34, 211, 238, .8);
}
.logo-main {
  font: 400 clamp(50px, 9.4vw, 112px)/1 var(--display); letter-spacing: -.01em;
  color: var(--gold);
  background: linear-gradient(180deg, #fff6b0 0 30%, #ffcc33 30% 52%, #ff8a1f 52% 74%, #ff3d5a 74% 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(3px 0 0 #000) drop-shadow(-3px 0 0 #000) drop-shadow(0 3px 0 #000) drop-shadow(0 -3px 0 #000) drop-shadow(6px 6px 0 #7a0f2a);
  animation: logo-in .6s cubic-bezier(.2, 1.5, .4, 1) both;
}
.logo-tag {
  margin-top: 12px; padding: 6px 12px 7px; font: 700 clamp(13px, 2.2vw, 18px) var(--pixel); letter-spacing: .2em;
  color: #1a0a20; background: var(--gold); border: 3px solid var(--edge); box-shadow: 4px 4px 0 var(--hot);
  animation: blink 1.2s steps(1) infinite;
}
@keyframes blink { 50% { opacity: .35; } }
@keyframes logo-in { from { transform: scale(2.2); opacity: 0; } to { transform: none; opacity: 1; } }

/* ------------------------------------------------------------- character select */
.select { width: min(900px, 100%); height: 100%; max-height: 560px; }
.who {
  flex: none; padding: 6px 10px; font: 700 20px var(--pixel); color: #000; background: var(--gold);
  border: 3px solid var(--edge); box-shadow: 3px 3px 0 var(--edge);
}
.who.p2 { background: var(--cool); }
.select-body { flex: 1; min-height: 0; display: flex; gap: 12px; }
.grid { flex: 0 1 auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 8px; width: min(52%, 420px); }
.grid.n9 { grid-template-rows: repeat(3, minmax(0, 1fr)); }
.grid.n9 .t-name small { display: none; }
.tile {
  position: relative; min-height: 0; padding: 4px 4px 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  background: linear-gradient(180deg, #2c1d55, #160d2c); border: 4px solid var(--edge); border-radius: 6px; cursor: pointer;
  box-shadow: 0 4px 0 var(--edge); color: var(--ink); overflow: hidden; font-family: var(--pixel);
}
.tile canvas { flex: 1; min-height: 0; width: 100%; object-fit: contain; image-rendering: pixelated; }
.tile .t-name {
  width: calc(100% + 8px); padding: 4px 2px 5px; text-align: center; font: 700 15px var(--pixel); letter-spacing: .04em;
  background: rgba(0,0,0,.55); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .t-name small { display: block; margin-top: 2px; font: 400 10px var(--pixel); color: var(--muted); letter-spacing: .02em; }
.tile.sel .t-name small { color: #3a2500; }
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.tile.sel { border-color: var(--gold); box-shadow: 0 4px 0 var(--edge), 0 0 0 3px var(--edge), 0 0 22px rgba(255,204,51,.5); background: linear-gradient(180deg, #5a3a1a, #2a140c); }
.tile.sel .t-name { background: var(--gold); color: #000; }
.tile.taken::after {
  content: attr(data-tag); position: absolute; top: 4px; left: 4px; padding: 2px 5px; font: 700 12px var(--pixel);
  background: var(--gold); color: #000; border: 2px solid var(--edge);
}
.tile.sel.p2 { border-color: var(--cool); background: linear-gradient(180deg, #13405a, #0b1a2c); }
.tile.sel.p2 .t-name { background: var(--cool); }

.detail {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px;
  background: var(--panel); border: 4px solid var(--edge); border-radius: 6px; box-shadow: 6px 6px 0 var(--edge), inset 0 0 0 2px #3a2a66;
  overflow-y: auto; touch-action: pan-y; scrollbar-width: none;
}
.detail-head { display: flex; align-items: center; gap: 10px; }
.detail-portrait { width: 72px; height: 72px; flex: none; background: #0d0820; border: 3px solid var(--edge); image-rendering: pixelated; }
.d-name { font: 400 clamp(24px, 4.6vw, 36px)/1 var(--display); color: var(--ink); text-shadow: 3px 3px 0 var(--edge); }
.d-title { margin-top: 4px; font: 700 13px/1.15 var(--pixel); color: var(--gold); }
.d-home { margin-top: 3px; font: 400 12px var(--pixel); color: var(--cool); }
.d-home::before { content: '\2302  '; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center; }
.stats span { font: 700 13px var(--pixel); color: var(--muted); }
.bars { display: flex; gap: 3px; }
.bars i { flex: 1; height: 12px; background: #2a1f4a; border: 2px solid var(--edge); }
.bars i.on { background: linear-gradient(180deg, #ffe680, #ff9a1f); }
.stats .spd i.on { background: linear-gradient(180deg, #b0f7ff, #22a9ee); }
.stats .rng i.on { background: linear-gradient(180deg, #e8ff9a, #6fe03a); }
.d-special { font: 700 13px var(--pixel); color: var(--muted); }
.d-special b { color: var(--hot); font-size: 16px; text-shadow: 1px 1px 0 var(--edge); }
.d-bio { margin: 0; font: 400 13px/1.3 var(--pixel); color: var(--ink); }

.select-foot { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.select-foot .seg { flex: 1; max-width: 420px; margin-right: auto; }
.btn-go { min-width: 180px; font-size: 26px; }
.seg { display: flex; border: 4px solid var(--edge); border-radius: 6px; overflow: hidden; box-shadow: 0 4px 0 var(--edge); }
.seg button {
  flex: 1; min-height: 44px; border: 0; background: var(--panel2); color: var(--muted);
  font: 700 17px var(--pixel); letter-spacing: .04em; cursor: pointer;
}
.seg button + button { border-left: 4px solid var(--edge); }
.seg button.sel { background: var(--cool); color: #04121a; }

/* ------------------------------------------------------------- stage select */
.stage { width: min(900px, 100%); height: 100%; max-height: 560px; }
.stage-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stile {
  position: relative; min-height: 0; padding: 0; overflow: hidden; cursor: pointer;
  border: 4px solid var(--edge); border-radius: 6px; background: #120a24; box-shadow: 0 4px 0 var(--edge); color: var(--ink);
}
.stile canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
.stile .s-name {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 6px 5px; text-align: left;
  font: 700 13px/1.1 var(--pixel); background: rgba(0,0,0,.7);
}
.stile.random { display: grid; place-items: center; background: repeating-linear-gradient(45deg, #2a1d4f 0 12px, #1c1238 12px 24px); }
.stile.random b { font: 400 54px/1 var(--display); color: var(--gold); text-shadow: 4px 4px 0 var(--edge); }
.stile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.stile.sel { border-color: var(--gold); box-shadow: 0 4px 0 var(--edge), 0 0 0 3px var(--edge), 0 0 22px rgba(255,204,51,.5); }
.stile.sel .s-name { background: var(--gold); color: #000; }
.stage-name { margin-right: auto; font: 400 clamp(18px, 3.4vw, 28px) var(--display); color: var(--ink); text-shadow: 3px 3px 0 var(--edge); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* ------------------------------------------------------------- VS splash */
.vs-screen { padding: 0; background: #000; overflow: hidden; }
.vs-side {
  position: absolute; top: 0; bottom: 0; width: 56%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.vs-l { left: 0; background: linear-gradient(135deg, #ff3d5a, #7a0f2a); clip-path: polygon(0 0, 100% 0, 80% 100%, 0 100%); animation: slide-l .35s cubic-bezier(.2, 1.2, .4, 1) both; padding-right: 10%; }
.vs-r { right: 0; background: linear-gradient(135deg, #1d3a9e, #22d3ee); clip-path: polygon(20% 0, 100% 0, 100% 100%, 0 100%); animation: slide-r .35s cubic-bezier(.2, 1.2, .4, 1) both; padding-left: 10%; }
.vs-side canvas { width: min(46vh, 30vw); height: min(46vh, 30vw); image-rendering: pixelated; filter: drop-shadow(6px 6px 0 rgba(0,0,0,.6)); }
.vs-r canvas { transform: scaleX(-1); }
.vs-name { font: 400 clamp(30px, 6.4vw, 64px)/1 var(--display); color: #fff; text-shadow: 4px 4px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000; }
.vs-home { font: 700 clamp(14px, 2.6vw, 20px) var(--pixel); color: #fff; letter-spacing: .12em; text-shadow: 2px 2px 0 #000; }
.vs-tag { font: 700 18px var(--pixel); padding: 3px 10px; background: #000; color: var(--gold); }
.vs-mid {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2;
  font: 400 clamp(70px, 15vw, 150px)/1 var(--display); color: var(--gold);
  text-shadow: 6px 6px 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000;
  animation: vs-in .45s .2s cubic-bezier(.2, 1.8, .4, 1) both;
}
.vs-stage { position: absolute; left: 0; right: 0; bottom: calc(var(--sab) + 10px); text-align: center; z-index: 2; font: 700 16px var(--pixel); color: #fff; text-shadow: 2px 2px 0 #000; }
@keyframes slide-l { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes slide-r { from { transform: translateX(100%); } to { transform: none; } }
@keyframes vs-in { from { transform: translate(-50%, -50%) scale(3); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

/* ------------------------------------------------------------- online / wifi */
.online { width: min(600px, 100%); text-align: center; }
.pane { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.room-label { font: 700 16px var(--pixel); letter-spacing: .2em; color: var(--muted); }
.room-code {
  font: 400 clamp(60px, 18vmin, 110px)/1 var(--display); letter-spacing: .1em; padding-left: .1em;
  color: var(--gold); text-shadow: 5px 5px 0 #000, 0 0 30px rgba(255,204,51,.4);
  -webkit-user-select: text; user-select: text;
}
.row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.status { margin: 0; color: var(--ink); font: 700 16px/1.35 var(--pixel); max-width: 480px; }
.status.big { font-size: 20px; color: var(--gold); text-shadow: 2px 2px 0 #000; }
.status.err { color: #ff8a9b; }
.status.big.err { font-size: 16px; text-shadow: none; }
.radar.done { display: none; }
.fallback { padding: 6px 10px; border: 3px dashed #4a3a7a; }
.fallback b { color: var(--gold); font-size: 18px; letter-spacing: .1em; }
.spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -1px;
  border: 3px solid rgba(255,255,255,.2); border-top-color: var(--cool);
  animation: spin .8s steps(8) infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.radar { position: relative; width: 96px; height: 96px; flex: none; }
.radar i { position: absolute; inset: 0; border: 4px solid var(--lime); border-radius: 50%; opacity: 0; animation: ping 2.4s linear infinite; }
.radar i:nth-child(2) { animation-delay: .8s; }
.radar i:nth-child(3) { animation-delay: 1.6s; }
.radar b { position: absolute; left: 50%; top: 50%; width: 20px; height: 20px; margin: -10px; background: var(--lime); border: 3px solid #000; }
.radar.done i { animation: none; }
@keyframes ping { from { transform: scale(.2); opacity: 1; } to { transform: scale(1); opacity: 0; } }
#join-form { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.join-row { display: flex; gap: 12px; align-items: center; }
.code-input {
  width: 5.6ch; padding: 4px 0 4px .25ch; text-align: center;
  font: 400 52px/1 var(--display); letter-spacing: .2ch; text-transform: uppercase;
  color: var(--gold); background: #0d0820; border: 4px solid var(--edge); border-radius: 6px; outline: none;
  box-shadow: inset 0 0 0 3px #3a2a66, 0 4px 0 var(--edge);
  -webkit-user-select: text; user-select: text; touch-action: manipulation;
}
.code-input:focus { box-shadow: inset 0 0 0 3px var(--cool), 0 4px 0 var(--edge); }
.code-input::placeholder { color: rgba(255,255,255,.14); }

/* ------------------------------------------------------------- how to */
.howto { width: min(860px, 100%); }
.howto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; background: var(--panel); border: 4px solid var(--edge); border-radius: 6px; box-shadow: 6px 6px 0 var(--edge); padding: 8px 18px 14px; }
.howto ul { margin: 0; padding-left: 18px; color: var(--ink); font: 400 14px/1.45 var(--pixel); }
.howto b { color: var(--gold); }
.keys { border-collapse: collapse; font: 700 14px var(--pixel); }
.keys th { text-align: left; color: var(--muted); font-size: 13px; padding: 2px 8px 4px 0; }
.keys td { padding: 3px 10px 3px 0; color: var(--muted); }
kbd {
  display: inline-block; min-width: 24px; padding: 3px 5px; margin: 0 2px 0 0; text-align: center;
  font: 700 13px var(--pixel); color: var(--ink); background: #2b2248; border: 2px solid var(--edge); border-radius: 3px; box-shadow: 0 2px 0 var(--edge);
}

/* ------------------------------------------------------------- match over */
#scr-over { align-items: flex-end; background: linear-gradient(rgba(8,5,18,0) 30%, rgba(8,5,18,.9) 78%); }
#scr-over .panel.modal { width: min(820px, 100%); margin: 0 auto; flex-direction: row; justify-content: space-between; text-align: left; gap: 14px; padding: 10px 14px; }
.over-portrait { width: 96px; height: 96px; flex: none; background: #0d0820; border: 4px solid var(--edge); box-shadow: 0 0 0 3px var(--gold); image-rendering: pixelated; }
#scr-over .over-info { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.over-kicker { font: 700 13px var(--pixel); letter-spacing: .25em; color: var(--muted); }
.over-title { font-size: clamp(28px, 6vmin, 44px); }
.over-title.lose { color: #9fb0ff; }
.quote { margin: 0; font: 700 15px/1.3 var(--pixel); color: var(--ink); }
.quote:not(:empty)::before { content: '“'; color: var(--gold); }
.quote:not(:empty)::after { content: '”'; color: var(--gold); }
.over-btns { flex-wrap: nowrap; flex-direction: column; gap: 10px; }
.over-btns .btn { min-width: 168px; min-height: 52px; font-size: 22px; }

/* ------------------------------------------------------------- in-game chrome */
#pause-btn {
  position: absolute; z-index: 15; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sab) + 10px);
}
@media (orientation: portrait) {
  /* top-right corner of the touch panel (bottom 42%), clear of the HUD combo counter */
  #pause-btn { left: auto; transform: none; bottom: auto; top: calc(58% + 10px); right: calc(var(--sar) + 10px); }
}
#rotate-hint {
  position: absolute; z-index: 16; top: calc(var(--sat) + 70px); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; white-space: nowrap;
  background: rgba(10, 6, 24, .9); border: 3px solid var(--edge); box-shadow: 4px 4px 0 var(--edge);
  font: 700 15px var(--pixel); color: var(--ink); animation: fade-in .3s;
}
@media (orientation: portrait) { #rotate-hint { top: calc(var(--sat) + 112px); } } /* below the pause button */
#rotate-hint svg { color: var(--cool); animation: tilt 1.6s ease-in-out infinite; }
@keyframes tilt { 0%, 30% { transform: none; } 60%, 100% { transform: rotate(-90deg); } }

/* ------------------------------------------------------------- touch controls */
.tc { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
.tc-left, .tc-right { position: absolute; top: 0; bottom: 0; width: 50%; pointer-events: auto; touch-action: none; }
.tc-left { left: 0; }
.tc-right { right: 0; }
.tc-stick { position: absolute; left: 0; top: 0; width: 0; height: 0; transition: opacity .15s; }
.tc-ring {
  position: absolute; left: -64px; top: -64px; width: 128px; height: 128px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.35); background: radial-gradient(rgba(255,255,255,.04), rgba(255,255,255,.12));
}
.tc-knob {
  position: absolute; left: -32px; top: -32px; width: 64px; height: 64px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #c9c0e6 55%, #8b80b5);
  border: 3px solid #000; box-shadow: 0 4px 0 rgba(0,0,0,.5);
}
.tc-stick.idle { opacity: .4; }
.tc-pad {
  position: absolute; right: calc(var(--sar) + 12px); bottom: calc(var(--sab) + 12px);
  width: 244px; height: 192px; transform-origin: 100% 100%;
}
.tc-btn {
  position: absolute; width: 82px; height: 82px; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 15px var(--pixel); letter-spacing: .02em; color: #fff; text-shadow: 2px 2px 0 rgba(0,0,0,.7);
  background: radial-gradient(circle at 35% 28%, rgba(255,255,255,.55), transparent 42%), var(--b);
  border: 4px solid rgba(0,0,0,.75);
  box-shadow: 0 5px 0 var(--be), 0 8px 18px rgba(0,0,0,.35);
  opacity: .8; transition: transform .05s, box-shadow .05s, opacity .05s;
}
.tc-btn.on { transform: translateY(4px) scale(.95); box-shadow: 0 1px 0 var(--be), 0 0 24px var(--b); opacity: 1; }
.tc-LP { left: 0;    bottom: 8px;   --b: #f5b81c; --be: #8f5a00; }
.tc-K  { left: 92px; bottom: 0;     --b: #2f86ff; --be: #13398f; }
.tc-HP { left: 44px; bottom: 100px; --b: #ff3d5a; --be: #8a1024; }
.tc-SP { left: 150px; bottom: 86px; width: 90px; height: 90px; font-size: 13px; --b: #9b5cff; --be: #46208f; }
@media (max-height: 360px) { .tc-pad { transform: scale(.84); } }
@media (min-height: 520px) and (orientation: landscape) { .tc-pad { transform: scale(1.12); } }

/* Portrait: touch controls become a bottom panel; the renderer draws above it (info.safeBottom). */
@media (orientation: portrait) {
  .tc { top: auto; height: 42%;
        background: linear-gradient(rgba(11,7,22,0), rgba(11,7,22,.6) 20%, rgba(11,7,22,.85)); }
  .tc-stick.idle { opacity: .55; }
  .title-wrap { flex-direction: column; gap: 24px; }
  .main-menu { width: min(320px, 100%); }
  .select-body { flex-direction: column; }
  .grid { width: 100%; flex: 0 0 auto; grid-template-rows: none; }
  .grid.n9, .grid.n9.n7 { grid-template-rows: none; }
  .tile { aspect-ratio: 1 / 1.05; }
  .stage-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: none; flex: 0 0 auto; }
  .stile { aspect-ratio: 16 / 10; }
  .select-foot { flex-wrap: wrap; }
  .select-foot .seg { flex-basis: 100%; max-width: none; }
  .btn-go { flex: 1; }
  .select, .stage { height: auto; max-height: none; }
  .howto-grid { grid-template-columns: 1fr; }
  .menu:not(.col):not(.over-btns) { flex-direction: column; align-items: stretch; width: min(320px, 100%); }
  #scr-over .panel.modal { flex-direction: column; text-align: center; align-items: center; }
  .over-btns { flex-direction: row; }
  .over-btns .btn { min-width: 0; }
  .vs-side { width: 100%; height: 56%; }
  .vs-l { top: 0; bottom: auto; clip-path: polygon(0 0, 100% 0, 100% 80%, 0 100%); padding: 0 0 8%; }
  .vs-r { top: auto; bottom: 0; clip-path: polygon(0 20%, 100% 0, 100% 100%, 0 100%); padding: 8% 0 0; }
  .vs-side canvas { width: min(30vh, 60vw); height: min(30vh, 60vw); }
  .join-row { flex-direction: column; }
}

@media (orientation: portrait) {
  .bar h2 { white-space: normal; font-size: clamp(22px, 6.4vw, 34px); }
}
@media (max-width: 430px) { .tile .t-name { font-size: 12px; letter-spacing: 0; } }
/* Narrow portrait phones: shrink the pad a little so PUNCH doesn't touch the idle stick ring. */
@media (orientation: portrait) and (max-width: 430px) { .tc-pad { transform: scale(.86); } }

/* Short portrait phones (iPhone SE 375x667): keep the select screen's OK button on screen. */
@media (orientation: portrait) and (max-height: 760px) {
  .tile { aspect-ratio: auto; }
  .tile canvas { flex: none; height: 52px; }
  .detail { padding: 8px 10px; gap: 5px; }
  .detail-portrait { width: 52px; height: 52px; }
  .bars i { height: 9px; }
  .d-bio { font-size: 12px; line-height: 1.22; }
}

/* Short landscape phones (e.g. 667x375 / 844x390): tighten menus. */
@media (orientation: landscape) and (max-height: 430px) {
  .screen { padding-top: calc(var(--sat) + 8px); padding-bottom: calc(var(--sab) + 10px); }
  .panel { gap: 8px; }
  .bar { min-height: 44px; }
  .back-btn { width: 48px; height: 44px; }
  .btn { min-height: 54px; }
  .btn-go { min-height: 54px; }
  .detail { padding: 8px 10px; gap: 6px; }
  .detail-portrait { width: 60px; height: 60px; }
  .howto-grid { padding: 4px 14px 10px; gap: 12px; }
  .howto ul { font-size: 13px; line-height: 1.38; }
  .panel.modal { padding: 14px 18px 16px; }
  .radar { width: 72px; height: 72px; }
}
@media (orientation: landscape) and (max-height: 430px) and (max-width: 740px) {
  .d-bio { font-size: 12px; line-height: 1.22; }
  .tile .t-name { font-size: 11px; letter-spacing: 0; }
  .detail { gap: 4px; }
  .detail-portrait { width: 48px; height: 48px; }
  .stats { gap: 2px 8px; }
  .stats span { font-size: 11px; }
  .bars i { height: 8px; border-width: 1px; }
  .over-portrait { width: 80px; height: 80px; }
}

/* ============================================================ fighter detail v3: preview + tabs */
.detail { flex-direction: row; gap: 10px; padding: 8px; overflow: hidden; touch-action: auto; }
.preview {
  position: relative; flex: 0 0 auto; width: clamp(96px, 17vw, 168px); align-self: stretch; padding: 0; cursor: pointer;
  border: 3px solid var(--edge); border-radius: 4px; overflow: hidden;
  background: radial-gradient(ellipse 80% 30% at 50% 92%, rgba(255,204,51,.28), transparent 70%), linear-gradient(#2a1c52, #0d0820);
  box-shadow: inset 0 0 0 2px #3a2a66;
}
.preview canvas { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.preview-hint {
  position: absolute; left: 50%; top: 5px; transform: translateX(-50%); padding: 2px 6px;
  font: 700 11px var(--pixel); color: var(--gold); background: #000; animation: blink 1.2s steps(1) infinite; pointer-events: none;
}
.preview:active { filter: brightness(1.2); }
.detail-main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 6px; }
.detail .detail-head { display: block; }
.detail .d-name { font-size: clamp(22px, 4vw, 34px); }
.tabs { display: flex; flex: none; border: 3px solid var(--edge); border-radius: 4px; overflow: hidden; box-shadow: 0 3px 0 var(--edge); }
.tabs button {
  flex: 1; min-height: 44px; padding: 0 4px; border: 0; background: var(--panel2); color: var(--muted); cursor: pointer;
  font: 700 14px var(--pixel); letter-spacing: .02em;
}
.tabs button + button { border-left: 3px solid var(--edge); }
.tabs button.sel { background: var(--gold); color: #000; }
.tab-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; scrollbar-width: thin; scrollbar-color: #4a3a7a transparent; padding-right: 2px; }
.tab-body.more { -webkit-mask-image: linear-gradient(#000 calc(100% - 26px), rgba(0,0,0,.15)); mask-image: linear-gradient(#000 calc(100% - 26px), rgba(0,0,0,.15)); }
.tab-pane { display: flex; flex-direction: column; gap: 6px; }
.p-bio { display: none; }
.tab-pane:not(.on) { display: none; }
.prof { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; }
.prof dt { font: 700 11px/1.35 var(--pixel); color: var(--muted); }
.prof dd { margin: 0; font: 400 13px/1.25 var(--pixel); color: var(--ink); }
.prof dd.rival { color: var(--hot); font-weight: 700; }
.story { margin: 2px 0 0; padding-top: 6px; border-top: 2px dashed #3a2a66; font: 400 13px/1.3 var(--pixel); color: var(--ink); }
.empty { margin: 0; font: 400 13px/1.3 var(--pixel); color: var(--muted); }
.mv {
  display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 6px 8px; text-align: left; cursor: pointer;
  background: #22164a; color: var(--ink); border: 3px solid var(--edge); border-radius: 4px; box-shadow: 0 3px 0 var(--edge);
  font-family: var(--pixel); min-height: 44px;
}
.mv:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--edge); }
.mv.playing { border-color: var(--gold); background: #3a2a14; }
.mv-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.mv-name { font: 700 14px var(--pixel); }
.mv-desc { font: 400 12px/1.25 var(--pixel); color: var(--muted); }
.chips { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.chip {
  display: inline-grid; place-items: center; min-width: 24px; height: 22px; padding: 0 5px;
  font: 700 11px/1 var(--pixel); color: #fff; text-shadow: 1px 1px 0 #000;
  background: #4a3a7a; border: 2px solid var(--edge); border-radius: 4px; box-shadow: 0 2px 0 var(--edge);
}
.chip.lp { background: #f5b81c; color: #2a1600; text-shadow: none; }
.chip.hp { background: #ff3d5a; }
.chip.k  { background: #2f86ff; }
.chip.sp { background: #9b5cff; }
.chip.dir { background: #efe9ff; padding: 0 3px; }
.chip.dir svg { width: 14px; height: 14px; fill: #000; }
.chip.txt { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); text-shadow: none; padding: 0 2px; min-width: 0; }
.plus { font: 700 12px var(--pixel); color: var(--muted); }

.tile .t-name.long { font-size: 12px; letter-spacing: -.06em; padding-left: 0; padding-right: 0; }
@media (orientation: landscape) and (max-height: 430px) {
  .grid { width: min(33%, 290px); }
  /* not enough height for stats + bio: Stats shows the numbers, the bio leads the Profile tab */
  #d-bio { display: none; }
  .p-bio { display: block; margin: 0; font: 400 12px/1.25 var(--pixel); color: var(--ink); }
  .tile .t-name.long { font-size: 10px; }
  .preview { width: clamp(150px, 26vw, 240px); }
  .tabs button { min-height: 38px; font-size: 13px; }
  .detail .d-title { font-size: 12px; }
  .mv { padding: 4px 6px; gap: 2px; min-height: 40px; }
  .mv-name { font-size: 13px; }
  .mv-desc { font-size: 11px; }
}
@media (orientation: landscape) and (max-height: 430px) and (max-width: 740px) {
  .grid { width: min(33%, 224px); gap: 6px; }
  .tile .t-name { font-size: 10px; }
  .tile .t-name small { font-size: 8px; letter-spacing: -.02em; }
  .tile .t-name.long { font-size: 8px; }
  .preview { width: 150px; }
  .detail { gap: 8px; }
  .detail .d-name { font-size: 22px; }
  .detail .d-title, .detail .d-home { font-size: 11px; margin-top: 2px; }
  .tabs button { font-size: 12px; }
  .prof dd, .story { font-size: 12px; }
}
/* Portrait: one row of small tiles, detail fills the rest (internal scroll, nothing clips). */
@media (orientation: portrait) {
  .select { height: 100%; max-height: none; }
  .grid { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: none; gap: 5px; }
  .grid.n9.n7 { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
  .grid.n9.n7.n8 { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; }
  .grid.n9, .grid.n9.n7 { grid-template-rows: none; }
  .tile { aspect-ratio: auto; padding: 2px 2px 0; border-width: 3px; }
  .tile canvas { flex: none; height: clamp(44px, 12vw, 72px); }
  .tile .t-name { display: none; }
  .tile.taken::after { font-size: 9px; top: 1px; left: 1px; padding: 1px 3px; }
  .select-body { min-height: 0; }
  .detail {
    flex: 1; min-height: 0; display: grid; gap: 8px 10px;
    grid-template-columns: clamp(130px, 40vw, 230px) minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "pv head" "tabs tabs" "body body";
  }
  .detail-main { display: contents; }
  .preview { grid-area: pv; width: auto; height: clamp(130px, 23vh, 240px); }
  .detail .detail-head { grid-area: head; align-self: center; }
  .tabs { grid-area: tabs; }
  .tab-body { grid-area: body; }
}
/* Tall portrait phones: full-width live preview (≥ 300px tall) above the name. */
@media (orientation: portrait) and (min-height: 780px) {
  .detail { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto minmax(0, 1fr); grid-template-areas: "pv" "head" "tabs" "body"; }
  .preview { height: clamp(220px, 30vh, 340px); }
  .detail .detail-head { text-align: left; }
}

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