/* ============================== */
/* TOKENS */
:root {
  --tile: #f2f2f2;
  --tile-border: #d7d7d7;
  --icon-size: 18px;
}

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

/* ============================== */
/* BROWSE HEAD */
.app-shell {
  --app-gap: 20px;
}
.browse-head {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--app-border);
}
.head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-logo {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
}
.brand-name {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.01em;
}
.filters {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(130px, 1fr));
  align-items: end;
  gap: 20px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--app-space-1);
  min-width: 0;
}
.field-label {
  margin: 0;
}
.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(--app-text-dim);
  pointer-events: none;
}
.filters .field-control input,
.filters .select-control select {
  padding: 8px 12px;
  background: var(--app-surface-2);
  border: 1px solid var(--app-border-strong);
  border-radius: var(--app-radius-md);
  font-size: 15px;
  font-weight: 600;
}
.filters .field-control input {
  padding-right: 34px;
  padding-left: 34px;
}
.filters .select-control select {
  padding-right: 32px;
  cursor: pointer;
}
.filters .field-control input:focus {
  border-color: var(--app-accent);
  box-shadow: 0 0 0 2px var(--app-accent-soft);
}
.filters .select-control select:focus {
  border-color: var(--app-border-strong);
  box-shadow: none;
}
.filters .select-control select:focus-visible {
  border-color: var(--app-accent);
  box-shadow: 0 0 0 2px var(--app-accent-soft);
}
.select-chevron {
  position: absolute;
  right: 10px;
  color: var(--app-text-dim);
  pointer-events: none;
}
.field-control input::-webkit-search-cancel-button {
  display: none;
}
.field-clear {
  position: absolute;
  right: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  color: var(--app-text-muted);
  background: transparent;
  border-radius: var(--app-radius-sm);
  cursor: pointer;
}
.field-clear:hover {
  background: var(--app-surface-hover);
}
.result-count {
  grid-column: 1 / -1;
  color: var(--app-text-dim);
  font-family: var(--app-mono);
  font-size: var(--app-fs-xs);
  text-align: right;
}

/* ============================== */
/* BROWSE GRID */
.browse-view {
  display: flex;
  flex-direction: column;
  gap: var(--app-space-5);
}
.grid-status {
  padding: var(--app-space-4);
  color: var(--app-text-muted);
  font-size: var(--app-fs-sm);
}
.grid-status[data-state="error"] {
  color: var(--app-danger-strong);
}
.grid-root {
  display: flex;
  flex-direction: column;
  gap: var(--app-space-6);
}
.emoji-group {
  content-visibility: auto;
  contain-intrinsic-size: auto 460px;
}
.emoji-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--app-space-3);
  margin-bottom: var(--app-space-3);
  padding: 0 var(--app-space-1) var(--app-space-2);
  border-bottom: 1px solid var(--app-border);
}
.emoji-group-head h2 {
  font-size: var(--app-fs-md);
  font-weight: 700;
}
.emoji-group-head span {
  color: var(--app-text-dim);
  font-family: var(--app-mono);
  font-size: var(--app-fs-xs);
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: var(--app-space-1);
}
.emoji-cell {
  display: block;
  padding: 3px;
  border-radius: var(--app-radius-sm);
  cursor: pointer;
  content-visibility: auto;
  contain-intrinsic-size: auto 54px;
}
.emoji-cell:hover {
  background: var(--app-surface-3);
}
.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(--app-radius-sm);
}
.emoji-tile .emoji-char {
  font-size: 30px;
  line-height: 1;
}
.emoji-tile.is-animated::after,
.compare-tile.is-animated::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid var(--app-text-dim);
}
.emoji-tile img {
  width: 74%;
  height: 74%;
  object-fit: contain;
}
.emoji-cell.is-missing .emoji-tile {
  background: var(--app-surface-2);
  border-style: dashed;
}
.emoji-cell.is-missing img {
  visibility: hidden;
}
.empty-state {
  padding: var(--app-space-5);
  color: var(--app-text-muted);
  text-align: center;
}

