/* ── Design tokens ────────────────────────────────────────────── */
:root {
  /* Brand palette */
  --color-brand:        #2C5F8A;
  --color-brand-light:  #3A7AB8;
  --color-brand-dark:   #1E4266;

  /* Surface */
  --color-bg:           #F2F2F7;
  --color-surface:      #FFFFFF;
  --color-surface-2:    #F9F9FB;
  --color-border:       #E1E1E6;

  /* Text */
  --color-text:         #1C1C1E;
  --color-text-secondary: #6E6E73;
  --color-text-inverse: #FFFFFF;

  /* Semantic */
  --color-success:      #34C759;
  --color-danger:       #FF3B30;
  --color-warning:      #FF9500;

  /* Tab bar */
  --color-tab-bg:       rgba(255,255,255,0.92);
  --color-tab-active:   #2C5F8A;
  --color-tab-inactive: #8E8E93;

  /* Card reveal */
  --color-hidden-bg:    #EEF3F8;
  --color-hidden-text:  #2C5F8A;

  /* Typography */
  --font-sans:          -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-size-ref:      16px;
  --font-size-verse:    14px;
  --font-size-sm:       12px;
  --font-size-lg:       18px;
  --font-size-xl:       22px;

  /* Spacing */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;

  /* Radius */
  --radius-sm:  8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Shadow */
  --shadow-card: 0 1px 4px rgba(0,0,0,0.08), 0 2px 12px rgba(0,0,0,0.04);
  --shadow-sheet: 0 -2px 24px rgba(0,0,0,0.12);

  /* Safe areas */
  --tab-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:           #1C1C1E;
    --color-surface:      #2C2C2E;
    --color-surface-2:    #3A3A3C;
    --color-border:       #3A3A3C;
    --color-text:         #F2F2F7;
    --color-text-secondary: #8E8E93;
    --color-tab-bg:       rgba(28,28,30,0.92);
    --color-hidden-bg:    #1E3A57;
    --color-hidden-text:  #5B9BD5;
  }
}

[data-theme="dark"] {
  --color-bg:           #1C1C1E;
  --color-surface:      #2C2C2E;
  --color-surface-2:    #3A3A3C;
  --color-border:       #3A3A3C;
  --color-text:         #F2F2F7;
  --color-text-secondary: #8E8E93;
  --color-tab-bg:       rgba(28,28,30,0.92);
  --color-hidden-bg:    #1E3A57;
  --color-hidden-text:  #5B9BD5;
}

/* Large font mode */
[data-large-font="true"] {
  --font-size-ref:   22px;
  --font-size-verse: 20px;
}

/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, textarea {
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom */
}

/* ── Layout ───────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-top);
}

/* ── Header ───────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-md) var(--space-sm);
  background: var(--color-bg);
}

.app-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--color-brand);
}

.header-actions {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-brand);
  font-size: 20px;
  transition: background 0.15s;
}

.btn-icon:active { background: var(--color-border); }

/* ── Tab bar ──────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  background: var(--color-tab-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-border);
  z-index: 100;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding-bottom: var(--safe-bottom);
  color: var(--color-tab-inactive);
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: color 0.15s;
}

.tab-btn .tab-icon { font-size: 22px; line-height: 1; }
.tab-btn[aria-selected="true"] { color: var(--color-tab-active); }

/* ── Main content area ────────────────────────────────────────── */
.tab-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + var(--space-lg));
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Verse list ───────────────────────────────────────────────── */
.verse-list {
  padding: var(--space-sm) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* ── Verse card ───────────────────────────────────────────────── */
.verse-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: transform 0.1s;
  user-select: none;
  -webkit-user-select: none;
}

.verse-card:active { transform: scale(0.99); }

.verse-card__body {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.verse-card__reference {
  font-size: var(--font-size-ref);
  font-weight: 600;
  color: var(--color-brand);
  line-height: 1.3;
}

.verse-card__text {
  font-size: var(--font-size-verse);
  line-height: 1.6;
  color: var(--color-text);
}

.verse-card__hidden {
  background: var(--color-hidden-bg);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-hidden-text);
  font-size: var(--font-size-sm);
  font-weight: 500;
  text-align: center;
  cursor: pointer;
}

.verse-card__actions {
  display: flex;
  border-top: 1px solid var(--color-border);
}

.verse-card__action {
  flex: 1;
  padding: var(--space-sm);
  font-size: var(--font-size-sm);
  font-weight: 500;
  text-align: center;
  color: var(--color-brand);
  transition: background 0.15s;
}

.verse-card__action:active { background: var(--color-border); }
.verse-card__action.danger { color: var(--color-danger); }
.verse-card__action + .verse-card__action {
  border-left: 1px solid var(--color-border);
}

/* ── Tab panel headers ────────────────────────────────────────── */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md) 0;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel-subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.btn-text {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-brand);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.btn-text:active { background: var(--color-border); }
.btn-text.danger { color: var(--color-danger); }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl) var(--space-lg);
  gap: var(--space-md);
  text-align: center;
}

.empty-state__icon {
  font-size: 48px;
  opacity: 0.3;
}

.empty-state__title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-secondary);
}

