:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --ink: #19202a;
  --muted: #68707d;
  --line: #ded8cb;
  --panel: #fffdf8;
  --red: #d64045;
  --gold: #d89b2b;
  --teal: #177e89;
  --green: #357960;
  --shadow: 0 12px 34px rgba(34, 30, 24, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(216, 155, 43, 0.2), transparent 34rem),
    linear-gradient(180deg, #f9f6ef 0%, var(--paper) 42%, #ebe6db 100%);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 28px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 10vw, 3.1rem);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
  letter-spacing: 0;
}

.pokeball-mark {
  position: relative;
  flex: 0 0 auto;
  width: 72px;
  aspect-ratio: 1;
  border: 5px solid var(--ink);
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(#d64045 0 47%, var(--ink) 47% 54%, #fffdf8 54% 100%);
  box-shadow: var(--shadow);
}

.pokeball-mark span {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 24px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: #fffdf8;
}

.pokeball-mark.small {
  width: 54px;
  margin: 0 auto 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.account-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
  padding: 0 2px 14px;
}

.account-bar label {
  margin: 0;
}

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

.account-actions button {
  width: 44px;
  padding: 0;
  font-size: 1.08rem;
}

dialog {
  width: min(calc(100% - 32px), 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 18px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(25, 32, 42, 0.36);
}

dialog .panel-heading {
  margin-bottom: 16px;
}

dialog label {
  margin-bottom: 16px;
}

.stats-grid article,
.panel,
.trade-card,
.empty-state {
  border: 1px solid rgba(25, 32, 42, 0.1);
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.stats-grid article {
  padding: 12px 10px;
  border-radius: 8px;
}

.stats-grid span {
  display: block;
  color: var(--red);
  font-size: 1.7rem;
  font-weight: 850;
  line-height: 1;
}

.stats-grid p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.panel {
  margin-bottom: 14px;
  padding: 16px;
  border-radius: 8px;
}

.panel-heading,
.action-row,
.data-actions,
.card-actions,
.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 14px;
}

.compact-heading {
  margin-bottom: 0;
}

.entry-mode {
  margin-bottom: 14px;
}

.entry-mode button {
  min-height: 40px;
}

.result-only[hidden] {
  display: none;
}

.optional-details {
  margin: 2px 0 14px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.optional-details summary {
  cursor: pointer;
  color: var(--teal);
  font-size: 0.84rem;
  font-weight: 800;
}

.optional-details[open] summary {
  margin-bottom: 12px;
}

.optional-details label:last-child {
  margin-bottom: 0;
}

.upcoming-list {
  display: grid;
  gap: 8px;
}

.upcoming-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.upcoming-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.upcoming-heading {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 8px;
}

.upcoming-heading strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upcoming-date {
  flex: 0 0 auto;
  color: var(--red);
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1.2;
  text-transform: uppercase;
}

.mini-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  background: rgba(23, 126, 137, 0.12);
  padding: 3px 6px;
  color: var(--teal);
  font-size: 0.68rem;
  font-weight: 850;
}

.upcoming-pokemon {
  display: grid;
  grid-column: 1;
  gap: 3px;
}

.upcoming-pokemon p {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.upcoming-pokemon p span {
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
}

.upcoming-actions {
  display: flex;
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  gap: 6px;
}

.upcoming-actions button {
  min-height: 36px;
  padding: 7px 9px;
  font-size: 0.76rem;
}

.upcoming-actions .icon-action {
  width: 36px;
  padding: 0;
  font-size: 1rem;
}

.upcoming-actions .danger {
  color: var(--red);
}

.upcoming-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: #39404b;
  font-size: 0.84rem;
  font-weight: 740;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 126, 137, 0.16);
}

.name-suggestion {
  min-height: 0;
  border: 0;
  background: transparent;
  padding: 0 2px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: left;
}

.name-suggestion[hidden] {
  display: none;
}

.pokemon-combobox {
  position: relative;
  display: block;
}

.pokemon-combobox input {
  padding-right: 44px;
}

.combo-toggle {
  position: absolute;
  top: 0;
  right: 0;
  width: 42px;
  min-height: 44px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0 8px 8px 0;
  background: transparent;
  padding: 0;
  color: var(--muted);
  font-size: 1.1rem;
}

.combo-options {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 4px;
  box-shadow: var(--shadow);
}

.combo-options[hidden] {
  display: none;
}

.combo-option {
  display: block;
  width: 100%;
  min-height: 38px;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  font-weight: 700;
  text-align: left;
}

.combo-option:hover,
.combo-option:focus {
  background: rgba(23, 126, 137, 0.1);
}

.combo-empty {
  display: block;
  padding: 9px 10px;
  color: var(--muted);
  font-size: 0.8rem;
}

.pill-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 2px 0 12px;
}