/* ============================== */
/* COMPARE */
.compare-view {
  display: flex;
  flex-direction: column;
  gap: var(--app-space-4);
  padding: var(--app-panel-pad);
}
.compare-view:not([hidden]) {
  animation: view-in 240ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes view-in {
  from {
    opacity: 0;
  }
}
.compare-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: stretch;
  gap: var(--app-space-3);
}
.compare-column {
  display: flex;
  flex-direction: column;
  gap: var(--app-space-2);
  min-width: 0;
  padding: var(--app-space-3);
  background: var(--app-surface-2);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-sm);
}
.compare-column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--app-space-3);
}
.compare-column-head strong {
  overflow: hidden;
  font-size: var(--app-fs-xs);
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}
.compare-column .field {
  gap: var(--app-space-1);
}
.compare-add {
  min-height: 100%;
}
.compare-note {
  color: var(--app-text-dim);
  font-size: var(--app-fs-xs);
}
.compare-board {
  overflow-x: auto;
  border: 1px solid var(--app-border);
  border-radius: var(--app-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(--app-surface-3);
  border-bottom: 1px solid var(--app-border-strong);
}
.compare-head span {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: var(--app-space-3) var(--app-space-4);
  color: var(--app-text-muted);
  font-size: var(--app-fs-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.compare-head span + span {
  border-left: 1px solid var(--app-border);
}
.compare-row {
  align-items: center;
  min-height: 72px;
  border-bottom: 1px solid var(--app-border);
  content-visibility: auto;
  contain-intrinsic-size: auto 72px;
}
.compare-row:last-child {
  border-bottom: 0;
}
.compare-row:nth-child(even) {
  background: var(--app-surface-2);
}
.compare-name-cell {
  display: flex;
  align-items: center;
  gap: var(--app-space-3);
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: var(--app-space-3) var(--app-space-4);
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.compare-name-cell:hover {
  background: var(--app-surface-3);
}
.compare-char {
  flex: 0 0 auto;
  width: 34px;
  font-size: 24px;
  line-height: 1;
  text-align: center;
}
.compare-name {
  overflow: hidden;
  font-size: var(--app-fs-sm);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compare-cell {
  display: grid;
  place-items: center;
  height: 100%;
  min-width: 0;
  padding: var(--app-space-2);
  border-left: 1px solid var(--app-border);
}
.compare-cell[data-brand] {
  cursor: pointer;
}
.compare-cell[data-brand]:hover {
  background: var(--app-surface-3);
}
.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(--app-radius-sm);
}
.compare-tile .emoji-char {
  font-size: 26px;
  line-height: 1;
}
.compare-tile.is-missing {
  color: var(--app-text-muted);
  font-size: 26px;
}
.compare-tile img {
  width: 76%;
  height: 76%;
  object-fit: contain;
}
.compare-missing {
  color: var(--app-text-dim);
  font-family: var(--app-mono);
  font-size: var(--app-fs-xs);
}

/* ============================== */
/* DETAIL DIALOG */
.detail-dialog {
  width: min(100% - 24px, 1080px);
  max-width: none;
  max-height: 92dvh;
  margin: auto;
  padding: 0;
  overflow: hidden;
  color: var(--app-text);
  background: transparent;
  border: 0;
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  transition:
    opacity 180ms ease-in,
    transform 180ms ease-in,
    overlay 180ms allow-discrete,
    display 180ms allow-discrete;
}
.detail-dialog[open] {
  opacity: 1;
  transform: none;
  transition:
    opacity 240ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 240ms cubic-bezier(0.16, 1, 0.3, 1),
    overlay 240ms allow-discrete,
    display 240ms allow-discrete;
}
@starting-style {
  .detail-dialog[open] {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
}
.detail-dialog::backdrop {
  background-color: var(--app-overlay);
  opacity: 0;
  transition:
    opacity 180ms ease-in,
    overlay 180ms allow-discrete,
    display 180ms allow-discrete;
}
.detail-dialog[open]::backdrop {
  opacity: 1;
  transition:
    opacity 240ms cubic-bezier(0.16, 1, 0.3, 1),
    overlay 240ms allow-discrete,
    display 240ms allow-discrete;
}
@starting-style {
  .detail-dialog[open]::backdrop {
    opacity: 0;
  }
}
.detail-shell {
  max-height: 92dvh;
  padding: var(--app-space-5);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--app-surface-1);
  border: 1px solid var(--app-border-strong);
  border-radius: var(--app-radius-lg);
}
.detail-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: var(--app-space-5);
}
.detail-preview {
  display: grid;
  place-items: center;
  width: 168px;
  height: 168px;
  overflow: hidden;
  background: var(--tile);
  border: 1px solid var(--tile-border);
  border-radius: var(--app-radius-sm);
}
.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(--app-space-3);
  min-width: 0;
}
.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--app-space-4);
}
.detail-heading h2 {
  font-size: var(--app-fs-xl);
  font-weight: 800;
  line-height: 1.15;
  text-wrap: balance;
}
.detail-code {
  color: var(--app-text-muted);
  font-family: var(--app-mono);
  font-size: var(--app-fs-xs);
  word-break: break-word;
}
.badge-row,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--app-space-1);
}
.tag {
  padding: 3px 7px;
  color: var(--app-text-muted);
  background: var(--app-surface-2);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-pill);
  font-size: var(--app-fs-micro);
}
.detail-meta .btn {
  align-self: flex-start;
}
.detail-dialog .btn {
  border-radius: var(--app-radius-sm);
}
.detail-section {
  margin-top: var(--app-space-5);
}
.detail-section h3 {
  margin-bottom: var(--app-space-3);
  padding-bottom: var(--app-space-2);
  border-bottom: 1px solid var(--app-border);
  font-size: var(--app-fs-md);
  font-weight: 700;
}
.vendor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: var(--app-space-3);
}
.vendor-card:hover {
  background: var(--app-surface-3);
  border-color: var(--app-border-strong);
}
.vendor-card {
  display: flex;
  flex-direction: column;
  gap: var(--app-space-2);
  min-width: 0;
  padding: var(--app-space-2);
  background: var(--app-surface-2);
  border: 1px solid var(--app-border);
  border-radius: var(--app-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(--app-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;
  min-height: 2.5em;
  overflow: hidden;
  font-size: var(--app-fs-xs);
  line-height: 1.25;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.vendor-tile.is-missing,
.history-tile.is-missing {
  color: var(--app-text-muted);
  font-size: 28px;
}
.vendor-card span {
  color: var(--app-text-dim);
  font-size: var(--app-fs-micro);
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--app-space-2);
}
.history-group summary:hover {
  background: var(--app-surface-3);
  border-radius: var(--app-radius-sm);
}
.history-group {
  background: var(--app-surface-2);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-sm);
}
.history-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--app-space-3);
  padding: var(--app-space-2) var(--app-space-3);
  font-size: var(--app-fs-sm);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.history-group summary::-webkit-details-marker {
  display: none;
}
.history-group summary::after {
  content: "+";
  color: var(--app-text-dim);
  font-family: var(--app-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(--app-text-dim);
  font-family: var(--app-mono);
  font-size: var(--app-fs-micro);
  font-weight: 600;
}
.history-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: var(--app-space-2);
  padding: 0 var(--app-space-3) var(--app-space-3);
}
.history-item {
  display: flex;
  flex-direction: column;
  gap: var(--app-space-1);
  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(--app-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(--app-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(--app-text-dim);
  font-family: var(--app-mono);
  font-size: 10px;
}
.attribution {
  margin-top: var(--app-space-5);
  padding-top: var(--app-space-3);
  color: var(--app-text-dim);
  border-top: 1px solid var(--app-border);
  font-size: var(--app-fs-xs);
}

/* ============================== */
/* TOAST */
.toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* ============================== */
/* RESPONSIVE */
@media (max-width: 980px) {
  .field--search {
    grid-column: 1 / -1;
  }
}
@media (max-width: 720px) {
  .head-row {
    align-items: center;
  }
  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }
  .field--search {
    grid-column: 1 / -1;
  }
  .field--wide {
    grid-column: 1 / -1;
  }
  .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(--app-space-4);
  }
  .detail-top {
    grid-template-columns: 96px minmax(0, 1fr);
    gap: var(--app-space-4);
  }
  .detail-preview {
    width: 96px;
    height: 96px;
  }
  .detail-preview span {
    font-size: 48px;
  }
  .detail-heading h2 {
    font-size: var(--app-fs-lg);
  }
  .vendor-grid {
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  }
  .history-items {
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  }
}

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