/* Super Smash Pepes — Saturday-Morning Cartoon Sticker Arcade & Dual-Joystick Mobile Styling */
:root {
  --ink: #141416;
  --obsidian: #0d101a;
  --cream: #fff7e0;
  --gold: #ffd54f;
  --crimson: #ff3b30;
  --crimson-cta: #d9261c;
  --leaf: #6ab023;
  --sky: #29b6f6;
  --emerald: #00e676;
  --panel: rgba(255, 247, 224, 0.97);
  --shadow: 0 0.34em 0 var(--ink);
  --font: "Fredoka", "Rubik", "Arial Rounded MT Bold", "Chalkboard SE", "Comic Sans MS", "Trebuchet MS", "Inter", "Segoe UI", system-ui, sans-serif;
  --u: clamp(14px, 1.45vmin + 0.35vw, 20px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: #0d2a4a;
  font-family: var(--font);
  font-size: var(--u);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  font-variant-numeric: tabular-nums;
}

canvas#gl, canvas#hud {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
canvas#hud { pointer-events: none; z-index: 2; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; background: #0d2a4a; color: var(--cream); font-size: 1.4rem; z-index: 99; }

#ui { position: fixed; inset: 0; z-index: 7; pointer-events: none; font-size: var(--u); }
#ui > * { pointer-events: auto; }

/* ------------------------------------------------------------ screens */
.screen {
  position: absolute;
  inset: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding:
    max(14px, calc(env(safe-area-inset-top, 0px) + 10px))
    max(20px, calc(env(safe-area-inset-right, 0px) + 16px))
    max(22px, calc(env(safe-area-inset-bottom, 0px) + 14px))
    max(20px, calc(env(safe-area-inset-left, 0px) + 16px));
  gap: 1.3em;
  animation: screenIn 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.screen.dim { background: radial-gradient(ellipse at center, rgba(10, 30, 60, 0.28), rgba(5, 15, 35, 0.78)); }
.screen.scrim { background: rgba(6, 16, 36, 0.68); backdrop-filter: blur(6px); }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px) scale(0.96); } to { opacity: 1; transform: none; } }

.logo { text-align: center; line-height: 0.9; margin: 0; text-transform: uppercase; letter-spacing: 0.02em; }
.logo .top {
  display: block;
  font-size: clamp(22px, 2.3em, 44px);
  color: var(--cream);
  -webkit-text-stroke: 0.11em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.13em 0 var(--ink);
  transform: rotate(-2.5deg);
}
.logo .main {
  display: block;
  font-size: clamp(46px, 5.8em, 112px);
  color: var(--gold);
  -webkit-text-stroke: 0.095em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.07em 0 var(--crimson), 0 0.15em 0 var(--ink), 0 0.22em 0.4em rgba(0,0,0,0.38);
  transform: rotate(-2.5deg);
}
.logo .main em {
  color: var(--leaf);
  font-style: normal;
  text-shadow: 0 0.07em 0 #3d6a12, 0 0.15em 0 var(--ink), 0 0.22em 0.4em rgba(0,0,0,0.38);
}
.tagline {
  margin: 0;
  color: var(--cream);
  font-size: max(14px, 1.02em);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  text-shadow: 0 2.5px 0 var(--ink), 0 0 10px rgba(0,0,0,0.5);
}

