:root {
  color-scheme: dark;
  --ink: #f7f1e2;
  --muted: #cbbfa6;
  --panel: rgba(35, 31, 33, 0.82);
  --panel-2: rgba(54, 48, 50, 0.72);
  --line: rgba(212, 185, 127, 0.35);
  --gold: #e4c98a;
  --red: #e16c5f;
  --green: #8cd086;
  --blue: #78c2ff;
  --shadow: rgba(0, 0, 0, 0.34);
  --glass: rgba(255, 244, 225, 0.08);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top, rgba(210, 172, 95, 0.16), transparent 28%),
    radial-gradient(circle at 20% 20%, rgba(117, 143, 177, 0.14), transparent 24%),
    linear-gradient(180deg, #121317, #090a0d 60%, #12161d);
  color: var(--ink);
}

#app {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.profile-panel,
.result-overlay {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

button {
  font: inherit;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #fff3a6;
  outline-offset: 3px;
}

.screen {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 20px;
}

.start-screen,
.settings-screen {
  min-height: 100vh;
  display: grid;
  align-content: center;
}

.start-layout,
.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
}

.start-panel,
.settings-card {
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(39, 32, 31, 0.92), rgba(14, 16, 22, 0.84));
  box-shadow: 0 24px 70px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.start-panel {
  padding: 26px;
}

.start-panel-main h1,
.settings-screen h1 {
  margin: 0 0 10px;
}

.start-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 220px);
  gap: 10px;
  margin: 22px 0 14px;
}

.asset-status {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #f2e3b6;
  font-size: 13px;
}

.asset-status.ready {
  color: #d6f4c8;
  border-color: rgba(140, 208, 134, 0.28);
}