.pill-row label {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  font-size: 0.78rem;
}

.pill-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--teal);
}

.action-row {
  align-items: stretch;
}

button,
.file-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  font-weight: 800;
  text-align: center;
}

.primary {
  width: 100%;
  border-color: var(--red);
  background: var(--red);
  color: white;
}

.ghost {
  background: transparent;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 1.15rem;
}

.tools-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.search-wrap input {
  margin: 0;
}

.segmented,
.data-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.segmented button.active {
  border-color: var(--teal);
  background: var(--teal);
  color: white;
}

.file-button {
  position: relative;
  display: block;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.iv-fieldset {
  margin: 2px 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.iv-fieldset legend {
  padding: 0 6px;
  color: #39404b;
  font-size: 0.84rem;
  font-weight: 800;
}

.iv-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.iv-grid label {
  margin-bottom: 4px;
}

.iv-preview {
  margin: 4px 0 0;
  color: var(--teal);
  font-size: 0.86rem;
  font-weight: 800;
}

.summary-chip {
  border-radius: 999px;
  background: rgba(23, 126, 137, 0.12);
  padding: 7px 9px;
  color: #10545c;
  font-size: 0.76rem;
  font-weight: 850;
  white-space: nowrap;
}

.species-stats {
  display: grid;
  gap: 8px;
}

.species-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.species-row p {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
  font-weight: 750;
}

.species-row span {
  color: var(--muted);
  font-size: 0.8rem;
}

.species-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.trade-list {
  display: grid;
  gap: 12px;
}

.trade-card,
.empty-state {
  border-radius: 8px;
  padding: 14px;
}

.card-title {
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.card-title h2 {
  font-size: 1.08rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 9px;
  background: rgba(216, 155, 43, 0.16);
  color: #6d4d0b;
  font-size: 0.74rem;
  font-weight: 850;
  white-space: nowrap;
}

.badge.green {
  background: rgba(53, 121, 96, 0.15);
  color: var(--green);
}

.badge.red {
  background: rgba(214, 64, 69, 0.14);
  color: var(--red);
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.meta-grid p,
.notes {
  margin: 0;
  border-radius: 8px;
  background: rgba(247, 243, 234, 0.9);
  padding: 9px 10px;
  color: #39404b;
  font-size: 0.86rem;
}

.meta-grid strong {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 3px;
}

.notes {
  margin-bottom: 12px;
}

.card-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.card-actions button {
  min-width: 76px;
}

.empty-state {
  padding: 30px 18px;
  text-align: center;
}

.empty-state p {
  margin-bottom: 0;
  color: var(--muted);
}

@media (max-width: 580px) {
  .field-grid,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .pill-row,
  .iv-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .iv-grid {
    grid-template-columns: repeat(3, 1fr);
  }

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

  .pokeball-mark {
    width: 60px;
  }

  .stats-grid span {
    font-size: 1.45rem;
  }

  .action-row {
    flex-direction: column;
  }

  .pill-row label {
    align-content: start;
    align-items: flex-start;
    font-size: 0.72rem;
  }

  .upcoming-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .upcoming-actions {
    grid-row: auto;
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

.pokemon-fields {
  grid-template-columns: 1fr;
}
