/* ============================== */
/* DESIGN TOKENS */
:root {
  --page-bg: #090909;
  --surface-1: #121212;
  --surface-2: #181818;
  --surface-3: #222222;
  --surface-hover: #2a2a2a;
  --border: #2d2d2d;
  --border-strong: #404040;
  --text: #ededed;
  --text-muted: #a0a0a0;
  --text-dim: #707070;
  --accent: #00e385;
  --accent-strong: #00b86f;
  --accent-dark: #008f55;
  --accent-glow: rgba(0, 227, 133, 0.12);
  --brand: #f0b429;
  --tile: #f2f2f2;
  --tile-border: #d7d7d7;
  --danger: #c34242;
  --danger-strong: #e15454;
  --font-xs: 12px;
  --font-sm: 14px;
  --font-md: 16px;
  --font-lg: 20px;
  --font-xl: 26px;
  --mono: "Atkinson Hyperlegible Mono";
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --icon-size: 18px;
  --icon-size-sm: 16px;
  --space-2: 2px;
  --space-3: 4px;
  --space-4: 6px;
  --space-5: 8px;
  --space-6: 12px;
  --space-7: 16px;
  --space-8: 24px;
  --transition: 160ms ease;
}

/* ============================== */
/* RESET */
*,
*::before,
*::after {
  box-sizing: border-box;
}
* {
  margin: 0;
  padding: 0;
}
[hidden] {
  display: none !important;
}
html {
  min-width: 320px;
  color-scheme: dark;
}
body {
  min-height: 100dvh;
  padding: var(--space-6);
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.035) 1px, transparent 0) 0 0 / 22px 22px,
    var(--page-bg);
  color: var(--text);
  font-family: "Atkinson Hyperlegible Next";
  font-weight: 600;
  font-size: var(--font-md);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
body.detail-open {
  overflow: hidden;
}
button,
input,
select {
  color: inherit;
  font: inherit;
}
button {
  border: 0;
}
a {
  color: var(--accent);
}
img {
  display: block;
  max-width: 100%;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ============================== */
/* LUCIDE ICONS */
.icon {
  display: inline-block;
  width: var(--icon-size);
  height: var(--icon-size);
  flex: 0 0 auto;
  background: currentColor;
  -webkit-mask: var(--icon-mask, none) center / contain no-repeat;
  mask: var(--icon-mask, none) center / contain no-repeat;
}

/* ============================== */
/* APP SHELL */
.app {
  width: min(100%, 1320px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.panel {
  min-width: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.app-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
  overflow: hidden;
  padding: var(--space-7);
}
.app-brand {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: var(--space-7);
  min-width: 0;
}
.app-logo {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
}
.app-copy {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}
.app-copy h1 {
  font-size: var(--font-xl);
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.1;
}
.app-copy p {
  max-width: 68ch;
  color: var(--text-muted);
  font-size: var(--font-sm);
  text-wrap: balance;
}
.app-actions {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex: 0 0 auto;
}

/* ============================== */
/* BUTTONS */
.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: linear-gradient(to bottom, var(--surface-3), #1b1b1b);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  transition:
    border-color var(--transition),
    opacity var(--transition);
}
.btn:hover:not(:disabled) {
  border-color: var(--accent-dark);
}
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}
.btn--primary {
  border-color: var(--accent-dark);
  background: linear-gradient(to bottom, var(--accent), var(--accent-strong));
  color: #04150d;
}
.btn--primary:hover:not(:disabled) {
  border-color: var(--accent);
}
.icon-button {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    color var(--transition),
    border-color var(--transition);
}
.icon-button:hover:not(:disabled) {
  color: var(--accent);
  background: var(--surface-hover);
  border-color: var(--accent-dark);
}
.btn:focus-visible,
.icon-button:focus-visible,
.emoji-cell:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================== */
/* TOOLBAR */
.toolbar {
  position: sticky;
  top: var(--space-5);
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(130px, 1fr));
  align-items: end;
  gap: var(--space-5);
  padding: var(--space-6);
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}
.field-label {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.field-control,
.select-control {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}
.field-icon {
  position: absolute;
  left: 10px;
  z-index: 1;
  color: var(--text-dim);
  pointer-events: none;
}
.field-control input,
.field select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text);
  font-size: var(--font-sm);
  font-weight: 600;
  transition: border-color var(--transition);
}
.field-control input {
  padding-left: 34px;
  padding-right: 34px;
}
.field-control input::placeholder {
  color: var(--text-dim);
}
.field-control input:hover,
.field select:hover {
  border-color: var(--border-strong);
}
.field select {
  appearance: none;
  padding-right: 32px;
  cursor: pointer;
}
.field select:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.field-control input::-webkit-search-cancel-button {
  display: none;
}
.select-chevron {
  position: absolute;
  right: 10px;
  color: var(--text-dim);
  pointer-events: none;
}
.field-clear {
  position: absolute;
  right: 4px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.field-clear:hover {
  color: var(--text);
  background: var(--surface-hover);
}
.result-count {
  grid-column: 1 / -1;
  color: var(--text-dim);
  font-size: var(--font-xs);
  font-family: var(--mono);
  text-align: right;
}

/* ============================== */
/* BROWSE GRID */
.browse-view {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.grid-status {
  padding: var(--space-5) var(--space-4);
  color: var(--text-muted);
  font-size: var(--font-sm);
}
.grid-status[data-state="error"] {
  color: #ffb3b3;
}
.grid-root {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}
.emoji-group {
  content-visibility: auto;
  contain-intrinsic-size: auto 460px;
}
.emoji-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-3);
  padding: 0 var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border);
}
.emoji-group-head h2 {
  font-size: var(--font-md);
  font-weight: 800;
  letter-spacing: 0.01em;
}
.emoji-group-head span {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: var(--font-xs);
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: var(--space-2);
}
.emoji-cell {
  display: block;
  padding: 3px;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
}
.emoji-cell:hover {
  background: var(--surface-2);
}
.emoji-tile {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--tile);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius-md);
}
.emoji-tile .emoji-char {
  font-size: 30px;
  line-height: 1;
  transition: transform var(--transition);
}
.emoji-cell:hover .emoji-tile .emoji-char {
  transform: scale(1.08);
}
.emoji-tile.is-animated::after,
.compare-tile.is-animated::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 0;
  height: 0;
  border-left: 6px solid var(--text-dim);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}
