@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg-cream: #f0e8c8; --bg-dark: #504838; --border-outer: #383028;
  --border-inner: #685848; --text-dark: #383028; --text-white: #f8f8f8;
  --hp-green: #58b858; --hp-yellow: #d8a838; --hp-red: #d83838;
  --btn-bg: #e8e0c0; --btn-border: #a89870; --btn-hover: #d8d0b0;
  --panel-bg: #f8f0d8; --fight-color: #e87858; --bag-color: #f8c840;
  --pkmn-color: #58a8e8; --run-color: #88c868;
}
html, body {
  width: 100%; height: 100%; background: #181818;
  display: flex; justify-content: center; align-items: center;
  font-family: 'Press Start 2P', monospace; overflow: hidden;
}
#game-container { width: 100%; max-width: 480px; aspect-ratio: 3/2; position: relative; transition: all 0.3s ease; }
#pixel-border { min-height: 320px;
  width: 100%; height: 100%; background: var(--bg-cream);
  border: 6px solid var(--border-outer); border-radius: 4px;
  outline: 3px solid var(--border-inner); outline-offset: -9px;
  position: relative; overflow: hidden; image-rendering: pixelated;
}
.screen { display: none; width: 100%; height: 100%; position: absolute; top: 0; left: 0; }
.screen.active { display: flex; }

