/* ReadThis Studio — warm editorial "recording studio".
   Paper and ink with a signal-red accent taken from the logo's sound waves. */

:root {
  --paper: oklch(97% 0.012 80);
  --paper-2: oklch(94% 0.016 78);
  --paper-3: oklch(90% 0.02 76);
  --ink: oklch(24% 0.02 60);
  --ink-2: oklch(42% 0.02 60);
  --ink-3: oklch(58% 0.02 65);
  --rule: oklch(84% 0.02 70);
  --signal: oklch(57% 0.2 28);
  --signal-soft: oklch(57% 0.2 28 / 0.14);
  --signal-ink: oklch(98% 0.01 80);
  --mark: oklch(90% 0.09 85);
  --ok: oklch(62% 0.13 150);

  --display: 'Fraunces', 'Noto Naskh Arabic', Georgia, serif;
  --body: 'Atkinson Hyperlegible', 'Noto Naskh Arabic', system-ui, sans-serif;

  --step--1: clamp(0.8rem, 0.78rem + 0.1vw, 0.86rem);
  --step-0: clamp(1rem, 0.96rem + 0.2vw, 1.1rem);
  --step-1: clamp(1.2rem, 1.1rem + 0.5vw, 1.45rem);
  --step-2: clamp(1.6rem, 1.3rem + 1.2vw, 2.3rem);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: oklch(21% 0.014 60);
    --paper-2: oklch(25% 0.016 60);
    --paper-3: oklch(30% 0.018 60);
    --ink: oklch(92% 0.015 80);
    --ink-2: oklch(78% 0.015 75);
    --ink-3: oklch(64% 0.015 70);
    --rule: oklch(36% 0.018 60);
    --signal: oklch(66% 0.18 30);
    --signal-soft: oklch(66% 0.18 30 / 0.2);
    --signal-ink: oklch(18% 0.02 40);
    --mark: oklch(40% 0.07 80);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0)/1.6 var(--body);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; text-decoration-color: var(--signal); text-underline-offset: 0.18em; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Masthead */
.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem 2rem;
  flex-wrap: wrap;
  padding: clamp(1rem, 3vw, 1.75rem) clamp(1rem, 4vw, 3rem) 0.9rem;
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; }
.brand img { align-self: center; }
.brand-name { font: 800 var(--step-1)/1 var(--display); letter-spacing: -0.01em; }
.brand-name em { font-style: italic; font-weight: 400; color: var(--signal); }
.promise { margin: 0; color: var(--ink-2); font-size: var(--step--1); letter-spacing: 0.01em; }
.promise strong { color: var(--ink); font-weight: 700; }
.home-link {
  font-size: var(--step--1);
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  white-space: nowrap;
}
.home-link:hover { border-color: var(--signal); }

/* Layout */
.studio {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 340px);
  gap: clamp(1.5rem, 4vw, 3.5rem);
  padding: clamp(1rem, 3vw, 2rem) clamp(1rem, 4vw, 3rem) 3rem;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
}

/* Manuscript */
.manuscript { position: relative; min-width: 0; }
.manuscript-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.doc-title {
  margin: 0;
  font: 600 var(--step-2)/1.1 var(--display);
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
}
.bar-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }

.text-btn {
  background: none;
  border: 0;
  padding: 0.3rem 0.5rem;
  color: var(--ink-2);
  cursor: pointer;
  border-radius: 4px;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 0.2em;
}
.text-btn:hover { color: var(--ink); text-decoration-color: var(--signal); }

.editor textarea {
  width: 100%;
  min-height: min(62vh, 640px);
  resize: vertical;
  padding: 1.25rem 1.4rem;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: 400 var(--step-0)/1.7 var(--body);
  color: var(--ink);
}
.editor textarea::placeholder { color: var(--ink-3); }
.editor textarea:focus { outline: none; border-color: var(--ink-3); }
.editor-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.4rem;
  font-size: var(--step--1);
  color: var(--ink-3);
}

/* Reader: the text as clickable sentences */
.reader {
  max-width: 68ch;
  font-size: var(--step-0);
  line-height: 1.75;
}
.reader h2 { font: 600 var(--step-1)/1.25 var(--display); margin: 1.8em 0 0.5em; }
/* Arabic-script text needs more room between lines for its marks */
.reader:is(:lang(ar), :lang(fa), :lang(ur)) { font-size: calc(var(--step-0) * 1.12); line-height: 2; }
.reader p { margin: 0 0 1.05em; }
.s {
  cursor: pointer;
  border-radius: 3px;
  transition: background-color 0.25s var(--ease-out), color 0.25s var(--ease-out);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.s:hover { background: var(--paper-3); }
.s.ready { }
.s.skipped { color: var(--ink-3); }
.s.now { background: var(--mark); color: var(--ink); }

.drop-veil {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: oklch(from var(--paper) l c h / 0.88);
  border: 3px dashed var(--signal);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease-out);
}
.drop-veil span { font: 600 var(--step-2)/1 var(--display); color: var(--signal); }
body.dragging .drop-veil { opacity: 1; }

