/* ===========================================================
   Spotify Color Accessibility Checker · v2
   Specimen-driven color combinator with live WCAG verdicts
   =========================================================== */

/* Spotify Mix Variable — covers all weights (100-900) and widths (75-125%)
   in a single file. Hosted behind Cloudflare Access; access is limited to
   @rarestandard.jp and @spotify.com Workspace accounts. */
@font-face {
  font-family: 'Spotify Mix';
  src: url('./fonts/SpotifyMixVariable.woff2') format('woff2-variations'),
       url('./fonts/SpotifyMixVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-stretch: 75% 125%;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Canvas chrome (the app frame itself — not affected by the picker) */
  --bg-canvas: #0a0a0a;
  --bg-surface: #131313;
  --bg-elevated: #1c1c1c;
  --bg-hover: #232323;
  --text-hi: #ffffff;
  --text-md: rgba(255, 255, 255, 0.74);
  --text-lo: rgba(255, 255, 255, 0.48);
  --text-faint: rgba(255, 255, 255, 0.28);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.2);
  --accent: #1ed760;
  --accent-soft: rgba(30, 215, 96, 0.16);
  --warn: #ff4834;

  /* Live tokens — picker writes to these */
  --bg: #191414;
  --fg: #1ed760;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --font-sans:
    'Spotify Mix', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-jp:
    'Spotify Mix', 'Inter', 'Noto Sans JP', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN',
    'Yu Gothic UI', sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--text-hi);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv11', 'ss03';
}

body {
  min-height: 100vh;
  overflow: hidden;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}

kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
  color: var(--text-md);
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ===========================================================
   Layout
   =========================================================== */
.app {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
}

/* ===========================================================
   Header
   =========================================================== */
.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-canvas);
}
.brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
}
.accent-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(30, 215, 96, 0.5);
}
.brand-mark h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}
.eyebrow {
  font-size: 11px;
  color: var(--text-lo);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 0 auto;
}

/* ===========================================================
   Pair bar (sticky)
   =========================================================== */
.pair-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.slot {
  flex: 0 0 auto;
  min-width: 240px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 2px 14px;
  align-items: center;
  background: var(--bg-elevated);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.slot:hover { background: var(--bg-hover); }
.slot:active { transform: scale(0.995); }
.slot[aria-pressed='true'] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-soft);
}

