:root {
  color-scheme: light;
  /* Specimen scale: vmin keeps portrait phones readable (not just vw-only) */
  --glyph-aa-size: clamp(2.9375rem, 10.75vmin + 3.5vw + 0.55rem, 7.125rem);
  --scene-perspective: clamp(620px, 78vw + 260px, 980px);
  --bg: #ffffff;
  --text: #000000;
  --muted: rgba(0, 0, 0, 0.5);
  --glyph: #000000;
  /* Edge wash: same hue as --bg so type fades into the page (not a dark frame) */
  --vignette-inner: color-mix(in srgb, var(--bg) 0%, transparent);
  --vignette-mid: color-mix(in srgb, var(--bg) 22%, transparent);
  --vignette-outer: color-mix(in srgb, var(--bg) 40%, transparent);
}

html.theme-dark {
  color-scheme: dark;
  --bg: #0c0c0c;
  --text: #f2f2f2;
  --muted: rgba(255, 255, 255, 0.48);
  --glyph: #fafafa;
  --vignette-inner: color-mix(in srgb, var(--bg) 0%, transparent);
  --vignette-mid: color-mix(in srgb, var(--bg) 22%, transparent);
  --vignette-outer: color-mix(in srgb, var(--bg) 40%, transparent);
}

* {
  box-sizing: border-box;
}

html {
  zoom: 90%;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  perspective: var(--scene-perspective);
  perspective-origin: 50% 50%;
}

.field {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.glyph-cell {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  transform-origin: 0 0;
  will-change: transform, opacity, filter;
  backface-visibility: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  z-index: 1;
}

.glyph-cell--selected {
  z-index: 50;
}

.glyph-cell:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--text), transparent 55%);
  outline-offset: 6px;
}

.glyph-cell__stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-style: preserve-3d;
}

.glyph-cell__aa {
  display: block;
  color: var(--glyph);
  font-size: var(--glyph-aa-size);
  line-height: 0.88;
  letter-spacing: -0.04em;
  text-rendering: geometricPrecision;
  transform-origin: 50% 0;
  transform: translate3d(0, 0, 0) scale(1);
  transition: transform 0.42s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@media (hover: hover) and (pointer: fine) {
  .glyph-cell:not(.glyph-cell--selected):hover .glyph-cell__aa {
    transform: translate3d(0, 0, 0) scale(0.965);
  }
}

.glyph-cell:not(.glyph-cell--selected):active .glyph-cell__aa {
  transform: translate3d(0, 0, 0) scale(0.97);
  transition-duration: 0.14s;
}

.glyph-cell--selected .glyph-cell__aa {
  transform: translate3d(0, -0.78em, 0) scale(0.795);
  transition: transform 0.48s cubic-bezier(0.22, 1, 0.36, 1);
}

.glyph-cell__info {
  box-sizing: border-box;
  width: min(340px, calc(100vw - 2.25rem));
  max-width: min(340px, calc(100vw - 2.25rem));
  margin-left: auto;
  margin-right: auto;
  margin-top: 0.06rem;
  padding-top: 0;
  opacity: 0;
  transform: translate3d(0, 12px, 0);
  pointer-events: none;
  user-select: text;
  transition:
    opacity 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.42s cubic-bezier(0.22, 1, 0.36, 1),
    margin-top 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.glyph-cell--selected .glyph-cell__info {
  /* Transforms on Aa don't shrink flow; offset by ~scaled specimen so blocks sit under drawn Aa + small gap */
  opacity: 1;
  margin-top: calc(-0.38 * var(--glyph-aa-size) + 0.75rem);
  transform: translate3d(0, 0, 0);
  pointer-events: auto;
  transition-delay: 0.05s;
}

.glyph-cell__titles-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.glyph-cell__titles {
  text-align: left;
  min-width: 0;
  flex: 1;
}

.glyph-cell__name {
  margin: 0 0 1px;
  font-family: inherit;
  font-size: clamp(0.95rem, 2.2vw, 1.05rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

.glyph-cell__meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.glyph-cell__blurb {
  margin: 6px 0 0;
  width: 100%;
  font-size: 0.8125rem;
  line-height: 1.42;
  color: var(--text);
  text-align: left;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
}

.glyph-cell__used-by {
  margin-top: 8px;
  padding-top: 5px;
  border-top: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
}

.glyph-cell__used-label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.625rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.glyph-cell__used-icons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.glyph-cell__used-icons li {
  margin: 0;
  padding: 0;
  line-height: 0;
}

.glyph-cell__used-icon {
  display: block;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid color-mix(in srgb, var(--text) 14%, transparent);
}

.glyph-cell__used-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--muted);
  background: color-mix(in srgb, var(--text) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
}

.glyph-cell__arrow {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-top: -2px;
  color: var(--text);
  border-radius: 8px;
  transition: background 0.2s ease, color 0.2s ease;
}

.glyph-cell__arrow:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.glyph-cell__arrow-icon {
  transform: rotate(0deg);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.glyph-cell__arrow:hover .glyph-cell__arrow-icon {
  transform: rotate(-10deg);
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    circle at 50% 50%,
    var(--vignette-inner) 0%,
    var(--vignette-inner) 40%,
    var(--vignette-mid) 80%,
    var(--vignette-outer) 100%
  );
}

.footer-bar {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom, 0px) + 10px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  max-width: min(520px, calc(100vw - max(28px, env(safe-area-inset-left, 0px) + env(safe-area-inset-right, 0px) + 24px)));
  padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
  z-index: 5;
  pointer-events: none;
}

.footer-bar .hint {
  pointer-events: auto;
}

.hint {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

@media (max-width: 599px) {
  :root {
    --glyph-aa-size: clamp(3rem, 12vmin + 2.85vw + 0.35rem, 7.125rem);
    --scene-perspective: min(690px, 115vw + 310px);
  }

  .glyph-cell__info {
    width: min(calc(100vw - 1.5rem), 24rem);
    max-width: min(calc(100vw - 1.5rem), 24rem);
  }

  .glyph-cell__name {
    font-size: clamp(1.02rem, 3.4vw + 0.72rem, 1.125rem);
  }

  .glyph-cell__meta {
    font-size: 0.84rem;
  }

  .glyph-cell__blurb {
    font-size: 0.9rem;
    line-height: 1.5;
  }

  .glyph-cell__used-label {
    font-size: 0.66rem;
  }

  .glyph-cell__used-icon {
    width: 38px;
    height: 38px;
    border-radius: 9px;
  }

  .glyph-cell__used-fallback {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    font-size: 0.72rem;
  }

  .glyph-cell__arrow {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .hint {
    font-size: 10px;
    text-align: center;
  }
}
