:root {
  color-scheme: light;
  --ink: #13203f;
  --midnight: #18245c;
  --lapis: #314aa4;
  --turquoise: #16a99b;
  --turquoise-soft: #d9f3ef;
  --saffron: #c8922f;
  --paper: #f7f8fb;
  --white: #ffffff;
  --muted: #69738e;
  --line: #dfe4ef;
  --danger: #a4344a;
  --shadow: 0 24px 70px rgba(22, 35, 86, 0.12);
  --radius: 28px;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(49, 74, 164, 0.09), transparent 28rem),
    radial-gradient(circle at 100% 30%, rgba(22, 169, 155, 0.08), transparent 24rem),
    var(--paper);
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.page-shell { width: min(100%, 1120px); margin: 0 auto; padding: 0 28px; }

.site-header {
  min-height: 98px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid rgba(49, 74, 164, 0.12);
}

.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  aspect-ratio: 1;
  border: 1px solid rgba(49, 74, 164, 0.28);
  border-radius: 50%;
  color: var(--lapis);
  font-size: 24px;
  background: rgba(255, 255, 255, 0.65);
}
.brand strong { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 20px; letter-spacing: -0.02em; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; letter-spacing: 0.15em; text-transform: uppercase; }

.corpus-status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.corpus-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--saffron); box-shadow: 0 0 0 4px rgba(200, 146, 47, 0.12); }
.corpus-status.ready i { background: var(--turquoise); box-shadow: 0 0 0 4px rgba(22, 169, 155, 0.13); }

.listen-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 0.8fr);
  grid-template-rows: auto auto;
  column-gap: 70px;
  align-items: center;
  min-height: 620px;
  padding: 72px 0 58px;
}

.intro-copy { align-self: center; }
.eyebrow { margin: 0 0 16px; color: var(--lapis); font-size: 11px; font-weight: 700; letter-spacing: 0.19em; text-transform: uppercase; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; letter-spacing: -0.045em; }
h1 { max-width: 650px; margin: 0; font-size: clamp(52px, 7vw, 86px); line-height: 0.95; }
h1 em { color: var(--lapis); font-weight: 400; }
.lede { max-width: 550px; margin: 30px 0 0; color: var(--muted); font-size: 17px; line-height: 1.75; }

.recorder-stage { position: relative; display: grid; place-items: center; min-height: 380px; isolation: isolate; }
.orbit { position: absolute; border-radius: 50%; border: 1px solid rgba(49, 74, 164, 0.12); pointer-events: none; }
.orbit-one { width: 310px; height: 310px; }
.orbit-two { width: 236px; height: 236px; border-style: dashed; border-color: rgba(22, 169, 155, 0.24); animation: orbit 28s linear infinite; }

#waveform {
  position: absolute;
  width: min(100%, 380px);
  height: auto;
  aspect-ratio: 1;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 360ms ease, transform 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
  pointer-events: none;
  z-index: 1;
}
.is-recording #waveform { opacity: 1; transform: scale(1); }

