/* ==========================================================================
   8-BIT ORCHARD — retro pixel theme
   Palette is deliberately small and NES-ish. No rounded corners, no smoothing.
   ========================================================================== */

/* Dark is the default. Backgrounds are true black / white; the small accent
   palette is shared, with a few hues nudged for contrast in light mode. */
/* Neutral grayscale chrome so the pixel-art apples carry all the colour.
   Accent hues (green/red/yellow/pink/cyan) are reserved for functional bits
   like stat pips and the logo. */
:root,
:root[data-theme="dark"] {
  --bg:        #000000;
  --bg-2:      #141414;
  --panel:     #1c1c1c;
  --panel-hi:  #292929;
  --ink:       #f4f3f0;
  --muted:     #9a9a9a;
  --line:      #3a3a3a;
  --green:     #7bc74d;
  --green-dk:  #4f8a2f;
  --red:       #e43b44;
  --yellow:    #ffd93b;
  --pink:      #f0728f;
  --cyan:      #63d6d0;
  --shadow:    4px 4px 0 var(--line);
}

:root[data-theme="light"] {
  --bg:        #ffffff;
  --bg-2:      #f0f0f0;
  --panel:     #f6f6f6;
  --panel-hi:  #e7e7e7;
  --ink:       #1a1a1a;
  --muted:     #6b6b6b;
  --line:      #1c1c1c;
  --green:     #3f7a24;
  --green-dk:  #2f5d1a;
  --red:       #d62b34;
  --yellow:    #c98a00;
  --pink:      #cf3f6a;
  --cyan:      #167f7a;
  --shadow:    4px 4px 0 var(--line);
}

* { box-sizing: border-box; }

html { image-rendering: pixelated; }

.hidden { display: none !important; }

body {
  margin: 0;
  padding: 0 16px 64px;
  background: var(--bg);
  color: var(--ink);
  font-family: 'VT323', monospace;
  font-size: 20px;
  line-height: 1.35;
  min-height: 100vh;
  -webkit-font-smoothing: none;
}

/* Subtle CRT scanlines over everything */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.16) 0,
    rgba(0, 0, 0, 0.16) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: multiply;
}

.pixel-font { font-family: 'Press Start 2P', monospace; }

/* ---- Hero ---------------------------------------------------------------- */
.hero { text-align: center; padding: 28px 0 8px; position: relative; }

.corner-btn {
  position: absolute;
  top: 20px;
  font-size: 18px;
  line-height: 1;
  width: 44px;
  height: 44px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 3px 3px 0 var(--line);
  cursor: pointer;
}
.corner-btn:hover { background: var(--panel-hi); }
.corner-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--line); }
.theme-toggle { right: 4px; }
.sound-toggle { right: 56px; }

.title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(18px, 4.5vw, 34px);
  margin: 0;
  color: var(--green);
  text-shadow: 3px 3px 0 var(--line), 6px 6px 0 rgba(228, 59, 68, 0.35);
  letter-spacing: 1px;
}

.subtitle { color: var(--muted); margin: 12px 0 0; font-size: 22px; }

/* ---- Controls ------------------------------------------------------------ */
.controls {
  max-width: 1180px;
  margin: 20px auto 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search {
  width: 100%;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  padding: 14px 16px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: var(--shadow);
  outline: none;
}
.search::placeholder { color: var(--muted); }
.search:focus { border-color: var(--green); }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.filter-group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.right-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
#random.chip { background: var(--panel-hi); color: var(--yellow); }
#random.chip:hover { background: var(--green); color: var(--line); }

.fave-chip { color: var(--yellow); }
.fave-chip.active { background: var(--yellow); color: var(--line); border-color: var(--line); }
.tried-chip { color: var(--green); }
.tried-chip.active { background: var(--green); color: var(--line); border-color: var(--green-dk); }

.chip {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--line);
  cursor: pointer;
  text-transform: uppercase;
  box-shadow: 3px 3px 0 var(--line);
  transition: transform 0.05s;
}
.chip:hover { background: var(--panel-hi); }
.chip:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--line); }
.chip.active { background: var(--green); color: var(--line); border-color: var(--green-dk); }

.sort-wrap {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sort {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 8px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--line);
  cursor: pointer;
}

.count {
  max-width: 1180px;
  margin: 16px auto 0;
  color: var(--muted);
  font-size: 20px;
  text-align: center;
}

