/* ===== Theme Variables ===== */
:root,
[data-theme="light"] {
  --bg: #f8f5f0;
  --bg-surface: #ffffff;
  --bg-surface-hover: #faf8f5;
  --text: #2c2c2c;
  --text-secondary: #7a7a7a;
  --text-muted: #b0aaa2;
  --primary: #8b6f5c;
  --primary-soft: #c4a98e;
  --accent: #d4a87c;
  --accent-light: #f5ece3;
  --border: #ebe5dd;
  --card: #ffffff;
  --card-stale: #f5f2ed;
  --save-green: #7cb38a;
  --dismiss-rose: #d4897a;
  --shadow: rgba(0,0,0,0.04);
  --shadow-md: rgba(0,0,0,0.06);
  --overlay: rgba(0,0,0,0.4);
}

[data-theme="dark"] {
  --bg: #1a1816;
  --bg-surface: #252220;
  --bg-surface-hover: #2e2a27;
  --text: #e8e2db;
  --text-secondary: #a09890;
  --text-muted: #6b635b;
  --primary: #c4a98e;
  --primary-soft: #8b6f5c;
  --accent: #d4a87c;
  --accent-light: #3a3028;
  --border: #3a3530;
  --card: #252220;
  --card-stale: #1e1c1a;
  --save-green: #7cb38a;
  --dismiss-rose: #d4897a;
  --shadow: rgba(0,0,0,0.15);
  --shadow-md: rgba(0,0,0,0.25);
  --overlay: rgba(0,0,0,0.6);
}

/* ===== Fonts ===== */
:root {
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --nav-height: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.3s, color 0.3s;
}

/* ===== App Layout ===== */
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ===== Loading Screen ===== */
#loading-screen {
  justify-content: center;
  align-items: center;
  background: var(--bg);
}
.loading-content { text-align: center; padding: 2rem; }
.logo-text {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 400;
  font-style: italic;
  color: var(--primary);
  letter-spacing: -0.02em;
}
.logo-tagline {
  font-size: 0.85rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 0.25rem;
  font-weight: 300;
}
.loading-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 2rem;
  margin-bottom: 1rem;
}
.loading-bar {
  width: 180px;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  margin: 0 auto;
  overflow: hidden;
}
.loading-fill {
  height: 100%;
  width: 30%;
  background: var(--accent);
  border-radius: 1px;
  animation: loading-slide 1.5s ease-in-out infinite;
}
@keyframes loading-slide {
  0%, 100% { transform: translateX(-100%); }
  50% { transform: translateX(300%); }
}

/* ===== App Header ===== */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.header-logo {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 400;
  font-style: italic;
  color: var(--primary);
}
#theme-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}
#theme-toggle:active { color: var(--primary); }

/* ===== Transcription Area ===== */
#transcription-area {
  padding: 0.75rem 1.25rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  display: flex;
  align-items: center;
}
#transcription-text {
  font-size: 0.9rem;
  font-weight: 300;
  color: var(--text-muted);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-style: italic;
}
#transcription-text.active {
  color: var(--text);
  font-style: normal;
  font-weight: 400;
}

/* ===== Mic Button ===== */
#mic-container {
  display: flex;
  justify-content: center;
  padding: 0.75rem 0 0.5rem;
  flex-shrink: 0;
}
#mic-btn {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
#mic-btn:active { transform: scale(0.95); }
#mic-btn.listening {
  background: var(--dismiss-rose);
  border-color: var(--dismiss-rose);
  color: white;
}
#mic-pulse {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1.5px solid var(--dismiss-rose);
  opacity: 0;
  pointer-events: none;
}
#mic-btn.listening #mic-pulse {
  animation: pulse-ring 1.5s ease-out infinite;
}
@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* ===== Verse Feed ===== */
#verse-feed {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 1rem 1rem;
  -webkit-overflow-scrolling: touch;
}

/* ===== Empty State ===== */
#empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}
.empty-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  font-weight: 300;
}
#empty-state.hidden { display: none; }

/* ===== Verse Cards ===== */
.verse-card {
  background: var(--card);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.6rem;
  box-shadow: 0 1px 3px var(--shadow), 0 1px 2px var(--shadow);
  border-left: 3px solid var(--accent);
  transition: opacity 0.6s ease, background 0.6s ease, border-color 0.6s ease;
  position: relative;
  touch-action: pan-y;
  will-change: transform;
}
.verse-card .verse-ref {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--primary);
  margin-bottom: 0.3rem;
  letter-spacing: 0.01em;
}
.verse-card .verse-text {
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text);
  font-weight: 300;
}
.verse-card .verse-reason {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  font-style: italic;
}

/* Verse aging */
.verse-card.fresh {
  border-left-color: var(--accent);
  opacity: 1;
}
.verse-card.fading {
  border-left-color: var(--primary-soft);
  opacity: 0.55;
}
.verse-card.stale {
  border-left-color: var(--border);
  opacity: 0.35;
  background: var(--card-stale);
}

