/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #1a1a2e;
  --accent:       #2dd4bf;
  --text:         #eee;
  --text-dim:     #aaa;
  --hp-green:     #10d070;
  --hp-yellow:    #f8d030;
  --hp-red:       #f03030;
  --info-bg:      #f8f0d0;
  --info-border:  #484040;
  --info-text:    #383028;
  --textbox-bg:   #f8f0d0;
  --battle-bg:    #98d8a0;
  --battle-bg2:   #b8e8b0;
  --menu-bg:      #f8f0d0;
  --profile-bg:   #222244;
  --profile-text: #ccc;
}

:root.light {
  --bg:           #f0f0f0;
  --text:         #222;
  --text-dim:     #666;
  --profile-bg:   #fff;
  --profile-text: #444;
}

html { font-size: 16px; }

body {
  font-family: 'Press Start 2P', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Header ──────────────────────────────────────────── */
header {
  width: 100%;
  max-width: 720px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.2rem 1rem;
}

header h1 {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

.social-links {
  display: flex;
  gap: 0.75rem;
}

.social-links a {
  transition: color 0.2s;
  display: flex;
  align-items: center;
  color: var(--text-dim);
}

.social-links a:hover {
  color: var(--accent);
}

/* ── Mute Button ─────────────────────────────────────── */
.mute-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 4px;
  transition: color 0.2s;
}

.mute-btn:hover {
  color: var(--accent);
}

/* ── Theme Toggle ────────────────────────────────────── */
.theme-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 4px;
  transition: color 0.2s;
}

.theme-toggle:hover {
  color: var(--accent);
}

/* ── Profile Intro ───────────────────────────────────── */
.profile-intro {
  background: var(--profile-bg);
  border-radius: 8px;
  padding: 1.5rem 1.25rem;
  margin-bottom: 1.25rem;
}

.profile-intro p {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--profile-text);
}

.profile-intro p + p {
  margin-top: 0.75rem;
}

.accent-picker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.accent-picker label {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.accent-picker select {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.8rem;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--text-dim);
  background: var(--profile-bg);
  color: var(--profile-text);
  cursor: pointer;
}

/* ── FX Canvas Overlay ───────────────────────────────── */
.fx-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

/* ── Professor Oak intro ─────────────────────────────── */
.oak-intro {
  width: 100%;
  border: 4px solid var(--info-border);
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(180deg, #88b8a0 0%, #a8d0b8 30%, #c8e8d0 60%, #d8f0e0 100%);
}

.oak-dialogue {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  min-height: 368px;
  padding: 0;
  text-align: left;
  width: 100%;
  position: relative;
}

.oak-sprite-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding-top: 24px;
  position: relative;
}

.oak-sprite {
  width: 128px;
  height: auto;
  image-rendering: pixelated;
  position: relative;
  z-index: 1;
}

.oak-sprite-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.oak-shadow {
  width: 80px;
  height: 10px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.12);
  margin-top: -6px;
}

.oak-input-area {
  position: absolute;
  bottom: 8px;
  right: 16px;
}

.oak-speech-box {
  width: 100%;
  background: rgba(248, 248, 248, 0.92);
  border-top: 3px solid #586868;
  padding: 14px 20px;
  min-height: 72px;
  box-sizing: border-box;
}

.oak-text {
  font-size: 0.65rem;
  color: #282828;
  line-height: 2;
  min-height: 3em;
  margin: 0;
  white-space: pre-line;
  text-align: left;
}

.oak-name-entry {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}

.oak-gender-entry {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
}

.oak-name-input {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.7rem;
  background: #fff;
  color: #282828;
  border: 3px solid #586868;
  border-radius: 6px;
  padding: 8px 12px;
  width: 160px;
  text-align: center;
  text-transform: uppercase;
  outline: none;
}

.oak-name-input:focus {
  border-color: #3898a0;
}

.oak-confirm-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
  background: #e0e8e4;
  color: #282828;
  border: 3px solid #586868;
  border-radius: 6px;
  padding: 8px 20px;
  cursor: pointer;
  transition: background 0.15s;
}

.oak-confirm-btn:hover {
  background: #c8d8d0;
}

