/* ====================================================
   하맘 성경노트 Pro — Apple Silver Design System
   "Simplicity is the ultimate sophistication." — Steve Jobs
   ==================================================== */

/* ── Design Tokens ── */
:root {
  /* Apple Silver Palette */
  --silver-50: #fafafa;
  --silver-100: #f5f5f7;
  --silver-200: #e8e8ed;
  --silver-300: #d2d2d7;
  --silver-400: #aeaeb2;
  --silver-500: #8e8e93;
  --silver-600: #636366;
  --silver-700: #48484a;
  --silver-800: #3a3a3c;
  --silver-900: #2c2c2e;
  --silver-950: #1c1c1e;

  /* Accent Colors */
  --blue: #007aff;
  --blue-light: #5ac8fa;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --purple: #af52de;
  --teal: #5ac8fa;
  --indigo: #5856d6;

  /* Category Colors */
  --sermon-color: #007aff;
  --faith-color: #34c759;
  --prayer-color: #ff9500;

  /* Surfaces */
  --bg-primary: #f5f5f7;
  --bg-elevated: #ffffff;
  --bg-grouped: #f2f2f7;
  --bg-frosted: rgba(255, 255, 255, 0.72);
  --bg-frosted-heavy: rgba(255, 255, 255, 0.88);

  /* Text */
  --text-primary: #1c1c1e;
  --text-secondary: #636366;
  --text-tertiary: #aeaeb2;
  --text-quaternary: #d2d2d7;

  /* Borders & Shadows */
  --separator: rgba(60, 60, 67, 0.08);
  --separator-opaque: #e5e5ea;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.08);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.1);

  /* Layout */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-full: 999px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-bar-height: 82px;
  --top-bar-height: 52px;
  --meta-strip-height: 48px;

  /* Motion */
  --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --duration-fast: 0.2s;
  --duration-normal: 0.35s;
  --duration-slow: 0.5s;
}

/* ── Reset & Base ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Noto Sans KR', 'SF Pro Display', 'Helvetica Neue', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.5;
  letter-spacing: -0.01em;
}

/* Status bar spacer for PWA */
.status-bar-spacer {
  height: env(safe-area-inset-top, 0px);
  background: var(--bg-frosted-heavy);
}

/* ── App Container ── */
#app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-primary);
}

/* ============================
   TOP BAR — Apple Navigation
   ============================ */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--top-bar-height);
  padding: 0 16px;
  background: var(--bg-frosted-heavy);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}

.top-bar-left,
.top-bar-right {
  width: 44px;
  display: flex;
  align-items: center;
}

.top-bar-right {
  justify-content: flex-end;
}

.top-bar-center {
  flex: 1;
  text-align: center;
}

.app-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.title-icon {
  font-size: 14px;
  color: var(--silver-400);
}

.title-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--blue);
  background: rgba(0, 122, 255, 0.1);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--blue);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-full);
  transition: background var(--duration-fast) var(--ease-out);
}

.icon-btn:active {
  background: rgba(0, 122, 255, 0.1);
}

.save-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  opacity: 0;
  transition: opacity var(--duration-normal);
}

.save-dot.active {
  opacity: 1;
  animation: savePulse 1.5s ease infinite;
}

@keyframes savePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================
   META STRIP — Date & Theme
   ============================ */
.meta-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-primary);
  overflow-x: auto;
  scrollbar-width: none;
}

.meta-strip::-webkit-scrollbar {
  display: none;
}

.meta-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 13px;
  white-space: nowrap;
  transition: all var(--duration-fast);
  flex-shrink: 0;
}

.meta-chip ion-icon {
  font-size: 15px;
  color: var(--silver-500);
}

.meta-chip input {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  width: auto;
  min-width: 60px;
}

.meta-chip input[type="date"] {
  width: 115px;
}

.meta-chip input[type="text"] {
  width: 100px;
}

.meta-chip.active {
  border-color: var(--blue);
  background: rgba(0, 122, 255, 0.04);
}

.category-select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--separator-opaque);
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
  transition: all var(--duration-fast);
}

.category-select:focus {
  border-color: var(--blue);
}

/* ============================
   CONTENT AREA — Tab Panels
   ============================ */
