:root {
  --primary: #010b13; /* Rich Black */
  --accent: #bd8a00; /* Butte Gold */
  --danger: #9c2925; /* Accent Red */
  --success: #27ae60;

  --card-bg: rgba(255, 255, 255, 0.72);
  --card-border: rgba(0, 0, 0, 0.06);
  --text: #111827;
  --text-muted: #4b5563;
  --bg: #f5f5f5;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.wv-topbar {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px 14px;
  background: rgba(255,255,255,0.9);
  border-bottom: 1px solid rgba(0,0,0,0.08);
  position: sticky;
  top: 0;
  z-index: 200;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.wv-back {
  flex: 0 0 auto;
  text-decoration: none;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.8);
}
.wv-back:focus, .wv-back:hover { background: #fff; }

.wv-title { min-width: 0; }
.wv-title h1 {
  margin: 2px 0 2px 0;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.wv-title p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.wv-container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 14px 24px 14px;
}

/* Sticky Timeline */
.timeline-sticky-wrapper {
  position: sticky;
  top: calc(54px + env(safe-area-inset-top, 0px));
  z-index: 100;
  background: var(--bg);
  padding: 0 0 12px 0;
  margin: 0 -14px 12px -14px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}
.timeline-section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 0;
  padding: 12px 14px;
  box-shadow: none;
  margin-bottom: 0;
  overflow-x: auto;
}
.timeline-grid {
  background: rgba(255,255,255,0.5);
}

