/* light-theme: manual
   Nexaman – handheld console look: a bezel with a pixel screen (canvas world +
   DOM overlays for dialogs, menus and battles), D-pad and A/B buttons.
   All overlay sizes use container units (cqw) of the screen, so the UI scales
   like a real handheld at any width. */

.nxm-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
  --nxm-font: "Monocraft", monospace;
  --nxm-pixel: "Press Start 2P", monospace;
}

.nxm-header { text-align: center; margin-bottom: 1.6rem; }

.nxm-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
}

.nxm-back:hover { color: var(--text-main); }

.nxm-logo {
  margin: 0;
  font-family: var(--nxm-pixel);
  font-size: clamp(1.8rem, 6vw, 3.2rem);
  letter-spacing: 0.06em;
  color: #fde047;
  text-shadow: 4px 4px 0 #1d4ed8, 8px 8px 0 #0b1220;
}

.nxm-tagline { margin-top: 0.8rem; color: var(--text-muted); }

/* --- console body --- */
.nxm-console {
  margin: 0 auto;
  max-width: 760px;
  padding: clamp(14px, 3vw, 26px);
  border-radius: 26px 26px 60px 26px;
  background: linear-gradient(160deg, #4338ca, #312e81 60%, #1e1b4b);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.18), inset 0 -6px 0 rgba(0, 0, 0, 0.3), 0 24px 60px rgba(0, 0, 0, 0.5);
}

.nxm-bezel {
  padding: clamp(10px, 2.6vw, 22px);
  border-radius: 14px 14px 40px 14px;
  background: #1f2433;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.5);
}

.nxm-screen {
  position: relative;
  container-type: inline-size;
  width: 100%;
  aspect-ratio: 240 / 176;
  overflow: hidden;
  border-radius: 4px;
  background: #000;
  image-rendering: pixelated;
  user-select: none;
  -webkit-user-select: none;
}

.nxm-screen canvas#nxm-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.nxm-screen.is-flash::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 50;
  background: #fff;
  pointer-events: none;
  animation: nxm-flash 0.6s ease-out forwards;
}

@keyframes nxm-flash { from { opacity: 1; } to { opacity: 0; } }

.nxm-screen .hidden { display: none !important; }

/* --- dialog box (classic two-line text box) --- */
.nxm-dialog {
  position: absolute;
  left: 2cqw;
  right: 2cqw;
  bottom: 2cqw;
  z-index: 40;
  min-height: 19cqw;
  padding: 2.6cqw 3.2cqw;
  border: 0.9cqw solid #1f2937;
  border-radius: 1.6cqw;
  background: #f8fafc;
  box-shadow: inset 0 0 0 0.6cqw #cbd5e1;
  color: #111827;
  font: 400 3.5cqw/1.45 var(--nxm-font);
}

.nxm-dialog p { margin: 0; white-space: pre-line; }

.nxm-dialog-arrow {
  position: absolute;
  right: 3cqw;
  bottom: 1.6cqw;
  font-size: 2.6cqw;
  color: #dc2626;
  opacity: 0;
}

.nxm-dialog.is-done .nxm-dialog-arrow { opacity: 1; animation: nxm-bob 0.7s steps(2) infinite; }

@keyframes nxm-bob { 50% { transform: translateY(0.6cqw); } }

/* --- choice menus --- */
.nxm-choices {
  position: absolute;
  z-index: 45;
  right: 2cqw;
  top: 2cqw;
  min-width: 34cqw;
  max-height: 72cqw;
  overflow-y: auto;
  padding: 1.6cqw;
  border: 0.9cqw solid #1f2937;
  border-radius: 1.6cqw;
  background: #f8fafc;
  box-shadow: inset 0 0 0 0.6cqw #cbd5e1;
  font: 400 3.3cqw/1.25 var(--nxm-font);
  color: #111827;
}

.nxm-choices-title {
  padding: 0.6cqw 1.6cqw 1.2cqw;
  font-family: var(--nxm-pixel);
  font-size: 2.1cqw;
  color: #475569;
}

.nxm-choices-grid { display: grid; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); gap: 0.4cqw 1.6cqw; }

