/* Aloud — lamp-lit radio look.
   Palette: ink-plum night, amber dial lamp, warm paper text. */

:root {
  --night: #191424;      /* page background */
  --panel: #221B33;      /* cards */
  --panel-edge: #322948; /* card borders, dividers */
  --paper: #F4EDE1;      /* primary text */
  --dim: #9D91B5;        /* secondary text */
  --lamp: #F5A34D;       /* amber accent */
  --lamp-deep: #C97A2B;  /* amber pressed / gradients */
  --rose: #E27D93;       /* error + delete */
  --radius: 18px;
  --font-display: "Bricolage Grotesque", "Avenir Next", sans-serif;
  --font-body: "Instrument Sans", -apple-system, sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

/* Author display rules (flex etc.) must not defeat the hidden attribute. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--night);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  padding: env(safe-area-inset-top) 16px calc(150px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin-inline: auto;
}

/* ---------- masthead ---------- */

.masthead { padding: 28px 4px 20px; }

.wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 44px;
  line-height: 1;
  letter-spacing: -0.02em;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--dim);
  transition: background 0.4s;
}
.status-dot.ready { background: var(--lamp); box-shadow: 0 0 10px var(--lamp); }

.tagline { margin: 8px 0 0; color: var(--dim); font-size: 15px; }
.build { font-family: var(--font-mono); font-size: 11px; opacity: 0.7; margin-left: 6px; }

/* ---------- compose card ---------- */

.compose {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  overflow: hidden;
}

.pad { padding: 14px 16px; }
.pad + .pad { border-top: 1px solid var(--panel-edge); }

textarea {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  background: transparent;
  border: none;
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.55;
}
textarea::placeholder, input::placeholder { color: var(--dim); opacity: 0.7; }
textarea:focus { outline: none; }

.compose-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--dim);
}

.upload-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--night);
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  font-size: 14px;
  max-width: 100%;
}
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button {
  background: var(--panel-edge);
  border: none;
  color: var(--paper);
  width: 24px; height: 24px;
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.controls { display: grid; gap: 14px; }

.field { display: grid; gap: 6px; }
.field-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--dim);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.field-label em { font-style: normal; text-transform: none; letter-spacing: 0; opacity: 0.7; }
.field-label output { font-family: var(--font-mono); color: var(--lamp); font-size: 13px; }

select, input[type="text"] {
  width: 100%;
  background: var(--night);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 16px;
  padding: 10px 12px;
  appearance: none;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--lamp);
  height: 28px;
}

/* ---------- buttons ---------- */

button { font-family: var(--font-body); }

.primary {
  width: 100%;
  background: linear-gradient(180deg, var(--lamp), var(--lamp-deep));
  color: #241505;
  border: none;
  border-radius: 12px;
  padding: 15px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: 0.45; cursor: default; }

.ghost {
  background: transparent;
  border: 1px solid var(--panel-edge);
  color: var(--paper);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
}

:is(button, select, input, textarea, audio):focus-visible {
  outline: 2px solid var(--lamp);
  outline-offset: 2px;
}

/* ---------- progress meter (signature) ---------- */

.meter {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 44px;
}
.meter i {
  flex: 1;
  background: var(--panel-edge);
  border-radius: 2px;
  transition: background 0.3s;
}
.meter i.lit { background: var(--lamp); box-shadow: 0 0 6px rgba(245, 163, 77, 0.5); }

@media (prefers-reduced-motion: no-preference) {
  .meter.running i.head { animation: pulse 0.9s ease-in-out infinite; }
}
@keyframes pulse {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.35); background: var(--lamp); }
}

.progress-label {
  margin: 10px 0 0;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--dim);
}
.progress-label.error { color: var(--rose); }

/* ---------- library ---------- */

.library h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  margin: 32px 4px 12px;
}

.library ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.lib-item {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
}
.lib-item.playing { border-color: var(--lamp); }

.lib-play {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--panel-edge);
  background: var(--night);
  color: var(--lamp);
  font-size: 16px;
  cursor: pointer;
}

.lib-main { min-width: 0; }
.lib-title {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lib-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--dim);
  margin-top: 2px;
}

.lib-wave { display: flex; gap: 2px; align-items: center; height: 14px; margin-top: 6px; width: 120px; }
.lib-wave i { flex: 1; background: var(--panel-edge); border-radius: 1px; }
.lib-item.playing .lib-wave i { background: var(--lamp); }

