:root {
  --bg: #07070e;
  --bg-card: #111120;
  --bg-card-hover: #1a1a2e;
  --bg-surface: #0d0d1a;
  --bg-input: #16162a;
  --border: #1e1e3a;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --primary: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.15);
  --accent: #22d3ee;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --nav-height: 72px;
  --header-height: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ───────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Header ──────────────────────────── */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--header-height) + var(--safe-top));
  padding-top: var(--safe-top);
  background: rgba(7, 7, 14, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
  z-index: 100;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.header-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  padding: 8px;
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition: var(--transition);
}
.header-btn:hover { color: var(--text); background: var(--bg-card); }

.sync-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition);
}
.sync-indicator.connected { background: var(--success); }
.sync-indicator.syncing { background: var(--warning); animation: pulse 1s infinite; }

/* ── Bottom Nav ──────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(7, 7, 14, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: relative;
}

.nav-item .nav-icon { font-size: 22px; transition: var(--transition); }
.nav-item.active { color: var(--primary); }
.nav-item.active .nav-icon { transform: scale(1.1); }
.nav-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 3px 3px;
}

/* ── Main Content ────────────────────── */
.main-content {
  padding-top: calc(var(--header-height) + var(--safe-top) + 8px);
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  padding-left: 16px;
  padding-right: 16px;
  min-height: 100vh;
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }

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

