:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #eef2fb;
  --border: #e2e8f4;
  --text: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --teal: #14b8a6;
  --orange: #f97316;
  --grad: linear-gradient(135deg, #3b82f6, #14b8a6);
  --shadow: 0 2px 10px rgba(30, 41, 59, 0.06);
  --radius: 16px;
  --success-bg: #dcfce7;
  --success-text: #15803d;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", sans-serif;
  min-height: 100vh;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
}

/* ── Layout ─────────────────────────────────────────── */

#app {
  display: flex;
  min-height: 100vh;
}

#topbar {
  display: none;
}

#sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
}

#main {
  flex: 1;
  min-width: 0;
  padding: 40px 48px 80px;
}

#overlay {
  display: none;
}

/* ── Sidebar ────────────────────────────────────────── */

.sidebar-header {
  padding: 24px 20px;
  background: var(--grad);
  color: #fff;
}
.sidebar-header h1 {
  font-size: 17px;
  font-weight: 800;
}
.sidebar-header p {
  font-size: 12px;
  opacity: 0.9;
  margin-top: 4px;
}
.overall-progress {
  margin-top: 14px;
}
.overall-progress-bar {
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.35);
  overflow: hidden;
}
.overall-progress-fill {
  height: 100%;
  background: #fff;
  border-radius: 99px;
  transition: width 0.3s ease;
}
.overall-progress span {
  display: block;
  font-size: 11px;
  margin-top: 6px;
  opacity: 0.9;
}

.strand-list {
  padding: 8px 0 24px;
}

.strand-group {
  border-bottom: 1px solid var(--border);
}
.strand-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  font-weight: 700;
  font-size: 14px;
}
.strand-toggle:hover {
  background: var(--surface-2);
}
.strand-icon {
  font-size: 18px;
}
.strand-name {
  flex: 1;
}
.strand-arrow {
  font-size: 11px;
  color: var(--text-3);
  transition: transform 0.2s ease;
}
.strand-group.open .strand-arrow {
  transform: rotate(180deg);
}

.chapter-list {
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.chapter-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px 10px 32px;
  font-size: 13px;
  color: var(--text-2);
  border-left: 3px solid transparent;
}
.chapter-link:hover {
  background: var(--surface-2);
  color: var(--text);
  border-left-color: var(--primary);
}
.chapter-grade {
  font-size: 11px;
  color: var(--text-3);
  min-width: 32px;
  flex-shrink: 0;
}
.chapter-title {
  flex: 1;
}
.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text-3);
  flex-shrink: 0;
}
.badge.mastered {
  background: var(--success-bg);
  color: var(--success-text);
}
.badge.practicing {
  background: #fef3c7;
  color: #b45309;
}
.chapter-link.complete .chapter-title {
  color: var(--text);
  font-weight: 600;
}

/* ── Home view ──────────────────────────────────────── */

.view h1 {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 12px;
}
.home-view .lead {
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.8;
  max-width: 640px;
  margin-bottom: 32px;
}

.strand-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.strand-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.strand-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(30, 41, 59, 0.1);
}
.strand-card-icon {
  font-size: 28px;
}
.strand-card-name {
  font-size: 17px;
  font-weight: 800;
}
.strand-card-tagline {
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.5;
}
.strand-card-count {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-dark);
}

/* ── Chapter (placeholder) view ─────────────────────── */

.breadcrumb {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 8px;
}
.placeholder-card {
  margin-top: 24px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  color: var(--text-2);
}
.placeholder-emoji {
  font-size: 32px;
  display: block;
  margin-bottom: 12px;
}
.placeholder-sub {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 6px;
}

/* ── Bottom tabs (mobile only) ──────────────────────── */

#bottom-tabs {
  display: none;
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 860px) {
  #topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
  }
  #topbar h2 {
    font-size: 15px;
    font-weight: 800;
  }
  #menu-btn {
    font-size: 20px;
    line-height: 1;
    padding: 4px 8px;
  }

  #app {
    flex-direction: column;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 40;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.15);
  }
  #sidebar.open {
    transform: translateX(0);
  }

  #overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 30;
  }
  #overlay.visible {
    display: block;
  }

  #main {
    padding: 24px 16px 96px;
  }

  #bottom-tabs {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 20;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 4px 8px;
    font-size: 10px;
    color: var(--text-2);
  }
  .tab-icon {
    font-size: 18px;
  }
}

@media (min-width: 861px) {
  #bottom-tabs {
    display: none !important;
  }
}
