:root {
  --bg: #f7f1e8;
  --bg-accent: #efe4d6;
  --paper: rgba(255, 250, 244, 0.92);
  --paper-strong: #fffaf4;
  --ink: #243b5b;
  --muted: #657182;
  --line: rgba(102, 82, 71, 0.18);
  --line-strong: rgba(102, 82, 71, 0.3);
  --accent: #253b5b;
  --accent-soft: #e8e9ed;
  --accent-strong: #253b5b;
  --warn: #b94c37;
  --warn-soft: #fbe3de;
  --ok: #2e6654;
  --ok-soft: #e4efe8;
  --shadow-lg: 0 20px 50px rgba(45, 39, 45, 0.1);
  --shadow-sm: 0 10px 24px rgba(45, 39, 45, 0.07);
  --radius-xl: 24px;
  --radius-2xl: 32px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(214, 155, 87, 0.12), transparent 30%),
    linear-gradient(180deg, #fbf7f0 0%, var(--bg) 100%);
}

button,
select,
textarea,
input {
  font: inherit;
}

button,
select,
textarea,
summary {
  -webkit-tap-highlight-color: transparent;
}

.page-shell {
  width: min(100% - 24px, 1120px);
  margin: 0 auto;
  padding: 16px 0 112px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.9);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-sm);
}

.account-area { display: flex; align-items: center; gap: 8px; }
.account-area form { margin: 0; }
.account-email { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .82rem; }
.account-link { display: inline-flex; align-items: center; text-decoration: none; }
.account-area .button-secondary { white-space: nowrap; }
@media (max-width: 700px) { .account-email { display: none; } }

.auth-body { display: grid; place-items: center; padding: 20px; }
.auth-shell { width: min(100%, 480px); }
.auth-brand { display: inline-flex; align-items: center; gap: 10px; margin: 0 0 18px; color: var(--ink); font-weight: 700; text-decoration: none; }
.auth-card { padding: clamp(22px, 6vw, 36px); border: 1px solid var(--line); border-radius: var(--radius-2xl); background: var(--paper-strong); box-shadow: var(--shadow-lg); }
.auth-card h1 { margin-top: 8px; font-size: clamp(1.8rem, 7vw, 2.5rem); }
.auth-form { display: grid; gap: 10px; margin-top: 22px; }
.auth-form label { margin-top: 6px; font-weight: 700; }
.auth-form input { width: 100%; min-height: 50px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: 14px; background: #fff; color: var(--ink); }
.auth-form input:focus { outline: 3px solid rgba(214, 155, 87, .35); border-color: #d69b57; }
.auth-submit { min-height: 52px; margin-top: 12px; border: 0; border-radius: 14px; }
.auth-error { margin: 18px 0 0; padding: 12px 14px; border-radius: 14px; color: #7d2e22; background: var(--warn-soft); font-weight: 600; }
.auth-switch { margin: 20px 0 0; color: var(--muted); text-align: center; }
.auth-switch a { color: var(--accent); font-weight: 700; }

.brand-block {
  min-width: 0;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.eyebrow,
.panel-label,
.metric-label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.5rem, 4vw, 2.6rem);
  line-height: 1.02;
}

h2 {
  font-size: 1.1rem;
}

.hero-text {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.workspace {
  position: relative;
}

.results-panel {
  display: grid;
  gap: 14px;
}

.result-card,
.control-drawer {
  border: 1px solid var(--line);
  border-radius: var(--radius-2xl);
  background: var(--paper);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-lg);
}

.result-card {
  padding: 18px;
}

.status-card,
.result-card-quran {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 255, 255, 0.78)),
    linear-gradient(180deg, rgba(31, 111, 98, 0.08), transparent 70%);
}

