:root {
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-soft: #eef3f8;
  --ink: #111827;
  --muted: #637083;
  --line: #dce4ee;
  --line-strong: #c7d2df;
  --blue: #1167e8;
  --blue-dark: #0b4eb7;
  --green: #108a4b;
  --amber: #b7791f;
  --red: #d21f1f;
  --slate: #213140;
  --shadow: 0 12px 30px rgba(28, 42, 58, 0.12);
  --radius: 8px;
  --tap: 44px;
  color-scheme: light;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(17, 103, 232, 0.08), rgba(255, 255, 255, 0) 260px),
    var(--bg);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  width: min(100%, 980px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 12px 12px calc(22px + env(safe-area-inset-bottom));
}

.loading-screen {
  display: grid;
  min-height: 80svh;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
}

.loading-mark {
  width: 42px;
  height: 42px;
  border: 4px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 4px 10px;
  backdrop-filter: blur(16px);
}

.brand {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

.rule-line {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.text-button,
.primary-button,
.ghost-button,
.danger-button,
.mini-button,
.slot-remove {
  display: inline-flex;
  min-height: var(--tap);
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 120ms ease,
    color 120ms ease,
    border-color 120ms ease;
}

.icon-button:active,
.text-button:active,
.primary-button:active,
.ghost-button:active,
.danger-button:active,
.mini-button:active,
.slot-remove:active {
  transform: translateY(1px);
}

.icon-button {
  width: var(--tap);
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
}

.text-button,
.ghost-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  white-space: nowrap;
}

.compact-button {
  min-width: 54px;
  padding: 0 11px;
}

.ghost-button.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.primary-button {
  width: 100%;
  padding: 0 18px;
  color: #fff;
  background: var(--green);
  box-shadow: 0 10px 24px rgba(16, 138, 75, 0.2);
}

.primary-button.secondary {
  background: var(--blue);
  box-shadow: 0 10px 24px rgba(17, 103, 232, 0.2);
}

.danger-button {
  padding: 0 12px;
  color: var(--red);
  background: #fff1f1;
}

.mini-button,
.slot-remove {
  width: 38px;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: var(--surface);
  font-size: 20px;
  line-height: 1;
}

.mini-button:disabled,
.primary-button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.tabs {
  position: sticky;
  top: calc(54px + env(safe-area-inset-top));
  z-index: 18;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 18px rgba(31, 45, 60, 0.06);
  backdrop-filter: blur(16px);
}

.tab-button {
  min-height: 42px;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 700;
}

.tab-button[aria-selected="true"] {
  color: #fff;
  background: var(--blue);
}

.filter-strip {
  display: grid;
  grid-template-columns: auto minmax(92px, 0.45fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.9);
  font-size: 12px;
  font-weight: 800;
}

.filter-strip select {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
}

.filter-strip span {
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.panel {
  overflow: clip;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(31, 45, 60, 0.06);
}

.panel.compact {
  box-shadow: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 10px 14px;
  color: #fff;
  background: var(--slate);
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.panel-meta {
  color: rgba(255, 255, 255, 0.74);
  font-size: 12px;
  white-space: nowrap;
}

.panel-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

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

.field {
  display: grid;
  gap: 6px;
}

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

.field input,
.field select,
.move-select,
.plain-select {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

.field input:focus,
.field select:focus,
.move-select:focus,
.filter-strip select:focus,
.plain-select:focus,
.stat-number:focus {
  outline: 3px solid rgba(17, 103, 232, 0.18);
  border-color: var(--blue);
}

.mega-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stats-list {
  display: grid;
}

.stat-row {
  display: grid;
  grid-template-columns: minmax(42px, 0.65fr) minmax(42px, 0.55fr) 38px minmax(96px, 1.35fr) 38px minmax(56px, 0.72fr);
  gap: 8px;
  align-items: center;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
}

.stat-row:last-child {
  border-bottom: 0;
}

.stat-label {
  min-width: 0;
  font-size: 15px;
  font-weight: 800;
}

.stat-value {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  text-align: right;
}

.stat-value small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.stat-row input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

.stat-number {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  text-align: center;
  font-weight: 800;
}

.point-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.point-summary strong {
  color: var(--ink);
  font-size: 16px;
}

.point-bar {
  flex: 1 1 140px;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.point-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.moves-list,
.damage-list,
.team-list {
  display: grid;
  gap: 8px;
}

.move-row,
.damage-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 50px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.slot-index {
  display: inline-flex;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  color: #fff;
  background: var(--blue);
  font-size: 13px;
  font-weight: 900;
}

.move-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.move-line {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.move-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  min-width: 44px;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 0 8px;
  color: #fff;
  background: #77808c;
  font-size: 12px;
  font-weight: 900;
}

.pill.neutral {
  color: var(--ink);
  background: var(--surface-soft);
}

.move-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.damage-value {
  color: var(--red);
  font-size: 14px;
  font-weight: 900;
  text-align: right;
  white-space: nowrap;
}

.damage-note {
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.damage-empty {
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: stretch;
}

.summary-box {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.summary-box h3 {
  margin: 0;
  font-size: 13px;
}

.summary-box dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 8px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.summary-box dd {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vs-box {
  display: grid;
  place-items: center;
  color: var(--slate);
  font-size: 24px;
  font-weight: 900;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.wide-actions {
  display: grid;
  gap: 8px;
}

.calc-grid {
  display: grid;
  gap: 12px;
}

.team-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.team-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.team-card h3 {
  margin: 0;
  font-size: 17px;
}

.team-card p,
.empty-state {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  border-radius: 6px;
  padding: 4px 7px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 800;
}

.bottom-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
}

.toast {
  position: fixed;
  right: 14px;
  bottom: calc(86px + env(safe-area-inset-bottom));
  z-index: 40;
  max-width: min(92vw, 360px);
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #fff;
  background: var(--slate);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.type-normal { background: #77808c; }
.type-fire { background: #df4d2f; }
.type-water { background: #2475d1; }
.type-electric { color: #2b2500; background: #f1c62f; }
.type-grass { background: #2f9c50; }
.type-ice { color: #063744; background: #62c6d6; }
.type-fighting { background: #b94535; }
.type-poison { background: #934bb8; }
.type-ground { background: #bd8140; }
.type-flying { background: #728ed8; }
.type-psychic { background: #db4f83; }
.type-bug { background: #7a9d32; }
.type-rock { background: #9d8650; }
.type-ghost { background: #5c5aa1; }
.type-dragon { background: #5f65d8; }
.type-dark { background: #4f4650; }
.type-steel { background: #728390; }
.type-fairy { background: #d66ca8; }

@media (min-width: 720px) {
  .app-shell {
    padding-right: 18px;
    padding-left: 18px;
  }

  .view.two-column {
    grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.92fr);
    align-items: start;
  }

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

  .calc-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

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

  .bottom-bar {
    right: 50%;
    left: auto;
    transform: translateX(50%);
  }
}

@media (max-width: 430px) {
  .brand h1 {
    font-size: 21px;
  }

  .rule-line {
    font-size: 11px;
  }

  .stat-row {
    grid-template-columns: minmax(38px, 0.6fr) minmax(34px, 0.44fr) 34px minmax(74px, 1fr) 34px minmax(48px, 0.62fr);
    gap: 6px;
  }

  .mini-button {
    width: 34px;
    min-height: 34px;
  }

  .stat-number {
    min-height: 34px;
    padding: 0;
  }

  .panel-body {
    padding: 12px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .vs-box {
    min-height: 24px;
    font-size: 18px;
  }
}