/* ---- Grid ---------------------------------------------------------------- */
.grid {
  max-width: 1180px;
  margin: 12px auto 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 18px;
}
@media (max-width: 1120px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 880px)  { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 620px)  { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.card {
  position: relative;
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: var(--shadow);
  padding: 14px 12px 12px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s;
}

.star {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  z-index: 2;
}
.star:hover { color: var(--yellow); }
.star.on { color: var(--yellow); }

.tried {
  position: absolute;
  top: 8px;
  right: 36px;
  font-size: 17px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  z-index: 2;
}
.tried:hover { color: var(--green); }
.tried.on { color: var(--green); }

.cmp {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 17px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  z-index: 2;
}
.cmp:hover { color: var(--cyan); }
.cmp.on { color: var(--cyan); text-shadow: 0 0 0 var(--cyan); }
.card .cmp.on::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 2px solid var(--cyan);
}
.card:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--line); background: var(--panel-hi); }
.card:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--line); }

.card canvas.sprite { width: 112px; height: 112px; image-rendering: pixelated; }

.card-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  margin: 10px 0 7px;
  color: var(--ink);
  line-height: 1.5;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-origin { color: var(--muted); font-size: 19px; }

.flag {
  height: 16px;
  width: auto;
  image-rendering: pixelated;
  border: 2px solid var(--line);
  vertical-align: -3px;
  margin-right: 2px;
}

.card-tags { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }

.tag {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 5px 6px;
  background: var(--bg-2);
  border: 2px solid var(--line);
  color: var(--cyan);
  text-transform: uppercase;
}

/* ---- Stat meters --------------------------------------------------------- */
.meter { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.meter-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  width: 74px;
  text-align: left;
  color: var(--muted);
}
.pips { display: flex; gap: 3px; }
.pip { width: 14px; height: 14px; border: 2px solid var(--line); background: var(--bg-2); }
.pip.on-sweet { background: var(--pink); }
.pip.on-tart  { background: var(--green); }
.pip.on-crisp { background: var(--yellow); }

/* ---- Modal --------------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(9, 7, 14, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.modal.hidden { display: none; }

.modal-card {
  position: relative;
  background: var(--panel);
  border: 4px solid var(--line);
  box-shadow: 8px 8px 0 var(--line);
  max-width: 520px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px 22px;
}

.modal-close {
  position: absolute;
  top: 10px; right: 10px;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: var(--ink);
  background: var(--red);
  border: 3px solid var(--line);
  width: 34px; height: 34px;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--line);
}
.modal-close:active { transform: translate(2px, 2px); box-shadow: none; }

.modal-head { display: flex; gap: 18px; align-items: center; margin-bottom: 6px; }
.modal-head canvas { width: 120px; height: 120px; image-rendering: pixelated; flex: none; }
.modal-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--green);
  margin: 0 0 8px;
  line-height: 1.5;
}
.modal-aka { color: var(--muted); font-size: 18px; }

.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.modal-star, .modal-cmp, .modal-tried {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 7px 9px;
  background: var(--bg-2);
  border: 3px solid var(--line);
  box-shadow: 2px 2px 0 var(--line);
  cursor: pointer;
}
.modal-star { color: var(--yellow); }
.modal-star.on { background: var(--yellow); color: var(--line); }
.modal-cmp { color: var(--cyan); }
.modal-cmp.on { background: var(--cyan); color: var(--line); }
.modal-tried { color: var(--green); }
.modal-tried.on { background: var(--green); color: var(--line); }
.modal-star:active, .modal-cmp:active, .modal-tried:active { transform: translate(2px, 2px); box-shadow: none; }

.flavor {
  border-left: 4px solid var(--yellow);
  background: var(--bg-2);
  padding: 10px 12px;
  margin: 16px 0;
  font-size: 21px;
  color: var(--ink);
}

.field-row { display: flex; gap: 10px; margin: 8px 0; font-size: 20px; }
.field-key {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--muted);
  width: 96px;
  flex: none;
  padding-top: 3px;
}
.field-val { color: var(--ink); }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.badge {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 5px 7px;
  border: 2px solid var(--line);
  text-transform: uppercase;
}
.badge.use { background: var(--bg-2); color: var(--cyan); }
.badge.season { background: var(--green-dk); color: #f4f1e6; }

.notes { margin-top: 16px; padding-top: 14px; border-top: 3px dashed var(--line); color: var(--muted); font-size: 20px; }

.wiki-link {
  display: inline-block;
  margin-top: 14px;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 8px 10px;
  color: var(--cyan);
  background: var(--bg-2);
  border: 3px solid var(--line);
  box-shadow: 2px 2px 0 var(--line);
  text-decoration: none;
}
.wiki-link:hover { background: var(--panel-hi); color: var(--ink); }
.wiki-link:active { transform: translate(2px, 2px); box-shadow: none; }

.stats-block { margin: 14px 0; }

/* ---- Compare tray -------------------------------------------------------- */
.compare-tray {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 94vw;
  padding: 10px 12px;
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 5px 5px 0 var(--line);
}
.tray-label { font-family: 'Press Start 2P', monospace; font-size: 9px; color: var(--muted); }
.tray-chip {
  font-family: 'VT323', monospace;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  color: var(--ink);
  background: var(--bg-2);
  border: 2px solid var(--line);
  cursor: pointer;
}
.tray-chip:hover { background: var(--panel-hi); }
.tray-sprite { width: 26px; height: 26px; image-rendering: pixelated; }
.tray-go {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  padding: 8px 12px;
  color: var(--line);
  background: var(--green);
  border: 3px solid var(--green-dk);
  box-shadow: 2px 2px 0 var(--line);
  cursor: pointer;
}
.tray-go:active { transform: translate(2px, 2px); box-shadow: none; }
.tray-hint { font-family: 'Press Start 2P', monospace; font-size: 8px; color: var(--muted); }
.tray-clear {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 8px 10px;
  color: var(--muted);
  background: var(--panel-hi);
  border: 2px solid var(--line);
  cursor: pointer;
}

