/* PokeTracker — clean-minimal with Game Boy / Pokedex whimsy.
   Display face: Press Start 2P (used sparingly). Body: monospace stack. */

:root {
  --bg: #efe9d8;          /* worn cartridge paper */
  --panel: #faf6ea;
  --ink: #2b2a24;
  --muted: #6f6a58;
  --line: #2b2a24;
  --accent: #d8433a;      /* Pokedex shell red */
  --lens: #3e8ed0;
  --lcd-bg: #c5d1a0;      /* Game Boy screen */
  --lcd-ink: #2f3a1c;
  --fill: #5b7a3a;
  --fill-shiny: #c99a2e;
  --card-shadow: 4px 4px 0 rgba(43, 42, 36, 0.9);
  --btn-shadow: 3px 3px 0 rgba(43, 42, 36, 0.9);
  --px: "Press Start 2P", monospace;
  --body: ui-monospace, "Cascadia Mono", "Courier New", monospace;
}
[data-theme="dark"] {
  --bg: #1e221c;          /* powered-off LCD */
  --panel: #2a2f27;
  --ink: #dce6c4;
  --muted: #97a184;
  --line: #10130e;
  --accent: #e2564d;
  --lcd-bg: #33402a;
  --lcd-ink: #b8d174;
  --fill: #8bac0f;
  --fill-shiny: #e0b341;
  --card-shadow: 4px 4px 0 rgba(0, 0, 0, 0.55);
  --btn-shadow: 3px 3px 0 rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.45;
}
a { color: inherit; }

