:root {
  color-scheme: dark;
  --ink: #dff5d1;
  --muted: #83ada0;
  --deep: #031418;
  --panel: #09262b;
  --panel-2: #0d3338;
  --line: #1f5555;
  --aqua: #58d5c9;
  --yellow: #f5cf59;
  --red: #ff786d;
  --shadow: #011012;
  --radius: 3px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--deep); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(88, 213, 201, .025) 1px, transparent 1px) 0 0 / 100% 4px,
    radial-gradient(circle at 75% -10%, #144e52 0, transparent 34rem),
    var(--deep);
  font-size: 1rem;
  line-height: 1.5;
}

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

.shell { width: min(1440px, 100%); margin: 0 auto; padding: 0 clamp(1rem, 3vw, 3rem); }

.topbar {
  min-height: 104px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: .9rem; }
.brand-mark { width: 52px; height: 52px; border: 3px solid var(--aqua); border-radius: 50%; display: grid; place-items: center; position: relative; box-shadow: inset 0 0 0 4px var(--deep); }
.brand-mark::before { content: ""; position: absolute; left: 0; right: 0; height: 5px; background: var(--aqua); }
.brand-mark span { width: 16px; height: 16px; z-index: 1; border-radius: 50%; background: var(--yellow); border: 4px solid var(--deep); outline: 3px solid var(--aqua); }
.brand h1 { margin: -.1rem 0 0; font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: -.08em; line-height: 1; }
.brand h1 b { color: var(--yellow); font-weight: 800; }
.eyebrow { color: var(--aqua); font-size: .75rem; letter-spacing: .13em; margin: 0 0 .35rem; font-weight: 700; }

main { padding: clamp(1.5rem, 4vw, 3.25rem) 0 4rem; }
.controls { border: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 88%, transparent); box-shadow: 8px 8px 0 var(--shadow); }
.controls-heading { display: flex; justify-content: space-between; align-items: end; gap: 1.5rem; padding: 1.35rem clamp(1rem, 2.5vw, 2rem); border-bottom: 1px solid var(--line); }
h2 { margin: 0; font-size: clamp(1.25rem, 3vw, 1.8rem); line-height: 1.2; }
.source-status { display: flex; align-items: center; gap: .55rem; color: var(--muted); font-size: .8rem; text-align: right; }
.status-light { width: 9px; height: 9px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 10px var(--yellow); flex: none; }
.source-status[data-state="network"] .status-light { background: var(--aqua); box-shadow: 0 0 10px var(--aqua); }
.source-status[data-state="cache"] .status-light { background: var(--yellow); }
.source-status[data-state="error"] .status-light { background: var(--red); box-shadow: 0 0 10px var(--red); }

.quick-filter { display: grid; grid-template-columns: minmax(220px, 2fr) minmax(170px, 1fr) auto; gap: 1rem; align-items: end; padding: 1.25rem clamp(1rem, 2.5vw, 2rem); }
label { display: grid; gap: .45rem; color: var(--muted); font-size: .82rem; font-weight: 700; letter-spacing: .04em; }
.type-filter-control { display: grid; gap: .45rem; position: relative; }
.control-label { color: var(--muted); font-size: .82rem; font-weight: 700; letter-spacing: .04em; }
input, select, textarea { width: 100%; color: var(--ink); background: var(--deep); border: 1px solid var(--line); border-radius: var(--radius); outline: 0; }
input, select { min-height: 46px; padding: .7rem .85rem; }
textarea { padding: .85rem; resize: vertical; line-height: 1.55; font-size: .83rem; }
input:focus, select:focus, textarea:focus { border-color: var(--aqua); box-shadow: 0 0 0 2px rgba(88, 213, 201, .18); }
.input-wrap { position: relative; display: block; }
.input-wrap input { padding-left: 2.65rem; }
.input-wrap svg { position: absolute; width: 19px; left: .85rem; top: 13px; fill: none; stroke: var(--muted); stroke-width: 2; z-index: 1; }
.type-filter { position: relative; }
.type-filter > summary { min-height: 46px; display: flex; align-items: center; justify-content: space-between; padding: .7rem .85rem; color: var(--ink); background: var(--deep); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; list-style: none; }
.type-filter > summary::-webkit-details-marker { display: none; }
.type-filter > summary::after { content: "+"; color: var(--aqua); font-size: 1.1rem; }
.type-filter[open] > summary { border-color: var(--aqua); box-shadow: 0 0 0 2px rgba(88, 213, 201, .18); }
.type-filter[open] > summary::after { content: "−"; }
.type-filter-options { position: absolute; z-index: 10; top: calc(100% + .4rem); left: 0; right: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .25rem; max-height: 290px; overflow: auto; padding: .55rem; background: var(--panel); border: 1px solid var(--aqua); box-shadow: 6px 6px 0 var(--shadow); }
.type-filter-options label { display: flex; align-items: center; gap: .5rem; min-height: 38px; padding: .4rem .5rem; color: var(--ink); cursor: pointer; }
.type-filter-options label:hover { background: var(--panel-2); }
.type-filter-options input { width: 17px; min-height: 17px; margin: 0; accent-color: var(--yellow); }