.menu { display: flex; flex-direction: column; gap: 0.72em; width: min(24.5em, 88vw); }
.btn {
  font: inherit;
  font-weight: 800;
  font-size: clamp(16px, 1.22em, 22px);
  min-height: 48px;
  min-width: 48px;
  color: var(--ink);
  background: linear-gradient(180deg, #fffdf5 0%, var(--cream) 100%);
  border: 3.5px solid var(--ink);
  border-radius: 16px;
  padding: 0.48em 1.08em;
  box-shadow: var(--shadow), inset 0 3px 0 rgba(255, 255, 255, 0.75);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  transition: transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.12s ease, background 0.12s;
}
.btn:hover, .btn:focus-visible {
  background: linear-gradient(180deg, #ffe57f 0%, var(--gold) 100%);
  outline: none;
  transform: translateY(-3px) scale(1.02) rotate(-0.6deg);
  box-shadow: 0 0.46em 0 var(--ink), inset 0 3px 0 rgba(255, 255, 255, 0.85);
}
.btn:active {
  transform: translateY(2px) scale(0.98);
  box-shadow: 0 0.12em 0 var(--ink);
}
.btn.primary {
  background: linear-gradient(180deg, #ff5247 0%, var(--crimson-cta) 100%);
  color: #ffffff;
  text-shadow: 0 2px 0 var(--ink);
  box-shadow: var(--shadow), inset 0 3px 0 rgba(255, 255, 255, 0.42);
}
.btn.primary:hover, .btn.primary:focus-visible {
  background: linear-gradient(180deg, #ff665c 0%, #ef352a 100%);
  color: #ffffff;
}
.btn.hero-cta {
  justify-content: space-between;
  padding: 0.52em 1.05em;
}
.btn-label {
  white-space: nowrap;
}
.btn-badge {
  font-size: 14px;
  font-weight: 900;
  background: var(--gold);
  color: var(--ink);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 2px 10px;
  box-shadow: 0 2px 0 var(--ink);
  text-shadow: none;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.btn.accent {
  background: linear-gradient(180deg, #ffe57f 0%, var(--gold) 100%);
  color: var(--ink);
}
.btn.accent:hover, .btn.accent:focus-visible {
  background: linear-gradient(180deg, #fff1a8 0%, #ffe07d 100%);
}
.btn.small { font-size: max(14px, 0.95em); min-height: 44px; padding: 0.4em 0.85em; }

.hint {
  color: var(--cream);
  font-size: max(14px, 0.9em);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 var(--ink);
  text-align: center;
  margin: 0;
  line-height: 1.35;
}
.hint kbd, .kbd, .keys kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.08em 0.42em;
  border: 2.5px solid var(--ink);
  border-radius: 7px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 2.5px 0 var(--ink);
  font: inherit;
  font-weight: 800;
  font-size: max(14px, 0.92em);
  text-align: center;
  text-shadow: none;
}
.hint.blink { animation: blink 1.5s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.45; } }

/* ------------------------------------------------------------ setup screen */
.setup {
  justify-content: space-between;
  gap: 0.7em;
}
.setup h2 {
  margin: 0;
  color: var(--cream);
  font-size: clamp(22px, 1.95em, 36px);
  text-transform: uppercase;
  -webkit-text-stroke: 0.1em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.1em 0 var(--ink);
  letter-spacing: 0.04em;
}
.setup-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 27.5em);
  gap: 1.2em;
  width: min(82em, 96vw);
  flex: 1;
  min-height: 0;
  align-items: center;
}
.card {
  background-color: var(--cream);
  background-image: radial-gradient(rgba(20, 20, 22, 0.06) 1.5px, transparent 1.5px);
  background-size: 14px 14px;
  border: 3.5px solid var(--ink);
  border-radius: 20px;
  box-shadow: var(--shadow), inset 0 4px 0 rgba(255, 255, 255, 0.65);
  padding: 0.95em 1.15em;
}
.rules {
  display: flex;
  flex-direction: column;
  gap: 0.38em;
  max-height: 100%;
  overflow-y: auto;
  touch-action: pan-y;
  padding: 0.72em 0.95em;
}
.rules-list {
  display: flex;
  flex-direction: column;
  gap: 0.16em;
}
.row {
  display: grid;
  grid-template-columns: 6.2em 1fr;
  align-items: center;
  gap: 0.45em;
  padding: 0.08em 0.32em;
  border-radius: 10px;
  outline: none;
}
.row:focus-visible, .row.active { background: rgba(255, 213, 79, 0.64); box-shadow: inset 0 0 0 2.5px var(--ink); }
.row label { font-size: max(14px, 0.9em); font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: #202024; }
.stepper { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 0.35em; }
.stepper .val { text-align: center; font-weight: 800; font-size: max(15px, 1.05em); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step {
  font: inherit;
  font-weight: 900;
  font-size: 16px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  background: linear-gradient(180deg, #fffdf5 0%, var(--cream) 100%);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 2.5px 0 var(--ink);
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
  transition: transform 0.09s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.1s;
}
.step:hover, .step:focus-visible { background: var(--gold); outline: none; transform: scale(1.06); }
.step:active { transform: translateY(2px); box-shadow: none; }

.bio {
  display: flex;
  flex-direction: column;
  gap: 0.26em;
  padding-top: 0.28em;
  border-top: 2.5px dashed rgba(20, 20, 22, 0.22);
}
.bio-head {
  display: flex;
  align-items: center;
  gap: 0.55em;
}
.bio-titles {
  display: flex;
  flex-direction: column;
  gap: 0.06em;
}
.char-sticker {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  filter: drop-shadow(0 3px 0 var(--ink));
  transform: rotate(-4deg);
}
.bio h3 { margin: 0; font-size: clamp(18px, 1.38em, 24px); line-height: 1.05; }
.bio .sub { margin: 0; font-size: max(14px, 0.88em); font-weight: 800; color: #323238; text-transform: uppercase; letter-spacing: 0.05em; }
.bio .stage-tag {
  margin: 0;
  font-size: max(14px, 0.88em);
  font-weight: 800;
  color: #1e3a8a;
  background: rgba(56, 189, 248, 0.24);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 0.18em 0.55em;
  box-shadow: 0 2px 0 var(--ink);
  letter-spacing: 0.02em;
}
.bio p { margin: 0; font-size: max(14px, 0.9em); line-height: 1.26; }
.bio > p:not(.sub):not(.stage-tag) {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bars {
  display: grid;
  grid-template-columns: max-content 1fr max-content 1fr;
  gap: 0.22em 0.55em;
  align-items: center;
  font-size: max(14px, 0.88em);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.bar { height: 12px; border-radius: 999px; border: 2.5px solid var(--ink); background: #e6dcc0; overflow: hidden; }
.bar > i {
  display: block;
  height: 100%;
  background-color: var(--accent, var(--leaf));
  background-image: repeating-linear-gradient(-45deg, rgba(255,255,255,0.28) 0 6px, transparent 6px 12px);
  border-right: 2.5px solid var(--ink);
}
.setup-actions { display: flex; gap: 0.9em; align-items: center; justify-content: center; }

/* ------------------------------------------------------------ pause / victory / controls */
.panel {
  width: min(52em, 94vw);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  gap: 0.78em;
}
.panel h2 { margin: 0; font-size: clamp(20px, 1.85em, 34px); text-transform: uppercase; text-align: center; }
.panel .menu { width: 100%; }
.pause-banner {
  margin: 0 auto;
  background: var(--gold);
  color: var(--ink);
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  padding: 0.35em 0.95em;
  box-shadow: 0 3px 0 var(--ink);
  font-size: max(14px, 0.92em);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
}
.pause-grid { display: grid; grid-template-columns: minmax(13em, 1fr) minmax(16.5em, 1.35fr); gap: 0.95em; align-items: start; }
.pause-grid .menu { gap: 0.48em; }
.pause-grid .btn { font-size: max(15px, 1.04em); min-height: 46px; padding: 0.42em 0.85em; }
.pause-settings {
  display: flex;
  flex-direction: column;
  gap: 0.22em;
  background: rgba(255, 255, 255, 0.62);
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  padding: 0.55em 0.68em;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.8);
}
.pause-settings h4 { margin: 0 0 0.18em; font-size: max(14px, 0.88em); font-weight: 900; text-transform: uppercase; letter-spacing: 0.07em; color: #202024; text-align: center; }
.pause-settings .row { grid-template-columns: 5.5em 1fr; padding: 0.12em 0.28em; }
.pause-settings .stepper .val { font-size: max(14px, 0.96em); }
.assist-note { margin: 0.24em 0 0; font-size: max(14px, 0.88em); line-height: 1.3; color: #26262a; text-align: center; }

.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.68em; align-items: stretch; }
[data-screen="controls"] .panel {
  overflow: hidden;
}
.controls-scroll {
  display: flex;
  flex-direction: column;
  gap: 0.52em;
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  touch-action: pan-y;
  padding-bottom: 0.24em;
}
.controls-scroll > * {
  flex-shrink: 0;
}
[data-screen="controls"] .panel > .menu {
  flex-shrink: 0;
  width: 100%;
  padding-top: 0.22em;
  border-top: 2px dashed rgba(20, 20, 22, 0.2);
}
.combo-recipes-card {
  padding: 0.45em 0.65em;
  gap: 0.24em;
}
.combo-recipes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.42em 0.72em;
  align-items: start;
}
.combo-fighter-col {
  display: flex;
  flex-direction: column;
  gap: 0.2em;
  min-width: 0;
}
.combo-fighter-title {
  font-size: 14px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink);
  border-bottom: 2px dashed rgba(20, 20, 22, 0.22);
  padding-bottom: 0.1em;
}
.combo-recipe {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.12em 0.45em;
  font-size: 14px;
  line-height: 1.22;
  padding: 0.14em 0.36em;
  border-radius: 8px;
  background: rgba(255, 247, 224, 0.84);
  border: 1.8px solid var(--ink);
  box-shadow: 0 2px 0 var(--ink);
}
.recipe-name {
  font-size: 14px;
  font-weight: 900;
  color: var(--crimson-cta);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.recipe-route {
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}
.recipe-route kbd {
  font-size: 14px;
  min-width: 1.4em;
  padding: 0.02em 0.26em;
}
table.moves { width: 100%; border-collapse: collapse; font-size: max(14px, 0.9em); }
table.moves th, table.moves td { text-align: left; padding: 0.32em 0.5em; border-bottom: 1.5px solid rgba(20,20,22,0.18); font-size: max(14px, 0.92em); }
table.moves th { text-transform: uppercase; letter-spacing: 0.05em; color: #2d2d32; }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 0.38em 0.7em; align-items: center; font-size: max(14px, 0.92em); }

.victory { gap: 1.05em; }
.victory .banner {
  font-size: clamp(38px, 4.2em, 78px);
  line-height: 0.95;
  text-transform: uppercase;
  color: var(--gold);
  -webkit-text-stroke: 0.095em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.08em 0 var(--crimson), 0 0.16em 0 var(--ink);
  text-align: center;
  margin: 0;
}
.victory .who { font-size: clamp(18px, 1.45em, 28px); font-weight: 800; color: var(--cream); text-shadow: 0 2.5px 0 var(--ink); margin: 0; text-transform: uppercase; text-align: center; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(10em, 1fr)); gap: 0.9em; width: min(40em, 92vw); }
.stat { text-align: center; }
.stat-head { display: flex; align-items: center; justify-content: center; gap: 0.45em; margin-bottom: 0.35em; }
.stat h4 { margin: 0; font-size: max(16px, 1.12em); text-transform: uppercase; }
.stat dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 0.25em 0.8em; font-size: max(14px, 0.94em); text-align: left; }
.stat dt { color: #323238; text-transform: uppercase; font-size: max(14px, 0.88em); font-weight: 800; letter-spacing: 0.05em; align-self: center; }
.stat dd { margin: 0; font-weight: 900; font-size: max(14px, 0.96em); }

.loading { color: var(--cream); font-size: clamp(18px, 1.35em, 26px); text-shadow: 0 2px 0 var(--ink); text-align: center; }
.loading small { font-size: max(14px, 0.85em); }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 5px solid rgba(255,255,255,0.3); border-top-color: var(--gold); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: absolute;
  left: 50%;
  bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 16px));
  transform: translateX(-50%);
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 0.5em 1.1em;
  box-shadow: var(--shadow);
  font-size: max(14px, 0.95em);
  font-weight: 800;
  pointer-events: none;
  animation: screenIn 0.25s both;
}

/* ------------------------------------------------------------ training panel */
.training-panel {
  position: fixed;
  top: max(12px, calc(env(safe-area-inset-top, 0px) + 10px));
  right: max(14px, calc(env(safe-area-inset-right, 0px) + 12px));
  z-index: 4;
  font-size: max(14px, calc(var(--u) * 0.9));
  background-color: var(--cream);
  background-image: radial-gradient(rgba(20, 20, 22, 0.06) 1.5px, transparent 1.5px);
  background-size: 14px 14px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow), inset 0 3px 0 rgba(255, 255, 255, 0.65);
  padding: 0.45em 0.65em;
  width: min(21.5em, 46vw);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  touch-action: pan-y;
  pointer-events: auto;
}
.training-panel[hidden] { display: none; }
.training-panel .lab-toggle {
  font: inherit;
  font-size: 14px;
  font-weight: 900;
  min-height: 44px;
  min-width: 44px;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 8px;
  background: transparent;
  border: 0;
  color: var(--ink);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
}
.training-panel .lab-chevron {
  font-size: 14px;
  font-weight: 900;
  color: var(--ink);
  background: var(--gold);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 2px 7px;
  box-shadow: 0 2px 0 var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
}
.training-panel.collapsed {
  padding: 2px 4px;
  width: auto;
  max-width: min(22.5em, calc(100vw - 88px));
}
.training-panel .lab-body {
  padding-top: 0.28em;
  border-top: 2px dashed rgba(20, 20, 22, 0.2);
}
.training-panel .lab-body[hidden] { display: none; }
body[data-touch-active="true"] .training-panel {
  top: max(64px, calc(env(safe-area-inset-top, 0px) + 60px));
  left: max(12px, calc(env(safe-area-inset-left, 0px) + 10px));
  right: auto;
  max-height: calc(100dvh - max(78px, calc(env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px) + 74px)));
  overflow-y: auto;
  touch-action: pan-y;
}
.training-panel h5 { margin: 0 0 0.28em; font-size: 14px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.06em; color: #2b2b30; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.training-panel .mv { font-size: max(15px, 1.04em); font-weight: 800; margin-bottom: 0.22em; min-height: 1.2em; color: var(--crimson-cta); }
.training-panel .fd { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 0.14em 0.5em; font-size: 14px; font-weight: 700; }
.training-panel .fd span:nth-child(odd) { color: #383840; text-transform: uppercase; letter-spacing: 0.03em; }
.training-panel .hit-log { margin-top: 0.3em; padding-top: 0.25em; border-top: 1.5px solid rgba(20,20,22,0.16); font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.training-panel .lab-tools { margin-top: 0.4em; display: flex; flex-wrap: wrap; gap: 6px; }
.training-panel .chip {
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  min-height: 44px;
  min-width: 44px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 2.5px solid var(--ink);
  background: var(--cream);
  color: var(--ink);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  box-shadow: 0 2.5px 0 var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.training-panel .chip:hover { background: var(--gold); }
.training-panel .chip.on { background: var(--sky); color: #082f49; }
.training-panel .tip { margin-top: 0.4em; font-size: 14px; color: #2d2d34; line-height: 1.3; }

/* ------------------------------------------------------------ dual-joystick touch arcade overlay */
.touch-controls {
  position: static;
  pointer-events: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  font-size: var(--u);
}
.touch-controls[hidden] { display: none; }

/* Top-right utility pills (Pause, Taunt, Fullscreen) */
.touch-top-bar {
  position: fixed;
  top: max(10px, calc(env(safe-area-inset-top, 0px) + 8px));
  right: max(18px, calc(env(safe-area-inset-right, 0px) + 14px));
  z-index: 6;
  display: flex;
  gap: 8px;
  pointer-events: auto;
  touch-action: none;
}
.touch-pill {
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.1;
  height: 44px;
  min-height: 44px;
  min-width: 56px;
  padding: 0 13px;
  border-radius: 13px;
  border: 3px solid var(--ink);
  background: rgba(13, 16, 26, 0.88);
  color: var(--cream);
  box-shadow: 0 3.5px 0 var(--ink);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  touch-action: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.touch-pill.touch-pause {
  border-color: var(--gold);
  color: var(--gold);
}
.touch-pill.pressed, .touch-pill:active {
  transform: translateY(2px) scale(0.96);
  box-shadow: 0 1px 0 var(--ink);
  background: rgba(41, 182, 246, 0.92);
  color: var(--ink);
}

/* Left & Right Screen Halves */
.touch-half {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 3;
  pointer-events: auto;
  touch-action: none;
}
.touch-half.left { left: 0; }
.touch-half.right { right: 0; }

/* Shared Floating Joystick Base Ring & Thumb Nub */
.touch-stick {
  position: absolute;
  border-radius: 50%;
  display: grid;
  place-items: center;
  pointer-events: none;
  touch-action: none;
  transition: box-shadow 0.12s ease, border-color 0.12s ease;
}
.touch-stick .stick-ring {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 247, 224, 0.42);
  pointer-events: none;
}
.touch-stick.move-stick {
  left: max(22px, calc(env(safe-area-inset-left, 0px) + 18px));
  bottom: max(22px, calc(env(safe-area-inset-bottom, 0px) + 18px));
  width: 112px;
  height: 112px;
  background: radial-gradient(circle, rgba(41, 182, 246, 0.26), rgba(13, 16, 26, 0.78));
  border: 3.5px solid rgba(41, 182, 246, 0.9);
  box-shadow: 0 5px 0 var(--ink), 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 0 14px rgba(41, 182, 246, 0.25);
}
.touch-stick.move-stick.active {
  border-color: var(--emerald);
  box-shadow: 0 4px 0 var(--ink), 0 0 22px rgba(0, 230, 118, 0.58), inset 0 0 16px rgba(0, 230, 118, 0.34);
}
.touch-stick.move-stick[data-zone="dash"] {
  border-color: var(--gold);
  box-shadow: 0 4px 0 var(--ink), 0 0 24px rgba(255, 213, 79, 0.72), inset 0 0 16px rgba(255, 213, 79, 0.4);
}
.touch-stick.move-stick[data-zone="jump"] {
  border-color: #40c4ff;
  box-shadow: 0 4px 0 var(--ink), 0 -6px 24px rgba(64, 196, 255, 0.78), inset 0 6px 16px rgba(64, 196, 255, 0.44);
}
.touch-stick.move-stick[data-zone="crouch"] {
  border-color: #ff9100;
  box-shadow: 0 4px 0 var(--ink), 0 6px 22px rgba(255, 145, 0, 0.72), inset 0 -6px 14px rgba(255, 145, 0, 0.4);
}

.touch-nub {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--ink);
  box-shadow: 0 3.5px 0 var(--ink), 0 4px 10px rgba(0, 0, 0, 0.4), inset 0 3px 0 rgba(255, 255, 255, 0.45);
  pointer-events: none;
  transition: transform 0.03s linear;
  line-height: 1;
}
.touch-nub span, .touch-nub small {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.touch-nub.move-nub {
  background: linear-gradient(180deg, #40c4ff, #0288d1);
  color: #ffffff;
  text-shadow: 0 1.5px 0 var(--ink);
}

/* Right Half Dock: C-Stick / Attack Joystick + Ergonomic Satellite Button Arc */
.touch-right-dock {
  position: absolute;
  right: max(18px, calc(env(safe-area-inset-right, 0px) + 14px));
  bottom: max(18px, calc(env(safe-area-inset-bottom, 0px) + 14px));
  width: 192px;
  height: 176px;
  pointer-events: none;
}
.touch-stick.c-stick {
  right: max(22px, calc(env(safe-area-inset-right, 0px) + 18px));
  bottom: max(22px, calc(env(safe-area-inset-bottom, 0px) + 18px));
  width: 102px;
  height: 102px;
  background: radial-gradient(circle, rgba(255, 213, 79, 0.32), rgba(24, 12, 18, 0.82));
  border: 3.5px solid var(--gold);
  box-shadow: 0 5px 0 var(--ink), 0 6px 18px rgba(0, 0, 0, 0.5), inset 0 0 14px rgba(255, 59, 48, 0.35);
}
.touch-stick.c-stick.floating {
  position: absolute;
}
.touch-stick.c-stick.active, .touch-stick.c-stick.tap-pulse {
  border-color: var(--crimson);
  box-shadow: 0 4px 0 var(--ink), 0 0 24px rgba(255, 59, 48, 0.72), inset 0 0 16px rgba(255, 213, 79, 0.48);
}

/* 4-Quadrant C-Stick Directional Wedge Arrows (Strictly >= 14px) */
.c-wedge {
  position: absolute;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  color: rgba(255, 247, 224, 0.78);
  text-shadow: 0 2px 0 var(--ink);
  pointer-events: none;
  transition: transform 0.08s ease, color 0.08s ease;
}
.c-wedge.up { top: 3px; left: 50%; transform: translateX(-50%); }
.c-wedge.down { bottom: 3px; left: 50%; transform: translateX(-50%); }
.c-wedge.left { left: 4px; top: 50%; transform: translateY(-50%); }
.c-wedge.right { right: 4px; top: 50%; transform: translateY(-50%); }
.touch-stick.c-stick[data-dir="up"] .c-wedge.up,
.touch-stick.c-stick[data-dir="down"] .c-wedge.down,
.touch-stick.c-stick[data-dir="left"] .c-wedge.left,
.touch-stick.c-stick[data-dir="right"] .c-wedge.right {
  color: var(--gold);
  filter: drop-shadow(0 0 6px rgba(255, 213, 79, 0.98));
}
.touch-stick.c-stick[data-dir="up"] { box-shadow: 0 4px 0 var(--ink), 0 -8px 24px rgba(255, 213, 79, 0.85), inset 0 6px 14px rgba(255, 213, 79, 0.55); border-color: var(--gold); }
.touch-stick.c-stick[data-dir="down"] { box-shadow: 0 4px 0 var(--ink), 0 8px 24px rgba(255, 59, 48, 0.85), inset 0 -6px 14px rgba(255, 59, 48, 0.55); border-color: var(--crimson); }
.touch-stick.c-stick[data-dir="left"] { box-shadow: 0 4px 0 var(--ink), -8px 0 24px rgba(255, 213, 79, 0.85), inset 6px 0 14px rgba(255, 213, 79, 0.55); border-color: var(--gold); }
.touch-stick.c-stick[data-dir="right"] { box-shadow: 0 4px 0 var(--ink), 8px 0 24px rgba(255, 213, 79, 0.85), inset -6px 0 14px rgba(255, 213, 79, 0.55); border-color: var(--gold); }

.touch-nub.c-nub {
  width: 54px;
  height: 54px;
  background: linear-gradient(180deg, #ffd54f 0%, #ff5252 100%);
  color: var(--ink);
}
.touch-nub.c-nub small {
  display: none;
}

.touch-arc {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.tbtn {
  position: absolute;
  width: 50px;
  height: 50px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 900;
  color: var(--ink);
  box-shadow: 0 3.5px 0 var(--ink), 0 4px 10px rgba(0, 0, 0, 0.38), inset 0 2.5px 0 rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  display: grid;
  place-items: center;
  padding: 0;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
}
.tbtn[hidden] { display: none; }
.tbtn span { font-size: 14px; line-height: 1; }
.tbtn.shld {
  left: 2px;
  bottom: 18px;
  background: linear-gradient(180deg, #80deea, #00acc1);
  color: var(--ink);
}
.tbtn.jump {
  left: 14px;
  bottom: 78px;
  background: linear-gradient(180deg, #b3e5fc, #29b6f6);
  color: var(--ink);
}
.tbtn.spec {
  left: 70px;
  bottom: 120px;
  background: linear-gradient(180deg, #ffe082, #ffb300);
  color: var(--ink);
}
.tbtn.grab {
  left: 128px;
  bottom: 114px;
  background: linear-gradient(180deg, #e1bee7, #ab47bc);
  color: #ffffff;
  text-shadow: 0 1.5px 0 var(--ink);
}
.tbtn.ultra {
  left: 48px;
  bottom: 176px;
  width: auto;
  min-width: 78px;
  height: 48px;
  min-height: 48px;
  padding: 0 11px;
  border-radius: 16px;
  border: 3px solid var(--ink);
  background: linear-gradient(180deg, #fff176 0%, #ff9100 52%, #ff1744 100%);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink), 0 0 18px rgba(255, 213, 79, 0.92), inset 0 2.5px 0 rgba(255, 255, 255, 0.75);
  animation: ultraPulse 0.9s ease-in-out infinite alternate;
}
@keyframes ultraPulse {
  from { transform: scale(1) rotate(-2deg); }
  to { transform: scale(1.06) rotate(2deg); }
}
.tbtn.pressed, .tbtn:active {
  transform: translateY(2px) scale(0.94);
  box-shadow: 0 1px 0 var(--ink);
  filter: brightness(1.15);
}

/* Optional Large (+14%) Touch Pad Scale */
.touch-controls[data-scale="large"] .touch-stick.move-stick:not(.floating) {
  transform: scale(1.12);
  transform-origin: bottom left;
}
.touch-controls[data-scale="large"] .touch-right-dock,
.touch-controls[data-scale="large"] .touch-stick.c-stick:not(.floating) {
  transform: scale(1.12);
  transform-origin: bottom right;
}

/* ------------------------------------------------------------ responsive portrait & mobile landscape */
@media (max-width: 920px), (pointer: coarse) {
  .training-panel {
    top: max(64px, calc(env(safe-area-inset-top, 0px) + 60px));
    left: max(12px, calc(env(safe-area-inset-left, 0px) + 10px));
    right: auto;
    max-height: calc(100dvh - max(78px, calc(env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px) + 74px)));
    overflow-y: auto;
    touch-action: pan-y;
  }
}

@media (max-width: 560px) {
  .touch-top-bar {
    left: max(10px, calc(env(safe-area-inset-left, 0px) + 8px));
    right: max(10px, calc(env(safe-area-inset-right, 0px) + 8px));
    gap: 6px;
  }
  .touch-pill {
    min-width: 50px;
    height: 44px;
    min-height: 44px;
    padding: 0 10px;
  }
  .touch-pill.touch-pause {
    margin-right: auto;
  }
  .touch-top-bar [data-t-btn="taunt"] {
    position: absolute;
    top: 50px;
    right: 0;
  }
  .touch-stick.move-stick {
    left: max(12px, calc(env(safe-area-inset-left, 0px) + 10px));
    bottom: max(108px, calc(env(safe-area-inset-bottom, 0px) + 76px));
    width: 102px;
    height: 102px;
  }
  .touch-right-dock {
    right: max(10px, calc(env(safe-area-inset-right, 0px) + 8px));
    bottom: max(108px, calc(env(safe-area-inset-bottom, 0px) + 76px));
    width: 176px;
    height: 168px;
  }
  .touch-stick.c-stick {
    right: max(14px, calc(env(safe-area-inset-right, 0px) + 12px));
    bottom: max(112px, calc(env(safe-area-inset-bottom, 0px) + 80px));
    width: 94px;
    height: 94px;
  }
  .tbtn.shld { left: 0px; bottom: 12px; }
  .tbtn.jump { left: 10px; bottom: 70px; }
  .tbtn.spec { left: 66px; bottom: 114px; }
  .tbtn.grab { left: 124px; bottom: 110px; }
  .tbtn.ultra { left: 48px; bottom: 172px; }
  .training-panel,
  body[data-touch-active="true"] .training-panel {
    top: max(62px, calc(env(safe-area-inset-top, 0px) + 58px));
    left: max(10px, calc(env(safe-area-inset-left, 0px) + 8px));
    right: auto;
    width: min(18.5em, calc(100vw - 108px));
    max-width: calc(100vw - 108px);
    max-height: calc(100dvh - 398px);
  }
  .training-panel.collapsed,
  body[data-touch-active="true"] .training-panel.collapsed {
    padding: 2px 4px;
    width: auto;
    max-width: calc(100vw - 108px);
  }
  .setup { gap: 0.28em; }
  [data-screen="title"] .menu {
    width: min(24.5em, 92vw);
  }
  [data-screen="title"] .btn.hero-cta {
    font-size: 15px;
    padding: 0.44em 0.68em;
    gap: 0.35em;
  }
  [data-screen="title"] .btn.hero-cta .btn-badge {
    padding: 2px 7px;
    font-size: 14px;
  }
  .setup .hint { display: none; }
  .card.rules { padding: 0.42em 0.65em; gap: 0.2em; }
  .rules-list { gap: 0.08em; }
  .row { padding: 0.02em 0.15em; }
  .panel { padding: 0.45em 0.65em; gap: 0.32em; }
  .panel h2 { font-size: 1.25em; line-height: 1.05; }
  .cols, .pause-grid { gap: 0.35em; }
  .pause-settings { padding: 0.28em 0.45em; gap: 0.05em; }
  .pause-settings h4 { margin: 0 0 0.06em; }
  .pause-settings .row { padding: 0.02em 0.12em; }
  .keys { gap: 0.2em 0.45em; line-height: 1.18; }
  .keys kbd { padding: 0.02em 0.28em; }
  [data-screen="pause"] .panel > .hint { display: none; }
}

@media (min-width: 561px) and (max-aspect-ratio: 1/1) {
  .touch-stick.move-stick {
    bottom: max(126px, calc(env(safe-area-inset-bottom, 0px) + 120px));
  }
  .touch-right-dock {
    bottom: max(126px, calc(env(safe-area-inset-bottom, 0px) + 120px));
  }
  .touch-stick.c-stick {
    bottom: max(130px, calc(env(safe-area-inset-bottom, 0px) + 124px));
  }
}

@media (max-width: 780px), (max-aspect-ratio: 1/1) {
  .setup-grid {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .setup-stage-spacer { display: none; }
  .logo .main { font-size: clamp(42px, 4.2em, 76px); }
  .cols, .stats, .pause-grid, .combo-recipes-grid { grid-template-columns: 1fr; }
  .bio > p:not(.sub):not(.stage-tag) { display: none; }
  .pause-grid .menu {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.35em;
  }
  .assist-note { display: none; }
}

/* Compact Mobile Landscape (e.g. 844x390) — Zero vertical overflow, full notch safe-area clearance */
@media (max-height: 500px) {
  .screen {
    padding:
      max(4px, calc(env(safe-area-inset-top, 0px) + 4px))
      max(42px, calc(env(safe-area-inset-right, 0px) + 40px))
      max(18px, calc(env(safe-area-inset-bottom, 0px) + 18px))
      max(42px, calc(env(safe-area-inset-left, 0px) + 40px));
    gap: 0.24em;
  }
  .logo { margin-bottom: 0.38em; }
  .logo .top { font-size: 1.28em; }
  .logo .main { font-size: 2.68em; }
  [data-screen="title"] .menu {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(46.5em, 92vw);
    gap: 0.45em;
  }
  [data-screen="title"] .btn {
    font-size: max(14px, 0.98em);
    padding: 0.36em 0.68em;
    gap: 0.35em;
  }
  [data-screen="title"] .btn.hero-cta .btn-badge {
    padding: 2px 7px;
    font-size: 14px;
  }
  .setup h2 { font-size: 1.12em; line-height: 1.05; }
  .setup-grid {
    grid-template-columns: 1fr;
    width: min(64em, 100%);
  }
  .setup-stage-spacer { display: none; }
  .card.rules {
    display: flex;
    flex-direction: column;
    gap: 0.2em;
    padding: 0.3em 0.65em;
  }
  .rules-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.12em 0.65em;
  }
  .row {
    grid-template-columns: 6.0em 1fr;
    gap: 0.45em;
    padding: 0.02em 0.14em;
  }
  .stepper {
    gap: 0.18em;
  }
  .bio {
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    gap: 0.08em 0.7em;
    align-items: center;
    padding-top: 0.16em;
    border-top: 1.5px solid rgba(20, 20, 22, 0.18);
  }
  .bio-head .char-sticker { width: 32px; height: 32px; }
  .bio h3 { font-size: 1.02em; line-height: 1.04; }
  .bio .sub, .bio .stage-tag { line-height: 1.1; }
  .bio .stage-tag { padding: 0.15em 0.5em; margin-top: 0.08em; }
  .bio .bars { grid-column: 2; grid-row: 1 / span 4; gap: 3px 8px; }
  .bio > p:not(.sub):not(.stage-tag) { display: none; }
  .setup-actions .btn { min-height: 44px; padding: 0.18em 0.9em; }
  .setup .hint { display: none; }
  .panel {
    width: min(60em, 100%);
    max-height: calc(100dvh - 24px);
    padding: 0.32em 0.65em;
    gap: 0.22em;
  }
  .panel h2 { font-size: 1.08em; line-height: 1.04; }
  [data-screen="controls"] .cols {
    grid-template-columns: 1.05fr 1fr;
    gap: 0.36em;
  }
  [data-screen="controls"] .cols > .card {
    padding: 0.28em 0.48em;
    gap: 0.16em;
  }
  [data-screen="controls"] .controls-scroll {
    gap: 0.28em;
    padding-bottom: 0.2em;
  }
  [data-screen="controls"] .combo-recipes-card {
    padding: 0.28em 0.52em;
    gap: 0.16em;
  }
  [data-screen="controls"] .combo-recipes-card h4 {
    margin: 0;
    font-size: 14px;
    line-height: 1.06;
  }
  [data-screen="controls"] .combo-recipes-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.22em 0.45em;
  }
  [data-screen="controls"] .combo-fighter-col {
    gap: 0.14em;
  }
  [data-screen="controls"] .combo-recipe {
    padding: 0.08em 0.28em;
  }
  [data-screen="controls"] .pause-settings {
    padding: 0.22em 0.42em;
    gap: 0.04em;
  }
  [data-screen="controls"] .pause-settings h4 { margin: 0; font-size: 14px; line-height: 1.05; }
  [data-screen="controls"] .keys { gap: 0.1em 0.42em; line-height: 1.1; }
  [data-screen="controls"] .keys kbd { padding: 0.02em 0.28em; }
  [data-screen="controls"] .assist-note { display: none; }
  [data-screen="controls"] .panel > .menu { padding-top: 0.16em; }
  [data-screen="controls"] .panel > .menu .btn { min-height: 44px; padding: 0.14em 0.8em; }
  [data-screen="pause"] .pause-grid {
    grid-template-columns: 0.68fr 1.52fr;
    gap: 0.35em;
    align-items: center;
  }
  [data-screen="pause"] .pause-grid .menu {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.24em;
  }
  [data-screen="pause"] .pause-grid .btn { min-height: 44px; padding: 0.14em 0.35em; font-size: 14px; }
  [data-screen="pause"] .pause-settings {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.1em 0.3em;
    padding: 0.26em 0.38em;
  }
  [data-screen="pause"] .pause-settings h4 { grid-column: 1 / -1; margin: 0; }
  [data-screen="pause"] .pause-settings .row { grid-template-columns: 4.4em 1fr; padding: 0.02em 0.06em; gap: 0.18em; }
  [data-screen="pause"] .pause-settings .stepper { gap: 0.12em; }
  [data-screen="pause"] .panel > .hint { display: none; }
  .training-panel,
  body[data-touch-active="true"] .training-panel {
    top: max(10px, calc(env(safe-area-inset-top, 0px) + 8px));
    left: max(14px, calc(env(safe-area-inset-left, 0px) + 12px));
    right: auto;
    width: min(20.5em, 320px);
    max-height: calc(100dvh - 146px);
    padding: 0.35em 0.55em;
  }
  .training-panel.collapsed,
  body[data-touch-active="true"] .training-panel.collapsed {
    padding: 2px 4px;
    width: auto;
    max-width: 320px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .screen, .toast, .tbtn.ultra { animation: none; }
  .hint.blink { animation: none; }
}
