*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #0c0e12;
  --bg-elevated: #141820;
  --border: #252a33;
  --text: #e8eaed;
  --text-muted: #8b939e;
  --accent: #6ea8fe;
  --accent-glow: rgba(110, 168, 254, 0.25);
  --header-height: 4.5rem;
  --ad-rail-width: 160px;
  --ad-rail-gap: 1rem;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
}

@media (min-width: 1024px) {
  body.ads-active {
    padding-right: calc(var(--ad-rail-width) + var(--ad-rail-gap) * 2);
  }
}

.ad-rail {
  display: none;
  position: fixed;
  top: 5.25rem;
  right: var(--ad-rail-gap);
  z-index: 90;
  width: var(--ad-rail-width);
  pointer-events: auto;
}

@media (min-width: 1024px) {
  .ad-rail:not([hidden]) {
    display: block;
  }
}

.ad-rail__label {
  margin: 0 0 0.35rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
}

.ad-rail__slot {
  overflow: hidden;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  min-height: 600px;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 300;
  padding: 0.5rem 0.75rem;
  background: var(--accent);
  color: #0c0e12;
  border-radius: 0.5rem;
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 1rem;
}

.search-header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.75rem 1rem 1rem;
  background: rgba(0 0 0 / 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.search-header__inner {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  width: 100%;
  max-width: 52rem;
  margin: 0 auto;
}

.search-header__inner-wrap {
  width: 100%;
  max-width: 52rem;
  margin: 0 auto;
}

.search-preview {
  list-style: none;
  width: 100%;
  max-width: 52rem;
  margin: 0.5rem auto 0;
  padding: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
}

.search-preview__item {
  border-bottom: 1px solid var(--border);
}

.search-preview__item:last-child {
  border-bottom: none;
}

.search-preview__btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: none;
  cursor: pointer;
}

.search-preview__btn:hover,
.search-preview__btn:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.search-preview__emoji {
  font-size: 1.75rem;
  line-height: 1;
  width: 2rem;
  text-align: center;
}

.search-preview__meta {
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.search-input {
  display: block;
  flex: 1;
  min-width: 0;
  padding: 0.85rem 1.1rem;
  font-size: 1.125rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  outline: none;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.header-controls {
  display: flex;
  flex-shrink: 0;
  align-items: stretch;
  gap: 0.5rem;
}

.skin-tone-picker {
  display: flex;
  flex-shrink: 0;
  gap: 0.2rem;
  padding: 0.35rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

.skin-tone-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  min-width: 2.35rem;
  margin: 0;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 0.45rem;
  cursor: pointer;
  transition:
    background 0.1s ease,
    border-color 0.1s ease;
}

.skin-tone-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.skin-tone-btn.is-selected {
  border-color: var(--accent);
  background: rgba(110, 168, 254, 0.12);
}

.skin-tone-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.main {
  padding: 0 0.5rem 2rem;
}

.emoji-section {
  margin-bottom: 0.5rem;
}

.emoji-section.is-hidden {
  display: none;
}

.section-title {
  margin: 0.75rem 1rem 0.35rem;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.section-title--inline {
  margin: 0;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.75rem 1rem 0.35rem;
}

.text-btn {
  margin: 0;
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  cursor: pointer;
}

.text-btn:hover,
.text-btn:focus-visible {
  background: rgba(110, 168, 254, 0.1);
  outline: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.status {
  margin: 0.5rem 1rem 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  min-height: 1.25rem;
}

.catalog {
  display: block;
}

.catalog-grid-host {
  position: relative;
  width: 100%;
  min-height: 3.5rem;
}

.virtual-grid__viewport {
  position: relative;
  width: 100%;
}

.virtual-grid__window {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}

.virtual-grid__spacer {
  width: 100%;
  pointer-events: none;
}

.pin-btn--visible {
  opacity: 1;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.25rem, 1fr));
  gap: 0.25rem;
  width: 100%;
  padding: 0.25rem 0.5rem;
}

.emoji-cell {
  position: relative;
  min-width: 0;
}

.emoji-cell.is-hidden {
  display: none;
}

.emoji-cell.is-highlighted .emoji-btn {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: rgba(110, 168, 254, 0.18);
}

.emoji-list-item {
  position: relative;
  min-width: 0;
}

.emoji-list-item .emoji-btn {
  width: 100%;
}

.pin-btn {
  position: absolute;
  top: -0.15rem;
  right: -0.15rem;
  z-index: 2;
  width: 0.9rem;
  height: 0.9rem;
  padding: 0;
  font-size: 0.5rem;
  line-height: 1;
  color: var(--text-muted);
  background: rgba(12, 14, 18, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  opacity: 0;
  transition:
    opacity 0.12s ease,
    color 0.12s ease;
}

.emoji-cell:focus-within .pin-btn,
.emoji-cell:hover .pin-btn,
.emoji-list-item:focus-within .pin-btn,
.emoji-list-item:hover .pin-btn,
.pin-btn:focus-visible {
  opacity: 1;
}

.pin-btn[aria-pressed="true"] {
  color: #ffd866;
  opacity: 1;
}

.emoji-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  margin: 0;
  padding: 0;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  line-height: 1;
  background: transparent;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background 0.1s ease,
    transform 0.1s ease;
}

.emoji-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.emoji-btn:active {
  transform: scale(0.92);
  background: rgba(110, 168, 254, 0.15);
}

.emoji-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 200;
  padding: 1.4rem 2.4rem;
  font-size: 2.125rem;
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.92);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .emoji-btn,
  .pin-btn,
  .skin-tone-btn,
  .search-input {
    transition: none;
  }

  .toast.is-visible {
    transform: translate(-50%, -50%);
  }
}

