:root {
  --bg-main: #f4f6fb;
  --bg-card: #ffffff;
  --primary: #1e3a8a;
  --primary-light: #2563eb;
  --primary-soft: #eff6ff;
  --gold: #d97706;
  --gold-soft: #fef3c7;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #ea580c;
  --warning-soft: #ffedd5;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  padding-bottom: 82px;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  color: #fff;
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18);
}

.header-top {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 1.5rem;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand p {
  font-size: 0.75rem;
  color: #cbd5e1;
}

.header-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.header-pill {
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(6px);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

/* Main Container */
.app-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

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

/* Search & Tag Filters */
.search-bar-wrap {
  background: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}

.search-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.search-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus {
  border-color: var(--primary-light);
}

.tag-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.tag-scroll::-webkit-scrollbar {
  display: none;
}

.tag-chip {
  white-space: nowrap;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #f1f5f9;
  color: var(--text-muted);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}

.tag-chip.active, .tag-chip:hover {
  background: var(--primary-soft);
  color: var(--primary-light);
  border-color: #bfdbfe;
}

/* Saints Grid */
.saints-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.saint-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.saint-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.saint-card-top {
  display: flex;
  gap: 12px;
  padding: 14px;
  align-items: center;
}

.saint-avatar {
  width: 68px;
  height: 68px;
  border-radius: 14px;
  object-fit: cover;
  object-position: center top;
  flex-shrink: 0;
  background: #e2e8f0;
  border: 2px solid #e2e8f0;
}

.saint-card-info {
  flex: 1;
  min-width: 0;
}

.saint-feast-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  margin-bottom: 4px;
}

.saint-card-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.25;
}

.saint-card-tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.saint-card-footer {
  padding: 8px 14px 12px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mini-tag {
  font-size: 0.7rem;
  padding: 2px 7px;
  background: #f8fafc;
  color: #475569;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

/* Modal / Detail Sheet (Online with Saints style) */
.detail-modal {
  position: fixed;
  inset: 0;
  background: var(--bg-main);
  z-index: 100;
  overflow-y: auto;
  display: none;
  padding-bottom: 40px;
}

.detail-modal.open {
  display: block;
  animation: fadeIn 0.18s ease-out;
}

.detail-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-btn {
  background: #f1f5f9;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-weight: 700;
}

.detail-topbar-title {
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-tabs {
  position: sticky;
  top: 61px;
  z-index: 19;
  background: #ffffff;
  display: flex;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.detail-tab-btn {
  flex: 1;
  min-width: max-content;
  padding: 11px 14px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.detail-tab-btn.active {
  color: var(--primary-light);
  border-bottom-color: var(--primary-light);
}

.detail-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.hero-profile-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: center;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.hero-portrait {
  width: 88px;
  height: 88px;
  border-radius: 16px;
  object-fit: cover;
  object-position: center top;
  border: 2px solid var(--primary-soft);
  flex-shrink: 0;
  cursor: zoom-in;
}

.info-list-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 6px 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.info-item {
  padding: 11px 0;
  border-bottom: 1px solid #f1f5f9;
}

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

.info-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.info-value {
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-main);
}

.speech-bubble {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-left: 4px solid var(--primary-light);
  padding: 14px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-style: italic;
  color: #1e3a8a;
  font-size: 0.94rem;
}

.virtue-row {
  margin-bottom: 14px;
}

.virtue-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.virtue-bar-bg {
  height: 10px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 4px;
}

.virtue-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #f59e0b);
  border-radius: 999px;
}

.linked-saint-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
}

.linked-saint-item.clickable {
  cursor: pointer;
  border-color: #bfdbfe;
  background: #f8fafc;
}

.linked-saint-item.clickable:hover {
  background: var(--primary-soft);
}

/* Quiz Section */
.panel-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.section-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.select-box {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  font-size: 0.92rem;
  font-weight: 600;
  background: #fff;
}

.level-pills {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.level-btn {
  padding: 10px 8px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: #f8fafc;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.level-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary {
  width: 100%;
  padding: 13px 18px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.btn-secondary {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text-main);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.option-btn {
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  margin-bottom: 9px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: #fff;
  font-size: 0.93rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary-light);
  background: var(--primary-soft);
}

.option-btn.correct {
  background: var(--success-soft);
  border-color: var(--success);
  color: #14532d;
  font-weight: 700;
}

.option-btn.wrong {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: #7f1d1d;
}

.quiz-explanation {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: #f8fafc;
  border-left: 4px solid var(--primary-light);
  font-size: 0.88rem;
  margin: 12px 0;
}

/* Flashcards SRS (Anki style) */
.srs-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.srs-stat-box {
  padding: 12px;
  border-radius: var(--radius-md);
  text-align: center;
  border: 1px solid var(--border);
  background: #f8fafc;
}

.srs-stat-num {
  font-size: 1.35rem;
  font-weight: 800;
}

.srs-stat-label {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 600;
}

.flashcard-stage {
  min-height: 270px;
  background: linear-gradient(145deg, #ffffff 0%, #f8fafc 100%);
  border: 2px solid #cbd5e1;
  border-radius: 20px;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  margin-bottom: 14px;
  position: relative;
}

.fc-category-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-light);
}

.fc-body {
  margin: 18px 0;
  font-size: 1.04rem;
  line-height: 1.55;
  text-align: center;
  white-space: pre-line;
}

.anki-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.anki-btn {
  padding: 10px 6px;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: #fff;
}

.anki-btn span.interval {
  font-size: 0.68rem;
  opacity: 0.9;
  font-weight: 500;
}

.anki-again { background: #dc2626; }
.anki-hard { background: #ea580c; }
.anki-good { background: #16a34a; }
.anki-easy { background: #2563eb; }

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 50;
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.06);
}

.nav-item {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}

.nav-item .nav-icon {
  font-size: 1.25rem;
}

.nav-item.active {
  color: var(--primary-light);
}

.md-content h3 {
  font-size: 1rem;
  color: var(--primary);
  margin: 14px 0 6px;
}

.md-content p, .md-content li {
  font-size: 0.92rem;
  color: #334155;
  margin-bottom: 8px;
}

.md-content ul {
  padding-left: 18px;
}
