:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --line: #d7e0e8;
  --text: #17212b;
  --muted: #617181;
  --primary: #d62f2f;
  --primary-strong: #b81f24;
  --accent: #16766b;
  --warning: #b76b08;
  --bad: #b3261e;
  --good: #18794e;
  --shadow: 0 12px 40px rgba(21, 31, 43, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar,
.control-strip,
.section-header,
.tabs,
.dialog-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
  padding: 18px 0 20px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 3vw, 3.1rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 1.25rem;
  letter-spacing: 0;
}

h3 {
  font-size: 1rem;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions,
.slot-stepper {
  display: flex;
  gap: 10px;
}

.brand-link {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 5px 12px 5px 7px;
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
}

.brand-link:hover {
  border-color: #a9b8c6;
}

.brand-link img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.primary-button,
.ghost-button,
.tab,
.slot-stepper button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 15px;
  font-weight: 700;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.ghost-button,
.tab,
.slot-stepper button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.ghost-button:hover,
.tab:hover,
.slot-stepper button:hover {
  border-color: #a9b8c6;
}

.compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.86rem;
}

.control-strip {
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 8px 10px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(22, 118, 107, 0.14);
}

.control-strip label:first-child {
  min-width: min(100%, 360px);
  flex: 1;
}

.control-strip label:nth-child(2) {
  width: 100px;
}

.control-strip label:nth-child(3) {
  min-width: 180px;
}

.status-pill {
  margin-left: auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 14px;
  background: #e6f3ef;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
}

.notice-band {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid #f0d69a;
  border-radius: 8px;
  background: #fff8e8;
  color: #65420a;
  line-height: 1.45;
}

.tabs {
  gap: 8px;
  margin: 18px 0 14px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab {
  white-space: nowrap;
}

.tab.is-active {
  background: #17212b;
  color: #ffffff;
  border-color: #17212b;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 16px;
  align-items: start;
}

.team-column,
.editor-panel,
.tool-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.team-column,
.editor-panel,
.tool-panel {
  padding: 16px;
}

.section-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-header.tight {
  margin-top: 18px;
  margin-bottom: 10px;
}

.team-list {
  display: grid;
  gap: 10px;
}

.team-card {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 8px;
}

.team-card.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(214, 47, 47, 0.12);
}

.team-card img,
.sprite-pane img {
  width: 100%;
  image-rendering: auto;
}

.team-card img {
  max-width: 54px;
}

.team-card-title {
  font-weight: 800;
}

.team-card-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.team-card button {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #f9fbfc;
}

.validator,
.result-box,
.battle-log,
.rules-summary {
  margin-top: 14px;
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
  color: var(--text);
  line-height: 1.45;
}

.validator ul,
.rules-summary ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.validator .ok,
.rules-summary .ok {
  color: var(--good);
  font-weight: 800;
}

.validator .warn,
.rules-summary .warn {
  color: var(--warning);
  font-weight: 800;
}

.validator .bad,
.rules-summary .bad {
  color: var(--bad);
  font-weight: 800;
}

.editor-grid {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 18px;
}

.sprite-pane {
  min-height: 204px;
  display: grid;
  align-content: center;
  justify-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfc;
  padding: 12px;
}

.sprite-pane img {
  max-width: 144px;
  min-height: 144px;
}

.type-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  min-height: 28px;
}

.availability-status {
  min-height: 18px;
  color: var(--good);
  font-size: 0.78rem;
  font-weight: 900;
}

.availability-status.is-bad {
  color: var(--bad);
}

.type-badge {
  border-radius: 999px;
  padding: 4px 9px;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.form-grid,
.battle-config {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 92px minmax(120px, 1fr) 86px;
  gap: 8px;
  align-items: center;
}

.stat-heading {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-name {
  font-weight: 900;
}

.stat-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 7px;
  background: #edf7f4;
  color: var(--accent);
  font-weight: 900;
}

.ev-total {
  border-radius: 999px;
  padding: 6px 10px;
  background: #edf7f4;
  color: var(--accent);
  font-weight: 900;
  font-size: 0.82rem;
}

.ev-total.over {
  background: #ffecea;
  color: var(--bad);
}

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

.move-row {
  display: grid;
  grid-template-columns: 1fr 80px 96px 78px;
  gap: 8px;
  align-items: end;
}

.sim-grid,
.rules-layout,
.pokedex-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
  align-items: start;
}