/* ---- Compare modal ------------------------------------------------------- */
.compare-heads { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; text-align: center; }
.compare-head { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.compare-sprite { width: 84px; height: 84px; image-rendering: pixelated; }
.compare-name { font-family: 'Press Start 2P', monospace; font-size: 11px; color: var(--green); line-height: 1.4; }
.compare-origin { color: var(--muted); font-size: 17px; }
.compare-season {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 4px 6px;
  background: var(--green-dk);
  color: #f4f1e6;
  border: 2px solid var(--line);
}
.compare-stats { margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.compare-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 14px; }
.compare-stat-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--muted);
  text-align: center;
  min-width: 56px;
}
.compare-pips.right { justify-content: flex-end; }
.compare-pips.left { justify-content: flex-start; }

/* ---- Back-to-top FAB ----------------------------------------------------- */
.to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 800;
  width: 46px;
  height: 46px;
  font-size: 16px;
  color: var(--line);
  background: var(--green);
  border: 3px solid var(--line);
  box-shadow: 3px 3px 0 var(--line);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.to-top.show { opacity: 1; pointer-events: auto; }
.to-top:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--line); }

/* ---- Footer -------------------------------------------------------------- */
.foot {
  max-width: 1180px;
  margin: 40px auto 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 16px;
  border-top: 3px solid var(--line);
  padding-top: 14px;
}
.foot code { color: var(--green); }
.foot-link { color: var(--green); text-decoration: none; }
.foot-link:hover { text-decoration: underline; }

.empty { text-align: center; color: var(--muted); grid-column: 1 / -1; padding: 40px 0; font-size: 22px; }

/* ==========================================================================
   Mobile (<=560px) — placed last so these overrides win over the base rules
   above on equal specificity. Scale cards, modals, and the compare view down
   so nothing is cramped; sprite sizes keep integer ratios of their source
   canvas (112 / 128 / 96 px) to stay crisp.
   ========================================================================== */
@media (max-width: 560px) {
  /* Header */
  .hero { padding-top: 62px; }
  .corner-btn { top: 10px; width: 40px; height: 40px; font-size: 16px; }
  .theme-toggle { right: 8px; }
  .sound-toggle { right: 52px; }
  .subtitle { font-size: 18px; }

  /* Cards */
  .grid { gap: 12px; }
  .card { padding: 10px 8px; }
  .card canvas.sprite { width: 80px; height: 80px; }
  .card-name { font-size: 9px; min-height: 0; margin: 8px 0 5px; }
  .card-origin { font-size: 16px; }
  .card .card-tags { display: none; }  /* still shown in the detail modal */
  .star, .tried, .cmp { font-size: 15px; }
  .tried { right: 30px; }

  /* Detail modal */
  .modal { padding: 10px; }
  .modal-card { padding: 16px 14px; }
  .modal-close { width: 30px; height: 30px; font-size: 11px; }
  .modal-head { gap: 12px; }
  .modal-head canvas { width: 80px; height: 80px; }
  .modal-name { font-size: 12px; }
  .modal-aka { font-size: 16px; }
  .flavor { font-size: 18px; padding: 8px 10px; }
  .field-key { width: 74px; font-size: 8px; }
  .field-val { font-size: 17px; }
  .notes { font-size: 17px; }
  .meter-label { width: 62px; }
  .pip { width: 12px; height: 12px; }

  /* Compare view */
  .compare-heads { gap: 8px; }
  .compare-sprite { width: 64px; height: 64px; }
  .compare-name { font-size: 9px; }
  .compare-origin { font-size: 15px; }
  .compare-row { gap: 8px; }
  .compare-stat-label { min-width: 44px; font-size: 8px; }
}
