/* Base & Design Tokens — Dez' Nutz Canopy Arcade */
:root {
  --font-display: 'Clash Display', 'Trebuchet MS', sans-serif;
  --font-body: 'Satoshi', 'Segoe UI', sans-serif;

  /* Woodland Twilight + Autumn Gold Palette */
  --color-bg: #131c18;
  --color-surface: rgba(18, 28, 22, 0.88);
  --color-surface-solid: #18251e;
  --color-surface-2: rgba(34, 48, 39, 0.92);
  --color-border: rgba(244, 197, 110, 0.25);
  --color-text: #f7f1e3;
  --color-text-muted: #c8beaa;

  /* Player & Semantic Accents */
  --color-p1: #f06a2b;
  --color-p2: #4ecdc4;
  --color-gold: #ffd166;
  --color-primary: #f29d38;
  --color-danger: #ef476f;
  --color-success: #80ed99;

  /* Fluid Type Scale */
  --text-xs: clamp(0.75rem, 0.72rem + 0.14vw, 0.84rem);
  --text-sm: clamp(0.875rem, 0.84rem + 0.16vw, 0.95rem);
  --text-base: clamp(1rem, 0.96rem + 0.18vw, 1.06rem);
  --text-lg: clamp(1.12rem, 1.04rem + 0.4vw, 1.35rem);
  --text-xl: clamp(1.55rem, 1.25rem + 1.15vw, 2.2rem);
  --text-2xl: clamp(2.25rem, 1.65rem + 2.5vw, 3.85rem);

  /* Spacing (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;

  --panel-radius: 12px;
  --panel-blur: 14px;
  --transition-ui: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: none;
}

input {
  font: inherit;
  color: var(--color-text);
  user-select: text;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  transition:
    transform var(--transition-ui),
    background-color var(--transition-ui),
    border-color var(--transition-ui),
    box-shadow var(--transition-ui),
    color var(--transition-ui);
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

/* Main Stage */
.stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 35%, #233329 0%, #101713 100%);
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

/* Shared Game Panel */
.game-panel {
  background: var(--color-surface);
  backdrop-filter: blur(var(--panel-blur));
  -webkit-backdrop-filter: blur(var(--panel-blur));
  border: 1px solid var(--color-border);
  border-radius: var(--panel-radius);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
}

/* Top HUD */
.hud {
  position: fixed;
  top: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  width: min(94vw, 920px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-3);
  z-index: 20;
  pointer-events: none;
}

.hud-player {
  background: rgba(16, 24, 19, 0.84);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(244, 197, 110, 0.24);
  border-radius: 10px;
  padding: var(--space-2) var(--space-3);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.hud-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}

.hud-name {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--color-text);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 18ch;
}

.hud-score {
  font-size: var(--text-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--color-gold);
  margin-left: auto;
  flex-shrink: 0;
}

.hud-p2 .hud-score {
  margin-left: 0;
  margin-right: auto;
}

.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

.p1-dot {
  background: var(--color-p1);
  box-shadow: 0 0 8px var(--color-p1);
}

.p2-dot {
  background: var(--color-p2);
  box-shadow: 0 0 8px var(--color-p2);
}

.meter-track {
  position: relative;
  height: 14px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 80ms linear;
}

.p1-rage {
  background: linear-gradient(90deg, #e07a22, #ff3d5a);
}

.p2-rage {
  background: linear-gradient(90deg, #2fb7ae, #ff477e);
}

.meter-fill.craze-active {
  animation: pulse-bar 260ms infinite alternate;
}

@keyframes pulse-bar {
  from { filter: brightness(1); }
  to { filter: brightness(1.45); }
}

.meter-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  pointer-events: auto;
}

.hud-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-level-pill {
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, rgba(255, 198, 92, 0.24) 0%, rgba(214, 128, 34, 0.2) 100%);
  border: 1px solid rgba(255, 209, 102, 0.55);
  padding: 4px 9px;
  border-radius: 999px;
  color: #ffd166;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  white-space: nowrap;
}

