/* ============================================================
   Stories for Always — styles
   Calm, warm, high-contrast. System fonts only. Mobile-first.
   ============================================================ */

:root {
  --bg: #FAF6F0;            /* warm paper */
  --surface: #FFFFFF;
  --ink: #372E24;           /* deep warm brown */
  --ink-soft: #75695A;      /* secondary text */
  --accent: #A9563C;        /* soft terracotta */
  --accent-dark: #8C4530;
  --accent-soft: #F3E4DC;
  --line: #E7DECF;
  --danger: #A33B2E;
  --danger-soft: #F6E3DF;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(55, 46, 36, 0.07), 0 4px 14px rgba(55, 46, 36, 0.06);
  --serif: "Iowan Old Style", "Palatino", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  min-height: 100vh;
}

.layout { display: flex; min-height: 100vh; }

.app {
  max-width: 660px;
  margin: 0 auto;
  padding: 20px 18px calc(110px + env(safe-area-inset-bottom));
  width: 100%;
}

/* ---------- Sidebar (story library, wider screens only) ---------- */

.sidebar { display: none; }

@media (min-width: 960px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 272px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 22px 16px;
  }

  .layout > .app { flex: 1; min-width: 0; margin: 0 auto; }
  .app { padding-bottom: 40px; }
}

.sidebar-home {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  padding: 2px 8px;
}

.sidebar-new { min-height: 46px; font-size: 1rem; }

.sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.sidebar-item {
  display: block;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-item:hover { background: var(--bg); }

.sidebar-item.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 600;
}

.sidebar-empty { color: var(--ink-soft); font-size: 0.9rem; padding: 6px 10px; }

/* ---------- Header ---------- */

.app-header { text-align: center; margin-bottom: 22px; }

.app-title-link { text-decoration: none; color: inherit; }

.app-title {
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
}

.app-tagline {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* ---------- Shared elements ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 14px 22px;
  min-height: 52px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }

.btn-quiet {
  background: transparent;
  color: var(--accent-dark);
  border: 1.5px solid var(--line);
}
.btn-quiet:hover { background: var(--accent-soft); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1.5px solid var(--line);
}
.btn-danger:hover { background: var(--danger-soft); }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.btn-row .btn { flex: 1 1 auto; }

.notice {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--ink);
}

input[type="text"],
input[type="search"],
textarea {
  width: 100%;
  font-family: var(--sans);
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  outline: none;
}

input:focus, textarea:focus { border-color: var(--accent); }

textarea { resize: vertical; line-height: 1.6; }

label.field-label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink-soft);
  margin: 18px 0 6px;
}

/* ---------- Home / Library ---------- */

.search-bar { margin-bottom: 16px; }

.new-story-cta {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 65%, rgba(250, 246, 240, 0));
  display: flex;
  justify-content: center;
  z-index: 10;
}

.new-story-cta .btn {
  width: 100%;
  max-width: 624px;
  font-size: 1.15rem;
  min-height: 58px;
  box-shadow: var(--shadow);
}

/* The sidebar has its own + New Story button; drop the floating one.
   (This must come after the .new-story-cta rules above to win.) */
@media (min-width: 960px) {
  .new-story-cta { display: none; }
}

.story-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }

.story-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  text-decoration: none;
  color: inherit;
}

.story-card:hover { border-color: var(--accent); }

.story-card-top { display: flex; align-items: baseline; gap: 10px; }

.story-card-title {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
  overflow-wrap: anywhere;
}

.story-card-audio {
  color: var(--accent);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
}

.story-card-date { color: var(--ink-soft); font-size: 0.9rem; margin: 2px 0 6px; }

.story-card-preview {
  margin: 0;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 48px 16px;
}

.empty-state .big { font-size: 2.4rem; margin-bottom: 8px; }

.library-tools {
  margin-top: 28px;
  display: flex;
  justify-content: center;
  gap: 18px;
  font-size: 0.92rem;
}

.library-tools button {
  background: none;
  border: none;
  color: var(--ink-soft);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  padding: 8px;
}

.library-tools button:hover { color: var(--accent-dark); }

/* ---------- Record screen ---------- */

.record-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 18px;
  text-align: center;
  margin-bottom: 8px;
}

.record-btn {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: background-color 120ms ease, transform 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

.record-btn:hover { background: var(--accent-dark); }
.record-btn:active { transform: scale(0.96); }
.record-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.record-btn.recording {
  background: var(--danger);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(163, 59, 46, 0.35); }
  50% { box-shadow: 0 0 0 16px rgba(163, 59, 46, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .record-btn.recording { animation: none; }
}

.record-hint { margin: 14px 0 0; color: var(--ink-soft); font-size: 1rem; }

.record-timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 600;
  margin: 12px 0 0;
}

.record-timer:empty { display: none; }

.record-wave[hidden] { display: none; }

.record-wave {
  display: block;
  width: 100%;
  max-width: 320px;
  height: 48px;
  margin: 10px auto 0;
}

.live-transcript {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 15px;
  margin-top: 14px;
  max-height: 190px;
  overflow-y: auto;
  font-size: 1.02rem;
  line-height: 1.6;
}

.live-transcript .interim { color: var(--ink-soft); }

.summary-box {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
}

.summary-box h3 {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-dark);
}

.summary-box p { margin: 0; line-height: 1.6; }

.audio-preview { margin-top: 16px; }
.audio-preview audio { width: 100%; }

.remove-audio-btn {
  background: none;
  border: none;
  color: var(--danger);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  margin-top: 8px;
  padding: 6px;
}

/* ---------- Detail screen ---------- */

.detail-title {
  font-family: var(--serif);
  font-size: 1.65rem;
  font-weight: 600;
  margin: 0 0 4px;
  overflow-wrap: anywhere;
}

.detail-date { color: var(--ink-soft); margin: 0 0 18px; font-size: 0.95rem; }

.detail-audio { width: 100%; margin-bottom: 18px; }

.detail-text {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  font-size: 1.1rem;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.detail-text.empty { color: var(--ink-soft); font-style: italic; }

/* ---------- Prompt studio ---------- */

.create-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}

.create-row-label {
  margin: 0 0 10px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.create-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-block;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.95rem;
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

.chip:hover { border-color: var(--accent); color: var(--accent-dark); }

.qa-pair { margin-bottom: 12px; }
.qa-q { font-weight: 600; margin: 0 0 2px; }
.qa-a { margin: 0; color: var(--ink-soft); white-space: pre-wrap; }

.question-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 14px;
}

.question-card .qa-q { font-size: 1.15rem; margin-bottom: 10px; }

.prompt-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 14px;
}

.prompt-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.prompt-card-head h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.15rem;
}

.prompt-card-head .btn { min-height: 40px; padding: 8px 16px; font-size: 0.95rem; }

.prompt-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--sans);
  font-size: 0.95rem;
  line-height: 1.55;
  background: var(--bg);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0;
  max-height: 340px;
  overflow-y: auto;
}

.back-link {
  display: inline-block;
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 600;
  margin-bottom: 14px;
  padding: 6px 0;
}

.back-link:hover { text-decoration: underline; }

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
  body { font-size: 16.5px; }
  .app { padding-top: 14px; }
  .app-title { font-size: 1.45rem; }
}