.start-feature-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.feature-card {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.feature-card strong {
  display: block;
  margin-bottom: 8px;
  color: #fff1bf;
}

.feature-card span,
.start-note,
.settings-list li {
  color: var(--muted);
  line-height: 1.6;
  font-size: 13px;
}

.sprite-gallery {
  display: grid;
  gap: 12px;
}

.sprite-card {
  margin: 0;
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.sprite-card img {
  display: block;
  width: 100%;
  max-width: 220px;
  margin: 0 auto 10px;
  image-rendering: pixelated;
}

.sprite-card figcaption {
  color: #f0ddb1;
  text-align: center;
  font-size: 13px;
}

.start-note {
  margin-top: 12px;
}

.hero-strip,
.battle-topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.hero-strip h1,
.battle-topbar h2 {
  margin: 0;
  color: #fff8eb;
  font-size: clamp(32px, 5vw, 68px);
  line-height: 1;
  font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  letter-spacing: 0.03em;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.32);
}

.battle-topbar h2 {
  font-size: clamp(24px, 3vw, 42px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.hero-copy {
  display: grid;
  gap: 8px;
}

.hero-subtitle {
  max-width: 600px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.match-chip,
.match-status,
.element-pill,
.profile-element {
  border: 1px solid rgba(228, 201, 138, 0.22);
  background: rgba(255, 245, 226, 0.08);
  color: #ffe7a2;
  padding: 8px 10px;
  backdrop-filter: blur(12px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 12px 30px rgba(0, 0, 0, 0.18);
}

.queue-ribbon {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 16px;
}

.queue-ribbon span {
  padding: 9px 12px;
  border: 1px solid rgba(228, 201, 138, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 12px;
}

.audio-toggle {
  border: 1px solid rgba(228, 201, 138, 0.28);
  border-radius: 999px;
  background: rgba(255, 248, 236, 0.08);
  color: var(--ink);
  padding: 10px 14px;
  cursor: pointer;
  backdrop-filter: blur(12px);
}

.narrow-button {
  width: auto;
  min-width: 120px;
}

.selection-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
}

.class-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.class-card,
.profile-panel,
.hud-panel,
.result-overlay {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(38, 34, 37, 0.92), rgba(18, 18, 24, 0.8));
  box-shadow: 0 24px 60px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.class-card {
  min-height: 156px;
  padding: 14px;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.class-card:hover,
.class-card.selected {
  transform: translateY(-4px);
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(58, 47, 39, 0.96), rgba(23, 22, 28, 0.9));
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.class-card h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 8px;
  color: #fff0b7;
  font-size: 20px;
}

.class-card p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.tag-row,
.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.tag,
.stat {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: #f4e6bd;
  padding: 5px 9px;
  font-size: 12px;
}

.profile-panel {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  min-height: 620px;
  padding: 14px;
}

#previewCanvas {
  width: 100%;
  max-width: 260px;
  height: auto;
  margin: 0 auto 12px;
  border: 1px solid rgba(228, 201, 138, 0.22);
  border-radius: 18px;
  background: #16141a;
  image-rendering: pixelated;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.profile-copy {
  flex: 1;
}

.profile-element {
  display: inline-block;
  margin: 0 0 8px;
  font-size: 12px;
}

.profile-copy h2 {
  margin: 0 0 8px;
  color: #fff7d7;
  font-size: 28px;
}

.profile-copy p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.5;
}

.skill-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.skill-list li {
  border-left: 3px solid var(--gold);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 10px;
  color: #e9dfbd;
  font-size: 13px;
  line-height: 1.45;
}

.primary-button {
  width: 100%;
  border: 1px solid rgba(255, 238, 204, 0.36);
  border-radius: 16px;
  background: linear-gradient(180deg, #e6c780, #b9893f);
  color: #211716;
  padding: 14px 18px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 18px 30px rgba(100, 60, 20, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.primary-button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.8) brightness(0.72);
}

.secondary-button {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  padding: 14px 18px;
  cursor: pointer;
}

.settings-card {
  padding: 24px;
}

.settings-card h3 {
  margin: 0 0 16px;
  color: #fff1bf;
  font-size: 24px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  color: #f4e8c1;
}

.settings-row-range {
  margin-bottom: 10px;
}

.volume-slider {
  width: 100%;
  margin-bottom: 18px;
  accent-color: #d6ad66;
}

.settings-preview-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.settings-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 18px;
}

.battle-screen {
  max-width: 1160px;
  touch-action: none;
}

.arena-wrap {
  position: relative;
  border: 1px solid rgba(228, 201, 138, 0.18);
  border-radius: 26px;
  background: #111;
  box-shadow: 0 28px 70px var(--shadow);
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #171515;
  image-rendering: pixelated;
  touch-action: none;
}

.touch-controls {
  display: none;
}

.virtual-joystick {
  position: absolute;
  display: grid;
  width: 132px;
  min-width: 44px;
  height: 132px;
  min-height: 44px;
  place-items: center;
  border: 2px solid rgba(255, 243, 194, 0.74);
  border-radius: 50%;
  background: rgba(12, 15, 22, 0.56);
  box-shadow: inset 0 0 28px rgba(255, 231, 162, 0.1), 0 8px 26px rgba(0, 0, 0, 0.34);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.joystick-knob {
  width: 58px;
  height: 58px;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(237, 205, 135, 0.94), rgba(154, 105, 50, 0.94));
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.46);
  pointer-events: none;
  transition: filter 80ms ease, box-shadow 80ms ease;
}

.virtual-joystick:active .joystick-knob {
  filter: brightness(1.22);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.42), 0 0 18px rgba(255, 225, 136, 0.44);
}

.touch-attack {
  position: absolute;
  display: grid;
  width: 82px;
  min-width: 44px;
  height: 82px;
  min-height: 44px;
  place-items: center;
  border: 2px solid rgba(255, 226, 184, 0.88);
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(225, 108, 95, 0.94), rgba(130, 43, 44, 0.94));
  color: #fff8eb;
  font-weight: 900;
  box-shadow: 0 9px 24px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.34);
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.48);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-attack:active {
  filter: brightness(1.24);
  transform: scale(0.94);
  box-shadow: 0 3px 11px rgba(0, 0, 0, 0.44), inset 0 2px 7px rgba(58, 12, 16, 0.42);
}