.hud-clock {
  font-size: var(--text-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums lining-nums;
  background: rgba(16, 24, 19, 0.88);
  border: 1px solid rgba(244, 197, 110, 0.28);
  padding: 4px 12px;
  border-radius: 999px;
  color: var(--color-text);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.hud-actions {
  display: flex;
  gap: var(--space-2);
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 24, 19, 0.88);
  border: 1px solid rgba(244, 197, 110, 0.26);
  color: var(--color-text);
}

.icon-btn:hover {
  background: rgba(42, 60, 48, 0.95);
  border-color: var(--color-gold);
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
}

.title-overlay {
  background: #101713;
  overflow-y: auto;
}

.title-bg-img {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.7;
  filter: saturate(1.08);
  pointer-events: none;
}

.title-scrim {
  position: fixed;
  inset: 0;
  background: radial-gradient(
    ellipse at 50% 42%,
    rgba(16, 23, 19, 0.44) 0%,
    rgba(12, 18, 15, 0.88) 76%
  );
  pointer-events: none;
}

.title-content {
  position: relative;
  z-index: 2;
  width: min(100%, 800px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin: auto;
}

.title-header {
  text-align: center;
}

.eyebrow {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--color-gold);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
  margin-bottom: clamp(10px, 1.8vw, 20px);
}

.game-title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-family: 'Bangers', var(--font-display), Impact, sans-serif;
  font-size: clamp(2.45rem, 6.2vw, 5.15rem);
  font-weight: 400;
  line-height: 0.92;
  letter-spacing: 0.045em;
  margin: 4px auto 2px;
  user-select: none;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.78));
}

.title-word {
  display: inline-flex;
  align-items: baseline;
  position: relative;
  z-index: 2;
}

.title-word .tl {
  display: inline-block;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: clamp(1.8px, 0.34vw, 3.2px) #121f08;
  paint-order: stroke fill;
}

.title-squirrel {
  transform: rotate(-3deg) translateY(2px);
  padding-right: clamp(6px, 1vw, 14px);
  filter:
    drop-shadow(0 4px 0 #162b0b)
    drop-shadow(0 0 14px rgba(255, 232, 36, 0.38));
}

.title-squirrel .tl {
  background-image: linear-gradient(180deg, #fffd82 0%, #ffe119 46%, #f2a200 100%);
}

.title-squirrel .tl:nth-child(1) { transform: rotate(-4deg) scale(1.06); }
.title-squirrel .tl:nth-child(2) { transform: rotate(2deg) translateY(-2px); }
.title-squirrel .tl:nth-child(3) { transform: rotate(-2deg); }
.title-squirrel .tl:nth-child(4) { transform: rotate(3deg) translateY(-1px); }
.title-squirrel .tl:nth-child(5) { transform: rotate(-3deg) scale(1.03); }
.title-squirrel .tl:nth-child(6) { transform: rotate(2deg) translateY(-2px); }
.title-squirrel .tl:nth-child(7) { transform: rotate(-2deg); }
.title-squirrel .tl:nth-child(8) { transform: rotate(4deg) translateY(1px); }

.title-crazy {
  transform: rotate(3.5deg) translateY(-1px);
  padding-left: clamp(6px, 1vw, 14px);
  filter:
    drop-shadow(0 4px 0 #102409)
    drop-shadow(0 0 18px rgba(132, 255, 24, 0.5));
}

.title-crazy .tl {
  background-image: linear-gradient(180deg, #f2ff52 0%, #86ff1a 46%, #1ec422 100%);
}

.title-crazy .tl:nth-child(1) { transform: rotate(-7deg) scale(1.06) translateY(-2px); }
.title-crazy .tl:nth-child(2) { transform: rotate(6deg) scale(0.98) translateY(3px); }
.title-crazy .tl:nth-child(3) { transform: rotate(-5deg) scale(1.1) translateY(-3px); }
.title-crazy .tl:nth-child(4) { transform: rotate(8deg) scale(1.02) translateY(2px); }
.title-crazy .tl:nth-child(5) { transform: rotate(-6deg) scale(1.14) translateY(-3px); }

.title-mascot-burst {
  position: relative;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(86px, 14vw, 168px);
  margin: -18px clamp(-16px, -1.6vw, -6px) -14px;
  pointer-events: none;
  flex-shrink: 0;
}

.title-burst-glow {
  position: absolute;
  inset: 6% 4%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(246, 255, 68, 0.52) 0%,
    rgba(118, 255, 28, 0.34) 44%,
    rgba(18, 36, 10, 0) 74%
  );
  filter: blur(6px);
  z-index: 0;
}

.title-mascot-img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: auto;
  display: block;
  transform-origin: 50% 62%;
  filter:
    drop-shadow(0 5px 10px rgba(0, 0, 0, 0.72))
    drop-shadow(0 0 10px rgba(208, 255, 42, 0.38));
  animation: manic-squirrel-pop 2.6s ease-in-out infinite;
}

@keyframes manic-squirrel-pop {
  0%, 100% { transform: scale(1) rotate(-2deg) translateY(0); }
  22% { transform: scale(1.06) rotate(3.5deg) translateY(-3px); }
  38% { transform: scale(1.02) rotate(-3.5deg) translateY(-1px); }
  55% { transform: scale(1.07) rotate(2deg) translateY(-4px); }
  75% { transform: scale(1) rotate(-1.5deg) translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .title-mascot-img { animation: none; }
}

@media (max-width: 640px) {
  .game-title {
    font-size: clamp(1.95rem, 8.8vw, 2.7rem);
    margin: 2px auto 0;
  }
  .title-mascot-burst {
    width: clamp(68px, 21vw, 96px);
    margin: -10px -8px -8px;
  }
}

.subtitle {
  margin-top: clamp(6px, 1vw, 12px);
  font-size: var(--text-sm);
  color: #efe7d6;
  max-width: 58ch;
  margin-inline: auto;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
}

.setup-panel {
  width: 100%;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Profile & Ranking Bar */
.profile-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.handle-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 210px;
}

.handle-input-row {
  display: flex;
  gap: var(--space-2);
}

.text-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: var(--text-sm);
  color: var(--color-text);
}

.text-input::placeholder {
  color: rgba(200, 190, 170, 0.55);
}

.mini-btn {
  padding: 7px 12px;
  border-radius: 8px;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--color-text);
  white-space: nowrap;
}

.mini-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: var(--color-gold);
}