.emoji-tile img {
  width: 74%;
  height: 74%;
  object-fit: contain;
  transition: transform var(--transition);
}
.emoji-cell:hover .emoji-tile img {
  transform: scale(1.08);
}
.emoji-cell.is-missing .emoji-tile {
  background: var(--surface-2);
  border-style: dashed;
}
.emoji-cell.is-missing img {
  visibility: hidden;
}
.empty-state {
  padding: var(--space-8) var(--space-6);
  color: var(--text-muted);
  text-align: center;
}

/* ============================== */
/* COMPARE */
.compare-view {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-6);
}
.compare-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-5);
  align-items: stretch;
}
.compare-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
  padding: var(--space-5);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.compare-column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.compare-column-head strong {
  overflow: hidden;
  font-size: var(--font-xs);
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}
.compare-column .field {
  gap: var(--space-2);
}
.compare-column .field + .field {
  margin-top: var(--space-2);
}
.compare-add {
  min-height: 100%;
}
.compare-note {
  color: var(--text-dim);
  font-size: var(--font-xs);
}
.compare-board {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.compare-head,
.compare-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) repeat(var(--cols, 2), minmax(110px, 1fr));
  min-width: 620px;
}
.compare-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border-strong);
}
.compare-head span {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: var(--space-4) var(--space-5);
  color: var(--text-muted);
  font-size: var(--font-xs);
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.compare-head span + span {
  border-left: 1px solid var(--border);
}
.compare-row {
  align-items: center;
  min-height: 72px;
  border-bottom: 1px solid var(--border);
  content-visibility: auto;
  contain-intrinsic-size: auto 72px;
}
.compare-row:last-child {
  border-bottom: 0;
}
.compare-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.018);
}
.compare-name-cell {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: var(--space-4) var(--space-5);
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.compare-name-cell:hover {
  background: rgba(255, 255, 255, 0.035);
}
.compare-name-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.compare-char {
  width: 34px;
  flex: 0 0 auto;
  font-size: 24px;
  line-height: 1;
  text-align: center;
}
.compare-name {
  overflow: hidden;
  font-size: var(--font-sm);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compare-cell {
  display: grid;
  place-items: center;
  height: 100%;
  min-width: 0;
  padding: var(--space-3);
  border-left: 1px solid var(--border);
}
.compare-cell[data-brand] {
  cursor: pointer;
}
.compare-cell[data-brand]:hover {
  background: rgba(255, 255, 255, 0.035);
}
.compare-tile {
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  overflow: hidden;
  background: var(--tile);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius-md);
}
.compare-tile .emoji-char {
  font-size: 26px;
  line-height: 1;
}
.compare-tile.is-missing {
  color: var(--text-muted);
  font-size: 26px;
}
.compare-tile img {
  width: 76%;
  height: 76%;
  object-fit: contain;
}
.compare-missing {
  color: var(--text-dim);
  font-size: var(--font-xs);
  font-family: var(--mono);
}

/* ============================== */
/* DETAIL DIALOG */
.detail-dialog {
  width: min(100% - 24px, 1080px);
  max-width: none;
  max-height: 92dvh;
  margin: auto;
  padding: 0;
  overflow: hidden;
  background: transparent;
  border: 0;
  color: var(--text);
}
.detail-dialog::backdrop {
  background: rgba(0, 0, 0, 0.8);
}
.detail-shell {
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-7);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
}
.detail-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-7);
  align-items: start;
}
.detail-preview {
  width: 168px;
  height: 168px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--tile);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius-lg);
}
.detail-preview img {
  width: 76%;
  height: 76%;
  object-fit: contain;
}
.detail-preview span {
  font-size: 88px;
  line-height: 1;
}
.detail-meta {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}
.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
}
.detail-heading h2 {
  font-size: var(--font-xl);
  font-weight: 800;
  line-height: 1.15;
  text-wrap: balance;
}
.detail-code {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--font-xs);
  word-break: break-word;
}
.badge-row,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}
.badge {
  padding: 3px 7px;
  background: var(--accent-glow);
  border: 1px solid rgba(0, 227, 133, 0.3);
  border-radius: var(--radius-pill);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}
