:root {
  --bg: #0f0d0a;
  --bg-2: #181510;
  --bg-3: #221d15;
  --text: #ede4d3;
  --text-dim: #9a8f7a;
  --text-faint: #5a5145;
  --accent: #e89d5a;
  --accent-deep: #c44f38;
  --border: rgba(237,228,211,0.08);
  --border-strong: rgba(237,228,211,0.16);
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --display: "Fraunces", "Hoefler Text", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* grain overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.04;
  z-index: 100;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: var(--vh, 100dvh);
  display: flex;
  flex-direction: column;
  padding:
    calc(14px + env(safe-area-inset-top, 0px))
    calc(22px + env(safe-area-inset-right, 0px))
    calc(24px + env(safe-area-inset-bottom, 0px))
    calc(22px + env(safe-area-inset-left, 0px));
  gap: 14px;
}

/* --- Nav --- */
nav.tabs {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.nav-brand {
  font-family: var(--display);
  font-variation-settings: "opsz" 72, "SOFT" 50;
  font-weight: 400;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--text);
}
.nav-brand em {
  font-style: italic;
  font-variation-settings: "opsz" 144, "SOFT" 100;
  color: var(--accent);
}
.tab-links {
  display: flex; gap: 16px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.tab-links a {
  color: var(--text-faint);
  text-decoration: none;
  padding: 4px 0;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab-links a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- Header --- */
header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-top: 2px;
}
.brand {
  font-family: var(--display);
  font-variation-settings: "opsz" 72, "SOFT" 50;
  font-weight: 400;
  font-size: 34px;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text);
}
.brand em {
  font-style: italic;
  font-variation-settings: "opsz" 144, "SOFT" 100;
  color: var(--accent);
}
.status {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  box-shadow: 0 0 0 0 transparent;
  transition: all 0.3s ease;
}
.status[data-state="loading"] .status-dot {
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
.status[data-state="ready"] .status-dot {
  background: #6ecb7d;
}
.status[data-state="error"] .status-dot {
  background: var(--accent-deep);
}
.status[data-state="generating"] .status-dot {
  background: var(--accent);
  animation: pulse 0.7s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232,157,90,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(232,157,90,0); }
}

/* --- Tagline / intro --- */
.intro {
  font-family: var(--display);
  font-weight: 300;
  font-variation-settings: "opsz" 144, "SOFT" 80;
  font-size: 15px;
  font-style: italic;
  color: var(--text-dim);
  line-height: 1.5;
  margin: -4px 0 2px;
  max-width: 38ch;
}
.intro .sep {
  color: var(--text-faint);
  margin: 0 6px;
}

/* --- Textarea --- */
.input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 200px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.input-wrap:focus-within {
  border-color: var(--border-strong);
}
.input-header {
  padding: 10px 16px 8px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
  min-height: 30px;
}
.input-header .meta {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
}
.input-header .meta.over { color: var(--accent); }
.input-header .actions {
  display: flex;
  gap: 0;
  flex-shrink: 0;
  white-space: nowrap;
}
.input-header button {
  background: transparent; border: 0; padding: 0;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
  cursor: pointer;
}
.input-header button:active { color: var(--accent); }
.input-header .sep { color: var(--text-faint); margin: 0 10px; }
textarea {
  flex: 1;
  width: 100%;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 16px 18px 18px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 17px;
  font-variation-settings: "opsz" 16;
  line-height: 1.55;
  resize: none;
  outline: none;
  -webkit-appearance: none;
}
textarea::placeholder {
  color: var(--text-faint);
  font-style: italic;
}

/* --- Controls grid --- */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.field {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px 11px;
  min-width: 0;
}
.field-label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 2px;
}
.field-value {
  font-family: var(--display);
  font-weight: 400;
  font-variation-settings: "opsz" 72, "SOFT" 50;
  font-size: 17px;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field select,
.field input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: transparent;
}
.field::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-30%);
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--text-dim);
  border-bottom: 1.5px solid var(--text-dim);
  transform-origin: center;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.field.slider-field::after { display: none; }

/* Visual slider track */
.slider-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  position: relative;
  overflow: hidden;
}
.slider-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.1s ease;
}

