:root {
  --bg: #060812;
  --card: #13172f;
  --line: rgba(255, 255, 255, 0.12);
  --text: #ecf2ff;
  --muted: #a6b2d5;
  --good: #5ff4c6;
  --accent: #ff5ad4;
  --danger: #ff809b;
  --shadow: 0 10px 40px rgba(6, 7, 20, 0.6);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at 20% 20%, rgba(127, 255, 212, 0.2), transparent 30%),
    radial-gradient(circle at 80% 10%, rgba(255, 90, 212, 0.22), transparent 35%),
    linear-gradient(180deg, #070a15, #05060d);
  font-family: 'Nunito', sans-serif;
  letter-spacing: 0.01em;
}

.aurora {
  position: fixed;
  inset: -20% 0;
  pointer-events: none;
  background: linear-gradient(120deg, rgba(127, 255, 212, 0.16), transparent 35%, rgba(255, 90, 212, 0.18));
  filter: blur(50px);
  z-index: -1;
}

.screen {
  width: 100%;
  margin: 0;
  padding: 0 16px 28px;
}

.hero, .panel {
  border: 1px solid var(--line);
  background: rgba(20, 24, 50, 0.76);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.hero { padding: 14px 24px; margin: 0 -16px 0; border-radius: 0; animation: floatIn .6s ease both; }

.eyebrow { color: var(--good); text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.2em; }

h1 { margin: 4px 0 6px; font-family: 'Orbitron', sans-serif; letter-spacing: 0.08em; font-size: clamp(1.6rem, 4vw, 2.4rem); }

.sub, .muted { color: var(--muted); }

.meta { margin: 4px 0 0; color: #d2dcff; }

.workspace { margin-top: 16px; display: grid; grid-template-columns: 1.45fr 0.85fr; gap: 16px; }

.model-battle-theater {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: end;
  min-height: calc(100vh - 88px);
  margin: 0 -16px 16px;
  padding: 16px;
  border: 1px solid rgba(95, 244, 198, 0.34);
  border-radius: 0 0 var(--radius) var(--radius);
  background:
    radial-gradient(circle at 18% 0%, rgba(95, 244, 198, 0.2), transparent 32%),
    radial-gradient(circle at 92% 12%, rgba(255, 90, 212, 0.2), transparent 34%),
    rgba(7, 12, 30, 0.88);
  box-shadow: var(--shadow), 0 0 36px rgba(95, 244, 198, 0.12);
}

.model-battle-theater h2 {
  margin: 0;
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(1.35rem, 3vw, 2.2rem);
  letter-spacing: 0.05em;
}

.theater-copy .sub { margin-bottom: 0; }

.theater-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.model-battle-frame-wrap {
  grid-column: 1 / -1;
  position: relative;
  overflow: hidden;
  min-height: calc(100vh - 228px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  background: #f6f7fb;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.model-battle-frame {
  width: 100%;
  height: calc(100vh - 228px);
  min-height: 420px;
  border: 0;
  display: block;
  background: #f6f7fb;
}

.model-battle-theater:fullscreen {
  width: 100vw;
  height: 100vh;
  margin: 0;
  border-radius: 0;
  padding: 12px;
  grid-template-rows: auto 1fr;
  background: #030611;
}

.model-battle-theater:fullscreen .model-battle-frame-wrap,
.model-battle-theater:fullscreen .model-battle-frame {
  height: 100%;
  min-height: 0;
}

.model-battle-theater:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  margin: 0;
  border-radius: 0;
  padding: 12px;
  grid-template-rows: auto 1fr;
  background: #030611;
}

.model-battle-theater:-webkit-full-screen .model-battle-frame-wrap,
.model-battle-theater:-webkit-full-screen .model-battle-frame {
  height: 100%;
  min-height: 0;
}

.panel-header, .panel-row, .rule-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.controls, .rule-grid { display: flex; gap: 8px; }
.controls { flex-wrap: wrap; }

input, select { border: 1px solid var(--line); border-radius: 10px; background: #0d1230; color: #fff; padding: 10px 12px; }

.pokedex { display: grid; gap: 10px; max-height: 62vh; overflow: auto; padding-right: 6px; }

.card,
section.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: rgba(11, 15, 37, 0.92);
}

.card h3,
section.card h3 { margin: 0 0 8px; font-family: 'Orbitron', sans-serif; color: var(--good); }

.battle-panel {
  margin-top: 16px;
  padding: 0;
  overflow: hidden;
}

.battle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 4px 10px;
}

.battle-header h2 {
  margin: 0;
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(1.25rem, 2.5vw, 2rem);
  letter-spacing: 0.04em;
}

.battle-scene {
  position: relative;
  overflow: hidden;
  min-height: clamp(320px, 46vh, 520px);
  border: 1px solid rgba(127, 255, 212, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 28%),
    linear-gradient(165deg, rgba(8, 14, 36, 0.92), rgba(20, 26, 48, 0.76) 48%, rgba(11, 18, 33, 0.9));
  perspective: 1200px;
  transform-style: preserve-3d;
  box-shadow: var(--shadow);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.battle-glow {
  position: absolute;
  inset: -20% -5%;
  transform: translateZ(-40px);
  background: radial-gradient(circle at 50% 30%, rgba(95, 244, 198, 0.24), transparent 52%);
  pointer-events: none;
  animation: arenaGlow 7s ease-in-out infinite;
}

.battle-surface {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 6%;
  height: 52%;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(95, 244, 198, 0.18), rgba(255, 90, 212, 0.16)),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.14) 0 1px, transparent 1px 42px),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.08) 0 1px, transparent 1px 34px);
  transform: rotateX(64deg);
  transform-origin: center bottom;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.65), 0 20px 60px rgba(0, 0, 0, 0.45);
}