.rank-pill {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: rgba(0, 0, 0, 0.36);
  border: 1px solid rgba(244, 197, 110, 0.24);
  border-radius: 999px;
  padding: 6px 12px;
}

.tier-badge {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-gold);
}

.elo-readout {
  font-size: var(--text-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--color-text);
}

.rankings-btn {
  padding: 8px 14px;
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.05em;
  background: rgba(255, 209, 102, 0.16);
  border: 1px solid rgba(255, 209, 102, 0.45);
  color: var(--color-gold);
}

.rankings-btn:hover {
  background: rgba(255, 209, 102, 0.26);
}

.setup-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  justify-content: space-between;
  align-items: center;
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 240px;
}

.option-label {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

.segmented {
  display: flex;
  gap: var(--space-1);
  background: rgba(0, 0, 0, 0.35);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.seg-btn {
  flex: 1;
  padding: 7px 8px;
  font-size: var(--text-sm);
  font-weight: 700;
  border-radius: 7px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.seg-btn:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.06);
}

.seg-btn.active {
  background: var(--color-primary);
  color: #1b1108;
  box-shadow: 0 2px 10px rgba(242, 157, 56, 0.35);
}

.ai-difficulty-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(10, 15, 12, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.segmented-4 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}

.segmented-4 .seg-btn {
  padding: 7px 8px;
}

.seg-btn-epic.active {
  background: linear-gradient(135deg, #ff4d6d 0%, #ff9f1c 55%, #ffd166 100%);
  color: #1b0a05;
  font-weight: 800;
  box-shadow: 0 0 16px rgba(255, 77, 109, 0.55);
}

.level-select-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(10, 15, 12, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.level-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.level-name-tag {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #ffd166;
  text-align: right;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 5px;
  width: 100%;
}

.lvl-btn {
  position: relative;
  padding: 7px 4px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(20, 30, 24, 0.85);
  color: var(--color-text-muted);
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.lvl-btn:hover {
  border-color: rgba(255, 209, 102, 0.5);
  color: var(--color-text);
}

.lvl-btn.cleared {
  border-color: rgba(132, 224, 150, 0.55);
  color: #c8f7d2;
}

.lvl-btn.cleared::after {
  content: '★';
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 8px;
  color: #ffd166;
  line-height: 1;
}

.lvl-btn.active {
  background: var(--color-primary);
  border-color: #ffe2a4;
  color: #1b1108;
  box-shadow: 0 2px 10px rgba(242, 157, 56, 0.4);
}

.lvl-btn.active.cleared::after {
  color: #1b1108;
}

.level-meta-note {
  margin: 0;
  font-size: 11px;
  line-height: 1.3;
  color: var(--color-text-muted);
  text-align: center;
}

@media (max-width: 600px) {
  .level-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .lvl-btn {
    padding: 8px 4px;
  }
}

.primary-cta {
  width: 100%;
  padding: 12px 18px;
  border-radius: 10px;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: 0.05em;
  background: linear-gradient(180deg, #ffba52 0%, #e77d24 100%);
  color: #1c1006;
  border: 1px solid #ffd894;
  box-shadow: 0 6px 22px rgba(231, 125, 36, 0.42);
}

.primary-cta:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.primary-cta:active {
  transform: translateY(1px);
}

.secondary-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.05em;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--color-text);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--color-gold);
}

/* Online Lobby Panel */
.online-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.online-actions {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1.2fr;
  gap: var(--space-2);
  align-items: stretch;
}

.join-row {
  display: flex;
  gap: var(--space-1);
}

.code-input {
  width: 82px;
  text-align: center;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.join-btn {
  flex: 1;
  white-space: nowrap;
}

.lobby-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: 8px;
  background: rgba(78, 205, 196, 0.14);
  border: 1px solid rgba(78, 205, 196, 0.4);
  font-size: var(--text-sm);
}

.room-code-badge {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  letter-spacing: 0.16em;
  color: var(--color-gold);
  background: rgba(0, 0, 0, 0.45);
  padding: 2px 10px;
  border-radius: 6px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.control-card {
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: var(--space-3);
}

.p1-card {
  border-color: rgba(240, 106, 43, 0.38);
}

.p2-card {
  border-color: rgba(78, 205, 196, 0.38);
}

.control-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 700;
  margin-bottom: var(--space-1);
  color: var(--color-text);
}

.control-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  margin-right: 3px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  color: #fff6e5;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 5px;
}

/* Modal Overlays (Pause / Victory / Rankings) */
.modal-overlay {
  background: rgba(8, 12, 10, 0.72);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(100%, 480px);
  padding: var(--space-5);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.rankings-card {
  width: min(100%, 680px);
  max-height: 86dvh;
  text-align: left;
}

.modal-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.rankings-scroll {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding-right: 4px;
}

.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums lining-nums;
}

.rank-table th,
.rank-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}

