/* ============================================
   BHible - Bible Reading Heat Map
   Mobile-first PWA styles
   ============================================ */

:root {
  /* Dark theme (default) */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-card: #1c2128;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --border: #30363d;
  --accent: #58a6ff;
  --accent-dim: #1f6feb33;

  /* Heat map colors (GitHub-style green) */
  --heat-0: #161b22;
  --heat-1: #0e4429;
  --heat-2: #006d32;
  --heat-3: #26a641;
  --heat-4: #39d353;

  /* Sizes */
  --header-h: 52px;
  --tabbar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eaeef2;
  --bg-card: #f0f3f6;
  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #b1bac4;
  --border: #d0d7de;
  --accent: #0969da;
  --accent-dim: #0969da22;
  --heat-0: #ebedf0;
  --heat-1: #9be9a8;
  --heat-2: #40c463;
  --heat-3: #30a14e;
  --heat-4: #216e39;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

/* ===== Header ===== */
#top-bar {
  display: flex;
  align-items: center;
  height: var(--header-h);
  padding: 0 12px;
  padding-top: var(--safe-top);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
  z-index: 100;
}

#page-title {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#top-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.icon-btn:active {
  background: var(--bg-tertiary);
}

/* ===== Settings Panel ===== */
#settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  transition: opacity 0.25s;
}

#settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  max-width: 85vw;
  height: 100%;
  height: 100dvh;
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  z-index: 310;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow: hidden;
}

#settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: calc(14px + var(--safe-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.settings-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.setting-group {
  margin-bottom: 20px;
}

.setting-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.setting-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.setting-options-col {
  flex-direction: column;
}

.setting-opt {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}

.setting-opt:active {
  transform: scale(0.97);
}

.setting-opt.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.setting-opt.data-btn {
  background: var(--bg-tertiary);
  flex: 1;
  text-align: center;
}

.setting-opt.data-btn:active {
  background: var(--border);
}

/* ===== Tab Bar ===== */
#tab-bar {
  display: flex;
  height: var(--tabbar-h);
  padding-bottom: var(--safe-bottom);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s;
  padding: 4px;
}

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

.tab svg {
  flex-shrink: 0;
}

/* ===== Main Content ===== */
#content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  padding-bottom: 12px;
}

.page {
  display: none;
  animation: fadeIn 0.2s ease;
}

.page.active {
  display: block;
}

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

/* ===== Testament Toggle ===== */
#testament-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 3px;
}

.testament-btn {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.testament-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ===== Book Grid (Heat Map) ===== */
#book-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-start;
}

.book-block {
  position: relative;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  min-width: 48px;
  min-height: 48px;
  padding: 2px;
}

.book-block:active {
  transform: scale(0.96);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.book-block canvas {
  display: block;
  border-radius: 3px;
  pointer-events: none;
}

.book-block .book-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1;
  padding: 1px 2px 0;
  pointer-events: none;
  z-index: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.book-block.large-block .book-label {
  font-size: 10px;
}

/* ===== Chapter Grid ===== */
#chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}

.chapter-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s;
  border: 1px solid transparent;
  position: relative;
  min-height: 56px;
}

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

.chapter-cell .chapter-num {
  z-index: 1;
  pointer-events: none;
}

.chapter-cell .chapter-progress {
  position: absolute;
  bottom: 4px;
  font-size: 8px;
  color: var(--text-secondary);
  pointer-events: none;
}

/* ===== Verse Grid ===== */
#verse-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.toolbar-btn {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.toolbar-btn:active {
  background: var(--bg-tertiary);
}

.relight-btn {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  margin-left: auto;
}

#verse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 5px;
  margin-bottom: 14px;
  user-select: none;
  -webkit-user-select: none;
}

.verse-cell {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.08s;
  border: 2px solid transparent;
  position: relative;
  min-height: 48px;
}

.verse-cell:active {
  transform: scale(0.9);
}

.verse-cell.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.verse-cell .read-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

#verse-actions {
  display: flex;
  gap: 8px;
  padding-bottom: 20px;
}

.primary-btn {
  flex: 1;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.primary-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.primary-btn:active:not(:disabled) {
  transform: scale(0.97);
}

/* ===== Legend ===== */
#legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 16px;
  padding: 10px 0;
}

.legend-label {
  font-size: 11px;
  color: var(--text-secondary);
}

.legend-cell {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--heat-4) calc(var(--heat) * 100%), var(--heat-0));
}

/* ===== Dashboard ===== */
#dashboard-content {
  padding-bottom: 20px;
}

.dash-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}

.dash-card h3 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-item {
  text-align: center;
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: 8px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Progress bars */
.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.progress-label {
  font-size: 13px;
  color: var(--text-primary);
  min-width: 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-bar-bg {
  flex: 1;
  height: 10px;
  background: var(--bg-tertiary);
  border-radius: 5px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 5px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.progress-pct {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 38px;
  text-align: right;
}

/* Hour chart */
.hour-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 60px;
  margin-top: 8px;
}

.hour-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.hour-bar {
  width: 100%;
  max-width: 12px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  min-height: 1px;
  transition: height 0.3s;
}

.hour-label {
  font-size: 7px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Day chart */
.day-chart {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 8px;
}

.day-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.day-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
}

.day-label {
  font-size: 10px;
  color: var(--text-secondary);
}

/* Months grid */
.months-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.month-item {
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}

.month-name {
  font-size: 11px;
  color: var(--text-secondary);
}

.month-days {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.month-suffix {
  font-size: 10px;
  color: var(--text-muted);
}

/* ===== Toast ===== */
#toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 500;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

/* Long press ripple */
@keyframes longPressRipple {
  0% { transform: scale(0); opacity: 0.5; }
  100% { transform: scale(2.5); opacity: 0; }
}

.long-press-indicator {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  pointer-events: none;
  animation: longPressRipple 0.6s ease-out forwards;
}

/* Scrollbar */
#content::-webkit-scrollbar {
  width: 4px;
}

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

#content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* ===== Category Section in Heat Map ===== */
.category-section {
  margin-bottom: 12px;
}

.category-header {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  padding-left: 2px;
}

.category-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-start;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

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