/* =========================================
   Hundred Dreams Academy — Output App CSS
   ========================================= */

:root {
  --bg: #f0f4f8;
  --bg-elevated: #ffffff;
  --accent: #1d4ed8;
  --accent-strong: #1e40af;
  --danger: #dc2626;
  --text: #0f172a;
  --text-soft: #475569;
  --border: rgba(15, 23, 42, 0.15);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-pill: 999px;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 8px 40px rgba(15, 23, 42, 0.12);
  /* Phase colors */
  --phase1: #2563eb;
  --phase2: #7c3aed;
  --phase3: #d97706;
  --phase4: #059669;
  --phase5: #e11d48;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #dbeafe 0, #f0f4f8 55%, #e8eef5 100%);
  min-height: 100%;
}

body { display: flex; align-items: stretch; justify-content: center; }

/* ── App Shell ── */
.app-root {
  width: 100%; max-width: 900px;
  margin: 24px auto;
  padding: 20px 22px 24px;
  border-radius: 26px;
  background: linear-gradient(135deg, #ffffff, #f8fafc);
  box-shadow: 0 8px 40px rgba(15, 23, 42, 0.1);
  border: 1px solid rgba(15, 23, 42, 0.1);
}

/* ── Header ── */
.app-header { padding: 4px 4px 16px; }

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

.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fbbf24, #f59e0b);
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.6);
  flex-shrink: 0;
}

.app-header h1 {
  margin: 0; font-size: 1.6rem; letter-spacing: 0.02em; color: var(--text);
}

.app-subtitle {
  margin: 4px 0 0; font-size: 0.84rem; color: var(--text-soft);
}

/* ── Tabs ── */
.tabs {
  display: inline-flex; padding: 3px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
  border: 1px solid rgba(15, 23, 42, 0.12);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  flex-wrap: wrap; gap: 2px;
}

.tab-button {
  position: relative; border: none; outline: none;
  border-radius: 999px; padding: 7px 16px;
  font-size: 0.82rem; letter-spacing: 0.02em;
  background: transparent; color: var(--text-soft);
  cursor: pointer;
  transition: color 0.15s ease;
}

