/* Heritage Voice Memoir — senior-friendly, offline-first */

:root {
  --accent: #7B2D3E;
  --accent-hover: #5C1F2E;
  --accent-soft: #F3E4E8;
  --accent-ink: #3D1520;
  --bg: #FBF7F2;
  --surface: #FFFFFF;
  --surface-2: #F3EEE6;
  --text: #1C1917;
  --text-muted: #57534E;
  --border: #D6D0C8;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --success: #166534;
  --success-soft: #DCFCE7;
  --warn: #92400E;
  --warn-soft: #FEF3C7;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(28, 25, 23, 0.08), 0 4px 16px rgba(28, 25, 23, 0.06);
  --shadow-lg: 0 8px 30px rgba(28, 25, 23, 0.12);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", Times, serif;
  --touch: 48px;
  --max: 920px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -100px;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 0.75rem;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.85rem 1rem 0;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.brand-mark {
  font-size: 1.75rem;
  line-height: 1;
  margin-top: 0.15rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.main-nav {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  padding-bottom: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.main-nav::-webkit-scrollbar {
  display: none;
}

.nav-btn {
  flex: 0 0 auto;
  min-height: var(--touch);
  padding: 0.65rem 1rem;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.nav-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-btn.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}

/* Main */
.main {
  flex: 1;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
}

.view[hidden] {
  display: none !important;
}

.view-header {
  margin-bottom: 1.25rem;
}

.view-header.row-between {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.view-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

.view-lead {
  margin: 0;
  color: var(--text-muted);
  max-width: 40rem;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (min-width: 640px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.stat-card.stat-ok {
  border-color: #D4A5AE;
  background: linear-gradient(180deg, #FBF0F2 0%, var(--surface) 100%);
}

.stat-label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stat-value {
  margin: 0.25rem 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.stat-link {
  display: inline-block;
  min-height: 44px;
  padding: 0.35rem 0;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.stat-link:hover {
  color: var(--accent-hover);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.15rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.hero-card {
  border-color: #D4A5AE;
  background: linear-gradient(180deg, #FFF8F9 0%, var(--surface) 55%);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}

.card-head h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-ink);
}

.card-body-text {
  margin: 0 0 1rem;
  color: var(--text-muted);
}

.card-note {
  margin: -0.25rem 0 0.75rem;
}

.muted-sm {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.book-title-line {
  margin: 0 0 0.75rem;
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-ink);
}

/* Session timer */
.session-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.session-timer {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.session-label {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.session-time {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1;
}

.session-status {
  font-weight: 600;
  color: var(--text-muted);
}

.session-status.is-live {
  color: var(--success);
}

/* Prompt */
.prompt-quote {
  margin: 0 0 1rem;
  padding: 1rem 1.1rem;
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.prompt-quote p {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-family: var(--font-serif);
  color: var(--text);
  line-height: 1.45;
}

.prompt-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

@media (min-width: 640px) {
  .prompt-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.prompt-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  text-align: left;
  min-height: var(--touch);
}

.prompt-card:hover {
  border-color: var(--border);
  background: var(--accent-soft);
}

.prompt-card-title {
  margin: 0;
  font-weight: 700;
  color: var(--accent-ink);
  font-size: 0.95rem;
}

.prompt-card-text {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: var(--touch);
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-weight: 600;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--accent-ink);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--text-muted);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #991B1B;
  border-color: #991B1B;
}

.btn-text {
  min-height: 44px;
  padding: 0.35rem 0.5rem;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-text:hover {
  color: var(--accent-hover);
}

.btn-icon {
  min-width: var(--touch);
  min-height: var(--touch);
  padding: 0;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-sm {
  min-height: 44px;
  padding: 0.45rem 0.85rem;
  font-size: 0.95rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.file-label {
  cursor: pointer;
}

.label-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.35rem;
}

.label-row label {
  margin: 0;
  font-weight: 600;
  font-size: 0.95rem;
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.field.grow {
  flex: 1;
  min-width: 12rem;
}

.field label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.req {
  color: var(--danger);
}

.field input,
.field select,
.field textarea {
  min-height: var(--touch);
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 100%;
}

.field textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: 1.45;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 0.75rem;
}

@media (min-width: 560px) {
  .field-row {
    grid-template-columns: 1fr 1fr;
  }
}

.filter-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem 0.75rem;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

@media (min-width: 560px) {
  .filter-bar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 800px) {
  .filter-bar {
    grid-template-columns: repeat(4, 1fr);
  }
}

.filter-bar .field {
  margin-bottom: 0;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
  margin-bottom: 0.85rem;
}

.inline-form .field {
  margin-bottom: 0;
}

.result-summary {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Lists */
.item-list,
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.item-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.85rem 0.9rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.item-row:hover {
  border-color: var(--border);
}

.item-main {
  flex: 1;
  min-width: 12rem;
}

.item-title {
  margin: 0;
  font-weight: 700;
  color: var(--text);
  font-size: 1rem;
}

.item-meta {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.empty-state {
  padding: 1.25rem 1rem;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

.empty-state p {
  margin: 0 0 0.75rem;
}

.empty-state p:last-child {
  margin-bottom: 0;
}

/* Story / chapter cards */
.entity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.entity-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.5rem;
}

.entity-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-ink);
}

.entity-meta {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.entity-excerpt {
  margin: 0.5rem 0 0.75rem;
  color: var(--text);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge-draft {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: #FCD34D;
}

.badge-polished {
  background: var(--success-soft);
  color: var(--success);
  border-color: #86EFAC;
}

.badge-in-book {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #D4A5AE;
}

.badge-sample {
  background: #E0E7FF;
  color: #3730A3;
  border-color: #A5B4FC;
}

/* Progress bar */
.bar-row {
  display: grid;
  grid-template-columns: minmax(5rem, 9rem) 1fr auto;
  gap: 0.5rem 0.75rem;
  align-items: center;
  padding: 0.5rem 0;
}

.bar-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.bar-track {
  height: 12px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 0;
}

.bar-count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.9rem;
  min-width: 2rem;
  text-align: right;
}

/* Book preview */
.book-preview {
  max-height: 28rem;
  overflow: auto;
  padding: 1.5rem 1.25rem;
  background: #FFFEFB;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
  line-height: 1.65;
  color: var(--text);
}

.book-preview .bp-title {
  margin: 0 0 0.35rem;
  font-size: 1.6rem;
  text-align: center;
  color: var(--accent-ink);
}

.book-preview .bp-author {
  margin: 0 0 1.25rem;
  text-align: center;
  font-style: italic;
  color: var(--text-muted);
}

.book-preview .bp-dedication {
  margin: 0 0 1.5rem;
  text-align: center;
  font-style: italic;
  color: var(--text-muted);
  max-width: 28rem;
  margin-left: auto;
  margin-right: auto;
}

.book-preview .bp-chapter {
  margin: 1.75rem 0 0.75rem;
  font-size: 1.25rem;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
}

.book-preview .bp-chapter-summary {
  margin: 0 0 1rem;
  font-style: italic;
  color: var(--text-muted);
}

.book-preview .bp-story-title {
  margin: 1.25rem 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.book-preview .bp-story-body p {
  margin: 0 0 0.85rem;
}

.book-preview .bp-empty {
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font);
}

/* Detail body */
.detail-body {
  padding: 0 0.15rem 0.5rem;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0 0 1rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.detail-section {
  margin-bottom: 1.15rem;
}

.detail-section h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-ink);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-prose {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.55;
  font-family: var(--font-serif);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
    padding: 1.5rem;
  }
}

.modal[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: min(92vh, 900px);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-lg);
  padding: 1rem 1.15rem 1.25rem;
  z-index: 1;
}

@media (min-width: 640px) {
  .modal-panel {
    border-radius: var(--radius);
  }
}

.modal-panel-wide {
  max-width: 720px;
}

.modal-panel-sm {
  max-width: 420px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
  padding-bottom: 0.35rem;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--accent-ink);
  padding-top: 0.35rem;
}

.modal-form {
  margin: 0;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.confirm-message {
  margin: 0 0 0.5rem;
  color: var(--text);
  line-height: 1.5;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(92vw, 28rem);
  padding: 0.85rem 1.15rem;
  background: var(--accent-ink);
  color: #fff;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  text-align: center;
}

.toast[hidden] {
  display: none !important;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 1rem;
  text-align: center;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.app-footer p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Print */
@media print {
  .app-header,
  .app-footer,
  .skip-link,
  .toast,
  .modal,
  .filter-bar,
  .btn,
  .nav-btn,
  .stat-link,
  .session-panel,
  #view-home,
  #view-stories,
  #view-insights,
  #view-settings {
    display: none !important;
  }

  body {
    background: #fff;
  }

  #view-book {
    display: block !important;
  }

  #view-book .view-header,
  #view-book .card:not([aria-labelledby="preview-heading"]),
  #view-book .result-summary,
  #view-book .card-head .btn-row {
    display: none !important;
  }

  .book-preview {
    max-height: none;
    overflow: visible;
    border: none;
    padding: 0;
    box-shadow: none;
  }

  .main {
    max-width: none;
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .nav-btn {
    transition: none;
  }
}