.record-button {
  position: relative;
  display: grid;
  place-items: center;
  gap: 12px;
  width: 180px;
  height: 180px;
  padding: 24px;
  border: 0;
  border-radius: 50%;
  color: var(--white);
  background: linear-gradient(145deg, #263b94, var(--midnight));
  box-shadow: 0 18px 48px rgba(24, 36, 92, 0.28), inset 0 1px 1px rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease;
  z-index: 2;
}
.record-button:hover { transform: translateY(-3px); box-shadow: 0 24px 58px rgba(24, 36, 92, 0.34), inset 0 1px 1px rgba(255, 255, 255, 0.3); }
.record-button:active { transform: scale(0.97); }
.record-button:focus-visible { outline: 4px solid rgba(22, 169, 155, 0.42); outline-offset: 6px; }
.record-button:disabled { cursor: wait; opacity: 0.85; }
.record-icon { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 50%; background: rgba(255, 255, 255, 0.12); }
.record-icon svg { width: 27px; fill: currentColor; }
.record-label { font-size: 13px; font-weight: 700; letter-spacing: 0.035em; }
.is-recording .record-button {
  transform: scale(var(--voice-scale, 1));
  background: linear-gradient(145deg, #bc3e58, #8f2942);
  box-shadow:
    0 18px 48px rgba(143, 41, 66, calc(0.28 + var(--voice-energy, 0) * 0.14)),
    0 0 0 calc(var(--voice-energy, 0) * 12px) rgba(188, 62, 88, calc(var(--voice-energy, 0) * 0.09)),
    inset 0 1px 1px rgba(255, 255, 255, 0.28);
}
.is-recording .record-icon svg { transform: scale(0.55); }
.is-processing .record-button { background: linear-gradient(145deg, #2b499f, #203170); }

.record-meta { grid-column: 2; display: flex; justify-content: center; align-items: center; gap: 18px; margin-top: -50px; color: var(--muted); font-size: 12px; }
.record-meta p { margin: 0; }
.record-meta time { min-width: 45px; padding-left: 16px; border-left: 1px solid var(--line); color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 700; }
.notice { grid-column: 1 / -1; width: min(100%, 680px); margin: 22px auto 0; padding: 14px 18px; border: 1px solid #f0c7d0; border-radius: 14px; color: var(--danger); background: #fff5f7; text-align: center; font-size: 14px; }

.results-section { padding: 72px 0 30px; border-top: 1px solid rgba(49, 74, 164, 0.12); }
.transcript-card { padding: 24px 28px; border: 1px solid rgba(22, 169, 155, 0.23); border-radius: 20px; background: linear-gradient(100deg, rgba(217, 243, 239, 0.68), rgba(255, 255, 255, 0.86)); }
.transcript-card span { color: var(--turquoise); font-size: 10px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
.transcript-card p { margin: 8px 0 0; font-family: "Noto Naskh Arabic", "Geeza Pro", "Times New Roman", serif; font-size: clamp(25px, 4vw, 38px); line-height: 1.75; }
.results-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 50px 0 22px; }
.results-heading .eyebrow { margin-bottom: 8px; }
.results-heading h2 { margin: 0; font-size: clamp(36px, 5vw, 54px); }
.results-heading > span { color: var(--muted); font-size: 12px; }
.match-list { display: grid; gap: 16px; }
.match-card {
  position: relative;
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 38px;
  gap: 26px;
  align-items: start;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 22px;
  color: inherit;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 30px rgba(22, 35, 86, 0.045);
  text-decoration: none;
  transition: border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}
.match-card:hover { transform: translateY(-2px); border-color: rgba(49, 74, 164, 0.36); box-shadow: var(--shadow); }
.match-card:focus-visible { outline: 3px solid rgba(22, 169, 155, 0.42); outline-offset: 3px; }
.match-card.best { border-color: rgba(49, 74, 164, 0.35); background: linear-gradient(105deg, rgba(255, 255, 255, 0.98), rgba(239, 242, 252, 0.9)); }
.match-rank { color: var(--muted); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; }
.match-rank strong { display: block; margin: 9px 0 3px; color: var(--lapis); font-family: Georgia, "Times New Roman", serif; font-size: 28px; font-weight: 400; letter-spacing: -0.03em; }
.match-rank small { display: block; color: var(--muted); font-size: 10px; letter-spacing: 0.05em; text-transform: none; }
.match-arabic { margin: 0; font-family: "Noto Naskh Arabic", "Geeza Pro", "Times New Roman", serif; font-size: clamp(24px, 3vw, 33px); line-height: 1.9; text-align: right; }
.match-english { margin: 14px 0 0; color: var(--muted); font-family: Georgia, "Times New Roman", serif; font-size: 15px; line-height: 1.65; }
.match-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.match-meta span { padding: 5px 9px; border-radius: 999px; color: #53607c; background: #f0f2f8; font-size: 10px; }
.match-arrow { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: var(--lapis); background: #eef1fb; font-size: 18px; }
.match-score { position: absolute; top: 0; right: 72px; padding: 5px 11px; border-radius: 0 0 10px 10px; color: var(--turquoise); background: var(--turquoise-soft); font-size: 10px; font-weight: 800; }

footer { padding: 24px 0 38px; border-top: 1px solid rgba(49, 74, 164, 0.12); color: var(--muted); text-align: center; font-size: 11px; letter-spacing: 0.08em; }

@keyframes orbit { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .page-shell { padding: 0 20px; }
  .site-header { min-height: 82px; }
  .corpus-status span { display: none; }
  .listen-panel { grid-template-columns: 1fr; grid-template-rows: auto auto auto auto; min-height: auto; padding: 54px 0 48px; }
  .intro-copy { text-align: center; }
  h1 { font-size: clamp(46px, 14vw, 70px); }
  .lede { margin: 24px auto 0; font-size: 15px; }
  .recorder-stage { min-height: 335px; }
  .orbit-one { width: 280px; height: 280px; }
  .orbit-two { width: 220px; height: 220px; }
  .record-button { width: 166px; height: 166px; }
  #waveform { width: min(100%, 340px); }
  .record-meta { grid-column: 1; margin-top: -32px; }
  .notice { grid-column: 1; }
  .results-section { padding-top: 54px; }
  .match-card { grid-template-columns: 82px minmax(0, 1fr) 32px; gap: 16px; padding: 22px 18px; }
  .match-rank strong { font-size: 23px; }
}

@media (max-width: 560px) {
  .page-shell { padding: 0 16px; }
  .brand-mark { width: 39px; }
  .brand strong { font-size: 18px; }
  .brand small { font-size: 8px; }
  .listen-panel { padding-top: 42px; }
  .eyebrow { font-size: 9px; }
  h1 { font-size: clamp(44px, 14vw, 61px); }
  .recorder-stage { min-height: 310px; }
  .orbit-one { width: 254px; height: 254px; }
  .orbit-two { width: 200px; height: 200px; }
  .record-button { width: 152px; height: 152px; }
  #waveform { width: min(100%, 306px); }
  .record-meta p { max-width: 225px; }
  .results-heading { align-items: flex-start; margin-top: 38px; }
  .results-heading > span { margin-top: 8px; }
  .transcript-card { padding: 20px; }
  .match-card { grid-template-columns: 1fr 32px; }
  .match-rank { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 8px; }
  .match-rank strong { display: inline; margin: 0; }
  .match-rank small { display: inline; }
  .match-content { grid-column: 1; }
  .match-arrow { grid-column: 2; grid-row: 2; }
  .match-score { right: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
