/* PokiPod — System 7 / MacPaint inspired 1-bit interface
   v3 — three reorderable collapsible panels, no menu bar, floating theme switch */

:root {
  --paper: #ffffff;
  --ink:   #000000;
  --border: 1px solid var(--ink);

  --titlebar-h: 32px;
  --rail-w: 40px;            /* width of a collapsed panel rail on desktop */
  --gap: 6px;

  --main-font:   "PixelOperator", system-ui, sans-serif;
  --chrome-font: var(--main-font);
  --body-font:   var(--main-font);
  --mono-font:   var(--main-font);
  --title-font:  var(--main-font);

  /* Pokémon type colors — used ONLY on type chips */
  --t-normal:   #A8A77A;
  --t-fire:     #EE8130;
  --t-water:    #6390F0;
  --t-electric: #F7D02C;
  --t-grass:    #7AC74C;
  --t-ice:      #96D9D6;
  --t-fighting: #C22E28;
  --t-poison:   #A33EA1;
  --t-ground:   #E2BF65;
  --t-flying:   #A98FF3;
  --t-psychic:  #F95587;
  --t-bug:      #A6B91A;
  --t-rock:     #B6A136;
  --t-ghost:    #735797;
  --t-dragon:   #6F35FC;
  --t-dark:     #705746;
  --t-steel:    #B7B7CE;
  --t-fairy:    #D685AD;
}
html[data-theme="dark"] {
  --paper: #000000;
  --ink:   #ffffff;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body-font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: none;
  font-smooth: never;
  image-rendering: pixelated;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

/* Workspace backdrop: fine 1px checker — reads almost gray */
body {
  background-color: var(--paper);
  background-image:
    linear-gradient(45deg, var(--ink) 25%, transparent 25%),
    linear-gradient(-45deg, var(--ink) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--ink) 75%),
    linear-gradient(-45deg, transparent 75%, var(--ink) 75%);
  background-size: 2px 2px;
  background-position: 0 0, 0 1px, 1px -1px, -1px 0;
}

#root {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Workspace + watermark
   ========================================================================== */
.workspace {
  flex: 1 1 auto;
  display: flex;
  flex-direction: row;
  padding: var(--gap);
  gap: var(--gap);
  min-height: 0;
  min-width: 0;
  position: relative;
  width: 100%;
}

/* Empty-state watermark — visible when the user collapses every panel.
   Sits behind the panels in the center of the workspace. */
.watermark {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  pointer-events: none;
  z-index: 0;
  color: var(--ink);
  user-select: none;
}
.watermark-logo {
  width: 400px;
  height: 400px;
  image-rendering: pixelated;
}
.watermark-msg {
  font-family: var(--chrome-font);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  max-width: 280px;
  line-height: 1.5;
}

/* ==========================================================================
   Panel shell — column with title-bar, body, optional toolbar
   ========================================================================== */
.panel {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;            /* above watermark */
  background: var(--paper);
  border: 3px solid var(--ink);
  transition: flex-basis 160ms ease;
  overflow: hidden;
}
.panel-body { background: var(--paper); }
.results-scroll { background: var(--paper); }
.details-body { background: var(--paper); }
/* Per-panel default widths on desktop — Search wider, Details medium, Sprite biggest */
.panel-search:not(.is-collapsed)   { flex: 1 1 0; }
.panel-details:not(.is-collapsed)  { flex: 0.7 1 0; }
.panel-sprite:not(.is-collapsed)   { flex: 1.2 1 0; }

.panel.is-collapsed,
.panel.panel-search.is-collapsed,
.panel.panel-details.is-collapsed,
.panel.panel-sprite.is-collapsed {
  flex: 0 0 var(--rail-w);
  flex-basis: var(--rail-w);
  flex-grow: 0;
}
.panel.is-dragging {
  opacity: 0.65;
}
/* Insertion-line indicators for drag reorder — a 4px line with padding */
.panel.is-drop-before::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: calc(-1 * var(--gap) - 1px);
  width: 4px;
  background: var(--ink);
  z-index: 10;
  pointer-events: none;
}
.panel.is-drop-after::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  right: calc(-1 * var(--gap) - 1px);
  width: 4px;
  background: var(--ink);
  z-index: 10;
  pointer-events: none;
}

