:root {
  --bg: #141618;
  --bg-subtle: #191B1F;
  --surface: #1F2227;
  --surface-hover: #262A30;
  --border: #2C3038;
  --text-main: #EDEDF0;
  --text-muted: #98A2B3;
  --accent-sage: #6AA590;
  --accent-sage-light: #8DC4B1;
  --accent-clay: #D8986B;
  --danger-soft: #D97373;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Georgia", "Merriweather", serif;
  
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* App Shell */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  position: relative;
  background-color: var(--bg);
}

/* Header */
.app-header {
  padding-top: calc(var(--safe-top) + 12px);
  padding-bottom: 12px;
  padding-left: 18px;
  padding-right: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background-color: var(--bg);
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.story-picker-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  text-align: left;
  max-width: 230px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease;
}

.story-picker-btn:hover {
  background-color: var(--surface);
}

.story-picker-btn span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chevron-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.95);
  background: var(--surface-hover);
}

/* Navigation Tabs */
.view-tabs {
  display: flex;
  padding: 8px 18px;
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background-color: var(--surface);
  color: var(--text-main);
}

.tab-badge {
  background-color: var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.tab-btn.active .tab-badge {
  background-color: var(--accent-sage);
  color: #121416;
  font-weight: 700;
}

/* Content Views */
.main-content {
  flex: 1;
  overflow-y: auto;
  position: relative;
  padding-bottom: 130px; /* Space for fixed recording bar */
}

.content-view {
  display: none;
  padding: 18px;
}

.content-view.active {
  display: block;
}

/* Notes & Scenes List */
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.note-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: border-color 0.2s ease;
}

.note-card:hover {
  border-color: #3D434D;
}

.note-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.note-order-tag {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-sage-light);
  background-color: rgba(106, 165, 144, 0.12);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

.note-time-info {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.note-audio-player {
  width: 100%;
  height: 36px;
  border-radius: var(--radius-sm);
  outline: none;
}

.note-text-block {
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--text-main);
  white-space: pre-wrap;
  word-break: break-word;
}

.note-text-block.raw {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.92rem;
  border-left: 2px solid var(--border);
  padding-left: 10px;
}

.note-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.card-actions {
  display: flex;
  gap: 8px;
}

.action-pill-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease;
}

.action-pill-btn.accent {
  background: rgba(106, 165, 144, 0.15);
  border-color: var(--accent-sage);
  color: var(--accent-sage-light);
}

.action-pill-btn:active {
  background: var(--surface-hover);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 24px;
  gap: 12px;
}

.empty-icon-circle {
  width: 68px;
  height: 68px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}

.empty-state h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-main);
}

.empty-state p {
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 320px;
}

/* Reader View (Kindle / Book Aesthetic) */
.reader-container {
  max-width: 540px;
  margin: 0 auto;
  padding: 12px 6px;
}

.reader-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.reader-header h1 {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  font-weight: 700;
  color: #F3F4F6;
  margin-bottom: 6px;
}

.reader-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-style: italic;
}

.reader-body {
  font-family: var(--font-serif);
  font-size: 1.12rem;
  line-height: 1.85;
  color: #E2E8F0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.reader-body p {
  text-indent: 1.4rem;
}

.reader-chapter-title {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent-clay);
  margin-top: 16px;
  text-indent: 0 !important;
}

/* Bottom Recording Dock */
.recorder-dock {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  background: linear-gradient(to top, var(--bg) 80%, rgba(20, 22, 24, 0.8) 95%, transparent);
  padding: 16px 20px calc(var(--safe-bottom) + 16px);
  z-index: 20;
  pointer-events: none;
}

.recorder-wrapper {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.recording-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius-full);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background-color: var(--text-muted);
  transition: all 0.3s ease;
}

.recording-status.active .status-dot {
  background-color: var(--accent-sage);
  box-shadow: 0 0 10px var(--accent-sage);
}

.recording-status.processing .status-dot {
  background-color: var(--accent-clay);
}

.record-btn {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: var(--radius-full);
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
}

.record-inner {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 2px solid var(--accent-sage);
  color: var(--accent-sage-light);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.record-btn:active .record-inner {
  transform: scale(0.92);
}

.record-btn.recording .record-inner {
  background: var(--accent-sage);
  color: #121416;
  border-color: var(--accent-sage-light);
  transform: scale(1.08);
}

.record-ring {
  position: absolute;
  inset: -6px;
  border-radius: var(--radius-full);
  border: 2px solid var(--accent-sage);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.record-btn.recording .record-ring {
  opacity: 0.6;
  animation: calmPulse 2s infinite ease-in-out;
}

@keyframes calmPulse {
  0% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.18); opacity: 0.15; }
  100% { transform: scale(1); opacity: 0.6; }
}

.btn-icon-stop {
  width: 20px;
  height: 20px;
  background-color: #121416;
  border-radius: 4px;
}

.hidden {
  display: none !important;
}

/* Modals & Bottom Sheets */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-sheet {
  background-color: var(--surface);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.calm-input {
  background-color: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  outline: none;
  width: 100%;
}

.calm-input:focus {
  border-color: var(--accent-sage);
}

.calm-textarea {
  background-color: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 1rem;
  line-height: 1.6;
  padding: 12px;
  border-radius: var(--radius-md);
  outline: none;
  resize: vertical;
  width: 100%;
  font-family: inherit;
}

.calm-textarea.secondary {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.calm-textarea:focus {
  border-color: var(--accent-sage);
}

.editor-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-label {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.new-story-box {
  display: flex;
  gap: 10px;
}

.calm-btn-primary {
  background-color: var(--accent-sage);
  color: #121416;
  border: none;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}

.calm-btn-primary:active {
  opacity: 0.85;
}

.calm-btn-danger {
  background-color: rgba(217, 115, 115, 0.15);
  color: var(--danger-soft);
  border: 1px solid var(--danger-soft);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.editor-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.stories-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.story-item {
  background-color: var(--bg);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: var(--radius-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.story-item.active {
  border-color: var(--accent-sage);
  background: rgba(106, 165, 144, 0.08);
}

.story-item-title {
  font-weight: 600;
  color: var(--text-main);
}

.story-item-count {
  font-size: 0.82rem;
  color: var(--text-muted);
}