.button { min-height: 42px; border: 1px solid transparent; border-radius: var(--radius); padding: .65rem 1rem; font-weight: 800; font-size: .82rem; color: var(--ink); background: transparent; }
.button:hover { filter: brightness(1.13); }
.button:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
.button:disabled { opacity: .35; cursor: not-allowed; }
.button-primary { background: var(--yellow); color: #172023; border-color: #fff1a7; box-shadow: 3px 3px 0 #896c1c; }
.button-secondary { background: var(--aqua); color: #072126; border-color: #a4fff1; }
.button-quiet { border-color: var(--line); background: var(--panel-2); }
.button-danger { color: #ff9b92; border-color: #713b3a; }

.filter-workbench { border-top: 1px solid var(--line); }
.filter-workbench summary { padding: .85rem clamp(1rem, 2.5vw, 2rem); cursor: pointer; color: var(--aqua); font-weight: 700; list-style-position: inside; }
.filter-workbench summary span { color: var(--muted); font-size: .75rem; margin-left: .5rem; font-weight: 400; }
.workbench-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 1.5rem; padding: .5rem clamp(1rem, 2.5vw, 2rem) 1.5rem; }
.editor-block, .saved-block { min-width: 0; }
.editor-actions { display: flex; align-items: center; gap: .8rem; margin-top: .75rem; }
.field-error { color: #ff9b92; font-size: .8rem; margin: 0; }
.saved-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.saved-block > p { color: var(--muted); font-size: .76rem; margin: 1rem 0 0; }

.results { padding-top: clamp(2rem, 4vw, 3.5rem); }
.results-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 1.25rem; }
.results-heading h2 { letter-spacing: -.04em; }
.results-heading h2 span { color: var(--yellow); }
.results-heading p { color: var(--muted); margin: 0; font-size: .82rem; }
.pokemon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem; }
.pokemon-card { position: relative; min-height: 246px; overflow: hidden; background: linear-gradient(145deg, var(--panel-2), var(--panel)); border: 1px solid var(--line); box-shadow: 5px 5px 0 var(--shadow); padding: 1rem; transition: transform 140ms ease, border-color 140ms ease; }
.pokemon-card:hover { transform: translateY(-3px); border-color: var(--aqua); }
.pokemon-card::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(transparent 50%, rgba(0,0,0,.05) 50%) 0 0 / 100% 4px; }
.card-top { display: flex; justify-content: space-between; color: var(--muted); font-size: .74rem; }
.caught-dot { width: 8px; height: 8px; margin-top: .25rem; background: var(--aqua); border-radius: 50%; }
.sprite-stage { height: 140px; display: grid; place-items: center; background: radial-gradient(circle, rgba(88,213,201,.16), transparent 66%); }
.sprite-stage img { width: 132px; height: 132px; image-rendering: pixelated; filter: drop-shadow(6px 8px 0 rgba(0,0,0,.25)); }
.pokemon-card h3 { margin: .2rem 0 .65rem; font-size: 1rem; text-transform: capitalize; letter-spacing: .02em; }
.types { display: flex; gap: .45rem; flex-wrap: wrap; }
.type-pill { --type-color: var(--aqua); color: var(--type-color); border: 1px solid color-mix(in srgb, var(--type-color) 55%, #183438); background: color-mix(in srgb, var(--type-color) 10%, transparent); padding: .18rem .5rem; font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; }

.state-panel { min-height: 310px; border: 1px dashed var(--line); display: grid; place-items: center; align-content: center; text-align: center; padding: 2rem; color: var(--muted); }
.state-panel h3 { color: var(--ink); margin: 1rem 0 .25rem; }
.state-panel p { margin: 0 0 1rem; max-width: 34rem; }
.state-icon { width: 56px; height: 56px; display: grid; place-items: center; border: 2px solid var(--aqua); border-radius: 50%; color: var(--yellow); font-size: 1.5rem; font-weight: 900; }
.scanline-orb { width: 56px; height: 56px; border: 5px solid var(--line); border-top-color: var(--yellow); border-radius: 50%; animation: spin 1s steps(8) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

footer { min-height: 70px; display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .7rem; letter-spacing: .08em; }

dialog { width: min(440px, calc(100% - 2rem)); color: var(--ink); background: var(--panel); border: 1px solid var(--aqua); border-radius: var(--radius); box-shadow: 10px 10px 0 var(--shadow); padding: 0; }
dialog::backdrop { background: rgba(1, 12, 14, .78); }
dialog form { padding: 1.5rem; }
dialog h2 { margin-bottom: 1.25rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.25rem; }

[hidden] { display: none !important; }

@media (max-width: 760px) {
  .topbar { min-height: 90px; }
  .topbar .button { padding-inline: .7rem; }
  .brand-mark { width: 42px; height: 42px; }
  .brand .eyebrow { display: none; }
  .quick-filter { grid-template-columns: 1fr; }
  .quick-filter .button { width: 100%; }
  .workbench-grid { grid-template-columns: 1fr; }
  .controls-heading, .results-heading { align-items: flex-start; flex-direction: column; }
  .source-status { text-align: left; }
  .pokemon-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
  .pokemon-card { min-height: 210px; padding: .75rem; }
  .sprite-stage { height: 115px; }
  .sprite-stage img { width: 110px; height: 110px; }
}

@media (max-width: 420px) {
  .pokemon-grid { grid-template-columns: 1fr; }
  .brand h1 { font-size: 1.3rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