/* ===== Title bar ===== */
.panel-title {
  flex: 0 0 var(--titlebar-h);
  height: var(--titlebar-h);
  border-bottom: var(--border);
  display: flex;
  align-items: stretch;
  position: relative;
  font-family: var(--chrome-font);
  font-weight: 700;
  font-size: 16px;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='6' height='6' shape-rendering='crispEdges'><rect x='0' y='0' width='6' height='1' fill='black'/><rect x='0' y='3' width='6' height='1' fill='black'/></svg>");
  background-size: 6px 6px;
  user-select: none;
  cursor: grab;
}
html[data-theme="dark"] .panel-title {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='6' height='6' shape-rendering='crispEdges'><rect x='0' y='0' width='6' height='1' fill='white'/><rect x='0' y='3' width='6' height='1' fill='white'/></svg>");
}
.panel-title:active { cursor: grabbing; }
.panel-title-text {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--paper);
  padding: 0 10px;
  white-space: nowrap;
  max-width: calc(100% - 60px);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  letter-spacing: 0.02em;
}
.panel-title-btn {
  width: 20px; height: 20px;
  border: 2px solid var(--ink);
  background: var(--paper);
  margin: 5px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--chrome-font);
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
  color: var(--ink);
}
@media (hover: hover) {
  .panel-title-btn:hover { background: var(--ink); color: var(--paper); }
}
.panel-title-btn:active { transform: translate(1px, 1px); }
.panel-title-btn-left { margin-right: auto; }
.panel-title-btn-right { margin-left: auto; }

/* When a panel is collapsed: rotate the entire title bar to read sideways
   and stretch it to the full panel height. */
.panel.is-collapsed .panel-title {
  flex: 1 1 auto;
  height: 100%;
  border-bottom: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  padding: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='6' height='6' shape-rendering='crispEdges'><rect x='0' y='0' width='1' height='6' fill='black'/><rect x='3' y='0' width='1' height='6' fill='black'/></svg>");
  background-size: 6px 6px;
}
html[data-theme="dark"] .panel.is-collapsed .panel-title {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='6' height='6' shape-rendering='crispEdges'><rect x='0' y='0' width='1' height='6' fill='white'/><rect x='3' y='0' width='1' height='6' fill='white'/></svg>");
}
.panel.is-collapsed .panel-title-text {
  position: static;
  writing-mode: vertical-rl;
  -webkit-writing-mode: vertical-rl;
  text-orientation: mixed;
  background: var(--paper);
  padding: 8px 0;
  margin: auto;
  letter-spacing: 0.08em;
  text-transform: none;
  font-size: 16px;
  white-space: nowrap;
  flex: 0 0 auto;
  pointer-events: none;
  width: auto;
  max-width: none;
  overflow: visible;
  transform: rotate(180deg);
}
.panel.is-collapsed .panel-title-btn {
  margin: 5px auto;
  background: var(--ink);
  color: var(--paper);
}
@media (hover: hover) {
  .panel.is-collapsed .panel-title-btn:hover {
    background: var(--paper);
    color: var(--ink);
  }
}

/* ===== Body + toolbars ===== */
.panel-body {
  flex: 1 1 auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel.is-collapsed .panel-body { display: none; }

.panel-toolbar {
  flex: 0 0 auto;
  border-bottom: var(--border);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--paper);
}
.panel-toolbar-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ==========================================================================
   Mobile: stack panels as accordion. No rotation; collapsed = body hidden.
   ========================================================================== */
