:root {
  color-scheme: light;
  --ink: #17191c;
  --muted: #687079;
  --line: #d9dde1;
  --soft: #f4f6f7;
  --paper: #ffffff;
  --signal: #14735b;
  --signal-dark: #0d5946;
  --accent: #d94b36;
  --focus: #1f6feb;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--soft);
  color: var(--ink);
}

button, select, textarea, input { font: inherit; }
button, select, input[type="range"] { cursor: pointer; }

.topbar {
  height: 64px;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ink);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-size: 16px;
  font-weight: 750;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
}

.service-state {
  color: #b9c0c7;
  font-size: 13px;
  font-weight: 650;
}

.service-state i {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: #858b92;
}

.service-state.online { color: #dcebe5; }
.service-state.online i { background: #56d39b; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.logout-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #555b61;
  background: transparent;
  color: #dce0e3;
  font-size: 12px;
  font-weight: 700;
}
.logout-button:hover { border-color: #9ba1a6; color: #fff; }

.workspace {
  width: min(1180px, calc(100% - 48px));
  min-height: 650px;
  margin: 42px auto;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(330px, 0.75fr);
  background: var(--paper);
  border: 1px solid var(--line);
}

.composer { padding: 40px; }
.output {
  min-width: 0;
  padding: 32px;
  border-left: 1px solid var(--line);
  background: #f9fafb;
}

.heading-row, .output-head, .action-row, footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--signal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 38px;
  line-height: 1.08;
  letter-spacing: 0;
}

.queue-state {
  min-width: 82px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.field-group {
  display: grid;
  gap: 9px;
  margin-top: 28px;
}

.field-label {
  color: #42484e;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.field-label output {
  float: right;
  color: var(--signal);
}

.segmented {
  width: 250px;
  height: 42px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid #bfc5ca;
}

.segment {
  border: 0;
  background: #fff;
  color: #42484e;
  font-weight: 700;
}

.segment + .segment { border-left: 1px solid #bfc5ca; }
.segment.active { background: var(--ink); color: #fff; }

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.7fr);
  gap: 22px;
}

select, textarea {
  width: 100%;
  border: 1px solid #bfc5ca;
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input[type="password"] {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  border: 1px solid #bfc5ca;
  border-radius: 0;
  background: #fff;
  color: var(--ink);
}

select { height: 44px; padding: 0 12px; }
textarea {
  min-height: 230px;
  resize: vertical;
  padding: 16px;
  font-size: 17px;
  line-height: 1.7;
}

textarea[dir="rtl"] {
  font-family: "Noto Nastaliq Urdu", "Noto Sans Arabic", Tahoma, sans-serif;
  font-size: 20px;
  line-height: 2;
}

select:focus, textarea:focus, input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent);
  outline-offset: 2px;
}

.speed-field input { width: 100%; accent-color: var(--signal); }
.text-field { position: relative; }
.character-count {
  position: absolute;
  right: 12px;
  bottom: 10px;
  padding: 2px 5px;
  background: rgba(255,255,255,.92);
  color: var(--muted);
  font-size: 11px;
}

.action-row { min-height: 58px; margin-top: 22px; gap: 18px; }
.conversion-panel {
  display: grid;
  gap: 9px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #f9fafb;
}

.conversion-head, .history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.conversion-state {
  color: var(--signal);
  font-size: 12px;
  font-weight: 700;
}

.conversion-panel textarea {
  min-height: 120px;
  resize: vertical;
}

.primary-action, .download-action {
  min-height: 46px;
  border: 0;
  background: var(--signal);
  color: #fff;
  font-weight: 800;
}

.primary-action { min-width: 176px; padding: 0 22px; }
.primary-action:hover, .download-action:hover { background: var(--signal-dark); }
.primary-action:disabled { cursor: wait; opacity: .58; }
.form-error { margin: 0; color: #a02d21; font-size: 13px; text-align: right; }

.output-head {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.empty-state, .progress-state {
  min-height: 460px;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
}

.empty-state p, .progress-state p { max-width: 280px; color: var(--muted); line-height: 1.55; }
.progress-state strong { margin-top: 25px; font-size: 18px; }

.wave {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.wave i {
  width: 5px;
  height: 18px;
  background: #b9bfc4;
}

.wave i:nth-child(2n) { height: 36px; }
.wave i:nth-child(3n) { height: 55px; }
.wave.active i { background: var(--signal); animation: pulse 1s ease-in-out infinite; }
.wave.active i:nth-child(2n) { animation-delay: .13s; }
.wave.active i:nth-child(3n) { animation-delay: .26s; }

@keyframes pulse {
  0%, 100% { transform: scaleY(.45); opacity: .55; }
  50% { transform: scaleY(1); opacity: 1; }
}

.result-state { padding-top: 36px; }
.result-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}

.result-meta div { min-width: 0; padding: 16px; background: #fff; }
.result-meta span, .result-meta strong { display: block; }
.result-meta span { margin-bottom: 5px; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.result-meta strong { overflow-wrap: anywhere; font-size: 14px; }
audio { width: 100%; margin: 28px 0 18px; }
.download-action {
  display: grid;
  place-items: center;
  width: 100%;
  text-decoration: none;
}

.history {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto 42px;
  padding-top: 28px;
  border-top: 1px solid #cbd0d5;
}

.history-head { padding-bottom: 20px; }
.history-head .eyebrow { margin-bottom: 5px; }
.history h2 { margin: 0; font-size: 24px; line-height: 1.2; }
.history-count { color: var(--muted); font-size: 12px; font-weight: 700; }
.history-empty {
  margin: 0;
  padding: 34px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

.history-list { border-top: 1px solid var(--line); }
.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 440px);
  gap: 32px;
  align-items: center;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}

.history-copy, .history-media { min-width: 0; }
.history-text {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.65;
}

.history-text[dir="rtl"] {
  font-family: "Noto Nastaliq Urdu", "Noto Sans Arabic", Tahoma, sans-serif;
  font-size: 18px;
  line-height: 1.9;
  text-align: right;
}

.history-source {
  display: -webkit-box;
  margin: 4px 0 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: var(--muted);
  font-size: 12px;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 16px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 11px;
}

.history-media {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.history-media audio { margin: 0; }
.history-download {
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 0 14px;
  border: 1px solid #aeb5bb;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.history-download:hover { border-color: var(--signal); color: var(--signal-dark); }
.history-status {
  justify-self: end;
  padding: 7px 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.history-status.processing { border-color: #8ab8aa; color: var(--signal-dark); }
.history-status.failed { border-color: #d5aaa5; color: #a02d21; }

.access-shell {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
  width: min(440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0;
}

.access-form {
  width: 100%;
  padding: 34px;
  border: 1px solid var(--line);
  background: var(--paper);
}
.access-form h1 { font-size: 31px; }
.access-form .primary-action { width: 100%; margin-top: 24px; }
.access-form .form-error { min-height: 20px; margin-top: 12px; text-align: left; }

footer {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto 30px;
  color: var(--muted);
  font-size: 12px;
}

[hidden] { display: none !important; }

@media (max-width: 850px) {
  .workspace { grid-template-columns: 1fr; width: min(680px, calc(100% - 28px)); margin: 22px auto; }
  .output { border-left: 0; border-top: 1px solid var(--line); }
  .empty-state, .progress-state { min-height: 300px; }
  footer { width: calc(100% - 28px); }
  .history { width: min(680px, calc(100% - 28px)); }
  .history-row { grid-template-columns: 1fr; gap: 14px; }
}

@media (max-width: 560px) {
  .topbar { height: 58px; padding: 0 16px; }
  .topbar-actions { gap: 10px; }
  .service-state { font-size: 0; }
  .service-state i { margin-right: 0; }
  .workspace { width: 100%; margin: 0; border-left: 0; border-right: 0; }
  .composer, .output { padding: 24px 18px; }
  h1 { font-size: 31px; }
  .heading-row { align-items: flex-end; }
  .queue-state { min-width: 70px; }
  .segmented { width: 100%; }
  .control-grid { grid-template-columns: 1fr; gap: 0; }
  textarea { min-height: 210px; }
  .action-row { align-items: stretch; flex-direction: column; }
  .primary-action { width: 100%; }
  .form-error { text-align: left; }
  .conversion-head { align-items: flex-start; flex-direction: column; gap: 4px; }
  .history-media { grid-template-columns: 1fr; }
  .history-download { min-height: 44px; }
  .history-status { justify-self: start; }
  .history-text[dir="rtl"] { text-align: right; }
  footer { align-items: flex-start; flex-direction: column; gap: 6px; }
  .access-shell { min-height: calc(100vh - 58px); width: 100%; padding: 0; }
  .access-form { border-right: 0; border-left: 0; padding: 30px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .wave.active i { animation: none; }
}