.content-area {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-panel {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: calc(var(--tab-bar-height) + 20px);
  -webkit-overflow-scrolling: touch;
}

.tab-panel.active {
  display: flex;
  animation: tabFadeIn var(--duration-normal) var(--ease-out);
}

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

/* ============================
   BIBLE TAB — Search & Verses
   ============================ */
.search-container {
  padding: 12px 16px 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-primary);
}

.apple-search-bar {
  display: flex;
  align-items: center;
  background: var(--bg-grouped);
  border-radius: var(--radius-md);
  padding: 0 12px;
  height: 40px;
  gap: 8px;
  transition: background var(--duration-fast);
}

.apple-search-bar:focus-within {
  background: var(--bg-elevated);
  box-shadow: 0 0 0 1px var(--blue);
}

.search-icon {
  font-size: 17px;
  color: var(--silver-400);
  flex-shrink: 0;
}

.apple-search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  color: var(--text-primary);
  outline: none;
}

.apple-search-bar input::placeholder {
  color: var(--silver-400);
}

.search-clear-btn {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--blue);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0;
  transition: transform var(--duration-fast);
}

.search-clear-btn:active {
  transform: scale(0.9);
}

.quick-selectors {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.version-selector {
  display: flex;
  background: var(--bg-grouped);
  padding: 2px;
  border-radius: var(--radius-md);
  margin-top: 8px;
}

.version-chip {
  flex: 1;
  text-align: center;
  position: relative;
  cursor: pointer;
}

.version-chip input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.version-chip span {
  display: block;
  padding: 6px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast);
}

.version-chip input:checked + span {
  background: var(--bg-elevated);
  color: var(--blue);
  box-shadow: var(--shadow-sm);
}

.version-chip:active span {
  transform: scale(0.97);
}

.apple-select {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  transition: all var(--duration-fast);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%23aeaeb2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.apple-select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

/* Verse List */
.verse-list {
  flex: 1;
  padding: 0 16px;
  overflow-y: auto;
}

.verse-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  margin: 0 -16px;
  border-bottom: 0.5px solid var(--separator);
  transition: all var(--duration-fast);
  cursor: pointer;
  user-select: none;
}

.verse-item:last-child {
  border-bottom: none;
}

.verse-item:active {
  background: rgba(0, 0, 0, 0.04);
}

.verse-item.selected {
  background: rgba(0, 122, 255, 0.08);
}

.verse-item-check {
  display: none; /* Hide native checkbox */
}

.verse-item-content {
  flex: 1;
  min-width: 0;
  position: relative;
  padding-left: 30px;
}

.verse-item-content::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--silver-300);
  border-radius: 50%;
  transition: all var(--duration-fast);
}

.verse-item.selected .verse-item-content::before {
  background: var(--blue);
  border-color: var(--blue);
}

.verse-item.selected .verse-item-content::after {
  content: '✓';
  position: absolute;
  left: 4px;
  top: 4px;
  color: white;
  font-size: 11px;
  font-weight: 700;
}

.verse-ref {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 4px;
  letter-spacing: 0.01em;
}

.verse-text {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-primary);
  word-break: keep-all;
}

/* Floating UI Toolbar */
.fab-container {
  position: fixed;
  bottom: calc(var(--tab-bar-height) + 16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  width: auto;
}

.fab-toolbar {
  display: flex;
  background: var(--bg-frosted-heavy);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 0.5px solid var(--separator);
  padding: 6px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  gap: 4px;
}

.fab-tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  position: relative;
  transition: all var(--duration-fast);
}

.fab-tool-btn:active {
  background: rgba(0, 0, 0, 0.05);
  transform: scale(0.9);
}

.tool-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--blue);
  color: white;
  font-size: 9px;
  font-weight: 800;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid white;
}

/* Search Highlight */
.search-highlight {
  background-color: #ffe082;
  color: #000;
  padding: 0 2px;
  border-radius: 2px;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(0,0,0,0.1);
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-tertiary);
}

.empty-state.small {
  padding: 30px 20px;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 15px;
  line-height: 1.5;
}

.empty-hint {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
  padding: 16px;
  font-style: italic;
}

/* Search Info */
.search-info {
  font-size: 13px;
  color: var(--blue);
  background: rgba(0, 122, 255, 0.06);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin: 8px 0 12px;
  font-weight: 500;
}

/* ============================
   NOTE TAB — Editor
   ============================ */