.lib-actions { display: grid; gap: 6px; }
.lib-actions a, .lib-actions button {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  padding: 4px 6px;
  text-align: right;
  font-family: var(--font-body);
}
.lib-actions a:hover, .lib-actions button:hover { color: var(--paper); }
.lib-actions .delete:hover { color: var(--rose); }

.lib-empty { color: var(--dim); font-size: 14px; padding: 8px 4px; }

/* ---------- player ---------- */

.player {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(25, 20, 36, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--panel-edge);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.player-inner-limit, .player > * { max-width: 608px; margin-inline: auto; }
.player-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player audio { display: none; }

.scrub-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.scrub-row .time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--dim);
  min-width: 44px;
}
#curTime { text-align: right; }
.scrub-row.scrubbing #curTime { color: var(--lamp); }

/* Seek slider: thin amber track, generous touch target. */
#seek {
  flex: 1;
  height: 34px;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  --played: 0%;
}
#seek::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--lamp) var(--played), var(--panel-edge) var(--played));
}
#seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--paper);
  border: none;
  margin-top: -6.5px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
#seek::-moz-range-track {
  height: 5px;
  border-radius: 3px;
  background: var(--panel-edge);
}
#seek::-moz-range-progress { height: 5px; border-radius: 3px; background: var(--lamp); }
#seek::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--paper);
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
#seek:disabled { opacity: 0.4; }

.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 2px;
}
/* Keep the play button centered even before a timeline exists. */
#transcriptBtn[hidden] {
  display: flex !important; /* outranks the global [hidden] rule by specificity */
  visibility: hidden;
  pointer-events: none;
}
.transport button {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
}
.transport svg { fill: currentColor; }
.transport svg text { font-family: var(--font-mono); font-weight: 500; }

.skip {
  width: 44px; height: 44px;
  background: transparent;
  border: none;
  color: var(--paper);
}
.skip svg { width: 28px; height: 28px; }
.skip:active { color: var(--lamp); }
.skip:disabled { opacity: 0.4; }

.play-pause {
  width: 54px; height: 54px;
  border: none;
  background: linear-gradient(180deg, var(--lamp), var(--lamp-deep));
  color: #241505;
}
.play-pause svg { width: 30px; height: 30px; }
.play-pause:active { transform: translateY(1px); }

.rate {
  min-width: 44px;
  height: 34px;
  padding: 0 8px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--panel-edge);
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 13px;
  cursor: pointer;
}
.rate:active { color: var(--lamp); border-color: var(--lamp); }

/* Resume marker in library metadata */
.lib-resume { color: var(--lamp); }

/* ---------- transcript ---------- */

.player { z-index: 20; }

.transcript {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--night);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

.transcript-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--panel-edge);
  max-width: 640px;
  width: 100%;
  margin-inline: auto;
}
.transcript-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.transcript-close {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  color: var(--paper);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

/* Own scroll container — page scroll and transcript scroll must never mix,
   or the follow-suspension logic can't tell who scrolled. */
.transcript-body {
  position: relative;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px calc(170px + env(safe-area-inset-bottom));
  max-width: 640px;
  width: 100%;
  margin-inline: auto;
}

.cue {
  margin: 0 0 2px;
  padding: 6px 12px;
  border-left: 3px solid transparent;
  border-radius: 6px;
  color: var(--dim);
  font-size: 17px;
  line-height: 1.6;
  cursor: pointer;
  transition: color 0.3s, background 0.3s;
}
.cue.active {
  color: var(--paper);
  border-left-color: var(--lamp);
  background: var(--panel);
}
.transcript.live .cue { cursor: default; }

.follow-pill {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(160px + env(safe-area-inset-bottom));
  z-index: 15;
  background: linear-gradient(180deg, var(--lamp), var(--lamp-deep));
  color: #241505;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ---------- auth gate ---------- */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 11, 24, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
}
.auth-card p { margin: 0; color: var(--dim); font-size: 15px; }
.auth-card input {
  background: var(--night);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 16px;
  padding: 12px 14px;
}
.auth-card input:focus { outline: none; border-color: var(--lamp); }
.auth-error { color: var(--rose); font-size: 14px; }