.details-columns {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.details-col-left {
  flex: 0.8 1 0;
  min-width: 0;
}
.details-col-right {
  flex: 1.2 1 0;
  min-width: 0;
}

@media (max-width: 1000px) {
  .workspace {
    flex-direction: column;
    padding: 4px;
    gap: 4px;
    overflow-y: auto;
  }
  .panel,
  .panel-search,
  .panel-details,
  .panel-sprite {
    flex: 0 0 auto;
    flex-basis: auto;
    width: 100%;
  }
  /* Sprite on top, search on bottom, details hidden by default */
  .panel-sprite { order: -1; }
  .panel-search { order: 1; }
  .panel-details { order: 0; }
  /* Equal space for open panels */
  .panel:not(.is-collapsed) { min-height: 0; max-height: 70vh; flex: 1 1 auto; overflow: hidden !important; }
  /* When only one panel is open, let it fill everything */
  .panel-search:not(.is-collapsed) { flex: 1 1 auto !important; min-height: 0 !important; }
  .panel-sprite:not(.is-collapsed) { min-height: 360px !important; }
  .has-solo-panel .panel:not(.is-collapsed) { max-height: none !important; flex: 1 1 0 !important; }
  .panel-details:not(.is-collapsed) {
    max-height: none !important;
    overflow: visible !important;
    flex: 0 0 auto !important;
    height: auto !important;
  }
  .panel-details .panel-body { overflow: visible !important; }
  .panel-details .details-body { overflow: visible !important; }
  .panel-sprite:not(.is-collapsed) .panel-body {
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }
  .panel-sprite .sprite-stage {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }
  .panel-sprite .sprite-toolbar {
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
  }
  .panel.is-collapsed {
    flex: 0 0 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    height: 36px !important;
    overflow: hidden !important;
  }
  .panel.is-collapsed .panel-title {
    flex: 0 0 var(--titlebar-h) !important;
    height: 100% !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-start !important;
    border-bottom: none;
    padding: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='6' height='6' shape-rendering='crispEdges'><rect x='0' y='0' width='6' height='1' fill='black'/><rect x='0' y='3' width='6' height='1' fill='black'/></svg>") !important;
    background-size: 6px 6px;
  }
  html[data-theme="dark"] .panel.is-collapsed .panel-title {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='6' height='6' shape-rendering='crispEdges'><rect x='0' y='0' width='6' height='1' fill='white'/><rect x='0' y='3' width='6' height='1' fill='white'/></svg>") !important;
  }
  .panel.is-collapsed .panel-title-text {
    position: absolute !important;
    left: 50% !important; top: 50% !important;
    transform: translate(-50%, -50%) !important;
    writing-mode: horizontal-tb !important;
    text-orientation: initial !important;
    text-transform: none !important;
    letter-spacing: 0.02em;
    flex: none !important;
    background: var(--paper);
    padding: 0 10px;
    white-space: nowrap;
    max-width: calc(100% - 60px);
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0 !important;
  }
  .panel.is-collapsed .panel-title-btn {
    margin: 5px;
    background: var(--ink) !important;
    color: var(--paper) !important;
  }
  .watermark { display: none; }

  /* Mobile font overrides moved to end of file for cascade priority */

  /* Details panel — tighter layout, vitals + stats side by side */
  .details-body {
    gap: 4px !important;
    padding: 0 12px 10px !important;
  }
  .details-section-title {
    margin-top: 6px;
    margin-bottom: 4px;
  }
  .kv-grid {
    row-gap: 2px;
    column-gap: 2px;
  }
  .statbar-row {
    grid-template-columns: 50px 22px 1fr !important;
    gap: 2px !important;
    margin-bottom: 1px !important;
  }
  .details-columns {
    display: flex;
    flex-direction: row;
    gap: 8px;
  }
  .details-col-left,
  .details-col-right {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
  }
}

/* ==========================================================================
   Form controls
   ========================================================================== */
.field {
  font-family: var(--mono-font);
  font-size: 16px;
  background: var(--paper);
  color: var(--ink);
  border: var(--border);
  padding: 2px 8px;
  outline: none;
  width: 100%;
  height: 26px;
}
.field::placeholder { color: var(--ink); opacity: 1; }
.field:focus { outline: 3px solid var(--ink); outline-offset: -3px; box-shadow: none; }

.select {
  font-family: var(--chrome-font);
  font-size: 16px;
  background: var(--paper);
  color: var(--ink);
  border: var(--border);
  padding: 4px 22px 4px 8px;
  height: 32px;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink) 50%),
    linear-gradient(-45deg, transparent 50%, var(--ink) 50%);
  background-position:
    calc(100% - 12px) 11px,
    calc(100% - 7px) 11px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
  text-transform: capitalize;
}
.select:focus { outline: 3px solid var(--ink); outline-offset: -3px; box-shadow: none; }

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.field-label {
  font-family: var(--chrome-font);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  flex-shrink: 0;
  min-width: 80px;
}
.panel-search .field-label {
  font-size: 16px;
}
.panel-search .panel-toolbar .field {
  width: 100%;
}
.panel-search .panel-toolbar .field-row .pixel-select {
  flex: 1 1 0;
  width: auto;
}