.note-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 0.5px solid var(--separator);
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 40px;
  height: 36px;
  border: none;
  background: var(--bg-grouped);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--duration-fast);
  padding: 0 10px;
}

.tool-btn ion-icon {
  font-size: 18px;
}

.tool-btn:active {
  transform: scale(0.94);
}

.tool-btn.highlight {
  background: #fff9c4;
  color: #f9a825;
}

.tool-btn.ai {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.tool-btn.ai:active {
  filter: brightness(0.9);
}

.tool-btn.save {
  background: var(--blue);
  color: white;
  margin-left: auto;
}

.tool-btn.recording-active {
  background: var(--red) !important;
  color: white !important;
  animation: micPulse 1.5s infinite;
}

#tts-btn.active {
  background: var(--blue);
  color: white;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--separator-opaque);
  margin: 0 4px;
}

@keyframes micPulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(255, 59, 48, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0); }
}

/* Verses Accordion */
.verses-accordion {
  margin: 0 16px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  overflow: hidden;
  margin-top: 8px;
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
}

.accordion-header span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.accordion-header ion-icon {
  font-size: 16px;
  color: var(--silver-400);
}

.accordion-chevron {
  transition: transform var(--duration-normal) var(--ease-out);
}

.verses-accordion.open .accordion-chevron {
  transform: rotate(180deg);
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  background: var(--blue);
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-full);
  padding: 0 6px;
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--duration-normal) var(--ease-out);
}

.verses-accordion.open .accordion-body {
  max-height: 300px;
  overflow-y: auto;
}

.selected-verse-chip {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 0.5px solid var(--separator);
  gap: 12px;
  animation: chipSlideIn 0.3s var(--ease-out);
}

.selected-verse-chip strong {
  font-size: 12px;
  color: var(--blue);
  display: block;
  margin-bottom: 4px;
}

.selected-verse-chip p {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.selected-verse-chip button {
  background: none;
  border: none;
  color: var(--red);
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  margin-top: 2px;
}

@keyframes chipSlideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Note Editor */
.editor-wrapper {
  flex: 1;
  padding: 12px 16px;
  padding-bottom: calc(var(--tab-bar-height) + 40px);
}

.note-editor-field {
  min-height: 420px;
  padding: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.8;
  color: var(--text-primary);
  outline: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  transition: border-color var(--duration-fast);
}

.note-editor-field:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.08);
}

.note-editor-field:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
  font-style: italic;
  pointer-events: none;
}

.note-editor-field mark {
  background: #fff59d;
  border-radius: 3px;
  padding: 1px 2px;
  color: var(--text-primary);
}

/* ============================
   CALENDAR TAB
   ============================ */
.calendar-card {
  margin: 12px 16px 0;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 16px;
  border: 1px solid var(--separator-opaque);
}

.cal-month-title {
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}

.cal-day-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  padding: 4px 0 8px;
}

.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  transition: all var(--duration-fast);
  position: relative;
}

.cal-cell:active {
  transform: scale(0.92);
}

.cal-cell.today {
  font-weight: 700;
  color: var(--blue);
}

.cal-cell.today::after {
  content: '';
  position: absolute;
  bottom: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--blue);
}

.cal-cell.active {
  background: var(--text-primary);
  color: white;
  border-radius: var(--radius-full);
}

.cal-cell.active.today::after {
  background: white;
}

.cal-cell.empty {
  cursor: default;
  pointer-events: none;
}

.cal-notes-indicator {
  display: flex;
  gap: 2px;
  margin-top: 3px;
  position: absolute;
  bottom: 3px;
}

.dot-sm {
  width: 4px;
  height: 4px;
  border-radius: 50%;
}

.dot-sm.sermon { background: var(--sermon-color); }
.dot-sm.faith { background: var(--faith-color); }
.dot-sm.prayer { background: var(--prayer-color); }

.calendar-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 10px 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-dot.sermon { background: var(--sermon-color); }
.legend-dot.faith { background: var(--faith-color); }
.legend-dot.prayer { background: var(--prayer-color); }