/* Accordions */
.wv-sections { display: flex; flex-direction: column; gap: 12px; }
.wv-accordion {
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.10);
  background: rgba(255,255,255,0.65);
  overflow: hidden;
}
.wv-accordion[open] { background: rgba(255,255,255,0.72); }
.wv-accordion-summary {
  cursor: pointer;
  padding: 12px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  list-style: none;
}
.wv-accordion-summary::-webkit-details-marker { display: none; }
.wv-accordion-title { font-weight: 900; color: var(--primary); }
.wv-accordion-meta {
  min-width: 0;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.86rem;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wv-accordion-summary::after {
  content: "▾";
  opacity: 0.6;
  margin-left: 8px;
  flex: 0 0 auto;
}
.wv-accordion[open] > .wv-accordion-summary::after { content: "▴"; }
.wv-accordion-body { padding: 0 12px 12px 12px; }

/* Term Selector */
.term-selector {
  display: flex;
  gap: 0;
  margin: 4px 0 14px 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.1);
  background: rgba(255,255,255,0.7);
}
.term-btn {
  flex: 1;
  padding: 10px 10px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
  border-right: 1px solid rgba(0,0,0,0.08);
  display: grid;
  justify-items: center;
  align-content: center;
  min-height: 54px;
}
.term-btn:last-child { border-right: 0; }
.term-btn:hover { background: rgba(255,255,255,0.85); }
.term-btn.active { background: var(--primary); color: var(--accent); }
.term-weeks { display: block; font-size: 0.72rem; font-weight: 500; opacity: 0.85; margin-top: 2px; }
.term-btn.active .term-weeks { color: rgba(255,255,255,0.78); }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 10px;
  margin: 0 0 14px 0;
}
.stat-box {
  background: var(--card-bg);
  padding: 14px 14px;
  border: 1px solid var(--card-border);
  border-top: 4px solid var(--accent);
  border-radius: 12px;
}
.stat-value { font-size: 1.35rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 4px; }
.stat-primary { color: var(--primary); }
.stat-success { color: var(--success); }
.stat-warning { color: var(--accent); }
.stat-danger { color: var(--danger); }
.stat-critical { color: #ff4444; }

/* Timeline */
.timeline-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.timeline-scroll:focus { outline: none; }
.timeline-grid {
  display: grid;
  gap: 1px;
  font-size: 0.72rem;
  background: rgba(0,0,0,0.12);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 8px;
  overflow: hidden;
  min-width: 680px; /* updated dynamically in JS for narrow screens */
}
.timeline-header {
  text-align: center;
  font-weight: 800;
  padding: 6px 2px;
  background: rgba(255,255,255,0.65);
  color: var(--primary);
}
.timeline-row-label {
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-weight: 700;
  color: var(--primary);
  background: rgba(255,255,255,0.55);
  font-size: 0.78rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.timeline-cell { height: 24px; background: rgba(255,255,255,0.35); position: relative; }
.timeline-bar { position: absolute; top: 4px; bottom: 4px; left: 1px; right: 1px; background: var(--primary); border-radius: 6px; opacity: 0.92; }
.timeline-summary-cell { text-align: center; padding: 4px 2px; font-weight: 900; font-size: 0.72rem; background: rgba(255,255,255,0.65); }
.timeline-heat-cell { height: 24px; background: rgba(255,255,255,0.65); }
.success-bg { background-color: var(--success) !important; color: #fff; }
.warning-bg { background-color: var(--accent) !important; color: #fff; }
.danger-bg { background-color: var(--danger) !important; color: #fff; }
.critical-bg {
  background-color: #1a1a1a !important;
  color: #ff4444 !important;
  font-weight: 900;
  animation: pulse-stop 0.8s ease-in-out infinite;
}
@keyframes pulse-stop { 0%, 100% { background-color: #1a1a1a; } 50% { background-color: #4a0000; } }

/* Assignments */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}
.controls-title { margin: 0; font-size: 1rem; color: var(--primary); }

.assignment-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 14px;
}

.assignment-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}
.assignment-title-group { flex: 1; display: flex; gap: 8px; flex-direction: column; }
.assignment-name input {
  width: 100%;
  font-weight: 700;
  font-size: 1rem;
  padding: 8px 10px;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.5);
}
.assignment-name input:focus { outline: none; border-color: var(--accent); background: #fff; }

.assignment-mode-toggle { display: flex; gap: 0; }
.mode-btn {
  border: 1px solid rgba(0,0,0,0.15);
  background: rgba(255,255,255,0.4);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}
.mode-btn:first-child { border-radius: 6px 0 0 6px; border-right: 0; }
.mode-btn:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.mode-btn.active { background: var(--primary); color: var(--accent); border-color: var(--primary); }

.assignment-body {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
}
.input-group {
  background: rgba(255,255,255,0.4);
  border-radius: 8px;
  padding: 8px;
  border: 1px solid rgba(0,0,0,0.05);
}
.group-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
  opacity: 0.8;
}
.inputs-row { display: flex; gap: 8px; }
.field-stack { flex: 1; }
.field-stack label { display: block; font-size: 0.7rem; font-weight: 600; margin-bottom: 2px; color: var(--text); }
.field-stack input, .field-stack select {
  width: 100%;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.1);
  background: #fff;
  font-weight: 600;
}
.field-stack input:focus, .field-stack select:focus { outline: none; border-color: var(--accent); }

.btn {
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 800;
  font-size: 0.92rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-add {
  background: var(--primary);
  color: var(--accent);
  border: 1px solid var(--primary);
}
.btn-add:hover { background: #222; }

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

.btn-remove {
  background: transparent;
  border: 0;
  color: #9ca3af;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  cursor: pointer;
}
.btn-remove:hover { color: var(--danger); background: rgba(0,0,0,0.04); }

.stepper {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  height: 38px;
}
.stepper-btn {
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(0,0,0,0.06);
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: 900;
  color: #374151;
  touch-action: manipulation;
}
.stepper-btn:hover { background: var(--accent); color: #fff; }
.stepper-btn:active { background: var(--primary); color: var(--accent); }
.stepper-value {
  text-align: center;
  font-weight: 900;
  color: #111;
  font-size: 0.9rem;
}

/* Info */
.info-panel {
  margin-top: 16px;
  font-size: 0.92rem;
  color: var(--text-muted);
  padding-top: 12px;
  border-top: 1px solid rgba(0,0,0,0.1);
}

.info-title, .info-subtitle { margin: 0 0 8px 0; color: #111; }
.info-ol, .info-ul { margin: 0 0 12px 0; padding-left: 20px; line-height: 1.6; }
.info-footnote { margin: 12px 0 0 0; font-size: 0.82rem; color: #6b7280; }
.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 999px; vertical-align: -1px; margin: 0 6px 0 6px; }
.status-dot.success { background: var(--success); }
.status-dot.warning { background: var(--accent); }
.status-dot.danger { background: var(--danger); }
.status-dot.critical { background: #1a1a1a; box-shadow: inset 0 0 0 2px #ff4444; }

@media (max-width: 420px) {
  .wv-title h1 { font-size: 1rem; }
  .wv-container { padding-left: 12px; padding-right: 12px; }
  .btn { padding: 10px 12px; }
  .term-btn { font-size: 0.85rem; }
}

@media (max-width: 600px) {
  .assignment-body { grid-template-columns: 1fr; gap: 10px; }
  .assignment-header { flex-direction: column; align-items: stretch; }
  .btn-remove { align-self: flex-end; margin-top: -40px; }
}

@media (max-width: 520px) {
  .timeline-grid { font-size: 0.7rem; }
  .wv-accordion-meta { max-width: 52vw; }

  /* Compact timeline: full-term view (no labels). */
  .timeline-grid.compact {
    min-width: 0 !important;
    border-radius: 10px;
  }
  .timeline-grid.compact .timeline-cell,
  .timeline-grid.compact .timeline-heat-cell {
    height: 18px;
  }
  .timeline-grid.compact .timeline-bar {
    top: 3px;
    bottom: 3px;
    border-radius: 5px;
  }
}