.battle-units, .battle-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.battle-unit {
  position: absolute;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  transform-style: preserve-3d;
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.45);
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #08122e;
  animation: unitIdle 3.2s ease-in-out infinite;
}

.battle-unit.ally {
  border-color: rgba(127, 255, 212, 0.85);
}

.battle-unit.enemy {
  border-color: rgba(255, 90, 180, 0.85);
}

.battle-unit .unit-core {
  width: 74%;
  height: 74%;
  border-radius: 50%;
  background: inherit;
}

.battle-fx span {
  position: absolute;
  border-radius: 999px;
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.9);
  opacity: 0.8;
}

.battle-state {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 8, 18, 0.72);
  backdrop-filter: blur(10px);
}

.battle-controls {
  display: flex;
  justify-content: flex-end;
}

.battle-feed {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.battle-feed li {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(11, 15, 37, 0.82);
  color: #dce6ff;
  padding: 8px 10px;
  font-size: 0.86rem;
  animation: feedIn 260ms ease both;
}

.battle-feed span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 20px;
  margin-right: 8px;
  border-radius: 6px;
  background: rgba(95, 244, 198, 0.14);
  color: var(--good);
  font-size: 0.72rem;
  font-weight: 900;
}

.scene-pulse {
  border-color: rgba(95, 244, 198, 0.72);
  box-shadow: 0 0 0 1px rgba(95, 244, 198, 0.24), var(--shadow);
}

.scene-alert {
  border-color: rgba(255, 128, 155, 0.72);
  box-shadow: 0 0 0 1px rgba(255, 128, 155, 0.24), var(--shadow);
}

.scene-win {
  border-color: rgba(255, 221, 87, 0.74);
  box-shadow: 0 0 0 1px rgba(255, 221, 87, 0.24), var(--shadow);
}

.stats { color: var(--muted); font-size: 0.92rem; }
.type-row { display: flex; flex-wrap: wrap; gap: 4px; }
.type-pill { display: inline-flex; padding: 4px 10px; background: rgba(127, 255, 212, 0.12); border: 1px solid rgba(127, 255, 212, 0.4); border-radius: 999px; color: #9ffff0; font-size: 0.8rem; }

.btn {
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn.primary { background: linear-gradient(90deg, rgba(127,255,212,0.9), rgba(255,90,212,0.9)); color: #070b1a; width: 100%; margin-top: 10px; }

.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }

.btn.btn-xs { width: auto; margin: 0; padding: 7px 10px; font-size: 0.82rem; }

.btn:hover { transform: translateY(-1px); }

.team-slots { display: grid; gap: 8px; }
.slot {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 10px;
  min-height: 68px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slot-empty { color: var(--muted); }
.slot h4 { margin: 0; }
.slot-btns { display: grid; gap: 8px; }
.slot-btns button { font-size: 0.75rem; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); color: #fff; }

.capability-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin-top: 8px; }

.capability { padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(18, 22, 53, 0.85); }
.capability h3 { margin: 0; }
.capability p { margin-top: 6px; margin-bottom: 0; }
.capability--active {
  border-color: rgba(95, 244, 198, 0.5);
  box-shadow: 0 0 16px rgba(95, 244, 198, 0.2);
}

.rule-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 10px;
}

.rule-grid label {
  display: grid;
  gap: 4px;
  color: #d5def8;
  font-size: 0.86rem;
}

.rule-grid input,
.rule-grid select { width: 100%; }

.feature-panel { margin-top: 10px; padding: 8px; border: 1px dashed var(--line); border-radius: 10px; background: rgba(10, 14, 31, 0.6); }
.feature-panel summary { cursor: pointer; font-size: 0.9rem; }
.feature-panel ul { margin: 8px 0 0; padding-left: 18px; }
.feature-panel[open] { border-color: rgba(95, 244, 198, 0.45); }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; }
.compact { font-size: 0.85rem; color: #b7c4ee; }

#flagList { margin: 6px 0 0 16px; }
#flagList li { margin: 0 0 4px; color: #cfd9f7; }

#exported, .rule-state {
  margin-top: 10px;
  background: #0b1231;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  max-height: 180px;
  overflow: auto;
  color: #c9d5ff;
}

#exported { max-height: 180px; }

.rule-state { white-space: pre-wrap; min-height: 42px; }
.rule-state.error { color: var(--danger); }

.hint { color: var(--muted); font-size: 0.9rem; }

.feature-hidden {
  display: none !important;
}

.reveal { animation: floatIn .6s ease both; }
.delay-1 { animation-delay: .1s; }
.delay-2 { animation-delay: .2s; }
.delay-3 { animation-delay: .3s; }
.delay-4 { animation-delay: .4s; }

@keyframes floatIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes twinkle {
  0%, 100% { opacity: 0; transform: translateZ(var(--z, 0px)) scale(0.6); }
  50% { opacity: 0.9; transform: translateZ(var(--z, 0px)) scale(1); }
}

@keyframes arenaGlow {
  0%, 100% { opacity: 0.76; transform: translateZ(-40px) scale(1); }
  50% { opacity: 1; transform: translateZ(-40px) scale(1.06); }
}

@keyframes unitIdle {
  0%, 100% { translate: 0 0; }
  50% { translate: var(--drift, 6px) -7px; }
}

@keyframes feedIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .model-battle-theater { grid-template-columns: 1fr; }
  .theater-actions { justify-content: flex-start; }
  .pager,
  .rule-grid,
  .rule-actions { flex-direction: column; align-items: stretch; }
}
