/* Original CSS inspired by the FireRed/LeafGreen battle screen layout. */
:root {
  --font: 'Pixelify Sans', ui-monospace, monospace;
  --bg: #1d2633;
  --ink: #283038;
  --paper: #f8f8f0;
  --cream: #f8f0d0;
  --frame: #506070;
  --frame-dark: #2c3640;
  --msg-bg: #384858;
  --msg-ink: #f8f8f8;
  --sky-top: #f0f8e0;
  --sky-bottom: #d8f0c0;
  --ground: #b8e090;
  --platform: #a0d078;
  --platform-edge: #78b058;
  --fire: #e04828;
  --fire-2: #f89030;
  --leaf: #38a048;
  --leaf-2: #88c840;
  --hp-green: #40c868;
  --hp-yellow: #f8c020;
  --hp-red: #f04830;
  --accent: #e04828;
  --ok: #38a048;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.35;
  min-height: 100vh;
}
#app { max-width: 880px; margin: 0 auto; padding: 16px; }
button, input, textarea { font: inherit; }

/* ---------- shared boxes ---------- */
.panel, .menu {
  background: var(--paper);
  border: 4px solid var(--frame);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 3px var(--cream), 0 4px 0 var(--frame-dark);
  padding: 16px;
}
.msgbox {
  background: var(--msg-bg);
  color: var(--msg-ink);
  border: 4px solid var(--frame-dark);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 3px #607888;
  padding: 14px 18px;
  min-height: 84px;
  text-shadow: 2px 2px 0 #202830;
}
.msgbox .err { color: #ffb0a0; display: block; }
.hint { color: #6a7680; font-size: 15px; }
.msgbox .hint { color: #c0d0d8; margin-top: 8px; }

label { display: block; font-weight: 600; margin: 4px 0 6px; }
input, textarea {
  width: 100%;
  border: 3px solid var(--frame);
  border-radius: 6px;
  background: #fff;
  padding: 8px 10px;
  color: var(--ink);
}
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 13px; resize: vertical; }
input:focus, textarea:focus { outline: 3px solid var(--fire-2); outline-offset: 1px; }

.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  border: 3px solid var(--frame);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--frame-dark);
}
.btn:hover:not(:disabled) { background: var(--cream); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--frame-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: #902818; color: #fff; box-shadow: 0 3px 0 #601808; }
.btn.primary:hover:not(:disabled) { background: #f05838; }
.btn.small { padding: 4px 10px; font-size: 15px; }
.btn.danger { border-color: #a03020; color: #a03020; }

/* ---------- home ---------- */
.home { display: grid; gap: 16px; max-width: 440px; margin: 6vh auto 0; }
.logo { color: #fff; text-align: center; font-size: clamp(28px, 7vw, 44px); margin: 0; text-shadow: 3px 3px 0 #000; }
.logo .fire { color: var(--fire); } .logo .fire2 { color: var(--fire-2); }
.logo .leaf { color: var(--leaf); } .logo .leaf2 { color: var(--leaf-2); }
.home .panel { display: grid; gap: 6px; }
.home .panel .btn.primary { margin-top: 8px; }
.home .row { margin-top: 0; }
.home .row input { flex: 1; text-transform: uppercase; letter-spacing: 3px; }
.or { text-align: center; color: #8a96a0; margin: 8px 0 0; }

/* ---------- room ---------- */
.room { display: grid; gap: 12px; }
.room-head { display: flex; align-items: center; gap: 12px; color: #fff; flex-wrap: wrap; }
.back { color: #c8d4dc; text-decoration: none; }
.room-code strong { letter-spacing: 3px; font-size: 22px; color: var(--fire-2); }
.conn { margin-left: auto; font-size: 14px; color: #c8d4dc; }
.conn.open::before { content: '● '; color: var(--hp-green); }
.conn.closed { color: #ffb0a0; }

.players { display: flex; align-items: center; gap: 10px; }
.player {
  flex: 1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--paper); border: 3px solid var(--frame); border-radius: 8px; padding: 6px 10px;
}
.player.me { border-color: var(--fire-2); }
.player em { color: #7a868e; font-style: normal; }
.vs { color: #fff; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #a0a8b0; }
.dot.on { background: var(--hp-green); }
.badge { margin-left: auto; font-size: 13px; padding: 1px 8px; border-radius: 10px; background: #e0e4e8; }
.badge.ok { background: var(--ok); color: #fff; }

.team-panel textarea { min-height: 300px; }
.problems { margin: 12px 0 0; padding-left: 20px; color: #b02818; }

/* ---------- battle field ---------- */
.battle { display: grid; gap: 12px; }
.field {
  position: relative;
  aspect-ratio: 16 / 10;
  min-height: 300px;
  border: 4px solid var(--frame-dark);
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(var(--sky-top), var(--sky-bottom) 55%, var(--ground) 55%);
}
.turn { position: absolute; left: 12px; top: 10px; font-size: 14px; color: #506050; }

.sprite { width: min(128px, 24vw); aspect-ratio: 1; image-rendering: pixelated; }
.lv { font-weight: 400; }

.field.preview {
  aspect-ratio: auto; min-height: 0; display: grid; gap: 12px; padding: 40px 14px 14px;
}
.preview-side { display: grid; gap: 6px; }
.preview-name { font-weight: 600; }
.preview-team { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.preview-chip {
  display: flex; align-items: center; gap: 6px; padding: 4px 8px;
  background: var(--cream); border: 2px solid var(--frame-dark); border-radius: 8px; font-size: 15px;
}
.sprite.mini, .side.near .sprite.mini { width: 64px; margin: -8px 0; }
.preview-mon .sprite.mini { margin: -6px 0 -4px; }
.sprite.placeholder.mini { font-size: 12px; border-width: 2px; }

/* ---------- bottom controls ---------- */
.bottom { display: grid; grid-template-columns: 1fr 1.15fr; gap: 12px; align-items: start; }
.menu { display: grid; gap: 10px; }
.menu-title { font-weight: 600; }

.preview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preview-mon {
  position: relative; display: grid; gap: 2px; text-align: left;
  background: #fff; border: 3px solid var(--frame); border-radius: 8px; padding: 8px; cursor: pointer;
}
.preview-mon small { color: #6a7680; font-size: 12px; }
.preview-mon .moves { font-size: 11px; }
.preview-mon.picked { border-color: var(--fire); background: #fff3e8; }
.preview-mon .order {
  position: absolute; top: -10px; right: -8px; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; background: var(--fire); color: #fff; font-weight: 600;
}

.log { background: var(--paper); border: 3px solid var(--frame); border-radius: 8px; padding: 6px 12px; }
.log summary { cursor: pointer; font-weight: 600; }
.log-lines { max-height: 260px; overflow-y: auto; font-size: 14px; }
.turn-line { font-weight: 600; margin-top: 6px; color: var(--accent); }

/* ---------- clocks, boosts, conditions ---------- */
.clock { margin-left: auto; font-size: 14px; color: #506070; font-variant-numeric: tabular-nums; }
.clock.urgent { color: #d02818; font-weight: 600; animation: pulse 1s steps(2) infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.conditions { position: absolute; left: 10px; top: 30px; display: grid; gap: 4px; justify-items: start; }
.cond { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: rgba(255,255,255,.85); border: 2px solid var(--frame); }
.cond.weather { border-color: #4878c8; }

/* ---------- details panel ---------- */
.inspect { display: grid; gap: 8px; padding: 12px 14px; }
.inspect-head { display: flex; align-items: center; gap: 10px; }
.inspect-head > div { flex: 1; }
.inspect-grid { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 15px; }
.inspect-grid dt { font-weight: 600; color: #506070; }
.inspect-grid dd { margin: 0; }
.type-badge { display: inline-block; font-size: 11px; color: #fff; padding: 0 6px; border-radius: 4px; margin-left: 4px; text-shadow: 1px 1px 0 rgba(0,0,0,.35); }
.type-bg-normal { background: #a8a878; }
.type-bg-fire { background: #f08030; }
.type-bg-water { background: #6890f0; }
.type-bg-electric { background: #f8d030; }
.type-bg-grass { background: #78c850; }
.type-bg-ice { background: #98d8d8; }
.type-bg-fighting { background: #c03028; }
.type-bg-poison { background: #a040a0; }
.type-bg-ground { background: #e0c068; }
.type-bg-flying { background: #a890f0; }
.type-bg-psychic { background: #f85888; }
.type-bg-bug { background: #a8b820; }
.type-bg-rock { background: #b8a038; }
.type-bg-ghost { background: #705898; }
.type-bg-dragon { background: #7038f8; }
.type-bg-dark { background: #705848; }
.type-bg-steel { background: #b8b8d0; }

/* ---------- GBA screen ---------- */
.gba-wrap { width: 100%; max-width: 720px; margin: 0 auto; }
.gba-screen { display: block; width: 100%; aspect-ratio: 3 / 2; image-rendering: pixelated; image-rendering: crisp-edges; background: #000; outline: none; border-radius: 4px; }

.pad-strip, .info-strip { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; max-width: 720px; margin: 0 auto; width: 100%; }
.info-strip .hint { color: #c8d4dc; }
.info-strip .conditions { position: static; display: flex; gap: 6px; }
.pad { min-width: 44px; font-weight: 600; }
.pad-a { background: #d84830; color: #fff; border-color: #902818; }
.pad-b { background: #484888; color: #fff; border-color: #282850; }
.bottom.single { grid-template-columns: 1fr; }
.battle > .menu { max-width: 720px; margin: 0 auto; width: 100%; }

/* ---------- teambuilder ---------- */
.tb { display: grid; gap: 12px; }
.tb-list, .tb-editor { display: grid; gap: 12px; }
.tb-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tb-card { display: grid; gap: 6px; }
.tb-sprites { display: flex; flex-wrap: wrap; min-height: 48px; }
.tb-sprites .sprite.mini { width: 48px; margin: 0; }
.tb-name { flex: 1; min-width: 160px; }
.tb-message { color: #c8d4dc; }
.tb-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 12px; }
.tb-slot { display: grid; gap: 8px; padding: 12px; }
.tb-slot-head { display: flex; align-items: center; gap: 8px; }
.tb-slot-head input { flex: 1; font-weight: 600; }
.tb-slot-head .bad { color: #b02818; font-size: 13px; }
.tb-fields { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.tb-fields label, .tb-evs label { font-size: 13px; margin: 0; display: grid; gap: 2px; font-weight: 600; }
.tb-fields input, .tb-fields select, .tb-moves input, .tb-evs input { padding: 5px 7px; font-size: 15px; }
select { width: 100%; border: 3px solid var(--frame); border-radius: 6px; background: #fff; padding: 5px 7px; font: inherit; color: var(--ink); }
.tb-moves { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tb-evs { display: grid; grid-template-columns: repeat(6, 1fr) ; gap: 4px; align-items: end; }
.tb-evs > .hint { grid-column: 1 / -1; }
.tb-evs .over { color: #b02818; font-weight: 600; }
.tb-ivs summary { cursor: pointer; font-size: 14px; color: #506070; }
.tb-add { min-height: 120px; border-style: dashed; }
.tb-pick { width: auto; padding: 3px 6px; font-size: 15px; }
.recovery summary { cursor: pointer; font-weight: 600; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; flex: 1; }

@media (max-width: 640px) {
  .tb-slots { grid-template-columns: 1fr; }
  .tb-fields { grid-template-columns: 1fr; }
  .tb-evs { grid-template-columns: repeat(3, 1fr); }

  #app { padding: 12px; }
  .bottom { grid-template-columns: 1fr; }
  .preview-grid { grid-template-columns: 1fr 1fr; }
  .field { min-height: 260px; aspect-ratio: 4 / 3.6; }
  .sprite { width: 80px; }
}