.damage-board {
  display: grid;
  grid-template-columns: minmax(250px, 0.82fr) minmax(320px, 1fr) minmax(250px, 0.82fr);
  gap: 14px;
  align-items: start;
}

.damage-combatant,
.damage-center > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
  padding: 14px;
}

.damage-combatant {
  display: grid;
  gap: 12px;
}

.damage-combatant.defender {
  background: #fff8f8;
}

.damage-side-head {
  display: grid;
  grid-template-columns: 1fr 82px;
  gap: 12px;
  align-items: center;
}

.damage-side-head img {
  width: 82px;
  height: 82px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.damage-center {
  display: grid;
  gap: 12px;
}

.damage-move-grid,
.compact-config {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.damage-stat-box {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.damage-stat-head,
.damage-stat-row {
  display: grid;
  grid-template-columns: 48px minmax(58px, 1fr) minmax(70px, 1fr) 58px;
  gap: 8px;
  align-items: center;
}

.damage-stat-head {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.damage-stat-row input,
.damage-stat-row select {
  min-width: 0;
}

.damage-stat-row b {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: #ffffff;
  color: var(--primary);
}

.damage-result-card .result-box {
  margin-bottom: 10px;
}

.speed-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.72fr);
  gap: 16px;
  align-items: start;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.meta-toggle-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.meta-source-toggle {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
}

.meta-source-toggle button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  padding: 0 14px;
  font-weight: 900;
}

.meta-source-toggle button:last-child {
  border-right: 0;
}

.meta-source-toggle button.is-active {
  background: #17212b;
  color: #ffffff;
}

.meta-source-note {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.meta-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px;
}

.meta-card-top {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: start;
}

.compact-types {
  justify-content: flex-start;
  margin-top: 6px;
}

.meta-lines {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.usage-meter {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.usage-meter > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.usage-meter strong {
  color: var(--text);
  font-size: 1.1rem;
}

.usage-bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1f5;
}

.usage-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.move-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.move-chip-list span {
  border-radius: 999px;
  background: #edf7f4;
  color: var(--accent);
  padding: 5px 8px;
  font-size: 0.78rem;
  font-weight: 900;
}

.pokedex-controls {
  display: grid;
  gap: 12px;
}

.pokedex-details {
  display: grid;
  gap: 14px;
}

.pokedex-head {
  display: grid;
  grid-template-columns: 116px 1fr;
  gap: 14px;
  align-items: center;
}

.pokedex-head img {
  width: 116px;
  min-height: 116px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfc;
}

.pokedex-stat-table {
  display: grid;
  grid-template-columns: 78px repeat(3, minmax(70px, 1fr));
  gap: 8px;
  align-items: center;
}

.pokedex-stat-table > div {
  min-height: 34px;
  display: flex;
  align-items: center;
}

.mega-benchmarks {
  display: grid;
  gap: 8px;
}

.mega-benchmark {
  display: grid;
  grid-template-columns: 52px minmax(130px, 1fr) minmax(150px, 1fr);
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.86rem;
}

.mega-benchmark img {
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.mega-benchmark strong {
  display: block;
  color: var(--text);
}

.battle-log {
  min-height: 286px;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
}

.speed-hero {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.speed-hero div,
.speed-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
  padding: 10px 12px;
}

.speed-hero span,
.speed-summary span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.speed-hero strong,
.speed-summary strong {
  display: block;
  color: var(--text);
  font-size: 0.98rem;
}

.speed-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.speed-controls label {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  padding: 8px 10px;
  color: var(--text);
}

.speed-controls label span {
  min-width: 0;
}

.speed-controls label strong,
.speed-controls label small {
  display: block;
}

.speed-controls label strong {
  font-size: 0.92rem;
}

.speed-controls label small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.check-control {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  padding: 8px 10px;
  color: var(--text);
}

.check-control input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
}

.speed-controls input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
}

.speed-controls select {
  min-width: 0;
  margin-left: auto;
}

.speed-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.speed-table {
  display: grid;
  gap: 8px;
}

.speed-table-head {
  display: grid;
  grid-template-columns: 44px minmax(180px, 1fr) 68px 76px 86px;
  gap: 10px;
  padding: 0 10px 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.speed-row {
  display: grid;
  grid-template-columns: 44px minmax(180px, 1fr) 68px 76px 86px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #ffffff;
}

.speed-name-cell {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  column-gap: 10px;
  align-items: center;
  min-width: 0;
}

.speed-name-cell img {
  grid-row: span 2;
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.speed-name-cell strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-pill {
  display: inline-flex;
  min-width: 34px;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 900;
}

.speed-stat,
.speed-final {
  font-weight: 900;
}

.speed-final {
  color: var(--primary);
  font-size: 1.12rem;
}

.rank-badge {
  border: 0;
  padding: 0;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: #17212b;
  color: #ffffff;
  font-weight: 900;
}

.opponent-grid {
  display: grid;
  gap: 10px;
}

.opponent-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.opponent-card-head {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.opponent-card-head img {
  width: 86px;
  height: 86px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.opponent-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.opponent-metrics div {
  min-height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.opponent-metrics span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.opponent-metrics strong {
  color: var(--primary);
  font-size: 1.22rem;
}

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

.opponent-fields label,
.opponent-card-head label {
  min-width: 0;
}

.opponent-fields input,
.opponent-fields select,
.opponent-card-head input {
  width: 100%;
  min-width: 0;
  height: 44px;
}

.opponent-toggles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.opponent-toggles label {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 900;
}

.opponent-toggles input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.roster-details {
  margin-top: 12px;
}

.roster-details summary {
  cursor: pointer;
  font-weight: 900;
}

.roster-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.roster-list span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 800;
}

#exportText,
#importText {
  width: 100%;
  min-height: 380px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
}

dialog {
  width: min(720px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.24);
  padding: 0;
}

dialog::backdrop {
  background: rgba(14, 22, 30, 0.46);
}

dialog form {
  padding: 18px;
}

dialog p {
  margin: 8px 0 12px;
  color: var(--muted);
}

.dialog-actions {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

@media (max-width: 1080px) {
  .layout-grid,
  .sim-grid,
  .rules-layout,
  .pokedex-layout {
    grid-template-columns: 1fr;
  }

  .team-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .topbar-actions button {
    width: 100%;
  }

  .team-list,
  .meta-grid,
  .editor-grid,
  .form-grid,
  .damage-board,
  .damage-move-grid,
  .compact-config,
  .battle-config,
  .move-grid,
  .speed-layout,
  .speed-hero,
  .speed-summary,
  .speed-controls,
  .opponent-fields,
  .opponent-toggles {
    grid-template-columns: 1fr;
  }

  .stat-grid {
    grid-template-columns: 58px 1fr 70px;
    font-size: 0.9rem;
  }

  .move-row,
  .mega-benchmark {
    grid-template-columns: 1fr;
  }

  .speed-table-head {
    display: none;
  }

  .speed-row {
    grid-template-columns: 44px 1fr;
  }

  .speed-row > div:nth-child(n + 3) {
    margin-left: 54px;
  }

  .pokedex-head {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .pokedex-stat-table {
    grid-template-columns: 64px repeat(3, minmax(58px, 1fr));
    font-size: 0.86rem;
  }

  .status-pill {
    margin-left: 0;
  }

  .meta-toggle-row,
  .meta-source-toggle {
    width: 100%;
  }

  .meta-source-toggle button {
    flex: 1;
  }
}