/* ---------- header: the Pokedex top panel ---------- */
.dex-top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--accent);
  border-bottom: 4px solid var(--line);
  color: #fff;
  flex-wrap: wrap;
}
.lens {
  width: 44px; height: 44px; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #cfe8ff 0 18%, var(--lens) 42%, #1d4e7c 100%);
  border: 3px solid var(--line);
  box-shadow: 0 0 0 4px #fff, 0 0 0 6px var(--line);
  flex: none;
}
.leds { display: flex; gap: 6px; align-self: flex-start; }
.led { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); display: block; }
.led-r { background: #ff6b5e; } .led-y { background: #ffd75e; } .led-g { background: #7ee08a; }
.dex-top h1 {
  font-family: var(--px);
  font-size: clamp(14px, 3vw, 22px);
  margin: 0;
  letter-spacing: 2px;
  text-shadow: 3px 3px 0 var(--line);
  flex: 1;
}
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- buttons ---------- */
.pixel-btn {
  font-family: var(--px);
  font-size: 10px;
  padding: 9px 12px;
  background: var(--panel);
  color: var(--ink);
  border: 3px solid var(--line);
  box-shadow: var(--btn-shadow);
  cursor: pointer;
  text-transform: uppercase;
}
.pixel-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--line); }
.pixel-btn.accent { background: var(--accent); color: #fff; }
.pixel-btn.small { font-size: 9px; padding: 7px 9px; }
.pixel-btn:focus-visible, select:focus-visible, input:focus-visible, .ball-btn:focus-visible {
  outline: 3px dashed var(--accent);
  outline-offset: 2px;
}

/* ---------- LCD progress ---------- */
.lcd {
  margin: 16px auto 0;
  max-width: 1200px;
  width: calc(100% - 32px);
  background: var(--lcd-bg);
  color: var(--lcd-ink);
  border: 4px solid var(--line);
  box-shadow: var(--card-shadow), inset 0 0 0 2px rgba(255, 255, 255, 0.15);
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}
.lcd-row { display: grid; grid-template-columns: 70px 1fr auto; align-items: center; gap: 10px; }
.lcd-label, .lcd-num { font-family: var(--px); font-size: 9px; }
.bar { height: 12px; border: 2px solid var(--lcd-ink); background: transparent; }
.bar-fill { height: 100%; width: 0; background: var(--fill); transition: width 0.25s steps(12); }
.bar-fill.shiny { background: var(--fill-shiny); }
@media (prefers-reduced-motion: reduce) { .bar-fill { transition: none; } }

/* ---------- controls ---------- */
.controls {
  max-width: 1200px;
  width: calc(100% - 32px);
  margin: 14px auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: end;
}
.control { display: flex; flex-direction: column; gap: 5px; }
.control label { font-family: var(--px); font-size: 8px; color: var(--muted); }
select, .pixel-dialog input {
  font-family: var(--body);
  font-size: 14px;
  padding: 7px 8px;
  background: var(--panel);
  color: var(--ink);
  border: 3px solid var(--line);
  box-shadow: var(--btn-shadow);
  min-width: 120px;
}
.control-end { margin-left: auto; }
.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- share banner ---------- */
.share-banner {
  max-width: 1200px;
  width: calc(100% - 32px);
  margin: 14px auto -2px;
  padding: 10px 12px;
  border: 3px dashed var(--line);
  background: var(--panel);
  font-family: var(--px);
  font-size: 9px;
  line-height: 1.8;
}

/* ---------- grid + cards ---------- */
.grid {
  max-width: 1200px;
  width: calc(100% - 32px);
  margin: 6px auto 30px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: var(--card-shadow);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}
.card.caught::after {
  content: "";
  position: absolute; top: 7px; right: 7px;
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(var(--accent) 0 44%, var(--line) 44% 56%, #fff 56% 100%);
  border: 2px solid var(--line);
}
.card .num { font-family: var(--px); font-size: 8px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.card img {
  width: 96px; height: 96px;
  margin: 0 auto;
  image-rendering: pixelated;
  background:
    linear-gradient(transparent 0 96%, rgba(43, 42, 36, 0.12) 96% 100%);
}
.card .name { font-size: 13px; font-weight: 700; min-height: 2.1em; }
.types { display: flex; gap: 5px; flex-wrap: wrap; }
.type-badge {
  font-family: var(--px);
  font-size: 7px;
  padding: 4px 6px;
  border: 2px solid var(--line);
  background: var(--bg);
  text-transform: uppercase;
}
.card-actions { display: flex; gap: 8px; margin-top: auto; }
.ball-btn {
  flex: 1;
  font-family: var(--px);
  font-size: 8px;
  padding: 8px 4px;
  border: 3px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--line);
}
.ball-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--line); }
.ball-btn[aria-pressed="true"] { background: var(--fill); color: #fff; }
.ball-btn.shiny[aria-pressed="true"] { background: var(--fill-shiny); color: var(--line); }
.ball-btn:disabled { cursor: default; opacity: 0.9; }

.empty, .foot {
  max-width: 1200px;
  width: calc(100% - 32px);
  margin: 20px auto;
  color: var(--muted);
}
.empty { text-align: center; font-family: var(--px); font-size: 10px; line-height: 2; }
.foot { font-size: 12px; display: flex; flex-direction: column; gap: 4px; padding-bottom: 26px; }
#sync-status { font-family: var(--px); font-size: 8px; }

/* ---------- dialog ---------- */
.pixel-dialog {
  border: 4px solid var(--line);
  box-shadow: 8px 8px 0 rgba(43, 42, 36, 0.5);
  background: var(--panel);
  color: var(--ink);
  padding: 18px;
  width: min(420px, 92vw);
}
.pixel-dialog::backdrop { background: rgba(20, 20, 16, 0.55); }
.pixel-dialog h2 { font-family: var(--px); font-size: 13px; margin: 0 0 12px; }
.pixel-dialog form { display: flex; flex-direction: column; gap: 8px; }
.pixel-dialog label { font-family: var(--px); font-size: 8px; color: var(--muted); margin-top: 4px; }
.tab-row { display: flex; gap: 8px; margin-bottom: 10px; }
.tab { opacity: 0.6; }
.tab.active { opacity: 1; background: var(--accent); color: #fff; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0; }
.error { font-size: 12px; color: var(--accent); font-weight: 700; min-height: 1em; margin: 0; }
#share-url { flex: 1; min-width: 0; font-size: 12px; }
#account-info { display: flex; flex-direction: column; gap: 10px; }

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .control-end { margin-left: 0; }
}

/* ---------- sub-dex group headers ---------- */
.group-head {
  grid-column: 1 / -1;
  font-family: var(--px);
  font-size: 11px;
  margin: 14px 0 2px;
  padding: 8px 10px;
  background: var(--panel);
  border: 3px solid var(--line);
  border-left: 10px solid var(--accent);
  box-shadow: var(--btn-shadow);
}
.group-head:first-child { margin-top: 0; }

#search-input {
  font-family: var(--body);
  font-size: 14px;
  padding: 7px 8px;
  background: var(--panel);
  color: var(--ink);
  border: 3px solid var(--line);
  box-shadow: var(--btn-shadow);
  min-width: 140px;
}