@media (min-width: 640px) {
  .emoji-grid {
    grid-template-columns: repeat(auto-fill, minmax(3.5rem, 1fr));
    gap: 0.35rem;
  }

  .skin-tone-btn {
    width: 2.5rem;
    min-width: 2.5rem;
    font-size: 1.45rem;
  }

  .settings-gear {
    width: 2.5rem;
    min-width: 2.5rem;
    padding: 0;
  }
}

@media (max-width: 480px) {
  .search-header__inner {
    flex-wrap: nowrap;
  }

  .skin-tone-picker:not(.is-expanded) .skin-tone-btn:not(.is-selected) {
    display: none;
  }

  .skin-tone-picker:not(.is-expanded) .skin-tone-btn.is-selected {
    border-color: transparent;
    background: transparent;
  }

  .skin-tone-picker.is-expanded {
    flex-wrap: wrap;
    justify-content: center;
  }

  .skin-tone-picker.is-expanded .skin-tone-btn {
    flex: 0 0 auto;
  }

  .pin-btn {
    display: none !important;
  }
}

.settings-gear {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  min-width: calc(2.35rem + 0.7rem);
  padding: 0.35rem 0.55rem;
  margin: 0;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

.settings-gear:hover {
  border-color: var(--accent);
}

.settings-gear:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.settings-gear__icon {
  font-size: 1.35rem;
  line-height: 1;
}

.emoji-action-overlay {
  position: fixed;
  inset: 0;
  z-index: 270;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(8, 10, 14, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.emoji-action-overlay[hidden] {
  display: none;
}

.emoji-action-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 16rem;
  padding: 1.25rem 1rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.55);
}

.emoji-action-display {
  font-size: 4rem;
  line-height: 1;
}

.emoji-action-title {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
}

.emoji-action-menu {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 0.35rem;
}

.emoji-action-menu__btn {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font: inherit;
  font-size: 0.9375rem;
  text-align: left;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
}

.emoji-action-menu__btn:hover,
.emoji-action-menu__btn:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(8, 10, 14, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.settings-overlay[hidden] {
  display: none;
}

.settings-dialog {
  width: 100%;
  max-width: 26rem;
  max-height: 95vh;
  overflow: auto;
  padding: 1.25rem 1.25rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.settings-dialog__title {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  font-weight: 600;
}

.settings-section {
  margin-bottom: 1.25rem;
}

.settings-section__title {
  margin: 0 0 0.35rem;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.settings-section__hint {
  margin: 0 0 0.65rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.settings-categories {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.settings-category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.9375rem;
}

.settings-category-row.is-hidden-category {
  opacity: 0.72;
}

.settings-category-row label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  flex: 1;
}

.settings-add-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.settings-input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.settings-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.settings-error {
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
  color: #f87171;
}

.settings-hidden-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 10rem;
  overflow: auto;
}

.settings-hidden-list:empty::before {
  content: "No individually hidden emoji.";
  display: block;
  font-size: 0.8125rem;
  color: var(--text-muted);
  padding: 0.35rem 0;
}

.settings-hidden-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.settings-hidden-item__meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  font-size: 0.875rem;
}

.settings-hidden-item__emoji {
  font-size: 1.35rem;
  line-height: 1;
}

.settings-hidden-item__name {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.settings-btn {
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.9375rem;
  border-radius: 0.5rem;
  cursor: pointer;
  border: 1px solid var(--border);
}

.settings-btn--secondary {
  color: var(--text);
  background: transparent;
}

.settings-btn--secondary:hover {
  background: rgba(255, 255, 255, 0.06);
}

.settings-btn--primary {
  color: #0c0e12;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.settings-btn--primary:hover {
  filter: brightness(1.05);
}

.settings-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
