/* Image2Genre — dark UI, bilingual (LTR/RTL).
   Mirroring is done with CSS logical properties (inline-start/end, padding-inline),
   so the RTL layout falls out of dir="rtl" rather than a separate stylesheet. */

:root {
  --bg: #0A0B0D;
  --surface: #101216;
  --panel: #111318;
  --raised: #14171C;
  --line: #1E2127;
  --line-soft: #1A1D22;
  --border: #23262C;

  --text: #EDEEF0;
  --text-2: #969CA6;
  --text-3: #6B717B;
  --text-4: #4E545C;

  --accent: #5AC8E0;          /* overridden inline per prediction */

  --font-display: 'Space Grotesk', 'Helvetica Neue', sans-serif;
  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;

  --r-sm: 7px; --r-md: 10px; --r-lg: 12px; --r-xl: 14px; --r-2xl: 18px;
  --gutter: 32px;
  --header-h: 60px;
}

/* Arabic: one superfamily switch, no letter-spacing (it breaks cursive joining),
   and more leading for descenders and diacritics. */
[data-lang="ar"] {
  --font-sans: 'IBM Plex Sans Arabic', 'IBM Plex Sans', system-ui, sans-serif;
  --font-display: 'IBM Plex Sans Arabic', 'Space Grotesk', sans-serif;
}

* { box-sizing: border-box; }

/* The hidden attribute is only display:none in the UA stylesheet, so ANY author
   rule that sets display beats it. .analyzing sets display:grid and #submit-btn
   is an inline-flex .btn-primary -- without this both render regardless of the
   attribute, and the fixed full-viewport overlay covers the whole app. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text-2); text-decoration: none; }
a:hover { color: var(--text); }

img { max-width: 100%; display: block; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.mono { font-family: var(--font-mono); }
.muted { color: var(--text-3); }

.sep {
  display: inline-block; width: 3px; height: 3px; border-radius: 50%;
  background: #333840; vertical-align: middle;
}
.rule { width: 1px; height: 16px; background: var(--border); }

/* ---------- small mono label; in Arabic it becomes weight-differentiated ---------- */
.eyebrow {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--text-3);
}
.eyebrow--accent { color: var(--accent); }
[data-lang="ar"] .eyebrow {
  font-family: var(--font-sans); font-size: 11.5px; font-weight: 500;
  letter-spacing: 0; text-transform: none;
}