.orientation-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  gap: 10px;
  min-width: 44px;
  min-height: 44px;
  place-content: center;
  padding:
    max(24px, env(safe-area-inset-top))
    max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(24px, env(safe-area-inset-left));
  background: rgba(7, 9, 14, 0.96);
  color: #fff3c2;
  text-align: center;
  backdrop-filter: blur(18px);
}

.orientation-overlay strong {
  font-size: clamp(30px, 8vw, 56px);
}

.orientation-overlay span {
  color: var(--muted);
  font-size: clamp(16px, 3.5vw, 22px);
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff3c2;
  font-size: clamp(80px, 16vw, 190px);
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.44);
  pointer-events: none;
}

.matchmaking-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  background: radial-gradient(circle, rgba(20, 20, 26, 0.72), rgba(6, 7, 10, 0.84));
  backdrop-filter: blur(10px);
}

.matchmaking-label {
  margin: 0 0 8px;
  color: var(--gold);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
}

.matchmaking-overlay h2 {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  font-size: clamp(34px, 4vw, 56px);
}

.matchmaking-overlay p {
  margin: 8px 0 14px;
  color: var(--muted);
}

.matchmaking-details {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.matchmaking-details span {
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: #f0dfba;
  font-size: 12px;
}

.eat-progress {
  position: absolute;
  left: 50%;
  bottom: 18px;
  width: min(300px, 70%);
  height: 18px;
  transform: translateX(-50%);
  border: 3px solid #654f36;
  background: rgba(22, 17, 14, 0.92);
  pointer-events: none;
}

.eat-progress span {
  display: block;
  width: var(--eat, 0%);
  height: 100%;
  background: #e6c36a;
}

.result-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(420px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  padding: 24px;
  text-align: center;
  animation: result-pop 420ms ease;
}

.result-overlay[data-state="win"] {
  box-shadow: 0 24px 80px rgba(185, 137, 63, 0.32), inset 0 0 0 1px rgba(255, 240, 187, 0.18);
}

.result-overlay[data-state="lose"] {
  box-shadow: 0 24px 80px rgba(116, 72, 82, 0.34), inset 0 0 0 1px rgba(255, 188, 188, 0.12);
}

.result-overlay h2 {
  margin: 0 0 8px;
  color: #fff3c2;
  font-size: 40px;
}

.result-overlay[data-state="win"] h2 {
  animation: glow-win 1.1s ease;
}

.result-overlay[data-state="lose"] h2 {
  animation: shake-lose 520ms ease;
}

.result-overlay p {
  margin: 0 0 18px;
  color: var(--muted);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 18px;
}

.result-stats div {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.result-stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.result-stats strong {
  color: #fff8eb;
  font-size: 18px;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.hud {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 290px;
  gap: 10px;
  margin-top: 12px;
}

.hud-panel {
  min-height: 98px;
  padding: 14px;
}

.fighter-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: #fff3c2;
  font-weight: 900;
}

.element-pill {
  padding: 4px 7px;
  font-size: 12px;
  box-shadow: none;
}

.star-meter {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 23px;
  letter-spacing: 0;
}

.star-meter span {
  color: #695746;
  text-shadow: 0 2px 0 #111;
}

.star-meter span.full {
  color: var(--gold);
}

.star-meter span.half {
  color: #ff9e50;
}

.bread-meter {
  display: flex;
  gap: 5px;
  margin-bottom: 8px;
}

.bread {
  position: relative;
  width: 29px;
  height: 18px;
  border: 2px solid #705331;
  background: #2f251c;
  overflow: hidden;
}

.bread::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: calc(var(--fill, 0) * 100%);
  height: 100%;
  background: linear-gradient(180deg, #ffe091, #ba762e);
}

.bread::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 4px;
  width: 5px;
  height: 4px;
  background: rgba(255, 255, 255, 0.28);
  box-shadow: 9px 0 0 rgba(255, 255, 255, 0.2);
}

.status-line {
  min-height: 18px;
  color: #cfc4a6;
  font-size: 12px;
}

.control-hint {
  margin-top: 10px;
  color: rgba(255, 246, 220, 0.62);
  font-size: 11px;
  line-height: 1.5;
}

@keyframes result-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -46%) scale(0.92);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes glow-win {
  0% {
    text-shadow: 0 0 0 rgba(255, 233, 156, 0);
  }
  45% {
    text-shadow: 0 0 24px rgba(255, 233, 156, 0.68);
  }
  100% {
    text-shadow: 0 0 6px rgba(255, 233, 156, 0.2);
  }
}

