:root {
  --bg: #faf8f4;
  --fg: #1a1a1a;
  --muted: #6a6a6a;
  --line: #e5e2dc;
  --accent: #5b3a29;
  --card: #ffffff;
  --warn: #a64015;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110d;
    --fg: #efece6;
    --muted: #8e8a82;
    --line: #2a2622;
    --accent: #c79b6b;
    --card: #1c1814;
    --warn: #e07e57;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 28px 18px 80px;
}

@media (max-width: 480px) {
  main { padding: 20px 16px 64px; }
  h1 { font-size: 24px; }
}

header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
  margin-bottom: 28px;
}

h1 {
  margin: 0 0 6px;
  font-weight: 600;
  font-size: 28px;
  letter-spacing: -0.01em;
}

h2 {
  margin: 32px 0 14px;
  font-weight: 600;
  font-size: 18px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.meta {
  font-size: 14px;
  color: var(--muted);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
  row-gap: 4px;
}

.dot { padding: 0 6px; opacity: 0.6; }

@media (max-width: 480px) {
  .meta { font-size: 13px; }
}

label {
  display: block;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 6px;
}

textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  resize: vertical;
  min-height: 96px;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
}

/* Segmented selector for episode length. The radio inputs are visually
   hidden but remain keyboard-focusable; the labels render as toggle pills. */
.depth-select {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card);
}

.depth-select input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
}

.depth-select label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 16px 18px;
  margin: 0;
  cursor: pointer;
  background: var(--card);
  color: var(--fg);
  border-right: 1px solid var(--line);
  transition: background 0.15s, color 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
}

.depth-select label:last-of-type { border-right: none; }

.depth-select input[type="radio"]:checked + label {
  background: var(--accent);
  color: var(--bg);
}

.depth-select input[type="radio"]:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.depth-select input[type="radio"]:disabled + label {
  opacity: 0.4;
  cursor: not-allowed;
}

.depth-select .opt-name {
  font-weight: 600;
  font-size: 16px;
}

.depth-select .opt-meta {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 3px;
}

/* Big primary submit. Spells out exactly what's about to happen. */
.primary-btn {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 16px 20px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  min-height: 52px;
  -webkit-tap-highlight-color: transparent;
}

.primary-btn .cost {
  font-weight: 400;
  opacity: 0.85;
  margin-left: 4px;
}

/* Credits help — collapsible "How credits work" */
.credits-help {
  margin-top: 16px;
  font-size: 14px;
  color: var(--muted);
}

.credits-help summary {
  cursor: pointer;
  user-select: none;
  padding: 8px 0;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
.credits-help summary::-webkit-details-marker { display: none; }

.credits-help summary::before {
  content: "▸";
  display: inline-block;
  font-size: 11px;
  opacity: 0.7;
  transition: transform 0.15s;
}
.credits-help[open] summary::before { transform: rotate(90deg); }

.credits-help summary:hover { color: var(--fg); }

.credits-help-body {
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
}

.credits-help-body p { margin: 0 0 8px; }
.credits-help-body p:last-child { margin-bottom: 0; }
.credits-help-body ul { margin: 0 0 8px 18px; padding: 0; }
.credits-help-body li { margin-bottom: 2px; }

.credits-help-body .topup {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

button {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  padding: 9px 18px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

button:hover { opacity: 0.9; }
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.msg { font-size: 14px; color: var(--muted); }
.msg.warn { color: var(--warn); }

.hidden { display: none !important; }

.active {
  margin-top: 24px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-text {
  font-size: 15px;
  flex: 1;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.episode-list { display: flex; flex-direction: column; gap: 18px; }

.episode {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
}

.ep-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 2px;
}

.ep-sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

audio {
  width: 100%;
  margin: 6px 0;
}

.ep-rationale {
  font-size: 14px;
  color: var(--fg);
  margin-top: 8px;
  font-style: italic;
  opacity: 0.85;
}

.ep-actions {
  margin-top: 8px;
  font-size: 13px;
}

.ep-actions a {
  color: var(--accent);
  text-decoration: none;
}

.ep-actions a:hover { text-decoration: underline; }

.empty {
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
}

/* Login */

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  margin-bottom: 14px;
}

input[type="text"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
}

.login-page main { max-width: 380px; }
.login form { display: flex; flex-direction: column; }
.login button { align-self: flex-start; margin-top: 4px; }
.login .hint {
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
}
.login .msg { margin-top: 14px; }

.meta #logout-form {
  display: inline;
  margin: 0;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 4px 0;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--line);
  -webkit-tap-highlight-color: transparent;
}
.link-btn:hover { color: var(--accent); }
.link-btn:active { color: var(--accent); }