/* ---------- type colors (canonical series palette) ---------- */
.type-badge { color: #fff; background: var(--muted); }
.type-normal   { background: #A8A77A; color: #23231c; }
.type-fire     { background: #EE8130; color: #2d1503; }
.type-water    { background: #6390F0; color: #0a1c4a; }
.type-electric { background: #F7D02C; color: #3a2f02; }
.type-grass    { background: #7AC74C; color: #14300a; }
.type-ice      { background: #96D9D6; color: #0d3532; }
.type-fighting { background: #C22E28; color: #fff; }
.type-poison   { background: #A33EA1; color: #fff; }
.type-ground   { background: #E2BF65; color: #3a2c07; }
.type-flying   { background: #A98FF3; color: #1d0f4a; }
.type-psychic  { background: #F95587; color: #47041c; }
.type-bug      { background: #A6B91A; color: #232805; }
.type-rock     { background: #B6A136; color: #2b2508; }
.type-ghost    { background: #735797; color: #fff; }
.type-dragon   { background: #6F35FC; color: #fff; }
.type-dark     { background: #705746; color: #fff; }
.type-steel    { background: #B7B7CE; color: #22222e; }
.type-fairy    { background: #D685AD; color: #3d0f27; }

/* ---------- mobile: FAB + filter sheet ---------- */
.fab, .sheet-backdrop, .sheet-done { display: none; }

@media (max-width: 640px) {
  body { font-size: 14px; }
  .dex-top { padding: 10px 12px; gap: 10px; }
  .lens { width: 34px; height: 34px; }
  .top-actions { width: 100%; }
  .top-actions .pixel-btn { flex: 1; padding: 9px 4px; font-size: 9px; }
  .lcd, .grid, .empty, .foot, .share-banner { width: calc(100% - 20px); }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card img { width: 80px; height: 80px; }

  /* Controls become a bottom sheet, opened by the FAB */
  .controls {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    margin: 0;
    width: 100%;
    max-height: 75vh;
    overflow-y: auto;
    background: var(--panel);
    border-top: 4px solid var(--line);
    box-shadow: 0 -6px 0 rgba(0, 0, 0, 0.25);
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
    transform: translateY(105%);
    transition: transform 0.22s ease-out;
  }
  body.filters-open .controls { transform: translateY(0); }
  @media (prefers-reduced-motion: reduce) { .controls { transition: none; } }
  .control { width: 100%; }
  .control select, #search-input { width: 100%; min-width: 0; }
  .control-end { margin-left: 0; }

  .sheet-done {
    display: block;
    width: 100%;
    margin-top: 4px;
  }

  .sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(20, 20, 16, 0.5);
  }
  body:not(.filters-open) .sheet-backdrop { display: none; }
  body.filters-open .sheet-backdrop { display: block; }

  .fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 40;
    width: 60px; height: 60px;
    border-radius: 50%;
    background: var(--accent);
    border: 4px solid var(--line);
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.4);
    cursor: pointer;
    padding: 0;
  }
  .fab:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4); }
  .fab svg { width: 30px; height: 30px; display: block; }
  body.filters-open .fab { display: none; }
  .fab .fab-badge {
    position: absolute;
    top: -6px; right: -6px;
    min-width: 20px; height: 20px;
    border-radius: 50%;
    background: var(--panel);
    color: var(--ink);
    border: 3px solid var(--line);
    font-family: var(--px);
    font-size: 9px;
    line-height: 15px;
    text-align: center;
  }
  .fab .fab-badge[hidden] { display: none; }
}
