/* ── Display Name Font picker (Settings) ──────────────────────────────
 * Subscriber-only feature. The picker renders for all users; non-subs
 * see the same tiles, can preview live, but the upsell block reveals on
 * click and the save is blocked. Polish bar: feel like a marquee of
 * tokens, not a flat checkbox grid (see public/store-mocks/ for the
 * visual target — rich gradients, glow, considered composition).
 */

/* Preview marquee above the grid. Horizontal-stripe arcade-cabinet
 * gradient so the preview reads at a glance regardless of which font
 * is currently selected. Sized to host an [size="hero"] retro-username. */
.settings-font-preview {
  position: relative;
  margin: 0 auto 16px;
  padding: clamp(14px, 2.5vw, 22px) clamp(16px, 3vw, 28px);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(0, 229, 160, 0.05) 0%, transparent 60%),
    linear-gradient(135deg, var(--surface2), var(--surface));
  border: 1px solid var(--border);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 2px 12px rgba(0, 0, 0, 0.5),
    var(--glow);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
  overflow: hidden;
}

/* Scanline overlay — pure CSS, no asset. Mimics a CRT marquee. */
.settings-font-preview::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.02) 0px,
    rgba(255, 255, 255, 0.02) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  z-index: 1;
}

.settings-font-preview retro-username {
  position: relative;
  z-index: 2;
}

/* Pipe the selected font from the picker through to the inner span of
 * <retro-username>. font-ui.js sets --display-name-font and
 * --display-name-font-scale on the host; we apply them via descendant
 * selector here so we don't fight with the inline-style logic in
 * retro-username.js (that one only fires once the equipped-cache
 * fetch resolves, post-save). */
.settings-font-preview retro-username[style*="--display-name-font"] .retro-username-text {
  font-family: var(--display-name-font);
  font-size: calc(var(--display-name-font-scale, 1) * 1em);
}

/* ── Grid ────────────────────────────────────────────────────────── */
.font-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(150px, 22vw, 200px), 1fr));
  gap: clamp(8px, 1.5vw, 14px);
  margin: 16px 0;
}

/* ── Tile ────────────────────────────────────────────────────────── */
.font-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 6px;
  padding: clamp(12px, 2vw, 18px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(135deg, var(--surface2), var(--surface));
  color: var(--text);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 2px 8px rgba(0, 0, 0, 0.4);
  font-family: inherit;
  text-align: left;
  overflow: hidden;
  min-height: 88px;
}

.font-tile:hover {
  transform: translateY(-1px);
  border-color: rgba(0, 229, 160, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 4px 14px rgba(0, 0, 0, 0.55),
    0 0 18px rgba(0, 229, 160, 0.15);
}

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

/* Sample line — the user's own display name rendered in the tile's font.
 * Single line, ellipsis if it overflows so a long username doesn't bust
 * the grid. */
.font-tile-sample {
  display: block;
  font-size: clamp(18px, 2.4vw, 22px);
  line-height: 1.15;
  color: #f4f4fb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

/* Caption label — short word like "Pixel", "Cabinet", in the system mono
 * font so it's always readable. */
.font-tile-name {
  display: block;
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: auto;
}

/* "Active" tag — hidden by default, revealed on the .active tile. */
.font-tile-active-tag {
  position: absolute;
  top: 8px;
  right: 8px;
  font-family: var(--font-pixel);
  font-size: 7px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0;
  transition: opacity 120ms ease;
  text-shadow: 0 0 6px rgba(0, 229, 160, 0.6);
}

.font-tile.active {
  border-color: var(--accent);
  background:
    linear-gradient(135deg, rgba(0, 229, 160, 0.08), transparent 40%),
    linear-gradient(135deg, var(--surface2), var(--surface));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 0 0 1px rgba(0, 229, 160, 0.4),
    0 0 22px rgba(0, 229, 160, 0.28);
}

.font-tile.active .font-tile-active-tag {
  opacity: 1;
}

/* Preview-only state for non-subscribers' un-owned tiles. Subtle lock
 * indicator + slight desaturation. The currently-active tile (if any)
 * never gets this class — the lock and the ACTIVE badge would otherwise
 * crowd the same corner — and the active tile already communicates
 * "selected" via the green border + glow. Lock sits in the bottom-right:
 * top-right is the ACTIVE badge, top-left would clip the font sample,
 * bottom-left is the caption — bottom-right is the only clean corner. */
.font-tile.preview-only::after {
  content: '🔒';
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 11px;
  opacity: 0.55;
  filter: grayscale(0.5);
}

.font-tile.preview-only {
  opacity: 0.88;
}

.font-tile.preview-only:hover {
  opacity: 1;
}

/* ── Upsell CTA ──────────────────────────────────────────────────── */
.settings-font-upsell {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  padding: 14px 16px;
  margin: 8px 0 4px;
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(0, 184, 255, 0.10), rgba(0, 229, 160, 0.06)),
    var(--surface);
  border: 1px solid rgba(0, 229, 160, 0.35);
  box-shadow: 0 0 18px rgba(0, 229, 160, 0.12);
}

.settings-font-upsell.hidden {
  display: none;
}

.settings-font-upsell .settings-font-upsell-cta {
  display: inline-block;
  align-self: flex-start;
}

/* ── Responsive tweaks ────────────────────────────────────────────── */
@media (max-width: 480px) {
  .font-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .font-tile {
    min-height: 76px;
    padding: 12px;
  }
  .font-tile-sample {
    font-size: 17px;
  }
}