.empty-state__subtitle {
  font-size: 15px;
  color: var(--color-text-secondary);
  max-width: 260px;
  line-height: 1.5;
}

/* ── FAB ──────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + var(--space-lg));
  right: var(--space-lg);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-brand);
  color: white;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(44,95,138,0.4);
  z-index: 90;
  transition: transform 0.15s, box-shadow 0.15s;
}

.fab:active {
  transform: scale(0.93);
  box-shadow: 0 2px 8px rgba(44,95,138,0.3);
}

/* ── Bottom sheet ─────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.sheet-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-sheet);
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: var(--safe-bottom);
  max-height: 90vh;
  overflow-y: auto;
}

.bottom-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--color-border);
  margin: var(--space-sm) auto var(--space-xs);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md) var(--space-md);
  border-bottom: 1px solid var(--color-border);
}

.sheet-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
}

.sheet-body {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* ── Form fields ──────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-input,
.form-textarea {
  background: var(--color-surface-2);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  font-size: 16px;
  color: var(--color-text);
  width: 100%;
  transition: border-color 0.15s;
  outline: none;
}

.form-input:focus,
.form-textarea:focus {
  border-color: var(--color-brand-light);
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}

.btn-primary {
  background: var(--color-brand);
  color: var(--color-text-inverse);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  font-size: 16px;
  font-weight: 600;
  width: 100%;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary:active { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: 15px;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-secondary:active { background: var(--color-border); }

.btn-danger {
  background: transparent;
  color: var(--color-danger);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: 15px;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-danger:active { background: rgba(255,59,48,0.08); }

/* ── Settings list ────────────────────────────────────────────── */
.settings-section {
  margin: var(--space-md);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
}

.settings-row:last-child { border-bottom: none; }

.settings-row-label {
  font-size: 16px;
  color: var(--color-text);
}

.settings-row-sublabel {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-top: 2px;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 31px;
  background: var(--color-border);
  transition: background 0.2s;
  cursor: pointer;
}

.toggle input:checked + .toggle-track { background: var(--color-success); }

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: transform 0.2s;
  pointer-events: none;
}

.toggle input:checked ~ .toggle-thumb { transform: translateX(20px); }

/* Time picker row */
.time-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.time-select {
  background: var(--color-surface-2);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px var(--space-sm);
  font-size: 15px;
  color: var(--color-text);
  outline: none;
}

/* ── Dialog / confirm ─────────────────────────────────────────── */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.dialog-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.dialog {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  width: 100%;
  max-width: 320px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
}

.dialog-title {
  padding: var(--space-lg) var(--space-lg) var(--space-sm);
  font-size: var(--font-size-lg);
  font-weight: 700;
  text-align: center;
}

.dialog-body {
  padding: 0 var(--space-lg) var(--space-lg);
  font-size: 15px;
  color: var(--color-text-secondary);
  line-height: 1.5;
  text-align: center;
}

.dialog-actions {
  border-top: 1px solid var(--color-border);
  display: flex;
}

.dialog-btn {
  flex: 1;
  padding: var(--space-md);
  font-size: 17px;
  font-weight: 500;
  text-align: center;
  color: var(--color-brand);
  transition: background 0.15s;
}

.dialog-btn:active { background: var(--color-border); }
.dialog-btn.confirm { font-weight: 600; }
.dialog-btn.destructive { color: var(--color-danger); font-weight: 600; }
.dialog-btn + .dialog-btn { border-left: 1px solid var(--color-border); }

/* ── Toast ────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + var(--space-lg));
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  background: rgba(44,44,46,0.92);
  color: white;
  padding: var(--space-sm) var(--space-md);
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  animation: toastIn 0.2s ease-out, toastOut 0.2s ease-in 2.4s forwards;
}

@keyframes toastIn  { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; } }

/* ── Sync badge ───────────────────────────────────────────────── */
.sync-badge {
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--color-border);
  color: var(--color-text-secondary);
}

.sync-badge.offline { background: rgba(255,149,0,0.15); color: var(--color-warning); }
.sync-badge.syncing { background: rgba(44,95,138,0.12); color: var(--color-brand); }

/* ── Loading overlay ──────────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  transition: opacity 0.3s;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Guide sheet ──────────────────────────────────────────────── */
.guide-content {
  padding: var(--space-md);
  line-height: 1.7;
  color: var(--color-text);
}

.guide-content h2 {
  font-size: var(--font-size-lg);
  font-weight: 700;
  margin-bottom: var(--space-sm);
  color: var(--color-brand);
}

.guide-content p {
  margin-bottom: var(--space-md);
  font-size: 15px;
}

.guide-content ul {
  padding-left: var(--space-lg);
  margin-bottom: var(--space-md);
}

.guide-content li {
  font-size: 15px;
  margin-bottom: var(--space-xs);
}

.week-legend {
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.week-legend-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
}

.week-badge {
  min-width: 80px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-brand);
}

.week-desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

/* ── Pull-to-refresh indicator ────────────────────────────────── */
.pull-indicator {
  text-align: center;
  padding: var(--space-sm);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  height: 0;
  overflow: hidden;
  transition: height 0.2s;
}

.pull-indicator.visible { height: 36px; }
