/* ── Reset & base ──────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: #10141a;
  color: #e6e8eb;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: #60a5fa; }

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .75rem;
  padding: .8rem 1rem calc(.8rem + env(safe-area-inset-top)); padding-top: calc(.8rem + env(safe-area-inset-top));
  background: #0c1016; border-bottom: 1px solid #1f2937;
}
header h1 { font-size: 1.05rem; margin: 0; flex-shrink: 0; }
.meta { font-size: .75rem; color: #94a3b8; flex: 1; }
.icon-btn {
  background: #1f2937; color: #e6e8eb; border: none; border-radius: 8px;
  width: 36px; height: 36px; font-size: 1.1rem; cursor: pointer;
}
.icon-btn:active { background: #374151; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
  position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 9;
  display: flex; background: #0c1016; border-bottom: 1px solid #1f2937;
}
.tab {
  flex: 1; padding: .8rem; background: transparent; border: none;
  color: #94a3b8; font-size: .9rem; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: #e6e8eb; border-bottom-color: #60a5fa; }

.tab-pane { display: none; padding: 1rem; }
.tab-pane.active { display: block; }

/* ── Filters ──────────────────────────────────────────────────────────────── */
.filters { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
fieldset.chips {
  border: none; padding: 0; margin: 0;
  display: flex; flex-wrap: wrap; gap: .35rem; align-items: center;
}
fieldset.chips legend { font-size: .7rem; color: #64748b; padding-right: .4rem; text-transform: uppercase; letter-spacing: .04em; }
fieldset.chips.inline { flex: 1; }
.chips label {
  position: relative; cursor: pointer;
}
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span {
  display: inline-block; padding: .35rem .7rem;
  background: #1f2937; border: 1px solid #1f2937; border-radius: 999px;
  font-size: .8rem; color: #94a3b8; user-select: none;
}
.chips input:checked + span { background: #1e3a8a; border-color: #3b82f6; color: #dbeafe; }
.chips input:focus-visible + span { outline: 2px solid #60a5fa; outline-offset: 2px; }

#farm-search {
  width: 100%; padding: .55rem .8rem; font-size: .9rem;
  background: #1f2937; color: #e6e8eb; border: 1px solid #374151; border-radius: 8px;
}

/* ── Summary bar ──────────────────────────────────────────────────────────── */
.summary-bar {
  display: flex; flex-wrap: wrap; gap: .5rem .9rem;
  padding: .6rem .8rem; margin-bottom: 1rem;
  background: #161c25; border: 1px solid #1f2937; border-radius: 10px;
  font-size: .8rem;
}
.summary-bar .stat { display: flex; gap: .3rem; align-items: baseline; }
.summary-bar .stat strong { color: #e6e8eb; font-size: .95rem; }
.summary-bar .stat span { color: #94a3b8; }

/* ── Groups & cards ───────────────────────────────────────────────────────── */
.group { margin-bottom: 1.5rem; }
.group-title {
  font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: #94a3b8; margin: 1.2rem 0 .6rem; display: flex; align-items: center; gap: .5rem;
}
.group-title .count { color: #64748b; font-weight: 500; }
.group-title.ready { color: #6ee7b7; }
.group-title.farm  { color: #fbbf24; }
.group-title.chain { color: #c084fc; }

.cards { display: flex; flex-direction: column; gap: .5rem; }

.card {
  background: #161c25; border: 1px solid #1f2937; border-radius: 10px;
  padding: .7rem .8rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  gap: .25rem .7rem;
  align-items: center;
}
.card.ready  { border-left: 3px solid #10b981; }
.card.farm   { border-left: 3px solid #f59e0b; }
.card.chain  { border-left: 3px solid #a855f7; }

.card .km {
  grid-column: 1; grid-row: 1 / span 2;
  font-weight: 700; font-size: 1.05rem; color: #fbbf24;
  min-width: 4ch; text-align: right;
}
.card.ready .km { color: #34d399; }

.card .name {
  grid-column: 2; grid-row: 1;
  font-weight: 600; font-size: .95rem; color: #f1f5f9;
}
.card .name .dex { color: #64748b; font-weight: 400; font-size: .8rem; margin-right: .35rem; }
.card .name .region { color: #64748b; font-weight: 400; font-size: .75rem; margin-left: .4rem; }
.card .name .cd { color: #fcd34d; margin-left: .35rem; }

.card .candy {
  grid-column: 3; grid-row: 1;
  font-size: .8rem; color: #94a3b8; white-space: nowrap;
}
.card .candy strong { color: #e6e8eb; }
.card .candy .cost { color: #64748b; }

.card .meta-line {
  grid-column: 2 / span 2; grid-row: 2;
  font-size: .75rem; color: #94a3b8;
  display: flex; flex-wrap: wrap; gap: .35rem .8rem;
}
.card .goal { color: #60a5fa; }
.card .goal.pve { color: #22d3ee; }
.card .goal.pvp { color: #06b6d4; }
.card .goal.dyn { color: #facc15; }
.card .buddy { color: #fb923c; }
.card .item  { color: #fde047; }
.card .cond  { color: #fb923c; }
.card .chain-via { color: #c084fc; font-style: italic; }
.card .purified  { color: #67e8f9; }

.empty { color: #64748b; font-style: italic; padding: .6rem 0; }

/* ── Progress tab ─────────────────────────────────────────────────────────── */
.totals {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: .5rem; margin-bottom: 1.2rem;
}
.totals .stat-card {
  background: #161c25; border: 1px solid #1f2937; border-radius: 10px;
  padding: .7rem .8rem; text-align: center;
}
.totals .stat-card .num { font-size: 1.4rem; font-weight: 700; color: #f1f5f9; }
.totals .stat-card .lbl { font-size: .7rem; color: #94a3b8; text-transform: uppercase; letter-spacing: .05em; }

.gen-list { display: flex; flex-direction: column; gap: .6rem; }
.gen-card {
  background: #161c25; border: 1px solid #1f2937; border-radius: 10px;
  padding: .7rem .8rem;
}
.gen-card h3 { margin: 0 0 .5rem; font-size: .9rem; color: #f1f5f9; display: flex; justify-content: space-between; }
.gen-card h3 .gen-total { color: #94a3b8; font-weight: 400; font-size: .8rem; }
.bars { display: grid; grid-template-columns: 70px 1fr 50px; gap: .25rem .6rem; align-items: center; font-size: .75rem; }
.bars .lbl   { color: #94a3b8; text-transform: uppercase; letter-spacing: .04em; font-size: .7rem; }
.bars .pct   { color: #94a3b8; text-align: right; font-variant-numeric: tabular-nums; }
.bars .track { background: #1f2937; height: 8px; border-radius: 4px; overflow: hidden; }
.bars .fill  { height: 100%; background: #3b82f6; transition: width .3s ease; }
.bars .fill.dex     { background: #60a5fa; }
.bars .fill.pve     { background: #22d3ee; }
.bars .fill.pvp     { background: #06b6d4; }
.bars .fill.dynamax { background: #facc15; }
.bars .fill.mega    { background: #c084fc; }
.bars .fill.shadow  { background: #94a3b8; }

.lucky-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .4rem; }
.lucky-grid .lucky-card {
  background: #161c25; border: 1px solid #1f2937; border-radius: 8px;
  padding: .45rem .6rem; font-size: .85rem;
}
.lucky-grid .lucky-card .dex { color: #64748b; font-size: .75rem; }

/* ── Decision tab ─────────────────────────────────────────────────────────── */
.decision-filters { flex-direction: row; align-items: center; }
#decision-search {
  flex: 1; min-width: 200px;
  padding: .55rem .8rem; font-size: .95rem;
  background: #1f2937; color: #e6e8eb; border: 1px solid #374151; border-radius: 8px;
}

#decision-results { display: flex; flex-direction: column; gap: .8rem; }

.dec-card {
  background: #161c25; border: 1px solid #1f2937; border-radius: 10px;
  padding: .9rem 1rem;
}
.dec-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: .35rem .6rem; margin-bottom: .5rem; }
.dec-head .dex     { color: #64748b; font-size: .85rem; font-weight: 400; }
.dec-head .name    { color: #f1f5f9; font-size: 1.15rem; font-weight: 700; }
.dec-head .region  { color: #94a3b8; font-size: .8rem; font-weight: 400; }
.dec-head .registered { font-size: .75rem; padding: .15rem .5rem; border-radius: 999px; background: #064e3b; color: #6ee7b7; }
.dec-head .not-registered { font-size: .75rem; padding: .15rem .5rem; border-radius: 999px; background: #422006; color: #fcd34d; }

.dec-section { margin-top: .8rem; }
.dec-section-title {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  color: #64748b; margin: 0 0 .3rem; font-weight: 700;
}

.dec-decisions { display: flex; flex-direction: column; gap: .35rem; }
.dec-decisions .row {
  display: flex; gap: .5rem; align-items: flex-start;
  padding: .35rem .55rem; background: #0c1016; border-radius: 6px;
  border-left: 3px solid #1f2937;
}
.dec-decisions .row.completed { opacity: .65; border-left-color: #10b981; }
.dec-decisions .row.cup-only { border-left-color: #06b6d4; }
.dec-decisions .icon { font-size: 1rem; }
.dec-decisions .lbl  { color: #f1f5f9; font-weight: 600; font-size: .85rem; min-width: 9ch; }
.dec-decisions .det  { color: #94a3b8; font-size: .8rem; flex: 1; }
.dec-decisions .row.completed .det::after { content: "  ✓"; color: #6ee7b7; }

.dec-tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.dec-tag {
  font-size: .72rem; padding: .15rem .55rem; border-radius: 999px;
  background: #1f2937; color: #94a3b8; white-space: nowrap;
}
.dec-tag.rare      { background: #422006; color: #fcd34d; }
.dec-tag.unique    { background: #4c1d95; color: #ddd6fe; }
.dec-tag.shadow    { background: #1e293b; color: #c4b5fd; }
.dec-tag.mega      { background: #4a044e; color: #f0abfc; }
.dec-tag.dynamax   { background: #422006; color: #fde047; }
.dec-tag.pve       { background: #164e63; color: #67e8f9; }
.dec-tag.pvp       { background: #134e4a; color: #5eead4; }
.dec-tag.cup       { background: #0c4a6e; color: #38bdf8; }
.dec-tag.cd        { background: #422006; color: #fcd34d; }
.dec-tag.gym       { background: #1e3a8a; color: #93c5fd; }

.dec-moveset { font-size: .8rem; color: #cbd5e1; line-height: 1.5; }
.dec-moveset .ms-line { padding: .15rem 0; border-bottom: 1px dashed #1f2937; }
.dec-moveset .ms-line:last-child { border-bottom: none; }
.dec-moveset .ms-empty { color: #64748b; font-style: italic; }

.dec-evo-chain { display: flex; flex-direction: column; gap: .3rem; }
.dec-evo {
  display: flex; align-items: center; gap: .5rem;
  font-size: .85rem; color: #cbd5e1;
  padding: .3rem .5rem; background: #0c1016; border-radius: 6px;
}
.dec-evo .arrow  { color: #64748b; }
.dec-evo .target { color: #f1f5f9; font-weight: 600; }
.dec-evo .cost   { color: #fbbf24; font-size: .75rem; margin-left: auto; }
.dec-evo .item   { color: #fde047; font-size: .75rem; }
.dec-evo .cond   { color: #fb923c; font-size: .75rem; }

.dec-family { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .4rem; }
.fam-card {
  background: #0c1016; border: 1px solid #1f2937; border-radius: 8px;
  padding: .5rem .6rem; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.fam-card:hover { border-color: #3b82f6; background: #161c25; }
.fam-card.current { border-color: #60a5fa; background: #1e3a8a33; }
.fam-card .fam-name {
  display: flex; justify-content: space-between; align-items: baseline; gap: .4rem;
  font-size: .85rem; color: #f1f5f9; font-weight: 600; margin-bottom: .25rem;
}
.fam-card .fam-name .fam-dex { color: #64748b; font-weight: 400; font-size: .75rem; }
.fam-card .fam-dots { display: flex; flex-wrap: wrap; gap: .2rem; }
.fam-card .dot {
  font-size: .65rem; padding: .1rem .4rem; border-radius: 999px;
  background: #1f2937; color: #475569;
}
.fam-card .dot.on { background: #064e3b; color: #6ee7b7; }
.fam-card .dot.title { background: transparent; color: #64748b; padding-left: 0; padding-right: 0; }

.search-results-info { color: #64748b; font-size: .8rem; margin-bottom: .6rem; }

/* ── Movesets tab ─────────────────────────────────────────────────────────── */
#moveset-search {
  width: 100%; padding: .55rem .8rem; font-size: .95rem;
  background: #1f2937; color: #e6e8eb; border: 1px solid #374151; border-radius: 8px;
}
#moveset-list, #moveset-results { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }

.dec-tag.todo-pve     { background: #422006; color: #fdba74; }
.dec-tag.todo-pvp     { background: #422006; color: #fdba74; }
.dec-tag.todo-dynamax { background: #422006; color: #fdba74; }
.dec-tag.done-pve, .dec-tag.done-pvp, .dec-tag.done-dynamax {
  background: #064e3b; color: #6ee7b7;
}

/* ── Footer legend ─────────────────────────────────────────────────────────── */
footer.legend {
  margin: 1.5rem 1rem calc(2rem + env(safe-area-inset-bottom));
  font-size: .8rem; color: #94a3b8;
}
footer.legend details {
  background: #161c25; border: 1px solid #1f2937; border-radius: 10px;
  padding: .6rem .8rem;
}
footer.legend summary {
  cursor: pointer; color: #cbd5e1; font-weight: 600; user-select: none;
  list-style: none;
}
footer.legend summary::-webkit-details-marker { display: none; }
footer.legend summary::before { content: "▸ "; color: #64748b; }
footer.legend details[open] summary::before { content: "▾ "; }
footer.legend .legend-body { margin-top: .6rem; display: flex; flex-direction: column; gap: .8rem; }
footer.legend .legend-section { line-height: 1.6; }
footer.legend ul { margin: .3rem 0 0; padding-left: 1.2rem; list-style: disc; }
footer.legend li { margin: .15rem 0; }
footer.legend code {
  background: #0c1016; color: #cbd5e1;
  padding: .05rem .35rem; border-radius: 4px;
  font-size: .9em;
}
footer.legend .dot {
  display: inline-block; font-size: .65rem; padding: .1rem .4rem;
  border-radius: 999px; background: #1f2937; color: #475569;
  margin: 0 .1rem;
}
footer.legend .dot.on { background: #064e3b; color: #6ee7b7; }

/* ── Wider screens: minor refinements ─────────────────────────────────────── */
@media (min-width: 720px) {
  main { max-width: 960px; margin: 0 auto; }
  .filters { flex-direction: row; flex-wrap: wrap; align-items: center; }
  #farm-search { flex: 1; min-width: 200px; }
}
