:root {
  color-scheme: light;
  --bg: #f4f5f1;
  --panel: #ffffff;
  --panel-soft: #f8faf8;
  --text: #171a1c;
  --muted: #66706c;
  --line: #d8ddd8;
  --accent: #0f766e;
  --accent-strong: #0b5e58;
  --warn: #b45309;
  --danger: #b42318;
  --shadow: 0 8px 20px rgba(23, 26, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: rgba(244, 245, 241, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

#statusText {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions,
.section-head,
.data-section,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-switch,
.prep-side-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e8eeeb;
}

.mode-btn {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.mode-btn.active {
  background: #ffffff;
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(23, 26, 28, 0.08);
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 16px;
}

.board-shell {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(360px, 0.9fr) minmax(280px, 1fr);
  gap: 12px;
  align-items: start;
}

.team-section,
.damage-section,
.data-section,
.editor-shell,
.team-board-panel,
.quick-import-section,
.battle-dock {
  min-width: 0;
}

.quick-import-section {
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.quick-import-section textarea {
  min-height: 108px;
  margin: 0;
}

.quick-import-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.team-preset-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.preset-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.preset-group > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.preset-btn {
  position: relative;
}

.preset-btn.has-preset::after {
  content: "";
  position: absolute;
  right: 5px;
  top: 5px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
}

body.prep-mode.prep-side-my .quick-paste-opp,
body.prep-mode.prep-side-my .quick-action-opp,
body.prep-mode.prep-side-my .editor-team-opp,
body.prep-mode.prep-side-my .team-board-panel-opp,
body.prep-mode.prep-side-opp .quick-paste-my,
body.prep-mode.prep-side-opp .quick-action-my,
body.prep-mode.prep-side-opp .editor-team-my,
body.prep-mode.prep-side-opp .team-board-panel-my {
  display: none;
}

body.prep-mode .damage-section {
  display: none;
}

body.prep-mode .board-shell {
  grid-template-columns: 1fr;
}

body.battle-mode .quick-import-section,
body.battle-mode .editor-shell,
body.battle-mode .data-section,
body.battle-mode .team-board-panel-my {
  display: none;
}

body.battle-mode .board-shell {
  grid-template-columns: minmax(0, 1fr);
}

body.battle-mode .damage-section {
  order: 1;
}

body.battle-mode .team-board-panel-opp {
  order: 2;
}

.section-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

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

.team-board {
  display: grid;
  grid-template-rows: repeat(6, minmax(126px, 1fr));
  gap: 8px;
}

.team-card {
  position: relative;
  min-height: 126px;
  overflow: hidden;
  padding: 10px;
  background: #202426;
  border: 1px solid #343b3d;
  border-radius: 8px;
  color: #f1f5f4;
  box-shadow: var(--shadow);
}

.team-card.empty {
  display: grid;
  place-items: center;
  color: #8a9693;
  background: #f9fbfa;
  border: 1px dashed var(--line);
}

.team-card-bg {
  position: absolute;
  right: -10px;
  top: 50%;
  width: 128px;
  height: 128px;
  transform: translateY(-50%);
  object-fit: contain;
  opacity: 0.28;
  pointer-events: none;
}

.team-card-content {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  height: 100%;
}

.team-card-main,
.team-card-side {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.team-card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.team-card-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 800;
}

.evo-buttons {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.evo-button {
  min-height: 20px;
  padding: 0 6px;
  border: 1px solid #5c6a67;
  border-radius: 5px;
  background: #30383a;
  color: #dce7e3;
  font-size: 10px;
  font-weight: 800;
}

.evo-button:hover,
.evo-button.active {
  border-color: #2dd4bf;
  background: #0f766e;
  color: #fff;
}

.team-card-meta {
  min-height: 16px;
  overflow: hidden;
  color: #bbc8c4;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.team-card-stats {
  display: grid;
  gap: 3px;
  margin-top: auto;
}

.mini-stat {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 48px;
  gap: 5px;
  align-items: center;
  font-size: 10px;
  color: #cad4d1;
}

.mini-stat-track {
  height: 4px;
  overflow: hidden;
  background: #121617;
  border-radius: 999px;
}

.mini-stat-bar {
  height: 100%;
  background: linear-gradient(90deg, #2dd4bf, #60a5fa);
}

.mini-stat-value {
  text-align: right;
  color: #96a5a1;
}

.team-card-effect {
  display: grid;
  gap: 4px;
  min-height: 42px;
  font-size: 10px;
  color: #c6d0cd;
}

.effect-row {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.effect-label {
  color: #90a09b;
  font-weight: 800;
}

.board-moves {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: auto;
}

.board-move {
  min-width: 0;
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 4px 6px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.board-move:hover {
  border-color: rgba(255, 255, 255, 0.72);
}

.board-move.no-move {
  grid-column: 1 / -1;
  justify-content: center;
  border-style: dashed;
  background: #eef2f1;
  color: #66706c;
}

.board-move-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-move-power {
  flex-shrink: 0;
  opacity: 0.86;
  font-size: 10px;
}

.battle-dock {
  display: none;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 36px rgba(23, 26, 28, 0.14);
}

body.battle-mode .battle-dock {
  display: grid;
  gap: 10px;
}

body.battle-mode .quick-import-section,
body.battle-mode .editor-shell,
body.battle-mode .data-section {
  display: none;
}

.battle-dock-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(130px, 190px);
  gap: 8px;
  align-items: center;
}

.dock-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

#dockAttackerName {
  display: block;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#dockAttackerSelect {
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.dock-move-buttons,
.move-button-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.dock-move,
.damage-move {
  min-width: 0;
  min-height: 42px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
  text-align: left;
}

.dock-move span,
.damage-move span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dock-move small,
.damage-move small {
  opacity: 0.86;
  font-size: 11px;
}

.dock-move.active,
.damage-move.active {
  outline: 3px solid rgba(15, 118, 110, 0.32);
  outline-offset: 2px;
}

.dock-move.empty,
.damage-move.empty {
  justify-content: center;
  background: #eef2f1;
  color: var(--muted);
}

.move-button-grid,
.stage-control-panel {
  margin-top: 8px;
}

.stage-control-panel {
  display: grid;
  gap: 8px;
}

.stage-card {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  padding: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stage-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.mega-control {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
  padding: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.mega-control > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.mega-control .evo-buttons {
  margin-top: 0;
}

.stage-stepper {
  display: inline-grid;
  grid-template-columns: auto 28px 38px 28px;
  gap: 4px;
  align-items: center;
  width: fit-content;
}

.stage-stepper.no-label {
  grid-template-columns: 28px 38px 28px;
}

.stage-stepper-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.stage-stepper button {
  min-height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font-weight: 900;
}

.stage-stepper .stage-value {
  color: var(--accent);
  background: #effaf8;
}

.edit-card-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 2;
  width: 30px;
  min-height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(20, 24, 25, 0.65);
  color: #fff;
}

.slot-card,
.damage-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.slot-card {
  padding: 12px;
}

.slot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.slot-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.icon-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
}

.primary-btn {
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

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

.ghost-btn {
  padding: 0 12px;
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}

.ghost-btn:hover {
  border-color: var(--accent);
}

.danger-btn {
  padding: 0 12px;
  background: #fff5f5;
  border-color: rgba(180, 35, 24, 0.35);
  color: var(--danger);
  font-weight: 800;
}

.danger-btn:hover {
  border-color: var(--danger);
  background: #ffe4e4;
}

.icon-btn {
  width: 36px;
  background: var(--panel-soft);
  border-color: var(--line);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.icon-btn:hover {
  color: var(--danger);
  border-color: #f0b4ad;
}

.field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.field input:focus,
.field select:focus,
textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.18);
  border-color: var(--accent);
}

.pokemon-strip {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin: 10px 0;
  min-height: 58px;
}

.sprite-box {
  width: 58px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.sprite-img {
  max-width: 52px;
  max-height: 52px;
  image-rendering: auto;
}

.pokemon-name {
  min-height: 22px;
  font-weight: 800;
  word-break: break-word;
}

.type-row,
.move-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.type-chip,
.info-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef2f1;
  color: #27302c;
  font-size: 12px;
  font-weight: 700;
}

.type-fire { background: #ffe2ce; color: #8a3300; }
.type-water { background: #ddecff; color: #16498a; }
.type-grass { background: #daf3df; color: #176330; }
.type-electric { background: #fff1b8; color: #7c5b00; }
.type-ice { background: #dff7fb; color: #176779; }
.type-fighting { background: #f7d7d7; color: #842029; }
.type-poison { background: #efd8ff; color: #67239a; }
.type-ground { background: #f3e2be; color: #76501a; }
.type-flying { background: #e4e4ff; color: #4242a0; }
.type-psychic { background: #ffd9e4; color: #9d2450; }
.type-bug { background: #eef5c2; color: #53620d; }
.type-rock { background: #ece0bd; color: #6f5a1b; }
.type-ghost { background: #e2d9f1; color: #4d3674; }
.type-dragon { background: #ded8ff; color: #4125a8; }
.type-dark { background: #ded8d4; color: #46322a; }
.type-steel { background: #e0e6ec; color: #445363; }
.type-fairy { background: #ffe0ef; color: #8a2d61; }
.type-normal { background: #ecece3; color: #535348; }

.field-grid,
.stats-grid,
.moves-grid,
.damage-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 8px;
}

.moves-grid {
  margin-top: 8px;
}

.opp-team .my-fields {
  display: none;
}

.damage-section {
  padding: 12px;
}

.damage-meta {
  min-height: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.damage-rows {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 8px;
}

.damage-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.damage-row .sprite-box {
  width: 42px;
}

.damage-row .sprite-img {
  max-width: 38px;
  max-height: 38px;
}

.damage-row-head {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.damage-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.damage-row .type-row {
  margin-top: 4px;
}

.damage-row-numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin-top: 4px;
}

.damage-row span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 0;
}

.damage-row .stage-stepper {
  flex-shrink: 0;
}

.speed-axis-container {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.speed-axis-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.speed-axis-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.speed-axis-toggle {
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.speed-axis-toggle.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.speed-opp-section,
.speed-team-section {
  display: grid;
  gap: 4px;
  min-height: 28px;
}

#speedOppBottom {
  margin-top: 6px;
}

#speedAxisMain {
  position: relative;
  min-height: 46px;
  margin: 6px 0;
  border-radius: 8px;
  background: #eef2f1;
  overflow: hidden;
}

#speedAxisMain::before {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
  background: #9aa9a4;
}

#speedMarkersMy {
  position: absolute;
  inset: 0;
}

.speed-my-sprite,
.speed-opp-sprite {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.speed-my-sprite {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

.speed-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(15, 23, 42, 0.16);
}

.speed-tick span {
  position: absolute;
  top: 2px;
  left: 3px;
  color: var(--muted);
  font-size: 10px;
}

.speed-my-tick {
  background: rgba(15, 118, 110, 0.45);
}

.speed-my-tick span {
  color: var(--accent);
  font-weight: 800;
}

.speed-opp-row,
.speed-row {
  position: relative;
  min-height: 28px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto auto;
  gap: 4px;
  align-items: center;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.speed-my-row {
  background: #eefaf8;
}

.speed-opp-bar {
  position: absolute;
  left: 38px;
  height: 4px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.28);
  pointer-events: none;
}

.speed-opp-text {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.speed-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.speed-value {
  min-width: 44px;
  text-align: right;
}

.speed-row .stage-stepper {
  grid-template-columns: 22px 32px 22px;
  gap: 2px;
}

.speed-row .stage-stepper-label {
  display: none;
}

.speed-row .stage-stepper button {
  min-height: 24px;
  border-radius: 6px;
}

.data-section {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.editor-shell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.editor-shell summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 800;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  padding: 0 12px 12px;
}

dialog {
  width: min(760px, calc(100vw - 24px));
  border: none;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(20, 25, 24, 0.44);
}

.dialog-card {
  padding: 14px;
  background: var(--panel);
}

textarea {
  min-height: 260px;
  margin: 10px 0;
  resize: vertical;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
}

@media (max-width: 920px) {
  .board-shell,
  .editor-grid,
  .quick-import-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr auto auto;
  }

  .app-shell {
    padding: 12px;
    gap: 14px;
  }

  .dock-move-buttons,
  .move-button-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .team-board {
    grid-template-columns: 1fr;
  }

  .team-card-content {
    grid-template-columns: 1fr;
  }

  .field-grid,
  .stats-grid,
  .moves-grid,
  .damage-controls {
    grid-template-columns: 1fr;
  }

  .data-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