/* Entrance animation */
.verse-card.entering {
  animation: card-enter 0.35s ease-out forwards;
}
@keyframes card-enter {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Swipe states */
.verse-card.swiping { transition: none; }
.verse-card .swipe-indicator {
  position: absolute;
  top: 0; bottom: 0;
  width: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.verse-card .swipe-save {
  right: 100%; margin-right: 6px;
  color: var(--save-green);
}
.verse-card .swipe-dismiss {
  left: 100%; margin-left: 6px;
  color: var(--dismiss-rose);
}
.verse-card.swipe-right-hint .swipe-save { opacity: 1; }
.verse-card.swipe-left-hint .swipe-dismiss { opacity: 1; }
.verse-card.swiped-right { animation: swipe-out-right 0.25s ease-out forwards; }
.verse-card.swiped-left { animation: swipe-out-left 0.25s ease-out forwards; }
@keyframes swipe-out-right { to { transform: translateX(120%); opacity: 0; } }
@keyframes swipe-out-left { to { transform: translateX(-120%); opacity: 0; } }

/* ===== Chapter Reader ===== */
#reader-screen { background: var(--bg); }
#reader-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
#reader-header button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
}
#reader-header button:active { background: var(--accent-light); }
#reader-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
}
#reader-nav { display: flex; gap: 0.15rem; }
#reader-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 2rem;
  -webkit-overflow-scrolling: touch;
}
.reader-verse { margin-bottom: 0.35rem; line-height: 1.75; }
.reader-verse .verse-num {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--primary);
  vertical-align: super;
  margin-right: 2px;
}
.reader-verse .verse-content {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 300;
}
.reader-verse.highlighted {
  background: var(--accent-light);
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
  margin-left: -0.65rem;
  margin-right: -0.65rem;
}

/* ===== Saved Screen ===== */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.screen-header h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
}
.header-action {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
}
.header-action:active { background: var(--accent-light); }
#saved-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1rem;
  -webkit-overflow-scrolling: touch;
}
.saved-card {
  background: var(--card);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.6rem;
  box-shadow: 0 1px 3px var(--shadow);
  cursor: pointer;
  border-left: 3px solid var(--primary);
  position: relative;
  touch-action: pan-y;
}
.saved-card .verse-ref {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--primary);
  margin-bottom: 0.25rem;
}
.saved-card .verse-text {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
  font-weight: 300;
}
.saved-card .saved-date {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}
.saved-card.swiped-left { animation: swipe-out-left 0.25s ease-out forwards; }
#saved-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 300;
}

/* ===== Settings Screen ===== */
#settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}
.setting-group { margin-bottom: 1.5rem; }
.setting-label {
  font-weight: 500;
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
}
.setting-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.6rem;
  line-height: 1.4;
  font-weight: 300;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  height: 4px;
}
.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.theme-options { display: flex; gap: 0.5rem; }
.theme-opt {
  flex: 1;
  padding: 0.55rem;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.theme-opt.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--accent-light);
}
.btn-danger {
  background: var(--dismiss-rose);
  color: white;
  border: none;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
}
.btn-danger:active { opacity: 0.85; }
.about { border-top: 1px solid var(--border); padding-top: 1.25rem; }
.version-current {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--primary);
  margin-bottom: 0.75rem;
}
.version-list { display: flex; flex-direction: column; gap: 0.6rem; }
.version-entry {
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  border-left: 2px solid var(--border);
}
.version-entry:first-child { border-left-color: var(--accent); }
.version-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
}
.version-date {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}
.version-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  line-height: 1.4;
  font-weight: 300;
}

/* ===== Share Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}
.modal-content {
  position: relative;
  background: var(--bg-surface);
  border-radius: 16px 16px 0 0;
  padding: 1.5rem;
  width: 100%;
  max-width: 430px;
  max-height: 80vh;
  overflow-y: auto;
  animation: modal-slide-up 0.3s ease-out;
}
@keyframes modal-slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
}
.modal-content h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.modal-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 1rem;
  font-weight: 300;
}
#share-form { display: flex; flex-direction: column; gap: 0.75rem; }
#share-form input {
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}
#share-form input:focus {
  outline: none;
  border-color: var(--primary);
}
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.7rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-body);
}
.btn-primary:active { opacity: 0.85; }
.share-link-box {
  display: flex;
  gap: 0.5rem;
}
.share-link-box input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--text);
}
.share-link-box button {
  padding: 0.6rem 1rem;
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  background: transparent;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}

/* ===== Bottom Nav ===== */
#bottom-nav {
  display: flex;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--nav-height) + var(--safe-bottom));
  flex-shrink: 0;
  transition: background 0.3s;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.6rem;
  font-weight: 400;
  letter-spacing: 0.03em;
  cursor: pointer;
  padding: 0.4rem;
  transition: color 0.2s;
}
.nav-btn.active { color: var(--primary); }
.nav-btn:active { opacity: 0.7; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--text);
  color: var(--bg);
  padding: 0.5rem 1.1rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Unsupported ===== */
#unsupported {
  position: fixed;
  inset: 0;
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
#unsupported p {
  font-size: 0.9rem;
  line-height: 1.5;
  margin-top: 0.5rem;
  color: var(--text-secondary);
  font-weight: 300;
}

/* ===== Desktop centering ===== */
@media (min-width: 500px) {
  #app {
    max-width: 430px;
    margin: 0 auto;
    box-shadow: 0 0 30px var(--shadow-md);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