/* Console */
.console {
  position: sticky;
  top: 1rem;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding-left: clamp(0rem, 2vw, 1.5rem);
  border-left: 1px solid var(--rule);
}

.on-air {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: var(--step--1);
  color: var(--ink-2);
  min-height: 1.6em;
}
.lamp {
  flex: none;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--paper-3);
  box-shadow: inset 0 0 0 1px var(--rule);
}
.lamp.loading { background: var(--mark); animation: breathe 1.4s ease-in-out infinite; }
.lamp.ready { background: var(--ok); }
.lamp.live { background: var(--signal); box-shadow: 0 0 0 4px var(--signal-soft); }
.lamp.error { background: var(--ink-3); }
@keyframes breathe { 50% { opacity: 0.35; } }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label {
  display: flex;
  justify-content: space-between;
  font-size: var(--step--1);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.field output { font-weight: 400; letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }
.voice-row { display: flex; gap: 0.5rem; }
select {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 5px;
}
input[type="range"] { width: 100%; accent-color: var(--signal); }

.check { display: flex; gap: 0.55rem; align-items: flex-start; font-size: var(--step--1); color: var(--ink-2); cursor: pointer; }
.check input { accent-color: var(--signal); margin-top: 0.2em; }
.check.small { font-size: 0.8rem; }

.ghost-btn {
  padding: 0.45rem 0.8rem;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background-color 0.15s;
}
.ghost-btn:hover:not(:disabled) { border-color: var(--ink-3); background: var(--paper-2); }
.ghost-btn:disabled { opacity: 0.45; cursor: default; }

.listen-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  border: 0;
  border-radius: 999px;
  background: var(--signal);
  color: var(--signal-ink);
  font: 600 var(--step-1)/1 var(--display);
  cursor: pointer;
  transition: transform 0.2s var(--ease-out), filter 0.2s;
}
.listen-btn:hover:not(:disabled) { filter: brightness(1.06); }
.listen-btn:active:not(:disabled) { transform: scale(0.98); }
.listen-btn:disabled { background: var(--paper-3); color: var(--ink-3); cursor: default; }
.listen-icon {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0.45em 0 0.45em 0.75em;
  border-color: transparent transparent transparent currentColor;
}
.listen-btn.playing .listen-icon {
  width: 0.7em;
  height: 0.9em;
  border: 0;
  border-left: 0.24em solid currentColor;
  border-right: 0.24em solid currentColor;
}

.transport { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.clock { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: var(--step--1); }

.tape-wrap { margin: 0; }
#tape {
  display: block;
  width: 100%;
  height: 56px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 5px;
  cursor: pointer;
}
.tape-wrap figcaption { margin-top: 0.3rem; font-size: 0.78rem; color: var(--ink-3); }

.export { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.export-label { font-size: var(--step--1); color: var(--ink-2); }
.export-row { display: flex; gap: 0.4rem; }

.engine { font-size: var(--step--1); color: var(--ink-2); border-top: 1px solid var(--rule); padding-top: 0.8rem; }
.engine summary { cursor: pointer; font-weight: 700; color: var(--ink); }
.engine p { margin: 0.6rem 0; }
.fine { font-size: 0.8rem; color: var(--ink-3); }
.meter { height: 4px; background: var(--paper-3); border-radius: 2px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--signal); transition: width 0.3s var(--ease-out); }

.notice {
  margin: 0;
  padding: 0.7rem 0.85rem;
  background: var(--signal-soft);
  border-radius: 5px;
  font-size: var(--step--1);
}

.colophon {
  padding: 1.2rem clamp(1rem, 4vw, 3rem) 1.6rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-3);
  font-size: 0.8rem;
}
.colophon p { margin: 0; max-width: 90ch; }

/* First paint: the console settles in after the manuscript */
@media (prefers-reduced-motion: no-preference) {
  .manuscript, .console { animation: rise 0.6s var(--ease-out) both; }
  .console { animation-delay: 0.08s; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Narrow screens: controls first, then the text */
@media (max-width: 820px) {
  .studio { grid-template-columns: 1fr; }
  .console {
    position: static;
    order: -1;
    border-left: 0;
    padding-left: 0;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--rule);
  }
  .editor textarea { min-height: 45vh; }
}