.slot-label {
  grid-column: 1 / -1;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-lo);
}
.slot-swatch {
  grid-column: 1;
  grid-row: 2;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--bg-elevated);
}
.slot-meta {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.slot-meta strong {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot-meta span { font-size: 11px; color: var(--text-md); }

.swap {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, transform 0.2s;
}
.swap:hover { color: var(--text-hi); border-color: var(--border-strong); transform: rotate(180deg); }

/* WCAG strip on right */
.wcag-strip {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}
.ratio { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.ratio-value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.ratio-caption { font-size: 11px; color: var(--text-md); margin-top: 2px; }

.chips { display: flex; gap: 6px; }
.chip {
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: var(--text-faint);
  font-weight: 500;
  transition: all 0.15s;
}
.chip b { font-weight: 800; }
.chip.pass {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(30, 215, 96, 0.35);
}
.chip.fail {
  color: var(--text-faint);
  border-color: rgba(255, 255, 255, 0.06);
}

/* ===========================================================
   Main split — specimens (left) | picker (right)
   =========================================================== */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 1fr);
  min-height: 0;
  overflow: hidden;
}

.specimens,
.picker {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.specimens {
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 24px;
  align-content: start;
}

.picker {
  border-left: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
}

/* ===========================================================
   Specimens
   =========================================================== */
.specimen {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.specimen-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.specimen-kicker {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 600;
}
.specimen-head h2 {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  color: var(--text-md);
}

.stage {
  position: relative;
  background: var(--bg);
  color: var(--fg);
  border-radius: var(--radius-lg);
  padding: 28px;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  font-family: var(--font-jp);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}

/* Low-contrast inline flag */
.stage-fail-flag {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 72, 52, 0.18);
  color: #ff7163;
  border: 1px solid rgba(255, 72, 52, 0.4);
  display: none;
  font-family: var(--font-sans);
}
.stage.is-low-contrast .stage-fail-flag { display: inline-block; }

/* --- Specimen 01: Now Playing UI --- */
.stage-now-playing {
  align-items: center;
  text-align: center;
  gap: 16px;
  padding: 32px 28px;
}
.np-art {
  width: 100%;
  max-width: 220px;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  background: color-mix(in srgb, var(--fg) 8%, var(--bg));
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  border: 1px solid color-mix(in srgb, var(--fg) 18%, transparent);
}
.np-art svg { width: 60%; height: 60%; color: var(--fg); }
.np-meta { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.np-title {
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 0.04em;
  font-stretch: 85%;
}
.np-artist { font-size: 12px; opacity: 0.78; }
.np-scrubber {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  max-width: 280px;
  font-size: 10px;
  opacity: 0.6;
}
.np-track {
  height: 3px;
  background: color-mix(in srgb, var(--fg) 22%, transparent);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}
.np-progress {
  position: absolute;
  inset: 0 60% 0 0;
  background: var(--fg);
  border-radius: 3px;
}
.np-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 4px;
}
.np-play {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.np-controls svg { opacity: 0.72; }

/* --- Specimen 02: Editorial Hero --- */
.stage-editorial {
  justify-content: center;
  padding: 36px 32px;
  gap: 14px;
  min-height: 320px;
}
.ed-eyebrow {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.7;
  margin: 0;
  font-weight: 600;
}
.ed-headline {
  font-size: clamp(36px, 5vw, 56px);
  font-weight: 900;
  line-height: 0.96;
  letter-spacing: -0.025em;
  margin: 0;
  font-stretch: 115%;
}
.ed-body { font-size: 14px; opacity: 0.84; margin: 4px 0 0; max-width: 360px; }
.ed-mark {
  margin-top: auto;
  display: inline-flex;
  align-items: center;
  color: var(--fg);
  opacity: 1;
}
.ed-mark svg {
  height: 50px;
  width: auto;
  display: block;
  opacity: 1;
}
.ed-mark svg path { fill: currentColor; opacity: 1; }

/* --- Specimen 03: Share Card --- */
.stage-wrapped {
  aspect-ratio: 1 / 1.05;
  min-height: 0;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 24px;
}
.wr-label {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.7;
  font-weight: 600;
}
.wr-stat {
  font-size: clamp(48px, 8vw, 88px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 0.92;
  margin: 14px 0;
  font-stretch: 75%;
}
.wr-foot {
  font-size: 12px;
  opacity: 0.7;
  font-weight: 500;
}

/* --- Specimen 04: Type Specimen --- */
.stage-type {
  gap: 14px;
  padding: 32px 28px;
}
.ts-h1 {
  font-size: clamp(40px, 5.5vw, 64px);
  font-weight: 900;
  line-height: 0.96;
  letter-spacing: -0.025em;
  margin: 0;
}
.ts-h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 6px 0 0;
}
.ts-body {
  font-size: 13px;
  line-height: 1.55;
  opacity: 0.88;
  margin: 0;
  max-width: 380px;
}
.ts-caption {
  font-size: 11px;
  opacity: 0.6;
  margin: auto 0 0;
}

/* ===========================================================
   Picker
   =========================================================== */
.picker-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 2;
}
.active-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
}
.active-toggle-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-lo);
  font-weight: 700;
}
.active-toggle-buttons {
  display: inline-flex;
  background: var(--bg-elevated);
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.t-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-md);
  padding: 6px 14px;
  border-radius: 999px;
  transition: color 0.15s, background 0.15s;
}
.t-btn.on {
  background: var(--accent);
  color: #0a1f0e;
}
.t-btn:not(.on):hover { color: var(--text-hi); }

.picker-search {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text-hi);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.picker-search::placeholder { color: var(--text-faint); }
.picker-search:focus { border-color: var(--accent); }

/* Matrix — each row is a family */
.matrix {
  padding: 12px 20px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.matrix-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}
.matrix-row-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.matrix-row-swatches {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
}

