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

:root {
  --bg: #ffffff;
  --primary: #1a1a2e;
  --accent: #4a90d9;
  --accent-light: #e8f2fc;
  --text: #1a1a2e;
  --muted: #6b7280;
  --surface: #f8f9fa;
  --border: #e5e7eb;
  --danger: #ef4444;
  --success: #22c55e;
  --star: #f59e0b;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(26,26,46,.08);
  --shadow-md: 0 4px 24px rgba(26,26,46,.12);
  --tab-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Layout ===== */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 8px);
  -webkit-overflow-scrolling: touch;
}

/* ===== Utilities ===== */
.hidden { display: none !important; }

/* ===== Tab Panels ===== */
.tab-panel {
  display: none;
  padding: 0 0 24px;
  animation: fadeIn .18s ease;
}
.tab-panel.active { display: block; }

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

/* ===== Tab Header ===== */
.tab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.tab-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.3px;
}

.tab-header-search {
  padding: 12px 16px;
}

/* ===== Bottom Tab Bar ===== */
.tab-bar {
  display: flex;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg);
  border-top: 1px solid var(--border);
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  z-index: 100;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  transition: color .15s;
  padding: 0;
}

.tab-btn.active { color: var(--primary); }

.tab-icon {
  font-size: 20px;
  line-height: 1;
}

.tab-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .2px;
}

.tab-btn.active .tab-label { font-weight: 700; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(.97); opacity: .85; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--primary); border: 1.5px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-full { width: 100%; }

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface); color: var(--primary); }
.icon-btn svg { width: 20px; height: 20px; }

/* ===== Setup Screen ===== */
.setup-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
}

.setup-error {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.5;
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}
.setup-error.setup-success {
  background: #f0fdf4;
  color: #15803d;
  border-color: #bbf7d0;
}

.setup-help {
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
}
.setup-help summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 0;
  user-select: none;
}
.setup-help ol {
  margin: 10px 0 0 18px;
  line-height: 1.8;
}
.setup-help li { margin-bottom: 2px; }

.setup-card {
  background: #fff;
  border-radius: 24px;
  padding: 36px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.setup-logo {
  width: 64px;
  height: 64px;
  background: var(--primary);
  color: #fff;
  font-size: 32px;
  font-weight: 900;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.setup-title {
  font-size: 24px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 8px;
}

.setup-subtitle {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 28px;
  line-height: 1.5;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 18px;
}

.form-group-half { flex: 1; }

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 0;
}

.form-row .form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: .1px;
}

.form-label-inline {
  display: inline;
  margin-bottom: 0;
  font-weight: 500;
  cursor: pointer;
}

.form-group-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color .15s;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

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

.form-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.form-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.4;
}

.form-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

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

.checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.checkbox-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  user-select: none;
}

.checkbox-chip input { display: none; }

.checkbox-chip.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.testamento-display {
  font-size: 14px;
  color: var(--muted);
  padding: 8px 0;
  font-style: italic;
}

.testamento-display.filled {
  color: var(--text);
  font-style: normal;
  font-weight: 500;
}

.agregar-form {
  padding: 8px 20px 32px;
}

.nemotecnia-note {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 18px;
  line-height: 1.5;
  border: 1px solid var(--border);
}

.agregar-feedback {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

.agregar-feedback.success {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.agregar-feedback.error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

/* ===== Verse Card ===== */
.verse-card {
  margin: 16px 20px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

.verse-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  gap: 12px;
}

.verse-ref {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
  letter-spacing: -.3px;
}

.verse-text {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 16px;
  line-height: 1.75;
  color: var(--text);
  white-space: pre-wrap;
}

.verse-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .1px;
}

.badge-version { background: var(--primary); color: #fff; }
.badge-libro { background: var(--surface); color: var(--primary); border: 1px solid var(--border); }
.badge-tema { background: var(--accent-light); color: var(--accent); }
.badge-keyword { background: #fef9c3; color: #854d0e; }

/* ===== Star Button ===== */
.star-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
  padding: 4px;
  transition: transform .2s;
  color: var(--star);
  flex-shrink: 0;
}
.star-btn:active { transform: scale(1.3); }

/* ===== Action Buttons ===== */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 20px;
  margin-top: 4px;
}

/* ===== Nemotecnia & Context ===== */
.nemotecnia-card, .context-card {
  margin: 12px 20px 0;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  border: 1px solid var(--border);
  animation: fadeIn .2s ease;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  margin-bottom: 10px;
}

.nemotecnia-text {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-wrap;
}

.context-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

/* ===== Loading & Error States ===== */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 15px;
}

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

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

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 20px;
  text-align: center;
}

.error-msg {
  font-size: 15px;
  color: var(--muted);
  line-height: 1.5;
  max-width: 280px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 15px;
}

/* ===== Flashcard ===== */
.flashcard-container {
  padding: 16px 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.flashcard {
  width: 100%;
  min-height: 280px;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  padding: 32px 24px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, box-shadow .15s;
}

.flashcard:active { transform: scale(.98); box-shadow: var(--shadow); }

.flashcard-inner {
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.flashcard-ref {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -.3px;
}

.flashcard-text {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 16px;
  line-height: 1.75;
  color: var(--text);
  text-align: left;
  animation: fadeIn .25s ease;
}

.flashcard-anchor {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  width: 100%;
  text-align: left;
  animation: fadeIn .25s ease;
}

.anchor-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #92400e;
  display: block;
  margin-bottom: 6px;
}

.flashcard-anchor p {
  font-size: 15px;
  font-weight: 600;
  color: #78350f;
  line-height: 1.5;
}

.flashcard-hint {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

.flashcard-progress {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.flashcard-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s, transform .1s;
  box-shadow: var(--shadow);
}

.nav-btn svg { width: 22px; height: 22px; color: var(--primary); }
.nav-btn:active { transform: scale(.94); background: var(--surface); }
.nav-btn-reset svg { width: 18px; height: 18px; }

/* ===== Toggle ===== */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.toggle-label input { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }
.toggle-text { user-select: none; }

/* ===== Search ===== */
.search-wrapper {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  pointer-events: none;
  line-height: 1;
}

.search-input {
  width: 100%;
  padding: 11px 14px 11px 38px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  -webkit-appearance: none;
}

.search-input:focus { border-color: var(--accent); background: var(--bg); }
.search-input::placeholder { color: var(--muted); }

.search-results {
  padding: 8px 16px 0;
}

.search-result-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 8px;
  transition: background .12s, box-shadow .12s;
  animation: fadeIn .15s ease;
}

.search-result-item:active { background: var(--surface); }

.search-result-ref {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

.search-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
  font-size: 15px;
}

/* ===== 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: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}

.modal-sheet {
  position: relative;
  z-index: 1;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 430px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  animation: slideUp .25s cubic-bezier(.32,.72,0,1);
}

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

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}

.modal-ref {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -.3px;
}

.modal-close-btn {
  background: var(--surface);
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
  transition: background .15s;
}

.modal-close-btn:hover { background: var(--border); color: var(--text); }

.modal-body {
  overflow-y: auto;
  padding: 20px 20px 40px;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-section { display: flex; flex-direction: column; gap: 8px; }

/* ===== Desktop ===== */
@media (min-width: 431px) {
  body { background: #f0f0f5; }
  .app { box-shadow: 0 0 0 1px var(--border), var(--shadow-md); }
  .setup-screen { background: linear-gradient(160deg, #1a1a2e, #16213e 60%, #0f3460); }
}