/* --- Generate button --- */
.generate {
  width: 100%;
  padding: 18px 20px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #1a0f05;
  font-family: var(--display);
  font-variation-settings: "opsz" 144, "SOFT" 50;
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease, opacity 0.2s ease;
  touch-action: manipulation;
  position: relative;
  overflow: hidden;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.generate:active { transform: scale(0.985); }
.generate:disabled {
  background: var(--bg-3);
  color: var(--text-faint);
  cursor: not-allowed;
  font-style: italic;
}
.generate.stop-mode {
  background: var(--accent-deep);
  color: #fff1e8;
}
.generate .progress-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent-deep);
  width: 0%;
  transition: width 0.2s ease;
}
.spinner {
  width: 14px;
  height: 14px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  opacity: 0.7;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Player --- */
.player {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px 16px;
  display: none;
  flex-direction: column;
  gap: 12px;
}
.player.visible { display: flex; animation: slideUp 0.3s ease; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.player-title {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.player-download {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  transition: background 0.15s ease;
}
.player-download:active { background: var(--bg-3); }
.player-download.disabled,
.player-download[aria-disabled="true"] {
  color: var(--text-faint);
  pointer-events: none;
}
.save-group {
  display: flex; align-items: stretch; gap: 0;
}
.save-group .player-download {
  border-radius: 7px 0 0 7px;
  border-right: 0;
}
.format-toggle {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 0 7px 7px 0;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 10px;
  cursor: pointer;
  min-width: 54px;
}
.format-toggle:active { background: var(--bg-3); }
.format-toggle:disabled { color: var(--text-faint); cursor: not-allowed; }

/* --- Streaming transport --- */
.transport {
  display: flex; align-items: center; gap: 12px;
}
.play-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #1a0f05;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s ease, opacity 0.2s ease;
}
.play-btn:active { transform: scale(0.94); }
.play-btn:disabled { background: var(--bg-3); color: var(--text-faint); cursor: not-allowed; }
.play-btn svg { width: 18px; height: 18px; }
.progress-area {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.progress-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  position: relative;
  cursor: default;
  touch-action: none;
}
.progress-track.seekable { cursor: pointer; }
.progress-track.seekable.dragging { cursor: grabbing; }
/* Extends the click/tap target to ~22px tall without changing the
   visual line height. Only intercepts pointer events when the bar is
   actually seekable — otherwise clicks pass through to nothing. */
.progress-track::before {
  content: "";
  position: absolute;
  inset: -10px 0;
  cursor: inherit;
  pointer-events: none;
}
.progress-track.seekable::before { pointer-events: auto; }
.progress-played, .progress-buffered {
  pointer-events: none;
}
.progress-played {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s linear;
}
.progress-buffered {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--text-faint);
  opacity: 0.35;
  border-radius: 2px;
}
.transport-meta {
  display: flex; justify-content: space-between;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.transport-meta .right { color: var(--text-dim); }

/* --- Warning modal (long-text confirmation) --- */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,13,10,0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal.visible { opacity: 1; pointer-events: auto; }
.modal-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 22px 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-card h3 {
  font-family: var(--display);
  font-variation-settings: "opsz" 144, "SOFT" 100;
  font-weight: 400;
  font-style: italic;
  font-size: 22px;
  color: var(--accent);
  margin: 0;
  letter-spacing: -0.01em;
}
.modal-card p {
  font-family: var(--serif);
  font-size: 14.5px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
}
.modal-card .actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 4px;
}
.modal-card .actions button {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
}
.modal-card .actions button.primary {
  background: var(--accent);
  color: #1a0f05;
  border-color: var(--accent);
}

/* --- Setup overlay --- */
.setup {
  position: fixed;
  inset: 0;
  background: rgba(15,13,10,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.setup.visible { opacity: 1; pointer-events: auto; }
.setup-inner {
  max-width: 340px;
  text-align: center;
}
.setup-title {
  font-family: var(--display);
  font-variation-settings: "opsz" 144, "SOFT" 100;
  font-weight: 400;
  font-style: italic;
  font-size: 28px;
  color: var(--accent);
  margin-bottom: 14px;
  letter-spacing: -0.01em;
}
.setup-body {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-dim);
  margin-bottom: 22px;
}
.setup-progress {
  width: 100%;
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
}
.setup-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
}
.setup-meta {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.setup-btn {
  margin-top: 18px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 12px 22px;
  border-radius: 8px;
  cursor: pointer;
}
.setup-btn.primary {
  background: var(--accent);
  color: #1a0f05;
  border-color: var(--accent);
}

/* footer note */
.footer {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  text-align: center;
  padding-top: 4px;
}
.footer span { color: var(--text-dim); }

/* toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 10px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 200;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