.rank-table th {
  color: var(--color-text-muted);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.rank-table tr.is-me {
  background: rgba(242, 157, 56, 0.16);
}

.table-empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-3);
}

.recent-title {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.recent-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--text-xs);
}

.recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.elo-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 209, 102, 0.14);
  border: 1px solid rgba(255, 209, 102, 0.42);
  font-size: var(--text-sm);
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: #fff6e5;
  letter-spacing: 0.03em;
}

.modal-sub {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  text-align: left;
}

.stat-col {
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 700;
  margin-bottom: 2px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums lining-nums;
}

.stat-row strong {
  color: var(--color-gold);
}

/* Game Boy Style Touch Controls */
.touch-controls {
  position: fixed;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 25;
  user-select: none;
  -webkit-user-select: none;
}

.gb-dpad-shell {
  pointer-events: auto;
  padding: 7px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(24, 28, 26, 0.68) 0%, rgba(14, 18, 16, 0.42) 72%, transparent 100%);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.48);
  touch-action: none;
}

.gb-dpad {
  display: grid;
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px 44px;
  grid-template-areas:
    ". up ."
    "left center right"
    ". down .";
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.65));
}

.gb-dir {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #32363b 0%, #1c1f23 100%);
  color: rgba(235, 240, 232, 0.72);
  font-size: 13px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 2px 2px rgba(255, 255, 255, 0.16), inset 0 -2px 3px rgba(0, 0, 0, 0.55);
  touch-action: none;
  transition: transform 60ms ease, background 60ms ease;
}

.gb-up {
  grid-area: up;
  border-radius: 9px 9px 0 0;
  border-bottom: none;
}

.gb-down {
  grid-area: down;
  border-radius: 0 0 9px 9px;
  border-top: none;
}

.gb-left {
  grid-area: left;
  border-radius: 9px 0 0 9px;
  border-right: none;
}

