:root {
  --bg0: #1a2f1a;
  --bg1: #2d4a2d;
  --bg2: #3d5c3d;
  --soil: #5c4030;
  --imo: #e8a87c;
  --imo-dark: #c4784a;
  --leaf: #7cb342;
  --leaf-dark: #558b2f;
  --cream: #f5e6c8;
  --ink: #1e2a1e;
  --panel: rgba(245, 230, 200, 0.95);
  --danger: #c62828;
  --hp-high: #66bb6a;
  --hp-mid: #fdd835;
  --hp-low: #ef5350;
  --font-display: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", sans-serif;
  --font-body: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 0%, #4a6b3a 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, #3d2a1a 0%, transparent 45%),
    linear-gradient(160deg, var(--bg0), var(--bg1) 40%, #243824);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 5c8 10 8 20 0 30-8-10-8-20 0-30z' fill='%23fff'/%3E%3C/svg%3E");
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100vh;
}

/* ---- screens ---- */
.screen {
  display: none;
  animation: fadeIn 0.35s ease;
}
.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes hpShrink {
  from { width: var(--from); }
  to { width: var(--to); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

@keyframes bounceIn {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

/* ---- hero / title ---- */
.title-hero {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
}

.brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.4rem, 8vw, 3.8rem);
  letter-spacing: 0.04em;
  color: var(--cream);
  text-shadow:
    0 2px 0 var(--imo-dark),
    0 6px 24px rgba(0, 0, 0, 0.35);
  margin: 0;
  line-height: 1.15;
  animation: bounceIn 0.6s ease;
}

.tagline {
  margin: 0.75rem 0 1.5rem;
  color: #c8dbb8;
  font-size: 1rem;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 320px;
  margin: 0 auto;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0.85rem 1.25rem;
  border-radius: 12px;
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
}
.btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
}
.btn:active {
  transform: translateY(0);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(180deg, var(--imo), var(--imo-dark));
  color: #fff;
  box-shadow: 0 4px 0 #8b5530, 0 8px 20px rgba(0, 0, 0, 0.25);
}
.btn-secondary {
  background: linear-gradient(180deg, var(--leaf), var(--leaf-dark));
  color: #fff;
  box-shadow: 0 4px 0 #3e6a20, 0 8px 20px rgba(0, 0, 0, 0.2);
}
.btn-ghost {
  background: transparent;
  color: var(--cream);
  border: 2px solid rgba(245, 230, 200, 0.35);
}
.btn-danger {
  background: linear-gradient(180deg, #ef5350, #c62828);
  color: #fff;
}
.btn-sm {
  font-size: 0.85rem;
  padding: 0.45rem 0.75rem;
}

.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0;
  color: var(--cream);
  font-size: 0.9rem;
}

.panel {
  background: var(--panel);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(92, 64, 48, 0.15);
}

.panel h2 {
  font-family: var(--font-display);
  margin: 0 0 1rem;
  font-size: 1.35rem;
}

/* ---- party builder ---- */
.party-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.char-card {
  cursor: pointer;
  padding: 0.75rem;
  border-radius: 12px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.55);
  text-align: center;
  transition: border-color 0.15s, transform 0.15s;
}
.char-card:hover {
  transform: translateY(-2px);
}
.char-card.selected {
  border-color: var(--imo-dark);
  background: #fff;
  box-shadow: 0 0 0 2px rgba(232, 168, 124, 0.4);
}
.char-card .sprite {
  font-size: 2.2rem;
  line-height: 1.4;
}
.char-card .name {
  font-weight: 700;
  font-size: 0.85rem;
}
.char-card .types {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: center;
  margin-top: 0.35rem;
}

.type-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}