/* ── Cards ───────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  transition: var(--transition);
}
.card:hover { border-color: rgba(99, 102, 241, 0.3); }

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

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ── Phase Banner ────────────────────── */
.phase-banner {
  background: linear-gradient(135deg, var(--bg-card), var(--bg-surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.phase-badge {
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 20px;
  white-space: nowrap;
}

.phase-info { flex: 1; }
.phase-info .phase-label { font-size: 13px; color: var(--text-secondary); }
.phase-info .phase-desc { font-size: 14px; font-weight: 500; margin-top: 2px; }

/* ── Stats Row ───────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* ── Session Card ────────────────────── */
.session-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: var(--transition);
  cursor: pointer;
}
.session-card:hover { background: var(--bg-card-hover); }
.session-card.done { opacity: 0.5; }
.session-card.done .session-subject { text-decoration: line-through; }

.session-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.session-info { flex: 1; min-width: 0; }
.session-subject { font-weight: 600; font-size: 15px; }
.session-type { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.session-review { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.session-review::before { content: '↻ '; }

.session-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
  cursor: pointer;
  background: none;
  color: transparent;
  font-size: 14px;
}
.session-check.checked {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

/* ── Timer ───────────────────────────── */
.timer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
}

.timer-ring-wrapper {
  position: relative;
  width: 260px;
  height: 260px;
  margin-bottom: 32px;
}

.timer-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 6;
}

.timer-ring-progress {
  fill: none;
  stroke: var(--primary);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke 0.3s;
}

.timer-ring-progress.break { stroke: var(--success); }
.timer-ring-progress.longBreak { stroke: var(--accent); }

.timer-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.timer-time {
  font-size: 56px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
}

.timer-phase-label {
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

.timer-sessions-dots {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: center;
}

.timer-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.timer-dot.filled { background: var(--primary); }

.timer-controls {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 32px;
}

.timer-btn {
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.timer-btn-main {
  width: 72px;
  height: 72px;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
}
.timer-btn-main:hover { transform: scale(1.05); }
.timer-btn-main:active { transform: scale(0.95); }

.timer-btn-sm {
  width: 48px;
  height: 48px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 18px;
}
.timer-btn-sm:hover { color: var(--text); background: var(--bg-card-hover); }

.timer-subject-select {
  width: 100%;
  max-width: 320px;
  margin-bottom: 20px;
}

.timer-subject-select label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  text-align: center;
}

.subject-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.subject-pill {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.subject-pill:hover { border-color: var(--primary); color: var(--text); }
.subject-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.timer-settings {
  width: 100%;
  max-width: 320px;
  margin-top: 16px;
}

.timer-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.timer-setting-label { font-size: 14px; color: var(--text-secondary); }

.timer-setting-value {
  display: flex;
  align-items: center;
  gap: 12px;
}

.timer-setting-value button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.timer-setting-value button:hover { background: var(--bg-card-hover); }

.timer-setting-value span {
  font-size: 16px;
  font-weight: 600;
  min-width: 32px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ── Week View ───────────────────────── */
.week-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.week-day-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: var(--transition);
}
.week-day-card.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary-glow); }

.week-day-name {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  width: 40px;
  flex-shrink: 0;
  color: var(--text-muted);
}
.week-day-card.today .week-day-name { color: var(--primary); }

.week-day-subjects { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }

.week-subject-tag {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
  color: #fff;
}

/* ── Gantt / Roadmap ─────────────────── */
.gantt-container { margin-top: 16px; }

.gantt-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  gap: 10px;
}

.gantt-label {
  font-size: 12px;
  font-weight: 600;
  width: 40px;
  text-align: right;
  flex-shrink: 0;
}

.gantt-bar-container {
  flex: 1;
  height: 28px;
  background: var(--bg-card);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.gantt-bar {
  height: 100%;
  border-radius: 6px;
  display: flex;
  align-items: center;
  padding-left: 8px;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  transition: width 0.5s ease;
}

.gantt-now {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--danger);
  z-index: 1;
}

/* ── Progress Tab ────────────────────── */
.checklist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.checklist-item:last-child { border-bottom: none; }

.checklist-checkbox {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 12px;
  flex-shrink: 0;
  transition: var(--transition);
}
.checklist-checkbox.checked {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.checklist-text { font-size: 14px; color: var(--text-secondary); }

/* ── Focus Mode ──────────────────────── */
#focus-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#focus-overlay.active { display: flex; }

.focus-subject-name {
  font-size: 16px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 32px;
}

.focus-timer-ring-wrapper {
  position: relative;
  width: 300px;
  height: 300px;
  margin-bottom: 40px;
}

@media (min-width: 640px) {
  .focus-timer-ring-wrapper { width: 360px; height: 360px; }
}

.focus-timer-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.focus-timer-ring .ring-bg { fill: none; stroke: var(--border); stroke-width: 4; }
.focus-timer-ring .ring-progress {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear;
}

.focus-timer-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.focus-timer-time {
  font-size: 72px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  letter-spacing: 4px;
}

.focus-phase-label {
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 8px;
}

.focus-session-count {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.focus-controls {
  display: flex;
  gap: 20px;
  align-items: center;
}

.focus-btn {
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.focus-btn-main {
  width: 80px;
  height: 80px;
  background: var(--primary);
  color: #fff;
  font-size: 32px;
}

.focus-btn-sm {
  width: 52px;
  height: 52px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 20px;
}

.focus-exit {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}
.focus-exit:hover { color: var(--text); border-color: var(--text-secondary); }

/* ── Method Tips ─────────────────────── */
.method-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}

.method-card h4 {
  font-size: 13px;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

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

/* ── Settings Panel ──────────────────── */
#settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
#settings-panel.active { display: flex; }

.settings-sheet {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  animation: slideUp 0.3s ease;
}

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

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

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

.settings-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}

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

.settings-group h3 {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

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

.settings-row-label { font-size: 14px; }

.settings-row-value {
  font-size: 14px;
  color: var(--text-secondary);
}

.btn {
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--text-secondary); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; justify-content: center; }

/* Firebase config form */
.firebase-form { margin-top: 12px; }
.firebase-form textarea {
  width: 100%;
  min-height: 120px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  padding: 12px;
  resize: vertical;
}
.firebase-form textarea:focus { outline: none; border-color: var(--primary); }

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name { font-weight: 600; font-size: 14px; }
.user-email { font-size: 12px; color: var(--text-muted); }

/* ── Utility ─────────────────────────── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  margin-top: 20px;
}

.section-subtitle {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  margin-top: 4px;
  padding-left: 2px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state .emoji { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

.days-counter {
  text-align: center;
  padding: 20px;
  background: linear-gradient(135deg, rgba(99,102,241,0.1), rgba(34,211,238,0.1));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.days-counter .days-num {
  font-size: 48px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.days-counter .days-label {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ── Animations ──────────────────────── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 var(--primary-glow); }
  50% { box-shadow: 0 0 0 12px transparent; }
}

.timer-btn-main.running { animation: breathe 2s infinite; }

/* ── Responsive ──────────────────────── */
@media (min-width: 640px) {
  .main-content { max-width: 560px; margin: 0 auto; }
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .timer-time { font-size: 64px; }
}

@media (min-width: 1024px) {
  .main-content { max-width: 640px; }
}

/* ── Focus mode body lock ────────────── */
body.focus-active {
  overflow: hidden;
}
body.focus-active .app-header,
body.focus-active .bottom-nav,
body.focus-active .main-content { display: none; }