/* ==========================================================================
   Custom pixel dropdown (PixelSelect)
   ========================================================================== */
.pixel-select {
  position: relative;
  font-family: var(--chrome-font);
  font-size: 16px;
  font-weight: 400;
  background: var(--paper);
  color: var(--ink);
  border: var(--border);
  padding: 2px 26px 2px 8px;
  height: 26px;
  width: 100%;
  cursor: pointer;
  text-transform: capitalize;
  display: flex;
  align-items: center;
  user-select: none;
  outline: none;
}
.pixel-select:focus { outline: 3px solid var(--ink); outline-offset: -3px; }
.pixel-select-value {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pixel-select-arrow {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
}
.pixel-select-menu {
  z-index: 10000;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-top: none;
  max-height: min(240px, 40vh);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--ink) var(--paper);
}
.pixel-select-option {
  padding: 3px 8px;
  cursor: pointer;
  font-family: var(--chrome-font);
  font-size: 16px;
  font-weight: 400;
  text-transform: capitalize;
  border-bottom: 1px solid var(--ink);
}
.pixel-select-option:last-child { border-bottom: none; }
.pixel-select-option:hover {
  outline: 3px solid var(--ink);
  outline-offset: -3px;
  z-index: 1;
  position: relative;
}
.pixel-select-option.is-selected {
  background: var(--ink);
  color: var(--paper);
}

/* Buttons */
.btn {
  font-family: var(--chrome-font);
  font-size: 16px;
  background: var(--paper);
  color: var(--ink);
  border: var(--border);
  padding: 4px 12px;
  cursor: pointer;
  min-height: 26px;
  white-space: nowrap;
  user-select: none;
  box-shadow: 1px 1px 0 0 var(--ink);
}
.btn:hover { box-shadow: 1px 1px 0 0 var(--ink), inset 0 0 0 1px var(--ink); }
.btn:active,
.btn[aria-pressed="true"],
.btn.is-active {
  background: var(--ink);
  color: var(--paper);
  box-shadow: none;
  transform: translate(1px, 1px);
}
.btn[disabled] {
  pointer-events: none;
  opacity: 0.45;
}

/* Toggle row (segmented) — shared with sprite controls */
.toggle-row {
  display: inline-flex;
  border: var(--border);
  background: var(--paper);
  height: 30px;
}
.toggle-row > button {
  font-family: "Dogica", system-ui, sans-serif;
  font-weight: 700;
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: none;
  background: var(--paper);
  color: var(--ink);
  border: none;
  border-right: var(--border);
  padding: 0 12px;
  cursor: pointer;
  letter-spacing: 0.04em;
}
.toggle-row > button:last-child { border-right: none; }
.toggle-row > button.is-active {
  background: var(--ink);
  color: var(--paper);
}
.toggle-row > button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ==========================================================================
   Search panel
   ========================================================================== */
.search-summary {
  flex: 0 0 auto;
  padding: 10px 10px 8px;
  border-bottom: var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--chrome-font);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.search-summary .label-results { flex-shrink: 0; }
.search-summary .count {
  font-family: var(--mono-font);
  font-size: 16px;
  letter-spacing: 0;
  text-transform: none;
}
.search-toolbar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: var(--border);
  padding-bottom: 4px;
  margin-bottom: 4px;
}
.search-reset-btn {
  font-family: "Dogica", system-ui, sans-serif;
  font-weight: 700;
  font-size: 6px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--paper);
  color: var(--ink);
  border: var(--border);
  padding: 4px 7px;
  line-height: 1.6;
  cursor: pointer;
  margin-left: 6px;
  white-space: nowrap;
}
.search-reset-btn:hover {
  background: var(--ink);
  color: var(--paper);
}
.search-summary .sort-row {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.results-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
}