.gb-right {
  grid-area: right;
  border-radius: 0 9px 9px 0;
  border-left: none;
}

.gb-center {
  grid-area: center;
  background: #22262b;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gb-center span {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #121417 0%, #2a2e33 100%);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8);
}

.gb-dir:active,
.gb-dir.is-pressed {
  background: linear-gradient(180deg, #1b1e22 0%, #2c3138 100%);
  color: var(--color-gold);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.8);
  transform: scale(0.95);
}

.gb-actions-shell {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 14px;
  margin-right: 4px;
  touch-action: none;
}

.gb-pill-btn {
  padding: 7px 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, #5d646b 0%, #373c42 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 3px 0 #1c1f22, 0 5px 10px rgba(0, 0, 0, 0.55), inset 0 1px 2px rgba(255, 255, 255, 0.28);
  color: #f4f1e6;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  transform: rotate(-16deg) translate(-28px, -2px);
  touch-action: none;
}

.gb-pill-btn:active,
.gb-pill-btn.is-pressed {
  transform: rotate(-16deg) translate(-28px, 1px);
  box-shadow: 0 1px 0 #1c1f22, inset 0 2px 5px rgba(0, 0, 0, 0.65);
  color: var(--color-gold);
}

.gb-ab-cluster {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  padding: 10px 16px 8px;
  border-radius: 999px;
  background: rgba(16, 20, 18, 0.56);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.55);
  transform: rotate(-18deg);
}

.gb-ab-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.gb-round-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #d93b6f 0%, #a51e4b 58%, #6d1030 100%);
  border: 2px solid rgba(255, 210, 224, 0.32);
  box-shadow: 0 4px 0 #47081e, 0 7px 14px rgba(0, 0, 0, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.34);
  color: #fff6f8;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
  touch-action: none;
  transition: transform 60ms ease, box-shadow 60ms ease;
}

.gb-round-btn:active,
.gb-round-btn.is-pressed {
  transform: translateY(3px) scale(0.95);
  box-shadow: 0 1px 0 #47081e, inset 0 3px 7px rgba(0, 0, 0, 0.6);
  filter: brightness(1.12);
}

.gb-btn-caption {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: rgba(244, 236, 214, 0.88);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

@media (orientation: portrait) and (max-width: 600px) {
  .touch-controls {
    bottom: max(26px, env(safe-area-inset-bottom));
    left: max(16px, env(safe-area-inset-left));
    right: max(16px, env(safe-area-inset-right));
  }
  .gb-dpad {
    grid-template-columns: 48px 48px 48px;
    grid-template-rows: 48px 48px 48px;
  }
  .gb-round-btn {
    width: 58px;
    height: 58px;
    font-size: 22px;
  }
  .gb-ab-cluster {
    gap: 20px;
    padding: 12px 18px 9px;
  }
  .gb-actions-shell {
    gap: 18px;
    margin-bottom: 18px;
  }
}

@media (max-height: 450px) {
  .touch-controls {
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
  }
  .gb-dpad-shell {
    padding: 5px;
  }
  .gb-dpad {
    grid-template-columns: 36px 36px 36px;
    grid-template-rows: 36px 36px 36px;
  }
  .gb-dir {
    font-size: 11px;
  }
  .gb-center span {
    width: 16px;
    height: 16px;
  }
  .gb-actions-shell {
    gap: 12px;
    margin-bottom: 10px;
  }
  .gb-pill-btn {
    padding: 5px 14px;
    font-size: 10px;
    transform: rotate(-16deg) translate(-26px, -2px);
  }
  .gb-pill-btn:active,
  .gb-pill-btn.is-pressed {
    transform: rotate(-16deg) translate(-26px, 0px);
  }
  .gb-ab-cluster {
    gap: 16px;
    padding: 8px 14px 6px;
  }
  .gb-round-btn {
    width: 46px;
    height: 46px;
    font-size: 18px;
  }
}

/* Responsive */
@media (max-width: 760px) {
  .controls-grid,
  .online-actions {
    grid-template-columns: 1fr;
  }
  .hud {
    top: var(--space-2);
    width: 96vw;
    gap: var(--space-2);
  }
  .hud-player {
    padding: 6px 8px;
  }
  .hud-name,
  .hud-score {
    font-size: 12px;
  }
}
