:root {
  --bg: #ebe4d6;
  --paper: #f4efe4;
  --ink: #1c1814;
  --muted: #7a7166;
  --line: rgba(28, 24, 20, 0.1);
  --clay: #9a4b32;
  --clay-2: #7c3c28;
  --font: "Sora", system-ui, sans-serif;
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pad: clamp(24px, 6vw, 64px);
  --pad-y: clamp(22px, 4.5vh, 48px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  opacity: 0.08;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  height: 100svh;
  max-width: 880px;
  margin: 0 auto;
  padding: var(--pad-y) var(--pad) calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  animation: fade 200ms ease both;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex: 0 0 auto;
  position: relative;
  z-index: 2;
}
.id { display: grid; gap: 4px; }
.brand {
  color: inherit;
  text-decoration: none;
  font-family: var(--display);
  font-size: clamp(1.7rem, 3vw, 2.15rem);
  font-weight: 620;
  letter-spacing: -0.04em;
  line-height: 1;
}
.tag {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 500;
}
.voices { display: flex; gap: 8px; padding-top: 6px; }

form {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: clamp(14px, 2.2vh, 22px);
  padding: 12px 0 0;
  overflow: hidden;
}

.script {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 36rem;
  overflow: hidden;
}
.kicker {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 500;
  flex: 0 0 auto;
}
#script-text {
  margin: 0;
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(1.2rem, 2.1vh + 0.8vw, 1.7rem);
  line-height: 1.38;
  letter-spacing: -0.025em;
  overflow: hidden;
}
#script-text .keep { white-space: nowrap; }

.drop {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 22px 26px;
  border: 1px dashed rgba(28, 24, 20, 0.22);
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font-size: 0.92rem;
  cursor: pointer;
  transition: border-color 0.5s var(--ease), color 0.5s var(--ease), background 0.5s var(--ease);
}
.drop:hover, .drop.drag {
  border-color: var(--ink);
  color: var(--ink);
  background: rgba(255, 250, 242, 0.4);
}
.drop.tall {
  flex: 1 1 auto;
  min-height: 0;
  justify-content: center;
  text-align: center;
}
#drop-file { display: flex; align-items: center; gap: 14px; width: 100%; justify-content: space-between; }
#drop-file strong { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.x {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
}
.x:hover { color: var(--ink); }

.write {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
  animation: fade 180ms ease both;
}
.write.done {
  flex: 1 1 auto;
  justify-content: center;
}
.write.done textarea {
  flex: 0 1 auto;
  border-bottom-color: transparent;
  padding-bottom: 8px;
  font-size: clamp(1.2rem, 2.1vh + 0.8vw, 1.7rem);
  line-height: 1.38;
  letter-spacing: -0.025em;
}
.write.done .duration { display: none; }
.duration {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  flex: 0 0 auto;
}
.duration-track {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  cursor: pointer;
  touch-action: none;
}
.duration-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--ink);
  opacity: 0.22;
}
.duration-thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--ink);
  pointer-events: none;
}
.duration.auto .duration-thumb { display: none; }
.duration-value {
  appearance: none;
  border: 0;
  background: none;
  flex: 0 0 3.2em;
  padding: 0;
  color: var(--muted);
  font: 500 0.78rem var(--font);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-align: right;
  cursor: pointer;
}
textarea {
  flex: 0 1 auto;
  min-height: 3.2em;
  field-sizing: content;
  width: 100%;
  resize: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: 500 1.2rem/1.5 var(--display);
  padding: 8px 0 20px;
  outline: none;
}
.write:not(.done) textarea {
  flex: 0 1 auto;
  border-bottom-color: transparent;
  padding-bottom: 0;
}
.write:not(.done) .duration-track::before,
.write:not(.done) .duration-thumb {
  top: 8px;
}
.write:not(.done) .duration-value {
  align-self: flex-start;
  padding-top: 2px;
}
.write:not(.done) textarea:focus { border-bottom-color: transparent; }
textarea:focus { border-bottom-color: var(--ink); }
textarea::placeholder { color: #a0978b; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  appearance: none;
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 500 0.78rem var(--font);
  padding: 6px 2px;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: inset 0 -1px 0 transparent;
  transition: color 0.4s var(--ease), box-shadow 0.4s var(--ease);
}
.chip:hover { color: var(--ink); }
.chip.on {
  color: var(--ink);
  box-shadow: inset 0 -1px 0 var(--ink);
}