@keyframes shake-lose {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-4px);
  }
  40% {
    transform: translateX(4px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(3px);
  }
}

.skill-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(76px, 1fr));
  gap: 8px;
}

.skill-button,
.item-button,
.weapon-slot {
  position: relative;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  color: #f7e7bd;
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.skill-button {
  min-height: 76px;
  padding: 7px;
  cursor: pointer;
  touch-action: none;
}

.skill-button:hover,
.item-button:hover,
.item-button.selected {
  border-color: var(--gold);
}

.skill-button.locked {
  filter: grayscale(0.9) brightness(0.62);
}

.skill-button .key {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  margin-bottom: 7px;
  border-radius: 999px;
  background: rgba(78, 60, 42, 0.8);
  color: #ffe68b;
  font-weight: 900;
}

.skill-button .name {
  position: relative;
  z-index: 1;
  display: block;
  font-size: 12px;
  line-height: 1.25;
}

.skill-button .meta {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 4px;
  color: #bdb292;
  font-size: 11px;
}

.skill-button .cooldown-fill {
  position: absolute;
  inset: 0;
  z-index: 0;
  transform-origin: bottom;
  transform: scaleY(var(--cool, 0));
  background: rgba(0, 0, 0, 0.58);
}

.skill-button.ultimate {
  border-color: #7b5e30;
  background: rgba(66, 42, 29, 0.22);
}

.inventory {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.weapon-slot {
  min-height: 35px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  color: #fff0b5;
}

.item-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.item-button {
  min-height: 43px;
  padding: 7px;
  cursor: pointer;
  font-size: 12px;
}

.item-button strong {
  display: block;
  margin-bottom: 3px;
  color: #fff0b5;
  font-size: 12px;
}

@media (max-width: 980px) {
  .start-layout,
  .settings-layout,
  .selection-layout,
  .hud {
    grid-template-columns: 1fr;
  }

  .start-actions,
  .start-feature-grid,
  .settings-preview-row {
    grid-template-columns: 1fr;
  }

  .result-actions,
  .result-stats {
    grid-template-columns: 1fr;
  }

  .profile-panel {
    position: static;
    min-height: auto;
  }

  .skill-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .screen {
    width: min(100vw - 16px, 1180px);
    padding-top: 12px;
  }

  .hero-strip,
  .battle-topbar {
    align-items: start;
    flex-direction: column;
  }

  .hero-actions {
    width: 100%;
    justify-content: space-between;
  }

  .start-panel,
  .settings-card {
    padding: 18px;
  }

  .class-grid {
    grid-template-columns: 1fr;
  }

  .class-card {
    min-height: auto;
  }

  .skill-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (pointer: coarse) and (orientation: landscape) {
  .select-screen {
    position: fixed;
    inset: 0;
    display: grid;
    width: 100vw;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding:
      max(10px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: hidden;
  }

  .select-screen .hero-strip {
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
  }

  .select-screen .hero-copy {
    gap: 2px;
  }

  .select-screen .eyebrow {
    display: none;
  }

  .select-screen .hero-strip h1 {
    font-size: clamp(28px, 4vw, 42px);
  }

  .select-screen .hero-subtitle {
    font-size: 12px;
    line-height: 1.25;
  }

  .select-screen .hero-actions {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .select-screen .match-chip,
  .select-screen .audio-toggle {
    padding: 7px 9px;
    font-size: 11px;
    white-space: nowrap;
  }

  .select-screen .queue-ribbon {
    flex-wrap: nowrap;
    gap: 6px;
    margin: 0 0 7px;
  }

  .select-screen .queue-ribbon span {
    padding: 5px 8px;
    font-size: 10px;
    white-space: nowrap;
  }

  .select-screen .selection-layout {
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) minmax(340px, 38vw);
    gap: 10px;
  }

  .select-screen .class-grid {
    min-height: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(4, minmax(0, 1fr));
    gap: 7px;
  }

  .select-screen .class-card {
    min-height: 0;
    padding: 8px 10px;
  }

  .select-screen .class-card h3 {
    margin-bottom: 3px;
    font-size: 15px;
  }

  .select-screen .class-card p {
    margin-bottom: 5px;
    font-size: 10px;
    line-height: 1.25;
  }

  .select-screen .tag-row {
    gap: 4px;
  }

  .select-screen .tag {
    padding: 3px 6px;
    font-size: 9px;
  }

  .select-screen .profile-panel {
    position: static;
    display: grid;
    min-height: 0;
    height: 100%;
    padding: 9px;
    grid-template-columns: clamp(88px, 11vw, 118px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 8px;
    overflow: hidden;
  }

  .select-screen #previewCanvas {
    width: 100%;
    margin: 0;
  }

  .select-screen .profile-copy {
    min-width: 0;
    min-height: 0;
  }

  .select-screen .profile-element {
    margin-bottom: 4px;
    padding: 4px 7px;
    font-size: 10px;
  }

  .select-screen .profile-copy h2 {
    margin-bottom: 4px;
    font-size: 20px;
  }

  .select-screen .profile-copy p {
    margin-bottom: 5px;
    font-size: 10px;
    line-height: 1.25;
  }

  .select-screen .stat-row {
    gap: 4px;
  }

  .select-screen .stat {
    padding: 3px 6px;
    font-size: 9px;
  }

  .select-screen .profile-panel .skill-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    margin-top: 6px;
  }

  .select-screen .profile-panel .skill-list li {
    padding: 4px 6px;
    font-size: 9px;
    line-height: 1.2;
  }

  .select-screen .profile-panel .primary-button {
    grid-column: 1 / -1;
    min-height: 44px;
    padding: 9px 14px;
  }

  .battle-screen {
    position: fixed;
    inset: 0;
    z-index: 1;
    display: grid;
    width: 100vw;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding:
      max(16px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
    place-items: center;
    overflow: hidden;
    overscroll-behavior: none;
    container-type: size;
    container-name: battle-viewport;
  }

  .battle-topbar {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    left: max(12px, env(safe-area-inset-left));
    z-index: 22;
    align-items: start;
    margin: 0;
    pointer-events: none;
  }

  .battle-topbar .eyebrow {
    display: none;
  }

  .battle-topbar h2 {
    font-size: clamp(18px, 2.4vw, 30px);
  }

  .battle-topbar .match-status {
    padding: 6px 9px;
    font-size: 12px;
  }

  .arena-wrap {
    width: calc(100vw - max(16px, env(safe-area-inset-left)) - max(16px, env(safe-area-inset-right)));
    max-width: 100%;
    height: auto;
    max-height: 100%;
    aspect-ratio: 16 / 9;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 28px 70px var(--shadow), inset 0 0 0 1px rgba(228, 201, 138, 0.18);
  }

  #gameCanvas {
    width: 100%;
    height: 100%;
    aspect-ratio: 16 / 9;
    object-fit: contain;
  }

  .touch-controls {
    position: fixed;
    inset: 0;
    z-index: 12;
    display: block;
    pointer-events: none;
  }

  .virtual-joystick {
    left: max(14px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    width: clamp(104px, 13vw, 132px);
    height: clamp(104px, 13vw, 132px);
    pointer-events: auto;
  }

  .touch-attack {
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    width: clamp(72px, 8.5vw, 88px);
    height: clamp(72px, 8.5vw, 88px);
    pointer-events: auto;
  }

  .hud {
    position: absolute;
    inset: 0;
    z-index: 18;
    display: block;
    margin: 0;
    pointer-events: none;
  }

  .hud-panel {
    min-height: 0;
    padding: 8px;
    border-radius: 14px;
    background: rgba(16, 17, 22, 0.7);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    pointer-events: none;
  }

  .vitals-panel {
    position: absolute;
    top: max(48px, calc(env(safe-area-inset-top) + 40px));
    left: max(12px, env(safe-area-inset-left));
    width: clamp(190px, 23vw, 265px);
  }

  .fighter-line,
  .star-meter,
  .bread-meter {
    margin-bottom: 4px;
  }

  .star-meter {
    font-size: 18px;
  }

  .bread {
    width: 23px;
    height: 15px;
  }

  .control-hint {
    display: none;
  }

  .skill-bar {
    position: absolute;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(clamp(220px, 25dvh, 260px), calc(env(safe-area-inset-bottom) + 200px));
    display: grid;
    width: clamp(70px, 8vw, 88px);
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .skill-button {
    min-height: 48px;
    padding: 4px 5px;
    border-radius: 12px;
    pointer-events: auto;
  }

  .skill-button .key {
    position: absolute;
    top: 3px;
    right: 3px;
    min-width: 18px;
    height: 18px;
    margin: 0;
    font-size: 10px;
  }

  .skill-button .name {
    padding-right: 17px;
    font-size: 10px;
  }

  .skill-button .meta {
    margin-top: 2px;
    font-size: 9px;
  }

  .inventory {
    position: absolute;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 50%;
    width: clamp(260px, 36vw, 420px);
    grid-template-columns: minmax(90px, 0.8fr) minmax(150px, 1.4fr);
    transform: translateX(-50%);
  }

  .weapon-slot {
    min-height: 44px;
  }

  .item-button {
    min-height: 44px;
    pointer-events: auto;
  }

  .matchmaking-overlay,
  .countdown,
  .result-overlay,
  .eat-progress {
    z-index: 40;
  }

  .matchmaking-overlay,
  .countdown,
  .result-overlay {
    pointer-events: auto;
  }

  .result-overlay {
    width: min(420px, calc(100% - 40px));
    max-height: calc(100% - 32px);
    overflow: auto;
  }
}

@container battle-viewport (min-aspect-ratio: 16 / 9) {
  .arena-wrap {
    width: auto;
    height: calc(100vh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
    height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
    aspect-ratio: 16 / 9;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 760px) {
  .select-screen {
    padding-top: max(7px, env(safe-area-inset-top));
    padding-bottom: max(7px, env(safe-area-inset-bottom));
  }

  .select-screen .hero-subtitle {
    display: none;
  }

  .select-screen .queue-ribbon {
    margin-bottom: 5px;
  }

  .select-screen #previewCanvas {
    max-width: 96px;
  }

  .select-screen .class-card {
    padding-block: 6px;
  }

  .select-screen .profile-panel {
    padding: 7px;
    gap: 6px;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  .skill-bar {
    bottom: max(112px, calc(env(safe-area-inset-bottom) + 104px));
    width: clamp(216px, 30vw, 252px);
    grid-template-columns: repeat(3, minmax(64px, 1fr));
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  .screen {
    width: 100%;
    padding:
      max(14px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(22px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .select-screen {
    min-height: 100vh;
    min-height: 100dvh;
  }

  .selection-layout {
    grid-template-columns: minmax(0, 1fr) minmax(240px, 38vw);
    align-items: start;
  }

  .class-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .class-card {
    min-height: 148px;
  }

  .profile-panel {
    position: sticky;
    top: max(12px, env(safe-area-inset-top));
    min-height: 0;
    max-height: calc(100vh - max(24px, env(safe-area-inset-top)) - max(24px, env(safe-area-inset-bottom)));
    max-height: calc(100dvh - max(24px, env(safe-area-inset-top)) - max(24px, env(safe-area-inset-bottom)));
    overflow: auto;
  }

  .profile-panel .primary-button {
    position: sticky;
    bottom: max(0px, env(safe-area-inset-bottom));
    min-height: 48px;
  }

  .orientation-overlay {
    width: 100vw;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
  }
}