/* History Section */
.history-section {
  padding: 4px 16px 20px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.note-summary-item {
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  border-left: 3px solid var(--blue);
  transition: all var(--duration-fast);
}

.note-summary-item:active {
  transform: scale(0.98);
  background: var(--bg-grouped);
}

.note-summary-item.sermon { border-left-color: var(--sermon-color); }
.note-summary-item.faith { border-left-color: var(--faith-color); }
.note-summary-item.prayer { border-left-color: var(--prayer-color); }

.note-summary-item h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.note-summary-item p {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-summary-item small {
  font-size: 11px;
  color: var(--text-tertiary);
}

.notes-list {
  max-height: 300px;
  overflow-y: auto;
}

/* ============================
   TAB BAR — Apple-style
   ============================ */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  height: var(--tab-bar-height);
  padding-top: 8px;
  padding-bottom: var(--safe-bottom);
  background: var(--bg-frosted-heavy);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  z-index: 200;
}


.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 10px;
  font-weight: 500;
  color: var(--silver-400);
  cursor: pointer;
  padding: 4px 16px;
  transition: color var(--duration-fast);
  position: relative;
}

.tab-item .tab-icon-active {
  display: none;
}

.tab-item .tab-icon {
  font-size: 24px;
  display: block;
}

.tab-item.active {
  color: var(--blue);
}

.tab-item.active .tab-icon {
  display: none;
}

.tab-item.active .tab-icon-active {
  display: block;
  font-size: 24px;
}

.tab-item span {
  font-size: 10px;
  margin-top: 1px;
}

.tab-item:active {
  transform: scale(0.9);
}

/* ============================
   MODAL — Apple Sheet Style
   ============================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
  animation: modalBgFade 0.3s var(--ease-out);
}

@keyframes modalBgFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 430px;
  max-height: 85vh;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  display: flex;
  flex-direction: column;
  animation: modalSlideUp 0.4s var(--ease-spring);
  overflow: hidden;
}

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

.modal-handle {
  width: 36px;
  height: 5px;
  background: var(--silver-300);
  border-radius: var(--radius-full);
  margin: 10px auto 6px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 0.5px solid var(--separator);
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-header h2 ion-icon {
  color: var(--purple);
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--silver-400);
  cursor: pointer;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  line-height: 1.8;
  font-size: 15px;
  color: var(--text-secondary);
}

.modal-body h4 {
  color: var(--text-primary);
  font-size: 16px;
  margin: 20px 0 8px;
}

.modal-body ul {
  padding-left: 20px;
}

.modal-body li {
  margin-bottom: 6px;
}

.modal-actions {
  padding: 16px 20px;
  padding-bottom: calc(16px + var(--safe-bottom));
  border-top: 0.5px solid var(--separator);
  display: flex;
  gap: 10px;
}

.action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 48px;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-fast);
}

.action-btn.primary {
  background: var(--blue);
  color: white;
}

.action-btn.primary:active {
  background: #006adf;
}

/* ============================
   CONTEXT MENU — Slide Up Sheet
   ============================ */
.menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 500;
  align-items: flex-end;
  justify-content: center;
}

.menu-overlay.active {
  display: flex;
  animation: modalBgFade 0.2s var(--ease-out);
}

.menu-sheet {
  width: 100%;
  max-width: 430px;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding-bottom: calc(16px + var(--safe-bottom));
  animation: modalSlideUp 0.35s var(--ease-spring);
}

.menu-handle {
  width: 36px;
  height: 5px;
  background: var(--silver-300);
  border-radius: var(--radius-full);
  margin: 10px auto 6px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 24px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: background var(--duration-fast);
}

.menu-item ion-icon {
  font-size: 22px;
  color: var(--blue);
}

.menu-item:active {
  background: var(--bg-grouped);
}

/* ============================
   FOOTER
   ============================ */
.app-footer {
  padding: 24px 16px;
  padding-bottom: calc(var(--tab-bar-height) + 24px);
  color: var(--text-tertiary);
  border-top: 0.5px solid var(--separator);
  background: var(--bg-primary);
}

.footer-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  margin-bottom: 6px;
}

.footer-brand {
  font-weight: 700;
  color: var(--text-secondary);
}

.footer-info {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.8;
}

.disclaimer {
  text-align: right;
  font-size: 10px;
  opacity: 0.5;
}

/* ============================
   SCROLLBAR — Minimal
   ============================ */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--silver-300);
  border-radius: var(--radius-full);
}

/* ============================
   UTILITY — Animations
   ============================ */