.banner {
  padding: 12px 0;
  color: var(--clay);
  font-size: 0.88rem;
}

.tape {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg);
}
.tape audio,
audio[data-audio] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.scrub {
  flex: 1 1 auto;
  min-width: 80px;
  height: 44px;
  display: block;
  cursor: pointer;
}
.clock {
  flex: 0 0 auto;
  color: var(--muted);
  font: 500 0.78rem var(--font);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}
.dl {
  flex: 0 0 auto;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 4px 0;
  box-shadow: inset 0 -1px 0 var(--ink);
}

.rec-box {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 16px;
  min-height: 56px;
}
.rec-box.reviewing #review-tape {
  flex: 1 1 100%;
  min-width: 0;
}
.rec, .go {
  appearance: none;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  min-height: 44px;
  padding: 12px 22px;
  font: 600 0.84rem var(--font);
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 250, 242, 0.12), 0 1px 0 rgba(28, 24, 20, 0.18);
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease, opacity 160ms ease;
}
.rec:active, .go:active:not(:disabled) { transform: scale(0.97); }
.rec.live {
  background: var(--clay);
  border-color: var(--clay);
}
#rec-time {
  color: var(--muted);
  font-size: 0.82rem;
}
#rec-preview { height: 36px; flex: 1; min-width: 0; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.consent {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
}
.consent input { accent-color: var(--clay); }
.go:disabled { opacity: 0.28; cursor: not-allowed; transform: none; }
.go.busy { opacity: 0.55; }
.go.ghost, .ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: none;
}
#rec-btn.ghost {
  border: 0;
  background: none;
  color: var(--muted);
  min-height: 0;
  padding: 8px 2px;
  border-radius: 0;
  box-shadow: none;
  font: 500 0.75rem var(--font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
#rec-btn.ghost:hover {
  color: var(--ink);
  background: none;
}
.play {
  appearance: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
  box-shadow: inset 0 1px 0 rgba(255, 250, 242, 0.12), 0 1px 0 rgba(28, 24, 20, 0.18);
  transition: transform 160ms ease, background 160ms ease;
}
.play:active { transform: scale(0.97); }
.play::after {
  content: "";
  position: absolute;
  left: 17px;
  top: 14px;
  border-style: solid;
  border-width: 8px 0 8px 13px;
  border-color: transparent transparent transparent var(--paper);
}
.play.on::after {
  left: 15px;
  top: 15px;
  width: 4px;
  height: 14px;
  border: 0;
  background: var(--paper);
  box-shadow: 8px 0 0 var(--paper);
}

.privacy {
  flex: 0 0 auto;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  line-height: 1.5;
  max-width: 36em;
}

.hidden { display: none !important; }

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (hover: hover) and (pointer: fine) {
  .rec:hover, .go:hover:not(:disabled), .play:hover { background: #2a241c; }
}

@media (max-width: 560px) {
  :root { --pad: 22px; --pad-y: 20px; }
  .script { max-width: none; }
  .rec-box.reviewing { gap: 12px; }
  .rec, .go { padding: 12px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .app, .write { animation: none; }
  .rec, .go, .play { transition: background 160ms ease, color 160ms ease, opacity 160ms ease; }
  .rec:active, .go:active:not(:disabled) { transform: none; }
}

.meter {
  position: relative;
  z-index: 3;
  display: block;
  width: 160px;
  height: 44px;
  flex: 0 0 auto;
  background: var(--bg);
}
.text-link {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: 500 0.75rem var(--font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0;
  cursor: pointer;
  text-align: left;
}
.text-link:hover { color: var(--ink); }
#upload-link { flex: 0 0 auto; }

#player-box.tape { flex: 0 0 auto; }
