:root {
  --bg-0: #0c1016;
  --bg-1: #121821;
  --bg-2: #1a2330;
  --panel: #151c27ee;
  --line: #2a384a;
  --text: #e8eef6;
  --muted: #8fa0b5;
  --cyan: #3ec7ff;
  --cyan-dim: #1a6f94;
  --danger: #6ec8ff;
  --danger-hot: #b8ecff;
  --safe-hint: #2dd4a8;
  --warn: #f0b429;
  --fail: #ff5d6c;
  --tile: #3a4554;
  --tile-alt: #323c49;
  --grate: #1e2632;
  --metal: #4a5566;
  --font: "Chakra Petch", sans-serif;
  --mono: "IBM Plex Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, #1a3a4f55, transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, #0d2a3555, transparent),
    var(--bg-0);
  color: var(--text);
  font-family: var(--font);
}

body {
  min-height: 100vh;
}

a {
  color: var(--cyan);
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2rem;
}

.app.is-playing {
  max-width: none;
  margin: 0;
  padding: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #05080c;
}

.app.is-playing .setup-panel,
.app.is-playing .legend,
.app.is-playing .dev-credit {
  display: none;
}

.app.is-playing .topbar {
  position: absolute;
  z-index: 6;
  top: 0;
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.55rem 1rem;
  background: linear-gradient(180deg, #070b10e8 0%, #070b1088 55%, transparent);
  pointer-events: none;
}

.app.is-playing .hud-stats {
  pointer-events: auto;
}

.app.is-playing .layout {
  flex: 1;
  display: block;
  min-height: 0;
  height: 100%;
}

.app.is-playing .stage-wrap {
  height: 100%;
  gap: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05080c;
}

/* PXG viewport 21×11 — largest fit without cropping or stretching */
.app.is-playing .stage {
  width: min(100vw, calc(100dvh * 21 / 11));
  max-width: 100%;
  max-height: 100dvh;
  height: auto;
  aspect-ratio: 21 / 11;
  border-radius: 0;
  border: 1px solid #1a2430;
  box-shadow: 0 0 0 1px #00000088;
  margin: 0;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background:
    linear-gradient(145deg, #2a9fd6, #0d4a66),
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 4px,
      #ffffff11 4px,
      #ffffff11 5px
    );
  box-shadow:
    0 0 0 1px #5ecfff44,
    0 0 24px #3ec7ff33;
  position: relative;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 10px 18px;
  background: #e8f7ff;
  clip-path: polygon(50% 0%, 62% 38%, 100% 38%, 70% 62%, 82% 100%, 50% 75%, 18% 100%, 30% 62%, 0% 38%, 38% 38%);
}

.brand h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1;
}

.subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.hud-stats {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.stat {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.8rem;
  min-width: 88px;
}

.stat-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.stat-value {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--cyan);
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.05rem 1.15rem;
  backdrop-filter: blur(8px);
}

.panel-block {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.pokemon-search-field {
  position: relative;
  margin-bottom: 0.7rem;
}

.pokemon-search-field .pokemon-results {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-0);
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.pokemon-results[hidden] {
  display: none !important;
}

.panel-block:last-of-type {
  border-bottom: none;
}

.panel h2 {
  margin: 0 0 0.7rem;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.7rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.field-inline {
  margin-bottom: 0;
}

.field-inline span {
  color: var(--muted);
  font-size: 0.85rem;
}

.toggle-end {
  margin-left: auto;
  flex-shrink: 0;
}

.field input,
.field select {
  background: var(--bg-0);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font-family: var(--font);
  font-size: 0.95rem;
}

.field input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  color: var(--muted);
}

.pokemon-pick {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-0);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.55rem;
}

.pokemon-pick img {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  background: #0a0e14;
  border-radius: 8px;
}

.pokemon-pick strong {
  display: block;
  font-size: 1rem;
}

.pokemon-pick span {
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--mono);
}

.pokemon-results li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  border-bottom: 1px solid #1c2633;
}

.pokemon-results li:hover,
.pokemon-results li[aria-selected="true"] {
  background: #1a3040;
}

.pokemon-results img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
}

.pokemon-results .meta {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--cyan);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.92rem;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: var(--cyan);
  width: 1.05rem;
  height: 1.05rem;
}

.toggle + .toggle {
  margin-top: 0.55rem;
}

.salac-icon {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
  flex-shrink: 0;
  filter: drop-shadow(0 0 4px rgba(62, 199, 255, 0.35));
}

.hint {
  margin: 0.45rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.seg-btn {
  background: var(--bg-0);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 0.45rem 0.3rem;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  color: var(--text);
  border-color: var(--cyan);
  background: #143447;
  box-shadow: inset 0 0 0 1px #3ec7ff55;
}

.controls-help ol {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.controls-help li {
  margin-bottom: 0.35rem;
}

.controls-help strong {
  color: var(--safe-hint);
}

.keys {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

kbd {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.1rem 0.35rem;
  color: var(--text);
}

.actions {
  display: grid;
  gap: 0.45rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.btn:hover {
  border-color: #4a6280;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: linear-gradient(180deg, #2a8eb8, #17668a);
  border-color: #4eb7e0;
  box-shadow: 0 0 20px #3ec7ff33;
}

.btn.primary:hover {
  border-color: #9adfff;
}

.stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.stage {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0a0e14;
  box-shadow:
    0 0 0 1px #ffffff08,
    0 20px 50px #00000066;
  aspect-ratio: 21 / 11;
  max-width: min(100%, 840px);
  margin: 0 auto;
  width: 100%;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #070b10cc;
  backdrop-filter: blur(3px);
  transition: opacity 0.25s, visibility 0.25s;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-card {
  text-align: center;
  max-width: 360px;
  padding: 1.4rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #121925ee;
  animation: rise 0.45s ease;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.overlay-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--cyan);
}

.overlay-card h2 {
  margin: 0.35rem 0 0.55rem;
  font-size: 1.8rem;
  letter-spacing: 0.03em;
}

.overlay-card p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.1rem;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 0.35rem;
  vertical-align: -1px;
  border: 1px solid #ffffff33;
}

.swatch.safe {
  background: #6e7484;
  box-shadow: inset 0 0 0 1px #9aa3b4;
}

.swatch.danger {
  background: var(--danger-hot);
  box-shadow: 0 0 8px var(--cyan);
}

.swatch.just-hit {
  background: var(--safe-hint);
}

.swatch.border {
  background: #2a5a78;
  box-shadow: 0 0 8px #4a98c088;
}

.swatch.blocked {
  background: #3a5566;
  box-shadow: inset 0 0 0 1px #5ecfff55;
}

.swatch.player {
  background: #f4d35e;
}

.dev-credit {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  margin-top: 1.25rem;
  color: var(--muted);
  opacity: 0.55;
}

.dev-credit-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

.dev-credit-row strong {
  font-weight: 600;
  color: inherit;
}

.dev-credit-logo {
  width: 18px;
  height: 18px;
  object-fit: contain;
  border-radius: 4px;
  flex-shrink: 0;
}

.dev-credit-url {
  display: inline;
  width: fit-content;
  max-width: 100%;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: inherit;
  text-decoration: none;
  opacity: 0.75;
  word-break: break-all;
  transition: opacity 0.15s, color 0.15s;
}

.dev-credit-url:hover {
  opacity: 1;
  color: var(--cyan);
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .setup-panel {
    order: 2;
  }

  .stage-wrap {
    order: 1;
  }
}