.spin {
  animation: spin 1s linear infinite;
}

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

/* ============================
   PLACEHOLDER TEXT (Old compat)
   ============================ */
.placeholder-text {
  text-align: center;
  color: var(--text-tertiary);
  padding: 40px 20px;
  font-style: italic;
  font-size: 14px;
}

/* ============================
   DESKTOP — Responsive Scaling
   ============================ */
@media (min-width: 431px) {
  body {
    background: linear-gradient(180deg, #e5e5ea 0%, #f5f5f7 50%, #e5e5ea 100%);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px 0;
  }

  #app {
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-xl), 0 0 0 0.5px rgba(0,0,0,0.08);
    min-height: calc(100vh - 40px);
    max-height: calc(100vh - 40px);
  }

  .tab-bar {
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  }
}

/* ============================
   LARGE DESKTOP
   ============================ */
@media (min-width: 768px) {
  #app {
    max-width: 430px;
  }
}
/* ============================
   STORY MODE — Card Display
   ============================ */
.story-card {
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
  transition: all var(--duration-normal) var(--ease-spring);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.story-card:active {
  transform: scale(0.98);
}

.story-card.expanded .story-body {
  max-height: 2000px;
  padding: 16px;
  opacity: 1;
}

.story-card.expanded .story-chevron {
  transform: rotate(180deg);
}

.story-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.story-title-badge {
  font-size: 10px;
  font-weight: 800;
  color: var(--purple);
  background: rgba(175, 82, 222, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.story-title {
  flex: 1;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.story-chevron {
  font-size: 18px;
  color: var(--silver-400);
  transition: transform var(--duration-normal);
}

.story-body {
  max-height: 0;
  overflow: hidden;
  padding: 0 16px;
  opacity: 0;
  transition: all var(--duration-normal) var(--ease-out);
  background: var(--silver-50);
}

.story-text {
  font-size: 16px;
  line-height: 1.8;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: keep-all;
}
/* ============================
   TOGETHER MODE — Settings
   ============================ */
.together-options {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg-grouped);
  border-radius: var(--radius-md);
  margin-top: 8px;
  animation: fadeIn var(--duration-fast);
}

.option-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
}

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

.option-chips label {
  font-size: 13px;
  background: var(--bg-elevated);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--separator-opaque);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.option-chips input:checked + span,
.option-chips label:has(input:checked) {
  border-color: var(--blue);
  color: var(--blue);
  background: rgba(0, 122, 255, 0.05);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Story Menu Grid UI */
.story-menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 10px 0 20px;
}

.story-choice-card {
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-md);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  box-shadow: var(--shadow-sm);
}

.story-choice-card:active {
  transform: scale(0.96);
  background: var(--silver-100);
}

.story-choice-num {
  font-size: 11px;
  font-weight: 800;
  color: var(--blue);
  background: rgba(0, 122, 255, 0.1);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  margin-bottom: 8px;
}

.story-choice-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: keep-all;
}

/* AI Summary Button Pulse */
@keyframes aiPulse {
  0% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(102, 126, 234, 0); }
  100% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0); }
}

.tool-btn.ai:not(:disabled) {
  animation: aiPulse 2s infinite;
}

/* TTS & API UI */
.api-setup-panel {
  padding: 12px 16px;
  background: var(--silver-100);
  margin-bottom: 12px;
  border-radius: var(--radius-md);
  display: flex;
  gap: 8px;
}
.api-setup-panel.hidden { display: none; }
.api-setup-panel input { flex:1; border: 1px solid var(--separator); padding: 8px; border-radius: var(--radius-sm); font-size: 13px; }

.status-btn { background: var(--blue); color: white; border: none; padding: 0 12px; border-radius: var(--radius-sm); font-weight: 600; }

.modal-header-actions { display: flex; gap: 8px; }
.icon-btn-sm { background: none; border: none; font-size: 20px; color: var(--text-secondary); cursor: pointer; }

.tts-card { padding-top: 10px; }
.modal-title { font-size: 15px; font-weight: 700; text-align: center; color: var(--text-secondary); margin-bottom: 15px; }

.tts-now-playing {
  background: var(--silver-50);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
  text-align: center;
}
.tts-ref { font-size: 13px; font-weight: 700; color: var(--blue); margin-bottom: 6px; }
.tts-text { font-size: 16px; font-weight: 500; color: var(--text-primary); line-height: 1.4; word-break: keep-all; }