.nxm-choice {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2cqw 1cqw;
  padding: 0.9cqw 1.4cqw 0.9cqw 3.8cqw;
  border: 0;
  border-radius: 1cqw;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.nxm-cursor { position: absolute; left: 0.8cqw; top: 1.2cqw; font-size: 2.4cqw; color: #111827; opacity: 0; }
.nxm-choice.is-active .nxm-cursor { opacity: 1; animation: nxm-cur 0.6s steps(2) infinite; }
.nxm-choice.is-active { background: rgba(37, 99, 235, 0.1); }

@keyframes nxm-cur { 50% { transform: translateX(0.5cqw); } }

.nxm-choice.is-disabled { opacity: 0.35; cursor: default; }
.nxm-choice-sub { width: 100%; font-size: 2.4cqw; color: #64748b; }

/* type-coloured options (moves, starters) */
.nxm-choice[style*="--tc"] .nxm-choice-label::before {
  content: "";
  display: inline-block;
  width: 1.8cqw;
  height: 1.8cqw;
  margin-right: 1cqw;
  border-radius: 0.4cqw;
  background: var(--tc);
  border: 0.3cqw solid #1f2937;
  vertical-align: middle;
}

/* battle command menu sits bottom-right, next to the text box */
.nxm-choices.is-battle-menu,
.nxm-choices.is-moves {
  top: auto;
  bottom: 2cqw;
  right: 2cqw;
  min-width: 0;
  width: 46cqw;
  min-height: 19cqw;
  font-family: var(--nxm-pixel);
  font-size: 2.4cqw;
}

.nxm-choices.is-moves { width: 70cqw; font-family: var(--nxm-font); font-size: 3cqw; }

/* lists (team, box, bag) take the whole screen */
.nxm-choices.is-list,
.nxm-choices.is-start-menu.is-list {
  left: 2cqw;
  right: 2cqw;
  top: 2cqw;
  bottom: auto;
  max-height: 68cqw;
}

.nxm-choices.is-start-menu { font-family: var(--nxm-pixel); font-size: 2.5cqw; min-width: 30cqw; }

.nxm-choices.is-starter { left: 6cqw; right: 6cqw; top: auto; bottom: 26cqw; }
.nxm-choices.is-starter .nxm-choice { justify-content: center; padding-left: 3.8cqw; }

.nxm-choices.is-title {
  left: 50%;
  right: auto;
  top: auto;
  bottom: 7cqw;
  translate: -50% 0;
  font-family: var(--nxm-pixel);
  font-size: 2.6cqw;
  background: rgba(15, 23, 42, 0.85);
  color: #fde047;
  border-color: #fde047;
  box-shadow: none;
}

.nxm-choices.is-title .nxm-cursor { color: #fde047; }
.nxm-choices.is-title .nxm-choice.is-active { background: rgba(253, 224, 71, 0.12); }

/* team rows */
.nxm-mini { display: inline-block; width: 7cqw; height: 7cqw; flex-shrink: 0; }
.nxm-mini canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.nxm-row-main { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 1.4cqw; flex: 1; min-width: 0; }
.nxm-row-main small { font-size: 2.4cqw; color: #475569; }
.nxm-row-hp { grid-column: 1 / -1; height: 1.3cqw; border-radius: 1cqw; background: #cbd5e1; overflow: hidden; }
.nxm-row-hp i, .nxm-b-hp i { display: block; height: 100%; background: #22c55e; }
.nxm-row-hp i.is-mid, .nxm-b-hp i.is-mid { background: #eab308; }
.nxm-row-hp i.is-low, .nxm-b-hp i.is-low { background: #ef4444; }

/* --- toast (map names) --- */
.nxm-toast {
  position: absolute;
  left: 2cqw;
  top: 2cqw;
  z-index: 30;
  padding: 1.2cqw 2.6cqw;
  border: 0.7cqw solid #1f2937;
  border-radius: 1cqw;
  background: #f8fafc;
  color: #111827;
  font: 400 2.4cqw var(--nxm-pixel);
  opacity: 0;
  pointer-events: none;
}

.nxm-toast.is-on { animation: nxm-toast 2.6s ease forwards; }

@keyframes nxm-toast {
  0% { opacity: 0; transform: translateY(-3cqw); }
  12%, 80% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-3cqw); }
}

/* --- title screen --- */
.nxm-title {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: grid;
  justify-items: center;
  align-content: start;
  padding-top: 9cqw;
  background:
    radial-gradient(circle at 50% 120%, #2563eb, transparent 60%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0 0.4cqw, transparent 0.4cqw 4cqw),
    #0b1030;
}

.nxm-title-logo {
  font: 400 9cqw var(--nxm-pixel);
  color: #fde047;
  text-shadow: 0.8cqw 0.8cqw 0 #1d4ed8, 1.6cqw 1.6cqw 0 #020617;
  animation: nxm-logo 2.4s ease-in-out infinite;
}

@keyframes nxm-logo { 50% { transform: translateY(-1cqw); } }

.nxm-title-sub { margin-top: 2cqw; font: 400 2.2cqw var(--nxm-pixel); color: #93c5fd; letter-spacing: 0.3em; }
.nxm-title-parade { display: flex; gap: 3cqw; margin-top: 5cqw; }
.nxm-title-parade canvas { width: 16cqw; height: 16cqw; image-rendering: pixelated; animation: nxm-hop 1.2s steps(2) infinite; }
.nxm-title-parade canvas:nth-child(2) { animation-delay: 0.4s; }
.nxm-title-parade canvas:nth-child(3) { animation-delay: 0.8s; }

@keyframes nxm-hop { 50% { transform: translateY(-1.6cqw); } }

/* --- creature preview (starter choice, details) --- */
.nxm-preview {
  position: absolute;
  z-index: 38;
  left: 50%;
  top: 6cqw;
  translate: -50% 0;
  padding: 2cqw;
  border: 0.9cqw solid #1f2937;
  border-radius: 50%;
  background: radial-gradient(circle, #fff, #e2e8f0);
}

.nxm-preview canvas { display: block; width: 26cqw; height: 26cqw; image-rendering: pixelated; }

/* --- battle --- */
.nxm-battle {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: linear-gradient(180deg, #bfe3ff 0%, #e8f6ff 45%, #b9e2a6 45%, #8fcf78 100%);
}

.nxm-battle.bg-forest { background: linear-gradient(180deg, #a7d8a0 0%, #d6efcf 45%, #6fae5a 45%, #4b8a3c 100%); }
.nxm-battle.bg-shore { background: linear-gradient(180deg, #9fd6ff 0%, #e0f2fe 45%, #f1e3b4 45%, #e3cf91 100%); }
.nxm-battle.bg-cave { background: linear-gradient(180deg, #2a2335 0%, #463b52 45%, #5b5068 45%, #3b3345 100%); }

.nxm-battle.is-intro { animation: nxm-battle-in 0.7s steps(7); }

@keyframes nxm-battle-in {
  0%, 28%, 57% { filter: invert(1); }
  14%, 42%, 71% { filter: none; }
  100% { filter: none; }
}

.nxm-side { position: absolute; inset: 0; pointer-events: none; }

.nxm-b-sprite { position: absolute; width: 30cqw; height: 30cqw; }
.nxm-b-sprite canvas { position: relative; z-index: 1; width: 100%; height: 100%; image-rendering: pixelated; }

.nxm-plat {
  position: absolute;
  left: -15%;
  right: -15%;
  bottom: 4%;
  height: 22%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.16);
  box-shadow: inset 0 -1cqw 0 rgba(0, 0, 0, 0.12);
}

.nxm-foe .nxm-b-sprite { right: 8cqw; top: 1.5cqw; width: 28cqw; height: 28cqw; }
.nxm-me .nxm-b-sprite { left: 8cqw; top: 21cqw; width: 30cqw; height: 30cqw; }

.nxm-b-box {
  position: absolute;
  padding: 1.4cqw 2.2cqw 1.6cqw;
  min-width: 44cqw;
  border: 0.8cqw solid #1f2937;
  border-radius: 1.6cqw 0.6cqw 1.6cqw 0.6cqw;
  background: #fefce8;
  color: #111827;
  font: 400 3.1cqw var(--nxm-font);
  box-shadow: 0.8cqw 0.8cqw 0 rgba(0, 0, 0, 0.25);
}

.nxm-foe .nxm-b-box { left: 3cqw; top: 4cqw; }
.nxm-me .nxm-b-box { right: 3cqw; top: 32cqw; }

.nxm-b-top { display: flex; align-items: baseline; gap: 1cqw; }
.nxm-b-name { font-weight: 700; }
.nxm-b-lvl { margin-left: auto; font-family: var(--nxm-pixel); font-size: 2cqw; }
.nxm-b-caught { color: #dc2626; font-size: 2.2cqw; }

.nxm-b-type {
  display: inline-block;
  margin-top: 0.4cqw;
  padding: 0.1cqw 1.2cqw;
  border-radius: 0.6cqw;
  color: #fff;
  font: 400 1.8cqw var(--nxm-pixel);
  text-shadow: 0.25cqw 0.25cqw 0 rgba(0, 0, 0, 0.45);
}

.nxm-b-hpwrap { display: flex; align-items: center; gap: 1cqw; margin-top: 0.8cqw; }
.nxm-b-hpwrap em { font: 400 1.8cqw var(--nxm-pixel); color: #f59e0b; font-style: normal; }

.nxm-b-hp {
  flex: 1;
  height: 1.6cqw;
  border: 0.4cqw solid #1f2937;
  border-radius: 1cqw;
  background: #475569;
  overflow: hidden;
}

.nxm-b-hp i { transition: width 0.6s steps(12), background 0.3s; }

.nxm-b-hptext { display: block; text-align: right; font: 400 2.1cqw var(--nxm-pixel); margin-top: 0.8cqw; }

.nxm-b-xp { height: 0.9cqw; margin-top: 0.8cqw; background: #cbd5e1; border-radius: 1cqw; overflow: hidden; }
.nxm-b-xp i { display: block; height: 100%; background: #38bdf8; transition: width 0.5s; }

/* hit / lunge / faint / switch-in */
.nxm-side.is-hit .nxm-b-sprite canvas { animation: nxm-hit 0.5s steps(2) 1; }
@keyframes nxm-hit { 0%, 50% { opacity: 0.1; } 25%, 75% { opacity: 1; } }

.nxm-foe.is-lunge .nxm-b-sprite { animation: nxm-lunge-l 0.3s ease; }
.nxm-me.is-lunge .nxm-b-sprite { animation: nxm-lunge-r 0.3s ease; }
@keyframes nxm-lunge-l { 50% { transform: translateX(-4cqw); } }
@keyframes nxm-lunge-r { 50% { transform: translateX(4cqw); } }

.nxm-side.is-faint .nxm-b-sprite canvas { transition: transform 0.5s ease-in, opacity 0.5s; transform: translateY(40%); opacity: 0; }
.nxm-side.is-in .nxm-b-sprite canvas { animation: nxm-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes nxm-in { from { transform: scale(0.2); opacity: 0; } }

.nxm-foe.is-captured .nxm-b-sprite canvas { transition: transform 0.35s ease-in, opacity 0.35s; transform: scale(0.1); opacity: 0; }

/* the thrown ball */
.nxm-ball {
  position: absolute;
  z-index: 5;
  right: 21cqw;
  top: 22cqw;
  width: 6cqw;
  height: 6cqw;
  border: 0.6cqw solid #111827;
  border-radius: 50%;
  background: linear-gradient(180deg, #ef4444 0 46%, #111827 46% 54%, #f8fafc 54%);
  opacity: 0;
}

.nxm-ball::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.8cqw;
  height: 1.8cqw;
  translate: -50% -50%;
  border: 0.4cqw solid #111827;
  border-radius: 50%;
  background: #f8fafc;
}

.nxm-ball.is-super { background: linear-gradient(180deg, #2563eb 0 46%, #111827 46% 54%, #f8fafc 54%); }
.nxm-ball.is-throw { opacity: 1; animation: nxm-throw 0.6s cubic-bezier(0.3, 0, 0.7, 1); }
@keyframes nxm-throw { from { transform: translate(-48cqw, 36cqw) rotate(-540deg); } }
.nxm-ball.is-shake { animation: nxm-shake 0.6s ease; }
@keyframes nxm-shake { 20% { transform: rotate(-24deg); } 45% { transform: rotate(20deg); } 70% { transform: rotate(-8deg); } }
.nxm-ball.is-caught::before { content: "✦"; position: absolute; left: 50%; top: -4cqw; translate: -50% 0; color: #facc15; font-size: 3cqw; }

/* --- evolution --- */
.nxm-evo {
  position: absolute;
  inset: 0;
  z-index: 36;
  display: grid;
  place-items: center;
  background: radial-gradient(circle, #1e3a8a, #020617 70%);
}

.nxm-evo canvas { width: 40cqw; height: 40cqw; image-rendering: pixelated; }

/* --- NexDex panel --- */
.nxm-panel {
  position: absolute;
  inset: 0;
  z-index: 42;
  display: flex;
  flex-direction: column;
  padding: 2cqw;
  background: #dc2626;
  font-family: var(--nxm-font);
}

.nxm-dex-head,
.nxm-dex-foot { font: 400 2.2cqw var(--nxm-pixel); color: #fff; padding: 1cqw 0.6cqw; text-shadow: 0.3cqw 0.3cqw 0 #7f1d1d; }

.nxm-dex {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1cqw;
  padding: 1.2cqw;
  border: 0.8cqw solid #7f1d1d;
  border-radius: 1.4cqw;
  background: #f8fafc;
}

.nxm-dex-cell {
  display: grid;
  justify-items: center;
  padding: 0.6cqw;
  border-radius: 1cqw;
  background: #e2e8f0;
}

.nxm-dex-cell.is-caught { background: #dcfce7; }
.nxm-dex-no { font: 400 1.5cqw var(--nxm-pixel); color: #64748b; }
.nxm-dex-spr canvas { width: 11cqw; height: 11cqw; image-rendering: pixelated; }
.nxm-dex-name { font-size: 2.2cqw; color: #111827; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* --- controls --- */
.nxm-pad {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  margin-top: clamp(14px, 3vw, 24px);
  user-select: none;
  touch-action: none;
}

.nxm-dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
}

.nxm-dpad button,
.nxm-ab button,
.nxm-start {
  border: 0;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.85);
  -webkit-tap-highlight-color: transparent;
}

.nxm-dpad button { background: #111827; box-shadow: inset 0 -4px 0 #000; font-size: 0.9rem; }
.nxm-dpad [data-btn="up"] { grid-column: 2; grid-row: 1; border-radius: 8px 8px 0 0; }
.nxm-dpad [data-btn="left"] { grid-column: 1; grid-row: 2; border-radius: 8px 0 0 8px; }
.nxm-dpad [data-btn="right"] { grid-column: 3; grid-row: 2; border-radius: 0 8px 8px 0; }
.nxm-dpad [data-btn="down"] { grid-column: 2; grid-row: 3; border-radius: 0 0 8px 8px; }
.nxm-dpad::after { content: ""; grid-column: 2; grid-row: 2; background: #111827; }
.nxm-dpad button.is-down { background: #000; box-shadow: none; translate: 0 2px; }

.nxm-mid { display: flex; justify-content: center; }

.nxm-start {
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  background: #1f2433;
  font: 400 0.6rem var(--nxm-pixel);
  box-shadow: inset 0 -3px 0 #000;
}

.nxm-ab { display: flex; gap: 0.9rem; align-items: center; rotate: -18deg; }

.nxm-ab button {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  font: 400 0.95rem var(--nxm-pixel);
  background: radial-gradient(circle at 35% 30%, #f87171, #b91c1c 70%);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.35), 0 4px 0 rgba(0, 0, 0, 0.4);
}

.nxm-ab [data-btn="A"] { translate: 0 -14px; }
.nxm-ab button.is-down,
.nxm-start.is-down { translate: 0 3px; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.35); }
.nxm-ab [data-btn="A"].is-down { translate: 0 -11px; }

.nxm-help {
  margin-top: 1.4rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.8;
}

.nxm-help kbd {
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--nx-line, rgba(148, 163, 184, 0.3));
  background: var(--nx-surface-2, rgba(30, 41, 59, 0.5));
  font: 600 0.75rem Inter, sans-serif;
}

@media (max-width: 520px) {
  .nxm-page { padding: 1rem 0.5rem 3rem; }
  .nxm-dpad { grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); }
  .nxm-ab button { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .nxm-title-logo, .nxm-title-parade canvas, .nxm-battle.is-intro { animation: none; }
}

html[data-theme="light"] .nxm-logo { text-shadow: 4px 4px 0 #1d4ed8, 8px 8px 0 #93c5fd; color: #eab308; }