/* LANDING */
#screen-landing { flex-direction: column; align-items: center; justify-content: flex-start; background: var(--bg-cream); padding: 8px 16px 6px; overflow-y: auto; }
.landing-content { text-align: center; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 0; padding-bottom: 4px; }
.title-text { font-size: 18px; color: var(--text-dark); line-height: 1.3; margin-bottom: 2px; text-shadow: 2px 2px 0 #a89870; animation: title-pulse 2s ease-in-out infinite; }
@keyframes title-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }
.pokeball-icon { font-size: 24px; color: var(--fight-color); margin: 2px 0; filter: drop-shadow(2px 2px 0 #a89870); }
.subtitle { font-size: 7px; color: var(--btn-border); margin-bottom: 4px; letter-spacing: 1px; }
.input-group { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.input-group label { font-size: 8px; color: var(--text-dark); }
.input-row { display: flex; align-items: center; gap: 0; }
.at-sign { font-size: 12px; color: var(--btn-border); background: var(--btn-bg); border: 3px solid var(--btn-border); border-right: none; padding: 6px 4px 6px 8px; border-radius: 3px 0 0 3px; }
#handle-input { font-family: 'Press Start 2P', monospace; font-size: 10px; background: var(--btn-bg); color: var(--text-dark); border: 3px solid var(--btn-border); border-radius: 0 3px 3px 0; padding: 6px 8px; width: 180px; outline: none; }
#handle-input::placeholder { color: #b8a880; font-size: 8px; }
#handle-input:focus { border-color: var(--text-dark); }
.pixel-btn { font-family: 'Press Start 2P', monospace; font-size: 10px; background: var(--fight-color); color: var(--text-white); border: 3px solid #b85838; border-radius: 3px; padding: 6px 20px; cursor: pointer; text-shadow: 1px 1px 0 #884028; transition: transform 0.1s; }
.pixel-btn:hover { transform: scale(1.05); background: #d86848; }
.pixel-btn:active { transform: scale(0.97); }

/* LOADING */
#screen-loading { flex-direction: column; align-items: center; justify-content: center; background: #181818; }
.loading-content { text-align: center; }
.loading-text { font-size: 10px; color: var(--text-white); margin-bottom: 16px; }
.loading-dots { font-size: 24px; color: var(--text-white); }
.loading-dots span { animation: blink 1.2s infinite; opacity: 0; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 50% { opacity: 1; } }

/* BATTLE SCREEN */
#screen-battle { flex-direction: column; background: var(--bg-cream); }
.battle-scene { flex: 1; position: relative; padding: 8px 12px; background: linear-gradient(180deg, #a8d8a8 0%, #88c088 40%, #e8d8a8 40%, #d8c898 100%); min-height: 0; }
.fighter-area { position: absolute; }
.opponent-area { top: 6px; left: 8px; right: 8px; display: flex; justify-content: space-between; align-items: flex-start; }
.player-area { bottom: 4px; left: 8px; right: 8px; display: flex; justify-content: space-between; align-items: flex-end; }
.info-box { background: var(--panel-bg); border: 3px solid var(--border-inner); border-radius: 4px; padding: 4px 8px; min-width: 155px; }
.fighter-name { font-size: 9px; color: var(--text-dark); }
.fighter-level { font-size: 8px; color: var(--text-dark); margin-left: 8px; }
.hp-bar-container { display: flex; align-items: center; gap: 4px; margin-top: 3px; }
.hp-label { font-size: 7px; color: var(--hp-yellow); font-weight: bold; }
.hp-bar-bg { flex: 1; height: 6px; background: #484038; border-radius: 2px; overflow: hidden; border: 1px solid var(--border-outer); }
.hp-bar { height: 100%; width: 100%; background: var(--hp-green); transition: width 0.6s ease, background-color 0.3s; border-radius: 1px; }
.hp-text { font-size: 7px; color: var(--text-dark); text-align: right; margin-top: 1px; }
.sprite-container { image-rendering: pixelated; }
.sprite-container canvas { width: 96px; height: 96px; image-rendering: pixelated; border: 2px solid var(--border-inner); border-radius: 4px; background: rgba(0,0,0,0.05); }

/* BATTLE PANEL */
.battle-panel { display: flex; height: 40%; border-top: 4px solid var(--border-outer); background: var(--panel-bg); }
.text-box { flex: 1; padding: 10px 14px; display: flex; align-items: flex-start; border-right: 3px solid var(--border-inner); }
#battle-text { font-size: 9px; line-height: 1.8; color: var(--text-dark); }
.action-grid, .move-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 8px; width: 48%; }
.hidden { display: none !important; }
.action-btn, .move-btn { font-family: 'Press Start 2P', monospace; font-size: 8px; border: 3px solid var(--btn-border); border-radius: 3px; padding: 4px; cursor: pointer; color: var(--text-dark); background: var(--btn-bg); transition: transform 0.08s, background 0.1s; display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.3; }
.action-btn:hover, .move-btn:hover { transform: scale(1.05); background: var(--btn-hover); }
.action-btn:active, .move-btn:active { transform: scale(0.95); }
.fight-btn { border-color: var(--fight-color); color: var(--fight-color); font-weight: bold; }
.bag-btn { border-color: var(--bag-color); color: #a88820; }
.pkmn-btn { border-color: var(--pkmn-color); color: var(--pkmn-color); }
.run-btn { border-color: var(--run-color); color: #508838; }
.move-btn { font-size: 6px; padding: 3px; line-height: 1.4; border-color: var(--fight-color); color: var(--fight-color); }

/* RESULT */
#screen-result { flex-direction: column; align-items: center; justify-content: flex-start; background: #181818; padding: 14px 16px 12px; text-align: center; overflow-y: auto; }
.result-content { display: flex; flex-direction: column; align-items: center; width: 100%; gap: 8px; }
.result-title { font-size: 18px; margin-bottom: 4px; text-shadow: 2px 2px 0 rgba(0,0,0,0.5); }
.result-title.win { color: var(--hp-green); }
.result-title.lose { color: var(--hp-red); }
.result-text { font-size: 8px; color: #d0d0d0; margin-bottom: 6px; line-height: 2; }
#screenshot-zone { background: var(--bg-tan); padding: 14px 20px 12px; border-radius: 4px; margin-bottom: 6px; display: flex; flex-direction: column; align-items: center; border: 3px solid var(--border-dark); width: 100%; box-sizing: border-box; }
.result-sprites { display: flex; align-items: center; gap: 16px; margin-bottom: 6px; }
.screenshot-credit { font-family: 'Press Start 2P', monospace; font-size: 5px; color: #aaa; margin-top: 2px; }
.result-buttons { display: flex; gap: 10px; align-items: center; width: 100%; }
.result-buttons .pixel-btn { flex: 1; font-size: 8px; padding: 10px 6px; }
.copy-btn { background: #2255cc; border-color: #1133aa; text-shadow: 1px 1px 0 #0a1a66; }
.copy-btn:hover { background: #3366dd; }
.copy-feedback { font-family: 'Press Start 2P', monospace; font-size: 6px; color: #88ff88; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.result-sprites canvas { width: 64px; height: 64px; image-rendering: pixelated; border: 2px solid var(--border-inner); border-radius: 4px; }
.vs-text { font-size: 14px; color: var(--hp-yellow); }

/* ANIMATIONS */
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes flash { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }
.shake { animation: shake 0.3s ease-in-out; }
.flash { animation: flash 0.15s ease-in-out 3; }
.hp-bar.critical { animation: flash 1s infinite; }

@media (max-width: 500px) {
  #game-container { max-width: 100vw; }
  .title-text { font-size: 16px; }
  .info-box { min-width: 120px; padding: 3px 5px; }
  .fighter-name { font-size: 7px; }
  .sprite-container canvas { width: 72px; height: 72px; }
}

/* Entrance animations */
@keyframes slide-in-left {
  from { transform: translateX(-200px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slide-in-right {
  from { transform: translateX(200px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.player-area { animation: slide-in-left 0.6s ease-out; }
.opponent-area { animation: slide-in-right 0.6s ease-out; }

/* Disabled state for buttons during animations */
.action-btn:disabled, .move-btn:disabled {
  opacity: 0.5; cursor: not-allowed; transform: none !important;
}

/* Text cursor blink in text box */
#battle-text::after {
  content: '▼'; font-size: 8px; animation: blink 1s infinite; margin-left: 4px;
}

/* Landing screen pokeball rotation */
@keyframes pokeball-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
.pokeball-icon:hover { animation: pokeball-spin 0.5s ease-in-out; }

/* Result screen fade in */
#screen-result.active {
  animation: fade-in 0.8s ease-out;
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* OPPONENT TOGGLE */
.opponent-toggle {
  display: flex;
  gap: 6px;
  margin: 2px 0 2px;
}
.toggle-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 6px 10px;
  border: 3px solid var(--btn-border);
  border-radius: 3px;
  background: var(--btn-bg);
  color: var(--btn-border);
  cursor: pointer;
  transition: all 0.1s;
  flex: 1;
  letter-spacing: 0.5px;
}
.toggle-btn.active {
  background: var(--fight-color);
  border-color: #b85838;
  color: var(--text-white);
  text-shadow: 1px 1px 0 #884028;
}
.toggle-btn:hover:not(.active) {
  background: var(--btn-hover);
  color: var(--text-dark);
}
.opponent-custom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  animation: fade-in 0.2s ease-out;
}
.opponent-custom label {
  font-size: 8px;
  color: var(--text-dark);
}

/* === STAT BARS === */
.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 3px;
  width: 100%;
}
.stat-row {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 8px;
}
.stat-label {
  font-size: 5px;
  color: var(--text-dark);
  width: 18px;
  text-align: right;
  flex-shrink: 0;
}
.stat-bar-bg {
  flex: 1;
  height: 5px;
  background: #a89878;
  border-radius: 1px;
  overflow: hidden;
  border: 1px solid #886848;
}
.stat-bar-fill {
  height: 100%;
  border-radius: 1px;
  transition: width 0.5s ease;
}
.stat-val {
  font-size: 5px;
  color: var(--text-dark);
  width: 12px;
  text-align: left;
  flex-shrink: 0;
}

/* Critical hit text flash */
@keyframes crit-flash {
  0%, 100% { color: var(--text-dark); }
  50% { color: #ff2200; text-shadow: 1px 1px 0 #ffcc00; }
}

/* Starchild promo block */
.starchild-promo {
  margin-top: 6px;
  padding: 14px 16px;
  background: #0d1117;
  border: 2px solid #3a7bd5;
  border-radius: 6px;
  text-align: center;
  width: 100%;
  box-sizing: border-box;
}
.starchild-promo p {
  font-family: 'Press Start 2P', monospace;
  margin: 0 0 8px 0;
  line-height: 1.9;
}
.starchild-promo p:last-child { margin-bottom: 0; }
.promo-built {
  font-size: 8px;
  color: #ffffff;
  border-bottom: 1px solid #2a4a7a;
  padding-bottom: 8px;
  margin-bottom: 10px !important;
}
.promo-built a { color: #60c8ff !important; }
.promo-cta {
  font-size: 7px;
  color: #c8d8f0;
  line-height: 2.2;
}
.promo-seed {
  font-size: 7px;
  color: #f7e96e;
  border-top: 1px solid #2a4a7a;
  padding-top: 10px;
  margin-top: 4px;
  line-height: 2.2;
}
.starchild-promo a {
  color: #60c8ff;
  text-decoration: none;
}
.starchild-promo a:hover {
  color: #fff;
  text-decoration: underline;
}