/* Individual swatch button */
.sw {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: transform 0.08s ease-out, box-shadow 0.15s;
  cursor: pointer;
  overflow: visible;
  min-height: 32px;
}
.sw:hover {
  transform: scale(1.12);
  z-index: 1;
  box-shadow: 0 0 0 2px var(--bg-surface), 0 4px 16px rgba(0, 0, 0, 0.5);
}
.sw:active { transform: scale(1.05); }
.sw.empty {
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.05);
  cursor: default;
  pointer-events: none;
}
.sw.empty:hover { transform: none; box-shadow: none; }

/* Badges showing current pair location */
.sw-badge {
  position: absolute;
  bottom: -5px;
  right: -5px;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: var(--accent);
  color: #0a1f0e;
  padding: 2px 4px;
  border-radius: 4px;
  border: 1.5px solid var(--bg-surface);
  pointer-events: none;
  line-height: 1;
}
.sw-badge.bg-badge {
  bottom: auto;
  top: -5px;
  background: var(--text-hi);
  color: #000;
}

/* Fluorescents — own block */
.fluor-section {
  margin-top: 16px;
  padding: 16px 20px 24px;
  border-top: 1px solid var(--border);
}
.fluor-title,
.picker-section-title {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-lo);
  font-weight: 700;
  margin: 0 0 10px;
}
.fluor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
}
.fluor-grid .sw { min-height: 44px; }

/* Brand essentials strip (sits above the matrix) */
.essentials-section {
  padding: 12px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.essentials {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
}
.essentials .sw {
  min-height: 52px;
  border-color: rgba(255, 255, 255, 0.16);
}

/* ===========================================================
   Footer
   =========================================================== */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-canvas);
  font-size: 11px;
  color: var(--text-lo);
}
.kbd-tip { display: flex; align-items: center; gap: 6px; }

/* ===========================================================
   Responsive
   =========================================================== */
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .picker { border-left: 0; border-top: 1px solid var(--border); }
}

@media (max-width: 720px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100vh; }
  .specimens, .picker { overflow-y: visible; }
  .pair-bar { flex-direction: column; align-items: stretch; }
  .slot { width: 100%; min-width: 0; }
  .wcag-strip { margin-left: 0; flex-wrap: wrap; }
  .chips { flex-wrap: wrap; }
  .app-footer { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* ===========================================================
   Scrollbars (webkit)
   =========================================================== */
.specimens::-webkit-scrollbar,
.picker::-webkit-scrollbar { width: 10px; height: 10px; }
.specimens::-webkit-scrollbar-track,
.picker::-webkit-scrollbar-track { background: transparent; }
.specimens::-webkit-scrollbar-thumb,
.picker::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}
.specimens::-webkit-scrollbar-thumb:hover,
.picker::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }

/* ===========================================================
   Auth gate
   =========================================================== */
body.is-anon { overflow: hidden; }
body.is-anon #app-root { display: none; }

.auth-gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(80% 80% at 50% 20%, rgba(30, 215, 96, 0.08), transparent 60%),
    radial-gradient(60% 60% at 80% 90%, rgba(64, 0, 255, 0.06), transparent 60%),
    #0a0a0a;
  z-index: 100;
}
body.is-authed .auth-gate { display: none; }

.auth-card {
  width: min(440px, 100%);
  padding: 36px 32px 28px;
  background: #131313;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.auth-card .accent-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #1ed760;
  margin-bottom: 18px;
}
.auth-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
}
.auth-sub {
  font-size: 14px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.7);
  margin: 0 0 24px;
}
.auth-sub strong { color: #1ed760; font-weight: 600; }

.auth-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 18px;
  background: #fff;
  color: #0a0a0a;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.auth-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }
.auth-btn:active { transform: translateY(0); }

.auth-error {
  margin: 16px 0 0;
  padding: 10px 14px;
  background: rgba(255, 80, 80, 0.12);
  border: 1px solid rgba(255, 80, 80, 0.3);
  color: #ffb4b4;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
}

.auth-foot {
  margin: 22px 0 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
}

/* Header auth bar (visible after sign-in) */
.auth-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
.auth-user {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.auth-signout {
  padding: 6px 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.auth-signout:hover {
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
}

@media (max-width: 720px) {
  .auth-bar { width: 100%; justify-content: flex-end; margin-top: 4px; }
}