.tts-controls-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 24px;
}
.tts-primary-btn {
  width: 56px;
  height: 56px;
  border-radius: 28px;
  border: none;
  background: var(--bg-grouped);
  color: var(--text-primary);
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.tts-primary-btn.active { background: var(--blue); color: white; }
.tts-small-btn {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
}

.tts-options-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}
.tts-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tts-chips { display: flex; background: var(--bg-grouped); padding: 2px; border-radius: var(--radius-sm); }
.tts-chips label { cursor: pointer; position: relative; }
.tts-chips input { position: absolute; opacity: 0; }
.tts-chips span { display: block; padding: 4px 10px; font-size: 12px; font-weight: 600; border-radius: 6px; }
.tts-chips input:checked + span { background: white; box-shadow: var(--shadow-sm); color: var(--blue); }

/* Font Size Picker */
.font-size-picker {
  display: flex;
  background: var(--bg-grouped);
  padding: 2px;
  border-radius: var(--radius-sm);
  margin-left: auto;
  gap: 2px;
}
.fs-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 700;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.fs-btn.active {
  background: white;
  color: var(--blue);
  box-shadow: var(--shadow-sm);
}
.fs-btn.small { width: 28px; height: 28px; font-size: 11px; }
.fs-btn.default { width: 32px; height: 32px; font-size: 15px; }
.fs-btn.large { width: 36px; height: 36px; font-size: 19px; }

/* Global Font Apply */
:root { --app-font-size: 16px; }
body { font-size: var(--app-font-size); }
.verse-text { font-size: 1em; } 
#note-memo { font-size: 1em; }

/* Chapter Navigation */
.chapter-nav-row, .story-nav-row {
  display: flex;
  gap: 12px;
  padding: 20px 0 40px;
  justify-content: center;
}
.nav-chapter-btn {
  background: white;
  border: 1px solid var(--separator-opaque);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  color: var(--blue);
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all 0.2s;
}
.nav-chapter-btn:active {
  transform: scale(0.95);
  background: var(--silver-50);
}
.nav-chapter-btn ion-icon { font-size: 18px; }
.story-choice-card {
  background: var(--apple-card-bg);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1px solid var(--apple-border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.story-choice-card:hover {
  background: var(--silver-50);
  transform: translateY(-2px);
  box-shadow: var(--apple-shadow);
}

.story-choice-num {
  width: 40px;
  height: 40px;
  background: var(--apple-blue);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  margin-right: 20px;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.story-choice-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--apple-text);
  flex: 1;
}

.story-menu-grid {
  padding: 10px;
}

/* English Word Study Styles */
.verse-text.niv span {
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 4px;
    padding: 2px 4px;
    display: inline-block;
}

.verse-text.niv span:hover {
    background: rgba(0, 122, 255, 0.1);
    color: var(--apple-blue);
}

.word-study-accordion {
    margin-top: 20px;
    border-top: 1px solid var(--apple-border);
}

.word-item {
    background: var(--apple-card-bg);
    border: 1px solid var(--apple-border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.word-item:hover {
    background: var(--silver-50);
}

.word-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.word-text {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--apple-blue);
}

.word-pronounce {
    font-size: 0.9rem;
    color: #8e8e93;
    font-family: monospace;
}

.word-meaning {
    font-size: 0.95rem;
    color: var(--apple-text);
    line-height: 1.5;
    background: rgba(0,0,0,0.03);
    padding: 10px;
    border-radius: 8px;
    display: none; /* Hide by default for study */
}

.word-item.show-meaning .word-meaning {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

#bible-eng-btn.eng {
    background: linear-gradient(135deg, #FF9500, #FF3B30);
    color: white;
}

.eng-icon {
    font-weight: 900;
    font-size: 0.7rem;
}

/* Modal for word info */
.word-info {
    min-height: 100px;
}

.word-info-group {
    margin-bottom: 15px;
}

.word-info-label {
    font-size: 0.8rem;
    color: #8e8e93;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.word-info-value {
    font-size: 1rem;
    font-weight: 500;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(0,0,0,0.1);
    border-radius: 50%;
    border-top-color: var(--apple-blue);
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

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