.chip-mono { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.09em; color: #5E646E; }
[data-lang="ar"] .chip-mono { font-family: var(--font-sans); font-size: 12px; letter-spacing: 0; }

/* ------------------------------- topbar ------------------------------- */
.topbar {
  height: var(--header-h); display: flex; align-items: center; justify-content: space-between;
  padding-inline: var(--gutter); border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 11px; color: var(--text); }
.brand:hover { color: var(--text); }
.brand__mark { flex: none; }
.brand__name { font-family: var(--font-display); font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
[data-lang="ar"] .brand__name { font-family: 'Space Grotesk', sans-serif; }

.topbar__end { display: flex; align-items: center; gap: 10px; }

.lang {
  min-width: 34px; height: 28px; padding-inline: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 500; color: var(--text-2);
}
.lang:hover { border-color: #343A42; color: var(--text); }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding-inline: 14px;
  border: 1px solid #2A2E35; border-radius: 8px; font-size: 12.5px; font-weight: 500; color: #C9CDD3;
}
.btn-ghost:hover { border-color: #3A4048; color: var(--text); }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  height: 46px; padding-inline: 26px; border-radius: 11px;
  background: var(--accent); color: #06222A; font-size: 14.5px; font-weight: 600;
}
.btn-primary--wide { width: 100%; margin-top: 14px; }

.alert {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin: 16px var(--gutter) 0; padding: 12px 14px;
  border: 1px solid #4A2328; border-radius: var(--r-md);
  background: #1A1013; color: #E7A9A9; font-size: 13px;
}

/* ------------------------------- landing ------------------------------- */
.landing {
  display: grid; grid-template-columns: minmax(0, 512px) minmax(0, 1fr);
  align-items: center; gap: 72px;
  padding: 56px var(--gutter);
  min-height: calc(100vh - var(--header-h));
}
.landing__copy { position: relative; z-index: 1; }

.hero {
  margin: 18px 0 0; font-family: var(--font-display);
  font-size: clamp(38px, 4.2vw, 60px); line-height: 1.0; font-weight: 700;
  letter-spacing: -0.035em; color: #F2F4F6; white-space: pre-line; text-wrap: pretty;
}
[data-lang="ar"] .hero { letter-spacing: 0; line-height: 1.45; font-size: clamp(34px, 3.6vw, 50px); }

.hero__body { margin: 24px 0 0; max-width: 44ch; font-size: 15px; line-height: 1.66; color: var(--text-2); text-wrap: pretty; }
[data-lang="ar"] .hero__body { line-height: 1.95; }

.vibes { margin-top: 40px; }
.vibes__list { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; padding: 0; list-style: none; }
.vibe {
  display: inline-flex; align-items: center; gap: 8px; height: 30px; padding-inline: 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  font-size: 12.5px; color: #B9BEC6;
}
.vibe__dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }

.drop__zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 424px; padding: 32px; text-align: center;
  border: 1.5px dashed #2C3138; border-radius: 20px;
  background: color-mix(in oklab, var(--accent) 4%, transparent);
  cursor: pointer; transition: border-color .18s ease, background .18s ease;
}
.drop__zone:hover, .drop__zone.is-over { border-color: var(--accent); background: color-mix(in oklab, var(--accent) 9%, transparent); }
.drop__icon {
  width: 76px; height: 76px; display: grid; place-items: center;
  border: 1px solid #262A31; border-radius: 20px; background: var(--raised);
}
.drop__title { margin-top: 22px; font-family: var(--font-display); font-size: 21px; font-weight: 600; letter-spacing: -0.015em; }
[data-lang="ar"] .drop__title { letter-spacing: 0; line-height: 1.6; }
.drop__or { margin-top: 9px; font-size: 13.5px; color: var(--text-3); }
.drop__zone .btn-primary { margin-top: 16px; }
.drop__formats { margin-top: 26px; display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-mono); font-size: 10.5px; color: #565C65; }
.drop__privacy { display: flex; align-items: center; gap: 9px; margin: 16px 4px 0; font-size: 12px; color: var(--text-3); }
.drop__privacy svg { flex: none; color: #565C65; }
.drop__zone.has-file .drop__title { color: var(--accent); }

/* ------------------------------- results ------------------------------- */
.results { padding: 24px var(--gutter) 28px; display: grid; gap: 22px; align-content: start; }

/* Grid and flex items default to min-width:auto, i.e. they refuse to shrink
   below their content. The playlist rail's min-content is the full width of all
   its cards (7 x 152 + gaps = 1160px), so without this it stretched the whole
   grid and dragged the image frames out to 1160px inside a 390px phone. The
   overflow-x on .rail__strip cannot fix that -- the constraint is on the items. */
.results > *, .stage > *, .frames > *, .rail > * { min-width: 0; }

.stage { display: grid; grid-template-columns: minmax(0, 1fr) 476px; gap: 28px; min-height: 0; min-width: 0; }

.frames { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; min-height: 0; }
.frames__tabs { display: none; }

.frame { margin: 0; display: flex; flex-direction: column; min-height: 0; }
.frame__label { display: flex; align-items: center; gap: 8px; height: 24px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase; color: #7B818B; }
.frame__label--accent { color: var(--accent); }
[data-lang="ar"] .frame__label { font-family: var(--font-sans); font-size: 11.5px; font-weight: 500; letter-spacing: 0; text-transform: none; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: #4A5058; flex: none; }
.dot--accent { background: var(--accent); }

.frame__media {
  position: relative; margin-top: 10px; flex: 1; min-height: 0;
  border-radius: var(--r-xl); overflow: hidden; background: #0D0F13;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
}
/* contain, not cover: this is a before/after comparison, so cropping hides the
   very regions the heatmap is there to point at. */
.frame__media img { width: 100%; height: 100%; object-fit: contain; }

.scale {
  position: absolute; inset-inline-end: 14px; top: 14px;
  display: flex; align-items: center; gap: 8px; height: 26px; padding-inline: 10px;
  border-radius: var(--r-sm); background: rgba(8, 10, 14, .72); border: 1px solid rgba(255, 255, 255, .10);
  font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .07em; text-transform: uppercase; color: #C9CDD3;
}
[data-lang="ar"] .scale { font-family: var(--font-sans); font-size: 10.5px; letter-spacing: 0; text-transform: none; }
.scale__bar {
  width: 74px; height: 5px; border-radius: 3px;
  background: linear-gradient(to right, #0033CC, #00A6FF, #43E07A, #FFD400, #FF7A00, #E8180C);
}
/* JET runs blue→red regardless of reading direction: don't mirror the ramp. */
[dir="rtl"] .scale__bar { transform: scaleX(-1); }

.frame__meta {
  height: 44px; margin-top: 10px; display: flex; align-items: center; gap: 10px;
  padding-inline: 14px; border: 1px solid var(--line-soft); border-radius: var(--r-md);
  background: var(--surface); font-family: var(--font-mono); font-size: 10.5px; color: var(--text-3);
}
[data-lang="ar"] .frame__meta { font-family: var(--font-sans); font-size: 11.5px; }
.frame__meta .mono { font-family: var(--font-mono); }

/* ------------------------------- verdict ------------------------------- */
.verdict {
  border: 1px solid var(--line); border-radius: var(--r-2xl); background: var(--panel);
  padding: 26px; display: flex; flex-direction: column; min-height: 0; overflow: auto;
}
.verdict__genre {
  margin: 10px 0 0; font-family: var(--font-display);
  font-size: 52px; line-height: 1; font-weight: 700; letter-spacing: -0.025em; color: var(--accent);
}
[data-lang="ar"] .verdict__genre { font-size: 46px; line-height: 1.35; letter-spacing: 0; margin-top: 8px; }
.verdict__desc { margin: 8px 0 0; font-size: 13.5px; line-height: 1.5; color: var(--text-2); text-wrap: pretty; }
[data-lang="ar"] .verdict__desc { line-height: 1.72; }

.dist { margin-top: 20px; }
.dist__list { margin: 12px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.dist__row { display: flex; align-items: center; gap: 12px; height: 18px; color: var(--text-3); font-size: 12.5px; }
.dist__row.is-top { color: #E4E7EA; }
.dist__name { width: 76px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dist__track { flex: 1; height: 6px; border-radius: 3px; background: #1D2026; overflow: hidden; }
.dist__track i { display: block; height: 6px; border-radius: 3px; background: #3A4048; }
.dist__row.is-top .dist__track i { background: var(--accent); }
.dist__pct { width: 38px; flex: none; text-align: end; font-family: var(--font-mono); font-size: 11px; }

.hr { height: 1px; border: 0; background: var(--line); margin: 16px 0; }

.explain { display: flex; flex-direction: column; gap: 18px; }
.explain__block--accent .eyebrow { color: var(--accent); }
.explain p { margin: 8px 0 0; font-size: 13px; line-height: 1.48; color: #C4C9D0; text-wrap: pretty; }
[data-lang="ar"] .explain p { line-height: 1.72; }

/* -------------------------------- rail -------------------------------- */
.rail { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.rail__head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.rail__title { display: flex; align-items: baseline; gap: 12px; }
.rail__title h2 { margin: 0; font-family: var(--font-display); font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
[data-lang="ar"] .rail__title h2 { letter-spacing: 0; font-size: 17px; }
.rail__controls { display: flex; align-items: center; gap: 14px; }

.seg { display: flex; padding: 3px; border-radius: 9px; background: var(--raised); border: 1px solid var(--line); }
.seg__btn { height: 26px; padding-inline: 15px; border-radius: 6px; font-size: 12.5px; font-weight: 500; color: #7B818B; }
.seg__btn.is-active { background: color-mix(in oklab, var(--accent) 14%, transparent); color: var(--accent); }

.arrows { display: flex; gap: 7px; }
.arrow { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 8px; color: #7B818B; }
.arrow:hover { border-color: #3A4048; color: var(--text); }

.rail__strip {
  display: flex; gap: 16px; margin-top: 14px; min-height: 0;
  overflow-x: auto; overflow-y: hidden; scroll-behavior: smooth;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.rail__strip::-webkit-scrollbar { display: none; }
.rail[data-tab="original"] .rail__strip[data-group="khaleeji"],
.rail[data-tab="khaleeji"] .rail__strip[data-group="original"] { display: none; }

.card {
  width: 188px; flex: none; scroll-snap-align: start;
  border: 1px solid #1C1F25; border-radius: var(--r-lg); background: var(--panel); overflow: hidden;
}
.card__poster { position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; padding: 0; overflow: hidden; }
.card__poster img { width: 100%; height: 100%; object-fit: cover; }
.card__poster::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(6, 8, 11, .62), rgba(6, 8, 11, .06)); }
.card__play {
  position: absolute; inset-inline-start: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%;
  background: rgba(10, 12, 16, .66); border: 1px solid rgba(255, 255, 255, .20); color: #F2F4F6; z-index: 1;
}
[dir="rtl"] .card__play { transform: translate(50%, -50%); }
.card__poster:hover .card__play { background: var(--accent); color: #06222A; border-color: transparent; }
.card__frame { width: 100%; aspect-ratio: 16 / 9; border: 0; display: block; }
.card__body { padding: 11px 12px 13px; }
.card__title {
  display: block; font-size: 12.5px; line-height: 1.28; font-weight: 500; color: #E4E7EA;
  max-height: 2.56em; overflow: hidden;
}
.card__title:hover { color: var(--accent); }
.card__channel { display: block; margin-top: 5px; font-size: 11.5px; color: #767C86; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.rail__note { margin: 12px 0 0; font-size: 11.5px; line-height: 1.5; color: var(--text-4); max-width: 90ch; }

/* ------------------------------ analyzing ------------------------------ */
.analyzing { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; place-items: center; padding: var(--gutter); }
.analyzing__inner { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 40px; align-items: center; width: min(1100px, 100%); }
.analyzing__preview .frame__media { aspect-ratio: 4 / 3; margin: 0; }
.analyzing__title { margin: 12px 0 0; font-family: var(--font-display); font-size: 30px; line-height: 1.2; font-weight: 600; letter-spacing: -0.02em; white-space: pre-line; }
[data-lang="ar"] .analyzing__title { letter-spacing: 0; line-height: 1.55; font-size: 28px; }

.scanline {
  position: absolute; inset-inline: 0; height: 30%;
  background: linear-gradient(to bottom, transparent, color-mix(in oklab, var(--accent) 18%, transparent) 62%, color-mix(in oklab, var(--accent) 58%, transparent) 96%, transparent);
  animation: sweep 2.6s cubic-bezier(.45, 0, .55, 1) infinite;
}
@keyframes sweep { 0% { top: -30%; } 100% { top: 100%; } }

.progress { height: 4px; margin-top: 26px; border-radius: 2px; background: #1D2026; overflow: hidden; }
.progress i { display: block; height: 4px; width: 4%; border-radius: 2px; background: var(--accent); transition: width .6s ease; }

.steps { margin: 30px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 20px; }
.step { display: flex; gap: 14px; align-items: flex-start; }
.step__mark { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 1.5px solid var(--border); }
.step__text b { display: block; font-size: 14px; font-weight: 500; color: var(--text-4); }
.step__text em { display: block; margin-top: 3px; font-size: 12.5px; line-height: 1.45; font-style: normal; color: #3E444C; }
.step.is-active .step__mark { border-color: var(--accent); border-top-color: transparent; animation: spin 1.1s linear infinite; }
.step.is-active .step__text b { color: var(--text); }
.step.is-active .step__text em { color: #7B818B; }
.step.is-done .step__mark { border-color: transparent; background: #17403C; }
.step.is-done .step__text b { color: #C4C9D0; }
.step.is-done .step__text em { color: var(--text-3); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .scanline, .step.is-active .step__mark { animation: none; }
  .rail__strip { scroll-behavior: auto; }
}

/* ------------------------------ desktop fit ----------------------------- */
/* The whole result fits one viewport where there's room for it; below that,
   scrolling is the honest answer rather than a squashed layout. */
@media (min-width: 1100px) and (min-height: 780px) {
  body:has(.results) { height: 100vh; overflow: hidden; }
  .results { height: calc(100vh - var(--header-h)); grid-template-rows: minmax(0, 1fr) 248px; }
}

/* ------------------------------- narrow -------------------------------- */
@media (max-width: 1099px) {
  :root { --gutter: 20px; }
  .landing { grid-template-columns: minmax(0, 1fr); gap: 40px; padding-block: 36px; }
  .stage { grid-template-columns: minmax(0, 1fr); }
  .verdict { overflow: visible; }

  /* One image at a time, switched by the tabs, instead of two tiny ones. */
  .frames { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .frames__tabs {
    display: flex; padding: 3px; margin-bottom: 12px;
    border-radius: var(--r-md); background: var(--raised); border: 1px solid var(--line);
  }
  .frames__tab { flex: 1; min-height: 44px; border-radius: var(--r-sm); font-size: 13px; font-weight: 500; color: #7B818B; }
  .frames__tab.is-active { background: #22262C; color: #E9EBEE; }
  .frame__label { display: none; }
  .frame__media { aspect-ratio: 4 / 3; }
  .frames[data-frame="source"] .frame[data-kind="cam"],
  .frames[data-frame="cam"] .frame[data-kind="source"] { display: none; }

  .analyzing__inner { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .analyzing__preview { display: none; }
}

@media (max-width: 560px) {
  .verdict { padding: 18px; }
  .verdict__genre { font-size: 38px; }
  [data-lang="ar"] .verdict__genre { font-size: 34px; }
  .topbar { padding-inline: 16px; }
  .topbar .chip-mono, .topbar .rule { display: none; }
  .frame__meta { overflow-x: auto; }
  .card { width: 152px; }
}