/* ── Trainer shrink transition ───────────────────────── */
.trainer-transition {
  width: 100%;
  min-height: 368px;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 4px solid var(--info-border);
  border-radius: 8px;
  overflow: hidden;
}

.trainer-transition-sprite {
  width: 128px;
  height: 128px;
  image-rendering: pixelated;
  filter: brightness(0) invert(1);
}

.trainer-transition-sprite.shrink {
  animation: trainerShrink 2s ease-in forwards;
}

@keyframes trainerShrink {
  0%   { transform: scale(1); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}

/* ── Grass walk scene ────────────────────────────────── */
.grass-walk-scene {
  width: 100%;
  border: 4px solid var(--info-border);
  border-radius: 8px;
  overflow: hidden;
}

.grass-walk-field {
  position: relative;
  width: 100%;
  height: 368px;
  background: var(--battle-bg);
  overflow: hidden;
}

.walk-avatar {
  position: absolute;
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 5;
  transition: left 0.4s linear, top 0.4s linear;
}

.grass-patch {
  position: absolute;
  width: 32px;
  height: 24px;
  background: #48a030;
  border-radius: 2px;
  opacity: 0.7;
}

.grass-patch::before,
.grass-patch::after {
  content: '';
  position: absolute;
  bottom: 0;
  width: 4px;
  background: #308020;
  border-radius: 2px 2px 0 0;
}

.grass-patch::before { left: 4px; height: 16px; }
.grass-patch::after { left: 14px; height: 12px; }

.tall-grass-patches .grass-patch:nth-child(odd)::before { height: 14px; }
.tall-grass-patches .grass-patch:nth-child(odd)::after { height: 18px; left: 22px; }

/* ── Loading ─────────────────────────────────────────── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  min-height: 368px;
  border: 4px solid var(--info-border);
  border-radius: 8px;
  background: var(--bg);
}

.loading p {
  font-size: 0.65rem;
  color: var(--text-dim);
}

.pokeball-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(to bottom, #ee1515 50%, #f0f0f0 50%);
  border: 3px solid #222;
  position: relative;
  animation: spin 1s linear infinite;
}

.pokeball-spinner::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #f0f0f0;
  border: 3px solid #222;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ── Battle Scene ────────────────────────────────────── */
main {
  width: 100%;
  max-width: 720px;
  padding: 0 1rem 2rem;
  flex: 1;
}

.battle-scene {
  border: 4px solid var(--info-border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--battle-bg);
  position: relative;
}

/* ── Battle Field ────────────────────────────────────── */
.battle-field {
  position: relative;
  height: 280px;
  background: linear-gradient(180deg, var(--battle-bg2) 0%, var(--battle-bg) 100%);
  overflow: hidden;
}

/* ── Opponent Area (top) ─────────────────────────────── */
.opponent-area {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 16px 0;
}

/* ── Player Area (bottom) ────────────────────────────── */
.player-area {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 16px 12px;
}

/* ── Info Boxes ──────────────────────────────────────── */
.info-box {
  background: var(--info-bg);
  border: 3px solid var(--info-border);
  border-radius: 6px;
  padding: 6px 10px 6px 10px;
  min-width: 220px;
  color: var(--info-text);
  z-index: 2;
  position: relative;
}

.opponent-info {
  align-self: flex-start;
}

.player-info {
  align-self: flex-end;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.poke-name {
  font-size: 0.7rem;
  text-transform: uppercase;
}

.poke-level {
  font-size: 0.6rem;
  color: var(--info-text);
}

.hp-bar-container {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hp-label {
  font-size: 0.45rem;
  font-weight: bold;
  color: var(--hp-yellow);
  background: #504840;
  padding: 1px 4px;
  border-radius: 2px;
  line-height: 1;
}

.hp-bar-track {
  flex: 1;
  height: 6px;
  background: #383028;
  border-radius: 3px;
  overflow: hidden;
}

.hp-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--hp-green);
  border-radius: 3px;
  transition: width 0.6s ease, background-color 0.4s ease;
}

.hp-numbers {
  text-align: right;
  font-size: 0.6rem;
  margin-top: 2px;
  color: var(--info-text);
}

/* ── Status tags ─────────────────────────────────────── */
.status-tag {
  display: inline-block;
  font-size: 0.4rem;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: bold;
  margin-top: 3px;
  color: #fff;
  text-transform: uppercase;
}

.status-psn { background: #a040a0; }
.status-par { background: #f8d030; color: #483818; }
.status-brn { background: #f08030; }
.status-slp { background: #a8a878; }
.status-frz { background: #98d8d8; color: #384868; }

/* ── Sprites ─────────────────────────────────────────── */
.sprite-container {
  z-index: 2;
  position: relative;
}

.pokemon-sprite {
  width: 128px;
  height: 128px;
  image-rendering: pixelated;
}

.trainer-sprite {
  width: 128px;
  height: 128px;
  image-rendering: pixelated;
}

/* Ground shadows */
.ground-shadow {
  position: absolute;
  bottom: 2px;
  width: 80px;
  height: 8px;
  border-radius: 50%;
  background: rgba(0,0,0,0.15);
  z-index: 1;
}

.opponent-shadow { right: 24px; }
.player-shadow   { left: 24px; }

/* Slide-in animations */
.opponent-sprite-container {
  opacity: 0;
  transform: translateX(80px);
}

.player-sprite-container {
  opacity: 1;
}

.slide-in-right {
  animation: slideInRight 0.5s ease-out forwards;
}

.slide-in-left {
  animation: slideInLeft 0.5s ease-out forwards;
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(80px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-80px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Trainer slides out to the left */
.trainer-slide-out {
  animation: trainerSlideOut 0.5s ease-in forwards;
}

@keyframes trainerSlideOut {
  0%   { transform: translateX(0); opacity: 1; }
  100% { transform: translateX(-160px); opacity: 0; }
}

/* Pokeball throw arc */
.pokeball-throw {
  position: absolute;
  bottom: 30px;
  left: 20px;
  width: 16px;
  height: 16px;
  z-index: 5;
}

.pokeball-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(180deg, #e03030 50%, #f8f8f8 50%);
  border: 2px solid #282828;
  position: relative;
}

.pokeball-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background: #f8f8f8;
  border: 2px solid #282828;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.pokeball-arc {
  animation: pokeballArc 0.45s ease-in forwards;
}

@keyframes pokeballArc {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  40%  { transform: translate(40px, -50px) rotate(180deg); opacity: 1; }
  70%  { transform: translate(60px, -30px) rotate(300deg); opacity: 1; }
  100% { transform: translate(50px, 0px) rotate(360deg); opacity: 0; }
}

/* Pokemon pop-in from pokeball (with white flash) */
.poke-pop-in {
  animation: pokePopIn 0.5s ease-out forwards;
}

@keyframes pokePopIn {
  0%   { transform: scale(0); opacity: 0; filter: brightness(3); }
  30%  { transform: scale(1.2); opacity: 1; filter: brightness(3); }
  60%  { transform: scale(1.15); opacity: 1; filter: brightness(1); }
  100% { transform: scale(1); opacity: 1; filter: brightness(1); }
}

/* Attack animations */
.attack-lunge-right {
  animation: lungeRight 0.25s ease-in-out;
}

.attack-lunge-left {
  animation: lungeLeft 0.25s ease-in-out;
}

@keyframes lungeRight {
  0%   { transform: translateX(0); }
  50%  { transform: translateX(20px); }
  100% { transform: translateX(0); }
}

@keyframes lungeLeft {
  0%   { transform: translateX(0); }
  50%  { transform: translateX(-20px); }
  100% { transform: translateX(0); }
}

/* Damage flash */
.damage-flash {
  animation: flash 0.5s steps(4);
}

@keyframes flash {
  0%, 100% { opacity: 1; }
  25%      { opacity: 0; }
  50%      { opacity: 1; }
  75%      { opacity: 0; }
}

/* Faint animation */
.faint {
  animation: faintDown 0.8s ease-in forwards;
}

@keyframes faintDown {
  0%   { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(40px); }
}

/* Screen shake */
.screen-shake {
  animation: screenShake 0.3s ease-in-out;
}

@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  10%  { transform: translate(-3px, 2px); }
  20%  { transform: translate(3px, -2px); }
  30%  { transform: translate(-2px, 3px); }
  40%  { transform: translate(2px, -1px); }
  50%  { transform: translate(-3px, 1px); }
  60%  { transform: translate(2px, 2px); }
  70%  { transform: translate(-1px, -2px); }
  80%  { transform: translate(3px, 1px); }
  90%  { transform: translate(-2px, -1px); }
}

/* ── Bottom Panel (text + menus) ─────────────────────── */
.bottom-panel {
  display: flex;
  border-top: 4px solid var(--info-border);
  min-height: 88px;
}

.text-box {
  flex: 1;
  background: var(--textbox-bg);
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  min-height: 88px;
}

.text-box p {
  font-size: 0.75rem;
  line-height: 1.8;
  color: var(--info-text);
  min-height: 1.8em;
}

/* ── Action Menu (FIGHT / PKMN / ITEM / RUN) ────────── */
.action-menu {
  width: 200px;
  background: var(--menu-bg);
  border-left: 3px solid var(--info-border);
  padding: 8px;
  display: grid;
  grid-template-columns: 1fr;
}

.menu-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  height: 100%;
}

.menu-item {
  font-size: 0.65rem;
  color: var(--info-text);
  display: flex;
  align-items: center;
  padding: 0 4px;
  cursor: default;
}

.menu-item.selected::before {
  content: '\25B6';
  margin-right: 4px;
  font-size: 0.5rem;
}

/* ── Move Menu ───────────────────────────────────────── */
.move-menu {
  flex: 1;
  background: var(--menu-bg);
  border-top: none;
  display: flex;
  min-height: 88px;
}

.move-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0;
  padding: 8px 12px;
}

.move-slot {
  font-size: 0.65rem;
  color: var(--info-text);
  display: flex;
  align-items: center;
  text-transform: uppercase;
  padding: 2px 0;
}

.move-slot.selected::before {
  content: '\25B6';
  margin-right: 4px;
  font-size: 0.5rem;
}

.move-info {
  width: 120px;
  border-left: 3px solid var(--info-border);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  font-size: 0.55rem;
  color: var(--info-text);
}

/* ── Fade overlay (white-out / black-out) ─────────────── */
.fade-overlay {
  position: absolute;
  inset: 0;
  opacity: 0;
  z-index: 50;
  pointer-events: none;
  transition: none;
}

.fade-overlay.fade-in {
  animation: fadeOverlay 2s ease-in forwards;
}

@keyframes fadeOverlay {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}

/* ── Pokemon Center retry screen ─────────────────────── */
.pokecenter-screen {
  width: 100%;
  min-height: 368px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--battle-bg);
  border: 4px solid var(--info-border);
  border-radius: 8px;
}

.pokecenter-text {
  font-size: 0.75rem;
  color: var(--info-text);
  line-height: 1.8;
  margin-bottom: 24px;
  min-height: 2em;
}

.retry-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.7rem;
  background: var(--menu-bg);
  color: var(--info-text);
  border: 3px solid var(--info-border);
  border-radius: 8px;
  padding: 12px 32px;
  cursor: pointer;
  image-rendering: pixelated;
  transition: background 0.15s;
}

.retry-btn:hover {
  background: #e8d8a0;
}

/* ── Footer ───────────────────────────────────────────── */
.site-footer {
  width: 100%;
  max-width: 720px;
  padding: 2rem 1rem 1.5rem;
  text-align: center;
}

.footer-rule {
  border: none;
  border-top: 1px solid var(--text-dim);
  opacity: 0.3;
  width: 40%;
  margin: 0 auto 1rem;
}

.site-footer p {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 540px) {
  header h1 { font-size: 1.4rem; }

  .battle-field { height: 220px; }

  .info-box { min-width: 150px; padding: 4px 6px; }
  .poke-name { font-size: 0.45rem; }
  .poke-level { font-size: 0.4rem; }
  .hp-numbers { font-size: 0.4rem; }

  .pokemon-sprite, .trainer-sprite { width: 96px; height: 96px; }

  .text-box p { font-size: 0.6rem; }
  .menu-item, .move-slot { font-size: 0.55rem; }
  .action-menu { width: 160px; }
  .move-info { width: 90px; font-size: 0.38rem; }
}
