* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--c-bg); color: var(--c-text); min-height: 100vh; }

/* ─── View Tabs Bar ─── */
#toolbar {
  position: fixed; top: 56px; left: 0; right: 0; z-index: 89;
  background: rgba(10,10,10,0.88); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--c-border); padding: 6px 16px;
  display: flex; align-items: center; justify-content: center;
}
.view-tabs { display: flex; gap: 4px; }
.view-tab {
  padding: 6px 14px; border-radius: 999px; border: none; cursor: pointer;
  background: transparent; color: var(--c-text-muted); font-size: 0.8rem; font-family: inherit;
  letter-spacing: 0.04em; transition: color 0.2s, background 0.2s;
}
.view-tab:hover { color: var(--c-text); background: var(--c-border); }
.view-tab.active { color: var(--c-text); background: rgba(224,224,224,0.06); border-bottom: 2px solid var(--c-text); }

/* ─── Page Wrap ─── */
.page-wrap {
  padding-top: calc(56px + 40px + 16px);
  padding-bottom: calc(56px + 16px); max-width: 1200px; margin: 0 auto; padding-left: 24px; padding-right: 24px;
  opacity: 0; animation: fadeIn 0.8s ease forwards;
}

/* ─── Grid Views ─── */
.grid-view { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.grid-row { display: flex; align-items: center; gap: 2px; }
.grid-row-label {
  width: 48px; flex-shrink: 0; display: flex; align-items: center; justify-content: flex-end; gap: 4px;
  padding-right: 8px; font-size: 0.65rem; color: var(--c-text-muted); letter-spacing: 0.02em;
}
.cell {
  border-radius: 2px; transition: transform 0.15s, box-shadow 0.15s;
  cursor: pointer; position: relative;
}
.cell-past { background: #374151; border: 1px solid #374151; }
.cell-future { border: 1px solid #4B5563; }
.cell-today { background: var(--c-text); outline: 2px solid var(--c-text); box-shadow: 0 0 6px rgba(224,224,224,0.4); z-index: 3; animation: pulse-ring 2s infinite; }
.cell-vacation { background: #0D9488; outline: 2px solid #0D9488; z-index: 2; }
.cell-phase { border-color: var(--phase-color); border-width: 2px; }
.cell-milestone { outline: 2px solid #F59E0B; outline-offset: -2px; z-index: 5; }
.cell-buckets { padding-bottom: 6px; }
.bucket-dot {
  position: absolute;
  bottom: 2px;
  left: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 2px rgba(0,0,0,0.5);
}
.bucket-dot:nth-child(2) { left: 7px; }
.bucket-dot:nth-child(3) { left: 12px; }
.bucket-dot:nth-child(4) { left: 17px; }

.phase-stripe {
  width: 3px; height: 7px; border-radius: 1px; flex-shrink: 0;
}

.cell-week { width: 12px; height: 12px; }
.cell-month { width: 20px; height: 20px; }
.cell-year { width: 30px; height: 30px; }
.cell-week.cell-today { width: 14px; height: 14px; }
.cell-month.cell-today { width: 22px; height: 22px; }
.cell-year.cell-today { width: 32px; height: 32px; }

.cell-week:hover, .cell-month:hover, .cell-year:hover {
  transform: scale(1.3); z-index: 10;
  box-shadow: 0 0 8px rgba(224,224,224,0.2);
}

.years-compact { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; max-width: 400px; margin: 20px auto; }
.cell-year-compact { width: auto; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; color: var(--c-text-secondary); border-radius: 4px; }

/* ─── Canvas Days ─── */
#days-canvas { display: block; margin: 20px auto; cursor: crosshair; max-width: 100%; }
#days-tooltip {
  position: fixed; pointer-events: none; z-index: 200;
  background: var(--c-border); border: 1px solid var(--c-border-hover); border-radius: 8px;
  padding: 6px 10px; font-size: 0.7rem; color: var(--c-text-secondary); white-space: nowrap;
  display: none; box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* ─── Two-Column Layout ─── */
.life-layout {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}
.life-grid {
  flex: 1;
  min-width: 0;
}
.life-sidebar {
  width: 260px;
  flex-shrink: 0;
  position: sticky;
  top: calc(56px + 40px + 8px);
  max-height: calc(100vh - (56px + 40px + 8px + 56px + 8px));
  overflow-y: auto;
}

/* ─── Mystery View ─── */
#mystery-view { max-width: 640px; margin: 0 auto; }
.mystery-item { margin-bottom: 24px; }
.mystery-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.mystery-icon { font-size: 1.2rem; }
.mystery-name { font-size: 0.85rem; color: var(--c-text); }
.mystery-counts { font-size: 0.75rem; color: var(--c-text-muted); margin-left: auto; }
.mystery-dots { display: flex; gap: 2px; flex-wrap: wrap; }
.mystery-dot { width: 8px; height: 8px; border-radius: 2px; }
.mystery-dot-used { background: #374151; }
.mystery-dot-remaining { border: 1px solid #4B5563; background: transparent; }
.mystery-dot-current { background: var(--c-text); border: 1px solid var(--c-text); }
.mystery-group { max-width: 620px; }

/* ─── Legend ─── */
#legend {
  display: flex; flex-direction: column; gap: 6px;
  padding: 16px; background: var(--c-bg-elevated); border: 1px solid var(--c-border);
  border-radius: 12px;
}
.legend-header {
  font-size: 0.65rem; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--c-text-muted); margin-bottom: 4px;
}
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.7rem; color: var(--c-text-secondary); cursor: default; }
.legend-item[title]:hover { color: var(--c-text); }
.legend-swatch { width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0; }
.legend-swatch-past { background: #374151; }
.legend-swatch-today { background: var(--c-text); }
.legend-swatch-future { border: 1px solid #4B5563; background: transparent; }
.legend-swatch-vacation { background: #0D9488; }
.legend-swatch-milestone { outline: 2px solid #F59E0B; width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.legend-swatch-bucket { width: 20px; height: 4px; border-radius: 2px; }

.legend-toggles {
  display: flex; flex-direction: column; gap: 8px; margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--c-border);
}
.legend-toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 0.7rem; color: var(--c-text-secondary);
}
.legend-toggle-row:hover { color: var(--c-text); }
.toggle-switch {
  width: 32px; height: 18px; border-radius: 9px;
  background: var(--c-border); border: 1px solid var(--c-border-hover);
  position: relative; cursor: pointer; flex-shrink: 0; margin-left: auto;
  transition: background 0.2s, border-color 0.2s;
}
.toggle-switch.on { background: rgba(74,222,128,0.2); border-color: rgba(74,222,128,0.4); }
.toggle-knob {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--c-text-dim); position: absolute; top: 2px; left: 2px;
  transition: left 0.2s, background 0.2s;
}
.toggle-switch.on .toggle-knob { left: 16px; background: var(--c-success); }
.legend-item { cursor: pointer; }
.legend-item.inactive .legend-swatch { opacity: 0.2; }
.legend-item.inactive { color: var(--c-text-dim); }

/* ─── Trip Modal ─── */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--c-bg-card); border: 1px solid var(--c-border); border-radius: 16px;
  padding: 24px; max-width: 400px; width: 90%; position: relative;
}
.modal h2 { font-size: 1.1rem; font-weight: 400; letter-spacing: 0.04em; margin-bottom: 16px; }
.modal p { font-size: 0.85rem; color: var(--c-text-secondary); line-height: 1.6; margin-bottom: 8px; }
.modal-close {
  position: absolute; top: 12px; right: 16px; background: none; border: none;
  color: var(--c-text-muted); font-size: 1.2rem; cursor: pointer; padding: 4px;
}
.modal-close:hover { color: var(--c-text); }

/* ─── Time Buckets Panel ─── */
.buckets-overlay {
  display: none; position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
.buckets-overlay.open { display: flex; }
.buckets-panel {
  background: var(--c-bg-card); border: 1px solid var(--c-border); border-radius: 16px;
  padding: 24px; max-width: 500px; width: 90%; max-height: 80vh; overflow-y: auto;
}
.buckets-panel h2 { font-size: 1.1rem; font-weight: 400; letter-spacing: 0.04em; margin-bottom: 16px; }
.bucket-card {
  background: var(--c-bg-elevated); border: 1px solid var(--c-border); border-radius: 12px;
  padding: 12px 16px; margin-bottom: 8px;
}
.bucket-card-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.bucket-card-row input, .bucket-card-row select {
  background: var(--c-bg); border: 1px solid var(--c-border); border-radius: 6px;
  color: var(--c-text); padding: 4px 8px; font-size: 0.8rem; font-family: inherit;
}
.bucket-card-row input:focus { outline: none; border-color: var(--c-text-muted); }
.bucket-color-input { width: 32px; height: 32px; padding: 0; border: none; cursor: pointer; border-radius: 6px; }
.bucket-age-input { width: 60px; }
.bucket-emoji-input { width: 48px; text-align: center; }
.bucket-label-input { flex: 1; min-width: 100px; }
.bucket-delete {
  background: none; border: 1px solid var(--c-border-hover); color: var(--c-error); border-radius: 6px;
  padding: 4px 8px; cursor: pointer; font-size: 0.7rem;
}
.bucket-delete:hover { border-color: var(--c-error); }
.bucket-add-btn {
  margin-top: 8px; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--c-border-hover);
  background: transparent; color: var(--c-text-secondary); cursor: pointer; font-size: 0.8rem; font-family: inherit;
}
.bucket-add-btn:hover { color: var(--c-text); border-color: var(--c-text-muted); }
.bucket-actions { display: flex; gap: 8px; margin-top: 16px; }
.bucket-actions button {
  padding: 8px 20px; border-radius: 999px; border: none; cursor: pointer;
  font-size: 0.8rem; font-family: inherit;
}
.btn-primary { background: var(--c-text); color: var(--c-bg); }
.btn-secondary { background: transparent; border: 1px solid var(--c-border-hover) !important; color: var(--c-text-secondary); }
.btn-primary:hover { background: #ccc; }
.btn-secondary:hover { color: var(--c-text); border-color: var(--c-text-muted); }

/* ─── Bucket Gantt ─── */
#bucket-gantt {
  display: flex; gap: 1px; height: 16px; border-radius: 4px; overflow: hidden;
  margin: 12px 0 20px; width: 100%;
}
.gantt-segment { height: 100%; position: relative; cursor: pointer; transition: opacity 0.2s; }
.gantt-segment:hover { opacity: 0.7; }

/* ─── Vacation Notice ─── */
.vacation-notice {
  text-align: center; font-size: 0.75rem; color: var(--c-text-dim); padding: 8px; margin-bottom: 12px;
}

/* ─── Animations ─── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224,224,224,0.4); }
  50% { box-shadow: 0 0 0 6px rgba(224,224,224,0); }
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading { display: flex; justify-content: center; padding: 60px; }
.spinner { width: 24px; height: 24px; border: 2px solid var(--c-border); border-top-color: var(--c-text-muted); border-radius: 50%; animation: spin 0.8s linear infinite; }

.hidden { display: none !important; }

@media (max-width: 768px) {
  .life-layout { flex-direction: column; gap: 16px; }
  .life-sidebar {
    width: 100%; position: static; max-height: none;
  }
  #legend { flex-direction: column; gap: 6px; }
  #legend .legend-header { width: 100%; }
  .legend-item { flex-wrap: nowrap; }
  .legend-toggle-row { flex-wrap: nowrap; }
  .stat-value { font-size: 0.95rem; }
  #toolbar { gap: 4px; padding: 6px 12px; }
  .view-tab { padding: 4px 10px; font-size: 0.75rem; white-space: nowrap; }
  .grid-row-label { width: 36px; font-size: 0.6rem; }
  .cell-week { width: 8px; height: 8px; }
  .cell-month { width: 14px; height: 14px; }
  .cell-year { width: 22px; height: 22px; }
  .cell-week.cell-today { width: 10px; height: 10px; }
  .cell-month.cell-today { width: 16px; height: 16px; }
  .cell-year.cell-today { width: 24px; height: 24px; }


@media (max-width: 600px) {
  .toggle-switch { width: 44px; height: 24px; }
  .toggle-knob { width: 18px; height: 18px; top: 2px; left: 2px; }
  .toggle-switch.on .toggle-knob { left: 22px; }
  #stats-view > div { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .mystery-dots { gap: 1px; }
  .mystery-dot { width: 6px; height: 6px; }
  .mystery-group { font-size: 0.65rem; }
}
@media (max-width: 480px) {
  .stat-item { min-width: 28%; }
  .stat-value { font-size: 0.85rem; }
  .stat-label { font-size: 0.5rem; }
  #toolbar { padding: 4px 8px; }
  .view-tab { padding: 3px 8px; font-size: 0.7rem; white-space: nowrap; }
  .grid-row-label { width: 28px; font-size: 0.55rem; }
  .grid-row { gap: 1px; }
  .cell-week { width: 8px; height: 8px; }
  .cell-month { width: 14px; height: 14px; }
  .cell-year { width: 20px; height: 20px; }
  .cell-week.cell-today { width: 7px; height: 7px; }
  .cell-month.cell-today { width: 12px; height: 12px; }
  .cell-year.cell-today { width: 20px; height: 20px; }
  .page-wrap { padding-left: 4px; padding-right: 4px; padding-top: calc(56px + 36px + 12px); }
}