.slot-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.party-slot {
  flex: 1;
  min-width: 100px;
  padding: 0.75rem;
  border-radius: 10px;
  background: var(--bg1);
  color: var(--cream);
  text-align: center;
  border: 2px dashed rgba(245, 230, 200, 0.3);
}
.party-slot.filled {
  border-style: solid;
  border-color: var(--imo);
}
.party-slot.selected {
  outline: 2px solid var(--cream);
}
.party-slot.pickable {
  cursor: pointer;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
}
.party-slot.pickable:hover {
  transform: translateY(-2px);
}
.party-slot.picked {
  border-color: var(--cream);
  box-shadow: 0 0 0 2px rgba(245, 230, 200, 0.45);
}
.party-slot.preview {
  opacity: 0.95;
}
.pick-order {
  position: absolute;
  top: 0.35rem;
  right: 0.45rem;
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--cream);
  background: var(--imo-dark);
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.pick-heading {
  font-family: var(--font-display);
  font-size: 1rem;
  margin: 0.75rem 0 0.4rem;
}
.pick-status {
  margin: 0.5rem 0 0;
  font-weight: 700;
  font-size: 0.9rem;
}
.hint {
  margin: -0.5rem 0 1rem;
  font-size: 0.9rem;
  opacity: 0.85;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}
.field-row label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  font-weight: 700;
}
.field-row select,
.field-row input {
  font-family: inherit;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid #bbb;
  min-width: 140px;
}

/* ---- battle ---- */
.battle-arena {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background:
    linear-gradient(180deg, #87ceeb 0%, #b8e0a8 45%, #6b8f4e 45%, #5a7a3e 100%);
  min-height: 380px;
  margin-bottom: 0.75rem;
  box-shadow: inset 0 -40px 60px rgba(0, 0, 0, 0.15);
}

.battle-side {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 46%;
}
.battle-side.opponent {
  top: 1rem;
  left: 4%;
}
.battle-side.player {
  bottom: 1.5rem;
  right: 4%;
  align-items: flex-end;
}

.poke-sprite {
  font-size: 4.5rem;
  line-height: 1;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.25));
  transition: transform 0.2s;
}
.poke-sprite.hit {
  animation: shake 0.35s ease;
}
.battle-side.opponent .poke-sprite {
  align-self: flex-start;
  margin-left: 1rem;
}
.battle-side.player .poke-sprite {
  align-self: flex-end;
  margin-right: 1rem;
  transform: scaleX(-1);
}

.hud {
  background: rgba(30, 42, 30, 0.85);
  color: var(--cream);
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  width: 100%;
  max-width: 240px;
}
.hud .hud-name {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}
.hp-bar {
  height: 10px;
  background: #333;
  border-radius: 5px;
  overflow: hidden;
}
.hp-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.45s ease, background 0.3s;
}
.hp-text {
  font-size: 0.75rem;
  margin-top: 0.2rem;
  opacity: 0.9;
}
.status-tag {
  display: inline-block;
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: #c62828;
  margin-left: 0.35rem;
}

.battle-log {
  background: var(--panel);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  min-height: 72px;
  max-height: 100px;
  overflow-y: auto;
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  border: 2px solid rgba(92, 64, 48, 0.2);
}

.command-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.move-btn {
  text-align: left;
  padding: 0.75rem;
  border-radius: 10px;
  border: 2px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s, border-color 0.12s;
}
.move-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--imo-dark);
}
.move-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.move-btn .move-name {
  font-weight: 700;
  display: block;
}
.move-btn .move-meta {
  font-size: 0.75rem;
  opacity: 0.75;
  margin-top: 0.2rem;
}

.switch-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.waiting-banner {
  text-align: center;
  padding: 1rem;
  color: var(--cream);
  font-weight: 700;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.modal {
  background: var(--panel);
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 400px;
  width: 100%;
  text-align: center;
  animation: bounceIn 0.4s ease;
}
.modal h3 {
  font-family: var(--font-display);
  margin: 0 0 0.75rem;
}

.room-code {
  font-family: monospace;
  font-size: 1.5rem;
  letter-spacing: 0.2em;
  background: var(--bg1);
  color: var(--cream);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  display: inline-block;
  margin: 0.5rem 0;
}

.record {
  color: #c8dbb8;
  font-size: 0.85rem;
}

@media (max-width: 600px) {
  .battle-arena {
    min-height: 320px;
  }
  .poke-sprite {
    font-size: 3.2rem;
  }
  .command-panel {
    grid-template-columns: 1fr;
  }
}