.gen-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--chrome-font);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-top: var(--border);
  border-bottom: var(--border);
  display: flex;
  justify-content: space-between;
}
.gen-header:first-child { border-top: none; }

/* Outline-based hover/selected indicator — outline doesn't affect layout, so
   rows sit tight against each other with no gap between dividers. */
.list-row {
  display: grid;
  grid-template-columns: 64px 46px 1fr auto;
  align-items: center;
  gap: 3px;
  padding: 10px 10px;
  cursor: default;
  font-family: var(--body-font);
  font-size: 16px;
  position: relative;
  background: var(--paper);
  border-bottom: 1px solid var(--ink);
  outline: 2px solid transparent;
  outline-offset: -1px;
  z-index: 0;
}
.list-row:hover {
  outline-color: var(--ink);
  z-index: 2;
}
.list-row.is-selected {
  background: var(--ink);
  color: var(--paper);
  outline-color: var(--ink);
  z-index: 1;
}
.list-row.is-selected:hover { background: var(--ink); color: var(--paper); }
.list-row .num {
  font-family: var(--chrome-font);
  font-size: 16px;
  letter-spacing: 0.02em;
}
.list-row .name {
  font-family: var(--chrome-font);
  font-size: 16px;
  font-weight: 700;
  text-transform: capitalize;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-row .types {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  margin-right: 4px;
}
.list-row .sprite-thumb {
  width: 54px; height: 54px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  margin-right: 14px;
}
.list-row .sprite-thumb img {
  max-width: 54px;
  max-height: 54px;
  width: auto;
  height: auto;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ==========================================================================
   Type chip — uses Pokémon type colors. Always solid, never dithered.
   ========================================================================== */
.chip {
  display: inline-block;
  font-family: "Dogica", system-ui, sans-serif;
  font-weight: 700;
  font-size: 6px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 7px;
  border: var(--border);
  background: var(--paper);
  color: var(--ink);
  border-radius: 2px;
  corner-shape: notch;
  white-space: nowrap;
  line-height: 1.6;
}
.chip[data-type="normal"]   { background: var(--t-normal);   color: #000; }
.chip[data-type="fire"]     { background: var(--t-fire);     color: #fff; }
.chip[data-type="water"]    { background: var(--t-water);    color: #fff; }
.chip[data-type="electric"] { background: var(--t-electric); color: #000; }
.chip[data-type="grass"]    { background: var(--t-grass);    color: #000; }
.chip[data-type="ice"]      { background: var(--t-ice);      color: #000; }
.chip[data-type="fighting"] { background: var(--t-fighting); color: #fff; }
.chip[data-type="poison"]   { background: var(--t-poison);   color: #fff; }
.chip[data-type="ground"]   { background: var(--t-ground);   color: #000; }
.chip[data-type="flying"]   { background: var(--t-flying);   color: #000; }
.chip[data-type="psychic"]  { background: var(--t-psychic);  color: #fff; }
.chip[data-type="bug"]      { background: var(--t-bug);      color: #000; }
.chip[data-type="rock"]     { background: var(--t-rock);     color: #fff; }
.chip[data-type="ghost"]    { background: var(--t-ghost);    color: #fff; }
.chip[data-type="dragon"]   { background: var(--t-dragon);   color: #fff; }
.chip[data-type="dark"]     { background: var(--t-dark);     color: #fff; }
.chip[data-type="steel"]    { background: var(--t-steel);    color: #000; }
.chip[data-type="fairy"]    { background: var(--t-fairy);    color: #000; }

/* When a list row is selected, keep chip type colors visible */
.list-row.is-selected .chip { border-color: var(--paper); }

/* ==========================================================================
   Details panel
   ========================================================================== */
.details-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
/* details-columns: default is column, mobile override switches to row */
.details-section-title {
  font-family: var(--title-font);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: var(--border);
  padding-bottom: 4px;
  margin-top: 10px;
  margin-bottom: 4px;
  line-height: 1;
}
.kv-grid {
  display: grid;
  grid-template-columns: 82px 1fr;
  row-gap: 3px;
  column-gap: 6px;
  font-size: 16px;
  margin: 0;
}
.kv-grid dt {
  font-family: var(--chrome-font);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.kv-grid dd {
  margin: 0;
  font-family: var(--mono-font);
  font-size: 16px;
}

.ability-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: var(--border);
  font-family: var(--body-font);
  font-size: 16px;
  text-transform: capitalize;
}
.ability-row:last-child { border-bottom: none; }
.ability-row .hidden-tag {
  font-family: "Dogica", system-ui, sans-serif;
  font-weight: 700;
  font-size: 6px;
  letter-spacing: 0.08em;
  border: var(--border);
  padding: 4px 7px;
  text-transform: uppercase;
  line-height: 1.6;
  border-radius: 2px;
  corner-shape: notch;
}

.statbar-row {
  display: grid;
  grid-template-columns: 72px 28px 1fr;
  align-items: center;
  gap: 2px;
  margin-bottom: 1px;
}
.statbar-row .label {
  font-family: var(--chrome-font);
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.label-mobile { display: none; }
.label-full { display: inline;
}
.statbar-row .val {
  font-family: var(--mono-font);
  font-size: 16px;
  text-align: right;
}
.statbar-track {
  height: 12px;
  border: var(--border);
  position: relative;
  /* checkerboard pixel pattern on the EMPTY track behind the fill */
  background-color: var(--paper);
  background-image:
    linear-gradient(45deg, var(--ink) 25%, transparent 25%),
    linear-gradient(-45deg, var(--ink) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--ink) 75%),
    linear-gradient(-45deg, transparent 75%, var(--ink) 75%);
  background-size: 2px 2px;
  background-position: 0 0, 0 1px, 1px -1px, -1px 0;
}
.statbar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--ink);
  transition: width 0.15s ease-out;
}

/* ==========================================================================
   Sprite panel — preview window with floating overview header & dex entry
   ========================================================================== */
.sprite-stage {
  flex: 1 1 auto;
  overflow: hidden;
  min-height: 280px;
  padding: 10px;
  background-color: var(--paper);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
}
html[data-theme="dark"] .sprite-stage {
  background-color: var(--paper);
}
html[data-theme="dark"] .sprite-canvas[style*="unknown"] {
  filter: invert(1);
}
/* Sprite area — fills remaining space between header and dex, centers the sprite */
.sprite-area {
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
/* Back view styling reserved for future use */
/* Sprite "preview frame" — fixed-size inset square with corner brackets.
   Header and dex boxes are positioned to OVERLAP this frame at top/bottom. */
.sprite-canvas-wrap {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  overflow: hidden;
  max-width: 100%;
  max-height: 100%;
  /* Drafting-style L-shaped corner brackets via background-images */
  --bracket: 18px;
  background-image:
    /* top-left */
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)),
    /* top-right */
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)),
    /* bottom-left */
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)),
    /* bottom-right */
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink));
  background-size:
    var(--bracket) 1px, 1px var(--bracket),
    var(--bracket) 1px, 1px var(--bracket),
    var(--bracket) 1px, 1px var(--bracket),
    var(--bracket) 1px, 1px var(--bracket);
  background-position:
    top left,    top left,
    top right,   top right,
    bottom left, bottom left,
    bottom right, bottom right;
  background-repeat: no-repeat;
}
.sprite-canvas {
  width: 100%;
  height: 100%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Scanline glitch-in for text */
@keyframes scan-in-lines {
  0% {
    clip-path: inset(0 0 100% 0);
    opacity: 0;
  }
  10% {
    clip-path: inset(0 0 80% 0);
    opacity: 1;
  }
  20% {
    clip-path: inset(0 0 40% 0);
  }
  25% {
    clip-path: inset(30% 0 30% 0);
  }
  35% {
    clip-path: inset(0 0 20% 0);
  }
  50% {
    clip-path: inset(0 0 0 0);
    opacity: 0.6;
  }
  55% {
    clip-path: inset(40% 0 0 0);
    opacity: 1;
  }
  65% {
    clip-path: inset(0 0 0 0);
  }
  75% {
    opacity: 0.7;
  }
  100% {
    clip-path: inset(0 0 0 0);
    opacity: 1;
  }
}
.scan-in {
  display: inline-block;
  animation: scan-in-lines 0.35s steps(6) both;
}

/* Pixel dissolve canvas */
.sprite-canvas-anim {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Overview header inside the sprite stage */
/* Compact mobile header — hidden on desktop */
.sprite-overview-compact {
  display: none;
  font-family: var(--chrome-font);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  background: var(--paper);
  border-bottom: var(--border);
  align-items: center;
  justify-content: space-between;
}
.sprite-overview-compact .compact-left,
.sprite-overview-compact .compact-right {
  flex-shrink: 0;
}
.sprite-overview-compact .compact-center {
  text-transform: capitalize;
  text-align: center;
}
.sprite-overview {
  flex: 0 0 auto;
  background: var(--paper);
  border: 1px solid var(--ink);
  outline: 1px solid var(--ink);
  outline-offset: 3px;
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.sprite-overview-name {
  font-family: var(--title-font);
  font-weight: 700;
  font-size: 36px;
  letter-spacing: 0.01em;
  text-transform: capitalize;
  margin: 0;
  line-height: 0.9;
}
.sprite-overview-num {
  font-family: var(--mono-font);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.sprite-overview-genus {
  font-family: var(--body-font);
  font-style: italic;
  font-size: 16px;
  margin-top: 4px;
}
.sprite-overview-types {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-self: center;
  align-items: flex-end;
}
.sprite-overview-types .chip {
  font-size: 10px;
}

/* Dex entry at bottom of stage */
.sprite-dex {
  flex: 0 0 auto;
  background: var(--paper);
  border: 1px solid var(--ink);
  outline: 1px solid var(--ink);
  outline-offset: 3px;
  padding: 22px 14px 10px;
  font-family: var(--body-font);
  font-size: 16px;
  line-height: 1.5;
  position: relative;
}
.sprite-dex-label {
  position: absolute;
  top: -16px;
  left: 8px;
  background: var(--paper);
  border: var(--border);
  padding: 1px 6px;
  font-family: var(--chrome-font);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sprite-toolbar {
  flex: 0 0 auto;
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  padding: 10px;
  border-top: var(--border);
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  min-height: 50px;
  overflow: visible;
}
.sprite-toolbar-right {
  margin-left: auto;
  display: flex;
  gap: 6px;
  align-items: center;
}
/* Icon buttons in the sprite toolbar (theme toggle, save) */
.toolbar-icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 0;
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}
.toolbar-icon-btn svg {
  width: 18px;
  height: 18px;
  display: block;
  image-rendering: pixelated;
}
.toolbar-icon-btn:active { transform: translate(1px, 1px); }
/* Theme toggle: inverted colors, NO hover state */
.toolbar-icon-btn-light {
  background: #000000;
  color: #ffffff;
  border-color: #000000;
}
.toolbar-icon-btn-dark {
  background: #ffffff;
  color: #000000;
  border-color: #ffffff;
}

/* ==========================================================================
   Floating theme switch — sun/moon icon, anchored bottom-right
   ========================================================================== */
/* Pixelated square button — opposite background of current theme */
.theme-switch {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: 38px;
  height: 38px;
  border-radius: 0;
  border: 2px solid var(--ink);
  cursor: pointer;
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: none;
  image-rendering: pixelated;
}
/* Light mode (white page): dark button, white icon */
.theme-switch-light {
  background: #000000;
  color: #ffffff;
  border-color: #000000;
}
/* Dark mode (black page): light button, black icon */
.theme-switch-dark {
  background: #ffffff;
  color: #000000;
  border-color: #ffffff;
}
.theme-switch:hover { outline: 3px solid var(--ink); outline-offset: 0px; }
.theme-switch:active { transform: translate(1px, 1px); }
.theme-switch svg { width: 20px; height: 20px; display: block; image-rendering: pixelated; }

/* ==========================================================================
   Loader + util
   ========================================================================== */
.loader {
  font-family: var(--chrome-font);
  font-size: 16px;
  text-align: center;
  padding: 40px 20px;
}
.loader::after {
  content: "";
  display: inline-block;
  width: 12px;
  text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

.empty-state {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 24px;
  text-align: center;
  font-family: var(--chrome-font);
  font-size: 16px;
  line-height: 1.6;
  letter-spacing: 0.05em;
}

.txt-cap { text-transform: capitalize; }
.txt-mono { font-family: var(--mono-font); }
.txt-chrome { font-family: var(--chrome-font); }
.divider {
  height: 1px;
  background-image: repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 4px);
  margin: 8px 0;
}

/* Scrollbar — use browser defaults */

/* Dialog */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(45deg, var(--ink) 25%, transparent 25%),
    linear-gradient(-45deg, var(--ink) 25%, transparent 25%);
  background-size: 2px 2px;
  background-color: transparent;
  opacity: 0.65;
  z-index: 5000;
}
.dialog {
  position: fixed;
  z-index: 5001;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--paper);
  border: var(--border);
  box-shadow: 4px 4px 0 0 var(--ink);
  min-width: 320px;
  max-width: 90vw;
}
.dialog-body {
  padding: 16px 18px;
  font-family: var(--body-font);
  font-size: 16px;
  line-height: 1.6;
}
.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 0 18px 14px;
}

/* ==========================================================================
   Mobile font size overrides — MUST be last to win the cascade
   ========================================================================== */
@media (max-width: 1000px) {
  html, body,
  .panel-title, .panel-title-text,
  .field, .select, .pixel-select, .pixel-select-option,
  .field-label, .panel-search .field-label,
  .btn,
  .search-summary, .search-summary .count,
  .list-row, .list-row .num, .list-row .name,
  .kv-grid, .kv-grid dt, .kv-grid dd,
  .ability-row,
  .statbar-row .label, .statbar-row .val,
  .sprite-overview-genus,
  .sprite-dex, .sprite-dex-label,
  .search-toolbar-header,
  .loader, .empty-state, .dialog-body { font-size: 14px !important; }
  .details-section-title { font-size: 16px !important; }
  .sprite-overview-name { font-size: 24px !important; }
  .sprite-overview-num { font-size: 16px !important; }
  .chip { font-size: 6px !important; }
  .label-full { display: none !important; }
  .label-mobile { display: inline !important; }
  .toggle-row > button { font-size: 6px !important; padding: 0 8px !important; }
  .toggle-row { height: 24px !important; }
  .toolbar-icon-btn { width: 24px !important; height: 24px !important; padding: 3px !important; }
  .sprite-toolbar {
    gap: 4px !important;
    padding: 4px 6px !important;
    min-height: 30px !important;
    flex-shrink: 0 !important;
  }
  .sprite-toolbar-right {
    margin-left: auto !important;
    gap: 4px !important;
  }

  /* Compact list rows on mobile */
  .list-row {
    padding: 4px 8px !important;
    gap: 2px !important;
    grid-template-columns: 44px 40px 1fr auto !important;
  }
  .list-row .sprite-thumb {
    width: 40px !important;
    height: 40px !important;
    margin-right: 6px !important;
  }
  .list-row .sprite-thumb img {
    max-width: 40px !important;
    max-height: 40px !important;
  }

  /* Sprite panel mobile: flex column, sprite first, overview below, no dex */
  .sprite-stage {
    display: flex !important;
    flex-direction: column !important;
    grid-template-rows: none !important;
    padding: 0 !important;
    gap: 0 !important;
  }
  .sprite-area {
    order: -1 !important;
    flex: 1 1 auto !important;
    min-height: 80px !important;
  }
  .sprite-overview-full {
    display: none !important;
  }
  .sprite-overview-compact {
    display: flex !important;
    order: -2 !important;
    padding: 3px 8px !important;
  }
  .sprite-dex {
    display: none !important;
  }

  /* Tighter line-height for details */
  .kv-grid {
    grid-template-columns: 66px 1fr !important;
    row-gap: 2px !important;
    column-gap: 2px !important;
    line-height: 1.2 !important;
  }
  .statbar-row {
    margin-bottom: 2px !important;
    line-height: 1.2 !important;
  }
  .ability-row {
    padding: 3px 0 !important;
    line-height: 1.2 !important;
  }
}