.tag {
  padding: 3px 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  font-size: 11px;
}
.detail-meta .btn {
  align-self: flex-start;
}
.detail-section {
  margin-top: var(--space-8);
}
.detail-section h3 {
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
  font-size: var(--font-md);
  font-weight: 800;
}
.vendor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: var(--space-5);
}
.vendor-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.vendor-tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--tile);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius-sm);
}
.vendor-tile img {
  width: 72%;
  height: 72%;
  object-fit: contain;
}
.vendor-card figcaption {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.vendor-card strong,
.vendor-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vendor-card strong {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: var(--font-xs);
  line-height: 1.25;
  min-height: 2.5em;
  white-space: normal;
}
.vendor-tile.is-missing,
.history-tile.is-missing {
  color: var(--text-muted);
  font-size: 28px;
}
.vendor-card span {
  color: var(--text-dim);
  font-size: 11px;
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.history-group {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.history-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  padding: var(--space-4) var(--space-5);
  cursor: pointer;
  list-style: none;
  font-size: var(--font-sm);
  font-weight: 700;
}
.history-group summary::-webkit-details-marker {
  display: none;
}
.history-group summary::after {
  content: "+";
  color: var(--text-dim);
  font-family: var(--mono);
}
.history-group[open] summary::after {
  content: "–";
}
.history-vendor-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-count {
  margin-left: auto;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
}
.history-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: var(--space-4);
  padding: 0 var(--space-5) var(--space-5);
}
.history-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}
.history-tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--tile);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius-sm);
}
.history-tile img {
  width: 72%;
  height: 72%;
  object-fit: contain;
}
.history-item figcaption {
  display: flex;
  flex-direction: column;
  min-width: 0;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.3;
}
.history-item figcaption span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item time {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 10px;
}
.attribution {
  margin-top: var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: var(--font-xs);
}

/* ============================== */
/* FOOTER */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-3);
  padding: var(--space-6);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.app-footer p {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
  padding-left: var(--space-3);
  font-size: var(--font-lg);
}
.app-footer a:not(.btn) {
  color: var(--text);
  font-weight: 700;
}
.heart {
  color: var(--accent);
}
.pizza-btn {
  flex: 0 0 auto;
}

/* ============================== */
/* TOAST */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: 9px 14px;
  transform: translate(-50%, 12px);
  background: var(--surface-3);
  border: 1px solid var(--accent-dark);
  border-radius: var(--radius-pill);
  color: var(--text);
  font-size: var(--font-sm);
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity var(--transition),
    transform var(--transition);
}
.toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

/* ============================== */
/* RESPONSIVE */
@media (max-width: 980px) {
  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .field--search {
    grid-column: 1 / -1;
  }
}
@media (max-width: 720px) {
  body {
    padding: var(--space-5);
  }
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-5);
    padding: var(--space-6);
  }
  .app-logo {
    width: 46px;
    height: 46px;
  }
  .app-copy h1 {
    font-size: var(--font-lg);
  }
  .app-actions .btn {
    width: 100%;
  }
  .toolbar {
    position: static;
    grid-template-columns: minmax(0, 1fr);
  }
  .field--search {
    grid-column: auto;
  }
  .result-count {
    text-align: left;
  }
  .emoji-grid {
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  }
  .compare-controls {
    grid-template-columns: minmax(0, 1fr);
  }
  .detail-dialog {
    width: calc(100% - 12px);
    max-height: 94dvh;
  }
  .detail-shell {
    max-height: 94dvh;
    padding: var(--space-6);
  }
  .detail-top {
    grid-template-columns: 96px minmax(0, 1fr);
    gap: var(--space-6);
  }
  .detail-preview {
    width: 96px;
    height: 96px;
  }
  .detail-preview span {
    font-size: 48px;
  }
  .detail-heading h2 {
    font-size: var(--font-lg);
  }
  .vendor-grid {
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  }
  .history-items {
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  }
  .app-footer {
    flex-direction: column;
    padding: var(--space-6);
    text-align: center;
  }
  .app-footer p {
    justify-content: center;
    padding-left: 0;
    font-size: var(--font-sm);
  }
  .pizza-btn {
    width: 100%;
  }
}

/* ============================== */
/* REDUCED MOTION */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