.content-card {
  gap: 16px;
  display: grid;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-header-start {
  align-items: flex-start;
}

.meta,
.translation-output {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.status-strip {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 20px;
  background: linear-gradient(180deg, #f5faf8, #edf5f2);
  border: 1px solid rgba(31, 111, 98, 0.12);
  color: var(--ink);
  font-weight: 600;
}

.status-metadata {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.metric-chip {
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
}

.metric-value {
  display: block;
  margin-top: 6px;
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  font-weight: 600;
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.95);
  padding: 15px 16px;
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

select:focus,
textarea:focus,
button:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(31, 111, 98, 0.18);
  outline-offset: 2px;
}

textarea {
  resize: vertical;
  min-height: 188px;
  line-height: 1.65;
}

button {
  border: none;
  border-radius: 999px;
  padding: 14px 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease, opacity 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

.primary-action,
#start-live-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 24px rgba(31, 111, 98, 0.24);
}

.primary-action.is-recording,
#start-live-button.is-recording {
  background: var(--warn);
  box-shadow: 0 12px 24px rgba(185, 76, 55, 0.22);
}

.button-secondary {
  background: rgba(231, 239, 236, 0.95);
  color: var(--ink);
  border: 1px solid rgba(128, 150, 143, 0.16);
}

.button-small,
.icon-button,
.menu-button {
  padding: 11px 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 8px 12px;
  background: #edf2f0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill.neutral {
  background: #edf2f0;
  color: var(--muted);
}

.live-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.stream-label {
  margin: 0 0 8px;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.stream-box {
  min-height: 128px;
  max-height: 220px;
  overflow: auto;
  padding: 14px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  line-height: 1.7;
}

.stream-box-muted {
  color: var(--muted);
  background: rgba(244, 248, 247, 0.95);
}

.arabic-block {
  margin-top: 14px;
  padding: 20px;
  border-radius: 26px;
  border: 1px dashed rgba(31, 111, 98, 0.28);
  background: rgba(255, 255, 255, 0.72);
  font-family: "Noto Naskh Arabic", serif;
  direction: rtl;
  font-size: 1.7rem;
  line-height: 2;
}

.debug-card summary {
  cursor: pointer;
  font-weight: 700;
}

pre {
  margin: 16px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}

.info-card {
  display: none;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 29;
  background: rgba(18, 35, 31, 0.28);
  backdrop-filter: blur(6px);
}

.control-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  width: min(92vw, 380px);
  padding: 18px;
  border-radius: 32px 0 0 32px;
  transform: translateX(105%);
  transition: transform 220ms ease;
  overflow: auto;
}

.control-drawer.is-open {
  transform: translateX(0);
}

.drawer-header,
.drawer-section,
.drawer-actions {
  display: grid;
  gap: 14px;
}

.drawer-header {
  grid-template-columns: 1fr auto;
  align-items: start;
  margin-bottom: 18px;
}

.drawer-section + .drawer-section {
  margin-top: 18px;
}

.drawer-actions {
  margin-top: 24px;
}

.bottom-action-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 25;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 30px;
  background: rgba(248, 251, 250, 0.92);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-lg);
}

.secondary-inline-action {
  min-width: 110px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (min-width: 700px) {
  .page-shell {
    width: min(100% - 36px, 1120px);
    padding-top: 22px;
  }

  .topbar {
    padding: 16px 18px;
  }

  .results-panel {
    gap: 18px;
  }

  .result-card {
    padding: 22px;
  }

  .live-grid {
    grid-template-columns: 1fr 1fr;
  }

  .info-card {
    display: block;
  }
}

@media (min-width: 980px) {
  .page-shell {
    padding-bottom: 34px;
  }

  .workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
    align-items: start;
  }

  .control-drawer {
    position: sticky;
    top: 92px;
    width: auto;
    transform: none;
    border-radius: var(--radius-2xl);
  }

  .drawer-backdrop,
  .menu-button,
  .icon-button {
    display: none;
  }

  .bottom-action-bar {
    position: fixed;
    left: auto;
    right: auto;
    bottom: 12px;
    width: min(calc(100% - 36px), 1120px);
    margin-top: 18px;
  }
}

button:disabled { opacity: 0.55; cursor: default; transform: none; }
.stop-action:not(:disabled) { background: var(--warn); color: white; }
.review-card { border-color: var(--warn); background: var(--warn-soft); }
#transcript, #live-transcript-log { font-family: "Noto Naskh Arabic", serif; font-size: 1.3rem; }
.arabic-block p, .translation-output p { margin: 0 0 1rem; }
.arabic-block p:last-child, .translation-output p:last-child { margin-bottom: 0; }
.page-shell { padding-bottom: 160px; }
@media (max-width: 540px) {
  .bottom-action-bar { grid-template-columns: 1fr 1fr; }
  .bottom-action-bar .primary-action { grid-column: 1 / -1; }
  .brand-row { flex-wrap: nowrap; gap: 8px; }
  .topbar { border-radius: 18px; padding: 10px 12px; }
  .hero-text { display: none; }
  h1 { font-size: 1.2rem; }
  .eyebrow { font-size: 0.6rem; }
  .brand-row .pill { min-height: 24px; padding: 4px 8px; font-size: 0.75rem; }
  #transcript { height: 188px; }
}

.bottom-action-bar { grid-template-columns: 1fr 1fr; }
@media (max-width: 540px) { .bottom-action-bar .primary-action { grid-column: auto; } }

