/* =========================================================
   System Design Primer — App styles
   Dark, modern, distraction-free.
   ========================================================= */

:root {
  --bg: #0b0f1a;
  --bg-2: #111726;
  --bg-3: #1a2236;
  --border: #26304a;
  --text: #e8ecf5;
  --muted: #93a0bd;
  --accent: #5b8cff;
  --accent-2: #7c5bff;
  --green: #3ddc97;
  --amber: #ffb84d;
  --red: #ff5c7a;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: radial-gradient(1200px 600px at 80% -10%, #16203a 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 15, 26, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-emoji { font-size: 28px; }
.brand h1 { font-size: 1.15rem; letter-spacing: 0.2px; }
.brand-sub { font-size: 0.78rem; color: var(--muted); }

.progress-wrap { flex: 1; max-width: 420px; margin-left: auto; }
.progress-label {
  display: flex; justify-content: space-between;
  font-size: 0.78rem; color: var(--muted); margin-bottom: 6px;
}
.progress-track {
  height: 8px; border-radius: 999px; background: var(--bg-3); overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.5s ease;
}

.ghost-btn {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 14px; font-size: 0.85rem; cursor: pointer;
  transition: 0.15s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Layout ---------- */
.layout { display: flex; max-width: 1200px; margin: 0 auto; min-height: calc(100vh - 66px); }

.sidebar {
  width: 250px; flex-shrink: 0;
  padding: 20px 14px;
  border-right: 1px solid var(--border);
  position: sticky; top: 66px; height: calc(100vh - 66px);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
}
.week-label {
  font-size: 0.7rem; letter-spacing: 1.2px; color: var(--muted);
  padding: 0 10px; margin-bottom: 8px;
}
#day-nav { display: flex; flex-direction: column; gap: 6px; }
.day-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid transparent;
  background: transparent; color: var(--text);
  cursor: pointer; text-align: left; font-size: 0.88rem;
  transition: 0.15s;
}
.day-nav-item:hover { background: var(--bg-2); }
.day-nav-item.active {
  background: var(--bg-3); border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}
.day-nav-item .nav-icon { font-size: 1.1rem; }
.day-nav-item .nav-meta { display: flex; flex-direction: column; flex: 1; }
.day-nav-item .nav-day { font-weight: 600; font-size: 0.8rem; color: var(--muted); }
.day-nav-item.active .nav-day { color: var(--accent); }
.day-nav-item .nav-title { font-size: 0.88rem; }
.day-nav-item .nav-check { margin-left: auto; font-size: 0.9rem; opacity: 0; transition: 0.2s; }
.day-nav-item.done .nav-check { opacity: 1; }
.day-nav-item.done .nav-title { color: var(--green); }

.sidebar-extra { display: flex; flex-direction: column; gap: 8px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.side-btn {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; font-size: 0.85rem; text-align: left;
  transition: 0.15s;
}
.side-btn:hover { border-color: var(--accent); background: var(--bg-3); }

/* ---------- Main content ---------- */
.main { flex: 1; padding: 28px 32px 80px; min-width: 0; }

.day-hero {
  display: flex; align-items: center; gap: 18px;
  margin-bottom: 28px;
}
.day-hero-icon {
  font-size: 2.2rem; width: 64px; height: 64px;
  display: grid; place-items: center;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 16px;
}
.day-hero h2 { font-size: 1.7rem; letter-spacing: 0.3px; }
.day-hero p { color: var(--muted); font-size: 0.95rem; }
.day-badges { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.badge {
  font-size: 0.72rem; padding: 4px 10px; border-radius: 999px;
  background: var(--bg-3); border: 1px solid var(--border); color: var(--muted);
}
.badge.goal { color: var(--green); border-color: rgba(61,220,151,0.3); }
.badge.budget { color: var(--amber); border-color: rgba(255,184,77,0.3); }

.section { margin-bottom: 34px; }
.section-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.05rem; margin-bottom: 14px;
}
.section-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.section-title .num {
  font-size: 0.75rem; font-weight: 700; color: var(--bg);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 6px; padding: 2px 8px;
}

/* Topic cards */
.topics-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px;
}
.topic-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  transition: transform 0.15s, border-color 0.15s;
}
.topic-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.topic-img-wrap {
  background: var(--bg-3); border-bottom: 1px solid var(--border);
  height: 150px; overflow: hidden; position: relative;
}
.topic-img-wrap img {
  width: 100%; height: 100%; object-fit: contain; padding: 10px;
  transition: opacity 0.3s;
}
.topic-img-wrap .caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  color: var(--text); font-size: 0.72rem; padding: 18px 10px 8px;
}
.topic-body { padding: 12px 14px 14px; }
.topic-name { font-weight: 600; font-size: 0.98rem; margin-bottom: 8px; }
.topic-points { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.topic-points li {
  font-size: 0.82rem; color: var(--muted); padding-left: 16px; position: relative;
}
.topic-points li::before { content: "›"; position: absolute; left: 4px; color: var(--accent); }
.topic-anchor {
  display: inline-block; margin-top: 10px; font-size: 0.78rem;
  color: var(--accent); cursor: pointer;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px;
  transition: 0.15s;
}
.topic-anchor:hover { border-color: var(--accent); background: var(--bg-2); }

/* Concepts */
.concepts { display: flex; flex-direction: column; gap: 8px; }
.concept-row {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
.concept-term {
  width: 100%; text-align: left;
  background: transparent; border: none; color: var(--text);
  padding: 12px 16px; font-size: 0.92rem; font-weight: 600;
  cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  gap: 10px;
}
.concept-term .caret { transition: transform 0.2s; color: var(--muted); font-size: 0.8rem; }
.concept-row.open .caret { transform: rotate(90deg); }
.concept-explain {
  display: none; padding: 0 16px 14px;
  font-size: 0.85rem; color: var(--muted); line-height: 1.6;
}
.concept-row.open .concept-explain { display: block; }

/* Drill */
.drill {
  background: linear-gradient(135deg, var(--bg-3), var(--bg-2));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px;
}
.drill h4 { margin-bottom: 4px; }
.drill .prompt { color: var(--muted); font-size: 0.85rem; margin-bottom: 14px; }
.drill ol { margin-left: 20px; display: flex; flex-direction: column; gap: 7px; }
.drill li { font-size: 0.88rem; color: var(--text); }
.drill li code {
  background: var(--bg); padding: 1px 6px; border-radius: 5px;
  font-size: 0.82rem; color: var(--green);
}

/* Self-check quiz */
.quiz { display: flex; flex-direction: column; gap: 10px; }
.quiz-item {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.quiz-q { font-weight: 500; font-size: 0.92rem; margin-bottom: 8px; }
.quiz-a {
  display: none; font-size: 0.85rem; color: var(--green);
  border-top: 1px dashed var(--border); padding-top: 10px;
}
.quiz-item.revealed .quiz-a { display: block; }
.quiz-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 10px;
  padding: 9px 16px; font-size: 0.85rem; font-weight: 600; cursor: pointer;
  transition: 0.15s;
}
.btn:hover { filter: brightness(1.1); }
.btn.small { padding: 6px 12px; font-size: 0.78rem; }
.btn.green { background: linear-gradient(90deg, #1f9d6a, var(--green)); }
.btn.gray { background: var(--bg-3); color: var(--text); border: 1px solid var(--border); }

/* Day completion */
.day-done-banner {
  display: none;
  align-items: center; gap: 12px;
  background: rgba(61, 220, 151, 0.1);
  border: 1px solid rgba(61, 220, 151, 0.4);
  border-radius: var(--radius); padding: 16px 20px;
  margin-bottom: 24px; font-weight: 600; color: var(--green);
}
.day-done-banner.show { display: flex; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 7, 14, 0.7); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 18px; width: 100%; max-width: 560px;
  box-shadow: var(--shadow); padding: 22px;
  animation: pop 0.18s ease;
}
@keyframes pop { from { transform: scale(0.96); opacity: 0; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { font-size: 1.1rem; }
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; width: 30px; height: 30px; cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

.review-count { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 12px 0 8px; }
.flashcard {
  min-height: 200px; display: grid; place-items: center;
  text-align: center; padding: 26px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 14px; cursor: pointer; user-select: none;
}
.flash-term { font-size: 1.15rem; font-weight: 600; }
.flash-explain { font-size: 0.9rem; color: var(--muted); max-width: 44ch; }
.review-controls { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.calc-field { display: flex; flex-direction: column; gap: 5px; }
.calc-field label { font-size: 0.76rem; color: var(--muted); }
.calc-field input {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 9px 12px; font-size: 0.95rem;
}
.calc-output {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; margin-bottom: 16px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.calc-stat { text-align: center; }
.calc-stat .v { font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.calc-stat .k { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }
.calc-notes { font-size: 0.74rem; color: var(--muted); line-height: 1.7; }

/* ---------- Full section modal ---------- */
.section-card { max-width: 780px; }
.section-body {
  max-height: 72vh; overflow-y: auto; padding-right: 6px;
  font-size: 0.9rem; line-height: 1.65; color: var(--text);
}
.section-body h1, .section-body h2, .section-body h3, .section-body h4, .section-body h5, .section-body h6 {
  margin: 18px 0 8px; color: var(--text); line-height: 1.3;
}
.section-body h1 { font-size: 1.4rem; }
.section-body h2 { font-size: 1.2rem; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.section-body h3 { font-size: 1.05rem; }
.section-body h4 { font-size: 0.98rem; }
.section-body h5, .section-body h6 { font-size: 0.9rem; color: var(--muted); }
.section-body p { margin: 8px 0; }
.section-body ul, .section-body ol { margin: 8px 0 8px 22px; }
.section-body li { margin: 4px 0; }
.section-body code {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 6px; font-size: 0.82rem; color: var(--green);
}
.section-body pre {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 10px 0;
}
.section-body pre code { background: transparent; border: none; padding: 0; color: var(--text); font-size: 0.82rem; }
.section-body img { max-width: 100%; height: auto; display: block; margin: 12px auto; border-radius: 10px; }
.section-body blockquote {
  border-left: 3px solid var(--accent); margin: 10px 0;
  padding: 6px 14px; color: var(--muted); background: var(--bg-3); border-radius: 0 8px 8px 0;
}
.section-body table {
  width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.82rem;
}
.section-body th, .section-body td {
  border: 1px solid var(--border); padding: 6px 10px; text-align: left;
}
.section-body th { background: var(--bg-3); color: var(--accent); }
.section-body a { color: var(--accent); }
.section-body hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---------- Full primer browser ---------- */
.primer-card { max-width: 640px; }
.search {
  width: 100%; background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 10px 14px;
  font-size: 0.9rem; margin: 12px 0;
}
.primer-list { max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.primer-item {
  text-align: left; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 9px 12px;
  font-size: 0.85rem; cursor: pointer; transition: 0.12s;
  display: flex; align-items: center; gap: 8px;
}
.primer-item:hover { border-color: var(--accent); }
.primer-item .hx {
  font-size: 0.68rem; color: var(--muted); flex-shrink: 0;
  background: var(--bg-3); border-radius: 5px; padding: 1px 6px;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; position: static; height: auto;
    border-right: none; border-bottom: 1px solid var(--border);
    flex-direction: row; align-items: flex-start; overflow-x: auto;
  }
  #day-nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-extra { flex-direction: row; border-top: none; padding-top: 0; margin-left: auto; }
  .day-nav-item .nav-day { display: none; }
}