.tab-button.active { color: #fff; }

.tab-button.active::before {
  content: ""; position: absolute; inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, #1e40af, #2563eb);
  z-index: -1;
  box-shadow: 0 4px 14px rgba(29, 78, 216, 0.4);
}

.tab-button:not(.active):hover { color: var(--text); }

/* ── Tab Panels ── */
.app-main { margin-top: 16px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Cards ── */
.card {
  margin-top: 14px; padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ── Section Header ── */
.section-header {
  margin-top: 20px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

.section-header h3 {
  margin: 0; font-size: 0.95rem; color: var(--text);
}

/* ── Phase Labels ── */
.phase-label {
  display: inline-block;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
  padding: 2px 10px; border-radius: 999px;
  background: #dbeafe; color: #1e40af;
}
.phase-label.p2 { background: #ede9fe; color: #5b21b6; }
.phase-label.p3 { background: #fef3c7; color: #92400e; }
.phase-label.p4 { background: #d1fae5; color: #065f46; }
.phase-label.p5 { background: #ffe4e6; color: #9f1239; }

/* ── Today Card ── */
.today-card {
  margin-top: 14px; padding: 22px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 60%, #2563eb 100%);
  color: #fff;
  box-shadow: 0 8px 32px rgba(29, 78, 216, 0.35);
}

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

.day-info { display: flex; flex-direction: column; gap: 6px; }

.day-badge {
  font-size: 2rem; font-weight: 800; letter-spacing: -0.02em;
  line-height: 1;
}

.streak-badge {
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,0.15); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 999px; padding: 6px 14px;
  font-size: 0.82rem; font-weight: 600; color: #fff;
}

.streak-fire { font-size: 1rem; }

.today-theme-label {
  margin: 0 0 4px; font-size: 0.75rem;
  opacity: 0.7; letter-spacing: 0.04em;
}

.today-theme {
  margin: 0 0 4px; font-size: 1.3rem; font-weight: 700; line-height: 1.4;
}

.today-concept {
  margin: 0 0 18px; font-size: 0.82rem; opacity: 0.8;
}

.today-card-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

.today-status {
  font-size: 0.8rem; font-weight: 600;
  padding: 4px 12px; border-radius: 999px;
  background: rgba(255,255,255,0.15);
}
.today-status.done { background: rgba(16, 185, 129, 0.35); }
.today-status.undone { background: rgba(245, 158, 11, 0.3); }

/* ── Progress Card ── */
.progress-card {
  margin-top: 14px; padding: 16px 18px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

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

.progress-title { font-size: 0.82rem; font-weight: 600; color: var(--text-soft); }
.progress-text { font-size: 0.82rem; font-weight: 700; color: var(--text); }

.progress-bar-wrap {
  position: relative; height: 10px; border-radius: 999px;
  background: #e2e8f0; overflow: hidden;
}

.progress-bar {
  position: absolute; height: 100%; border-radius: 999px;
  transition: width 0.5s ease;
}

.phase1-bar { background: linear-gradient(90deg, #2563eb, #3b82f6); left: 0; }
.phase2-bar { background: linear-gradient(90deg, #7c3aed, #a78bfa); }
.phase3-bar { background: linear-gradient(90deg, #d97706, #fbbf24); }
.phase4-bar { background: linear-gradient(90deg, #059669, #34d399); }
.phase5-bar { background: linear-gradient(90deg, #e11d48, #fb7185); }

.phase-legend {
  display: flex; gap: 14px; margin-top: 10px; flex-wrap: wrap;
}

.phase-legend span { font-size: 0.74rem; color: var(--text-soft); display: flex; align-items: center; gap: 5px; }

.legend-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0;
}
.phase1-dot { background: var(--phase1); }
.phase2-dot { background: var(--phase2); }
.phase3-dot { background: var(--phase3); }
.phase4-dot { background: var(--phase4); }
.phase5-dot { background: var(--phase5); }
.done-dot { background: #10b981; }
.recorded-dot { background: #94a3b8; }

/* ── Stats ── */
.stats-row {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; margin-top: 14px;
}

.stat-card {
  padding: 14px 10px; text-align: center;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.stat-value { margin: 0; font-size: 1.6rem; font-weight: 800; color: var(--accent); }
.stat-label { margin: 4px 0 0; font-size: 0.72rem; color: var(--text-soft); }

/* ── Recent List ── */
.recent-list { display: flex; flex-direction: column; gap: 8px; }

.recent-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: box-shadow 0.15s ease;
}
.recent-item:hover { box-shadow: var(--shadow); }

.recent-day {
  font-size: 0.72rem; font-weight: 700;
  width: 44px; flex-shrink: 0;
  text-align: center;
  color: var(--text-soft);
}

.recent-body { flex: 1; min-width: 0; }

.recent-theme {
  font-size: 0.85rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.recent-action-preview {
  font-size: 0.75rem; color: var(--text-soft); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.recent-status {
  font-size: 0.72rem; font-weight: 700;
  padding: 3px 10px; border-radius: 999px; flex-shrink: 0;
}
.recent-status.done { background: #dcfce7; color: #166534; }
.recent-status.undone { background: #fef3c7; color: #92400e; }

.empty-state {
  padding: 32px 16px; text-align: center;
  color: var(--text-soft); font-size: 0.85rem;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
}

/* ── Record Form ── */
.record-day-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 14px;
}

.record-day-info { display: flex; flex-direction: column; gap: 5px; }

.record-day-title { margin: 0; font-size: 1.4rem; font-weight: 800; }

.day-input-wrap { display: flex; align-items: center; gap: 6px; }
.day-input-label { font-size: 0.78rem; color: var(--text-soft); }

.day-input {
  width: 64px; padding: 6px 8px; text-align: center;
  border: 1px solid rgba(15,23,42,0.2); border-radius: var(--radius-md);
  font-size: 0.9rem; font-weight: 700;
  background: #f8fafc; color: var(--text);
  outline: none;
}
.day-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(29,78,216,0.15); }

.theme-display {
  padding: 12px 14px; margin-bottom: 18px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #eff6ff, #f0f4ff);
  border-left: 4px solid var(--accent);
}

.theme-display-label { margin: 0 0 4px; font-size: 0.72rem; color: var(--text-soft); letter-spacing: 0.04em; }
.theme-title { margin: 0 0 3px; font-size: 1rem; font-weight: 700; color: var(--accent-strong); }
.theme-concept { margin: 0; font-size: 0.8rem; color: var(--text-soft); }

/* Form fields */
.form-field { margin-bottom: 18px; }

.form-field label {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 0.85rem; font-weight: 600; margin-bottom: 7px;
}

.field-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 0.72rem; font-weight: 700; flex-shrink: 0;
  margin-right: 4px;
}

.field-hint {
  font-size: 0.75rem; font-weight: 400; color: var(--text-soft);
}

textarea, input[type="text"], input[type="date"], select {
  width: 100%; padding: 9px 11px;
  border: 1px solid rgba(15,23,42,0.2); border-radius: var(--radius-md);
  background: #f8fafc; color: var(--text);
  font-size: 0.86rem; font-family: inherit;
  outline: none; resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

textarea:focus, input[type="text"]:focus, input[type="date"]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29,78,216,0.15);
  background: #fff;
}

input::placeholder, textarea::placeholder { color: rgba(71,85,105,0.5); }

/* Completion Toggle */
.completion-toggle {
  display: flex; gap: 8px;
}

.toggle-opt {
  flex: 1; padding: 10px;
  border: 2px solid var(--border); border-radius: var(--radius-md);
  background: #f8fafc; color: var(--text-soft);
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  transition: all 0.15s ease;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}

.toggle-opt:hover { border-color: #94a3b8; color: var(--text); }

.toggle-opt.selected-done {
  border-color: #10b981; background: #dcfce7; color: #166534;
}

.toggle-opt.selected-undone {
  border-color: #f59e0b; background: #fef3c7; color: #92400e;
}

.toggle-icon { font-size: 0.9rem; }

/* Form Actions */
.form-actions {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px;
}

/* ── Buttons ── */
.btn {
  border-radius: 999px; border: none;
  padding: 8px 20px; font-size: 0.82rem; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn.primary {
  background: linear-gradient(135deg, #1e40af, #2563eb);
  color: #fff;
  box-shadow: 0 4px 14px rgba(29,78,216,0.35);
}
.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(29,78,216,0.5); }

.btn.ghost {
  background: #fff; color: var(--text-soft);
  border: 1px solid rgba(15,23,42,0.2);
}
.btn.ghost:hover { background: #f1f5f9; color: var(--text); }

.btn-text {
  border: none; background: none; padding: 0;
  font-size: 0.75rem; color: var(--text-soft);
  cursor: pointer; text-decoration: underline;
  font-family: inherit;
}
.btn-text:hover { color: var(--accent); }

/* ── Tracker ── */
.tracker-legend {
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 0.74rem; color: var(--text-soft);
}
.tracker-legend span { display: flex; align-items: center; gap: 5px; }

.tracker-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  margin-top: 14px;
}

.tracker-cell {
  aspect-ratio: 1; border-radius: 8px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-size: 0.62rem; font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  border: 2px solid transparent;
  position: relative;
}

.tracker-cell:hover { transform: scale(1.12); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }

.tracker-cell.phase1 { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.tracker-cell.phase2 { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.tracker-cell.phase3 { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.tracker-cell.phase4 { background: #d1fae5; color: #065f46; border-color: #6ee7b7; }
.tracker-cell.phase5 { background: #ffe4e6; color: #9f1239; border-color: #fda4af; }

.tracker-cell.recorded { opacity: 0.85; }
.tracker-cell.recorded.phase1 { background: #93c5fd; border-color: #60a5fa; }
.tracker-cell.recorded.phase2 { background: #c4b5fd; border-color: #a78bfa; }
.tracker-cell.recorded.phase3 { background: #fcd34d; border-color: #fbbf24; }
.tracker-cell.recorded.phase4 { background: #6ee7b7; border-color: #34d399; }
.tracker-cell.recorded.phase5 { background: #fda4af; border-color: #fb7185; }

.tracker-cell.completed.phase1 { background: #1d4ed8; color: #fff; border-color: #1e40af; }
.tracker-cell.completed.phase2 { background: #6d28d9; color: #fff; border-color: #5b21b6; }
.tracker-cell.completed.phase3 { background: #d97706; color: #fff; border-color: #b45309; }
.tracker-cell.completed.phase4 { background: #059669; color: #fff; border-color: #047857; }
.tracker-cell.completed.phase5 { background: #e11d48; color: #fff; border-color: #be123c; }

.tracker-cell.today { box-shadow: 0 0 0 3px #f59e0b, 0 4px 12px rgba(0,0,0,0.15); }

.tracker-cell.future { opacity: 0.4; }

.tracker-cell-num { font-size: 0.7rem; font-weight: 800; line-height: 1; }
.tracker-cell-check { font-size: 0.6rem; margin-top: 2px; }

/* Tracker Popup */
.tracker-popup {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.tracker-popup.hidden { display: none; }

.tracker-popup::before {
  content: ""; position: absolute; inset: 0;
  background: rgba(15,23,42,0.4); backdrop-filter: blur(4px);
}

.tracker-popup-inner {
  position: relative; z-index: 1;
  background: #fff; border-radius: var(--radius-lg);
  padding: 20px; width: 100%; max-width: 480px;
  box-shadow: var(--shadow-lg);
}

/* ── History ── */
.history-toolbar {
  display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap;
}

.search-input {
  flex: 1; min-width: 180px; padding: 8px 12px;
  border-radius: var(--radius-pill);
}

.filter-select {
  padding: 8px 12px; border-radius: var(--radius-pill);
  background: #f8fafc; width: auto;
}

.history-list { display: flex; flex-direction: column; gap: 10px; }

.history-item {
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  overflow: hidden;
}

.history-item-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer;
  transition: background 0.1s ease;
}
.history-item-header:hover { background: #f8fafc; }

.history-day-badge {
  font-size: 0.72rem; font-weight: 700;
  padding: 3px 10px; border-radius: 999px;
  background: #f1f5f9; color: var(--text-soft);
  flex-shrink: 0;
}

.history-title { flex: 1; font-size: 0.88rem; font-weight: 600; }

.history-date { font-size: 0.72rem; color: var(--text-soft); flex-shrink: 0; }

.history-completion {
  font-size: 0.72rem; font-weight: 700;
  padding: 3px 10px; border-radius: 999px; flex-shrink: 0;
}
.history-completion.done { background: #dcfce7; color: #166534; }
.history-completion.undone { background: #fef3c7; color: #92400e; }

.history-item-body {
  padding: 0 16px 14px; display: none;
  border-top: 1px solid var(--border);
}
.history-item-body.open { display: block; }

.history-field { margin-top: 10px; }
.history-field-label {
  font-size: 0.72rem; font-weight: 700; color: var(--text-soft);
  letter-spacing: 0.04em; margin-bottom: 3px;
}
.history-field-value { font-size: 0.84rem; color: var(--text); white-space: pre-wrap; }

.history-item-actions {
  display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end;
}

/* ── Modals ── */
.modal {
  position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  box-sizing: border-box;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,23,42,0.5); backdrop-filter: blur(6px);
}

.modal-box {
  position: relative; z-index: 1;
  background: #fff; border-radius: var(--radius-lg);
  padding: 24px; width: 100%; max-width: 520px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h3 { margin: 0; font-size: 1rem; }

.close-btn {
  border: none; background: #f1f5f9; color: var(--text-soft);
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem; cursor: pointer;
}
.close-btn:hover { background: #e2e8f0; }

.share-textarea {
  width: 100%; min-height: 160px; resize: vertical; font-size: 0.83rem;
  background: #f8fafc; font-family: inherit;
}

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.setup-desc { font-size: 0.85rem; color: var(--text-soft); margin-bottom: 16px; line-height: 1.6; }

/* ── Footer ── */
.app-footer {
  margin-top: 20px; font-size: 0.75rem; color: var(--text-soft);
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 14px; border-top: 1px solid var(--border);
}

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff;
  padding: 10px 22px; border-radius: 999px;
  font-size: 0.84rem; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 999; white-space: nowrap;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.hidden { display: none; }
.toast.success { background: #166534; }
.toast.error { background: #991b1b; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .app-root { margin: 12px; padding: 16px 14px; border-radius: 20px; }
  .tabs { width: 100%; }
  .tab-button { flex: 1; text-align: center; padding: 7px 8px; font-size: 0.75rem; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .tracker-grid { gap: 4px; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }
  .today-card-actions { flex-direction: column; align-items: flex-start; }
}