/* Task-first navigation for narrow screens and the future app shell. */
.page-shell { max-width: 760px; }
.topbar { position: static; border-radius: 22px; justify-content: flex-start; }
.brand-icon { width: 44px; height: 44px; flex: none; border-radius: 12px; }
.topbar .home-link { margin-left: auto; }
.home-link { flex: 0 0 auto; }
.entry-screen, .setup-screen { padding: clamp(22px, 5vw, 42px); background: var(--paper-strong); border: 1px solid var(--line); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm); }
.entry-screen { display: flex; flex-direction: column; min-height: min(740px, calc(100dvh - 155px)); background: transparent; border: 0; box-shadow: none; }
.home-lead { margin: auto 0 28px; }
.home-lead h2 { max-width: 560px; margin: 12px 0; font-size: clamp(2.35rem, 7vw, 3.8rem); line-height: 1.08; letter-spacing: -.035em; font-weight: 600; }
.home-lead p:last-child { color: var(--muted); line-height: 1.55; margin: 16px 0 0; }
.accent-rule { display: block; width: 52px; height: 4px; border-radius: 5px; background: #d69b57; }
.entry-screen h2, .setup-screen h2 { margin: 8px 0 18px; font-size: clamp(1.5rem, 4vw, 2rem); }
.entry-actions { display: grid; gap: 10px; }
.entry-action { display: flex; flex-direction: column; gap: 6px; width: 100%; padding: 20px; border: 1px solid var(--line-strong); border-radius: 20px; background: var(--paper-strong); color: var(--ink); text-align: left; text-decoration: none; box-shadow: var(--shadow-sm); }
.entry-action strong { font-size: 1.15rem; }
.entry-action span { color: var(--muted); font-size: .95rem; line-height: 1.45; font-weight: 400; }
.entry-primary { min-height: 112px; justify-content: center; background: var(--accent); border-color: var(--accent); color: #fff; }
.entry-primary span { color: #e9d9c8; }
.entry-action:focus-visible, .recent-actions a:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.recent-session { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line-strong); }
.recent-session p:not(.panel-label) { line-height: 1.5; }
.recent-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.recent-actions a { display: inline-flex; align-items: center; padding: 12px 18px; border-radius: 999px; text-decoration: none; font-weight: 700; }
.setup-screen .control-drawer { display: block; position: static; width: 100%; padding: 0; margin: 22px 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; transform: none; overflow: visible; }
.setup-screen .drawer-header, .setup-screen .drawer-section.text-settings, .setup-screen .drawer-actions.text-settings { display: none; }
.setup-screen .drawer-section { display: grid; gap: 18px; }
.setup-screen .advanced-options { padding-top: 8px; }
.advanced-options summary { color: var(--accent-strong); font-weight: 700; }
.advanced-options .field { margin-top: 16px; }
.setup-cta { width: 100%; min-height: 54px; }
.setup-screen #setup-readiness { margin-top: 14px; }
.text-intro { display: grid; gap: 8px; padding: 4px 4px 10px; }
.text-intro select { max-width: 320px; }
#text-screen { display: block; }
#text-screen .results-panel { display: grid; }
#text-screen .status-card, #text-screen .info-card, #text-screen .live-grid { display: none; }
#text-screen .control-drawer { display: block; position: static; width: 100%; padding: 0; margin-top: 14px; border: 0; border-radius: 0; background: transparent; box-shadow: none; transform: none; overflow: visible; }
#text-screen .drawer-header, #text-screen .control-drawer > .drawer-section:not(.text-settings), #text-screen .drawer-actions { display: none; }
#text-screen .text-settings { display: block; }
#text-screen .drawer-section.text-settings { margin: 0; }
#text-screen .drawer-section.text-settings summary { font-weight: 700; color: var(--accent-strong); padding: 10px 0; }
#text-screen .drawer-section.text-settings .field { margin-top: 8px; }
#text-actions { grid-template-columns: 1fr; width: min(calc(100% - 24px), 736px); left: 50%; right: auto; transform: translateX(-50%); bottom: max(12px, env(safe-area-inset-bottom)); }
#text-actions .primary-action { grid-column: auto; min-height: 50px; }
@media (max-width: 540px) {
  .page-shell { padding-bottom: 100px; }
  .entry-screen, .setup-screen { padding: 22px 18px; }
  .entry-action { min-height: 86px; }
  .topbar { margin-bottom: 12px; }
}

.eyebrow, .panel-label { color: #9d663a; }
.entry-action:not(.entry-primary) { background: var(--paper-strong); }
.button-secondary { background: #efe7dc; border-color: var(--line); }
.result-card, .setup-screen { background: var(--paper-strong); }
.status-card, .result-card-quran { background: var(--paper-strong); }
.status-strip { background: #f3ece2; border-color: var(--line); }
.metric-chip, select, textarea, .stream-box, .arabic-block { background: #fffdf9; }
.arabic-block { border-color: #d4b184; }
.stream-box-muted { background: #f5eee6; }
.pill.neutral, .pill { background: #eee8e0; }
.bottom-action-bar { background: rgba(255, 250, 244, .95); }
.primary-action, #start-live-button { box-shadow: 0 12px 24px rgba(37, 59, 91, .18); }
.button-secondary:hover { background: #e7d9c8; }
select:focus, textarea:focus, button:focus-visible, summary:focus-visible { outline-color: rgba(214, 155, 87, .65); }
.setup-screen .advanced-options summary, #text-screen .drawer-section.text-settings summary { color: var(--accent); }
@media (max-width: 540px) {
  .home-lead { margin: auto 0 26px; }
  .home-lead h2 { font-size: clamp(2.2rem, 10vw, 3rem); }
  .entry-screen { min-height: calc(100dvh - 130px); }
  .entry-action:not(.entry-primary) { min-height: 70px; padding: 14px 18px; }
  .entry-action:not(.entry-primary) span { font-size: .84rem; }
}
