:root {
  --bg: #120d18;
  --bg-2: #1a1123;
  --panel: #21162b;
  --panel-soft: #291b35;
  --line: rgba(255, 193, 102, 0.16);
  --line-strong: rgba(255, 193, 102, 0.32);
  --text: #fff8ef;
  --muted: #c7b8c9;
  --accent: #ffb454;
  --accent-2: #ffd393;
  --mint: #7ee2bd;
  --pink: #ef91b8;
  --danger: #ff8f8f;
  --topbar-h: 72px;
  --sidebar-w: 320px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { scroll-behavior: smooth; }
body {
  color: var(--text);
  background:
    radial-gradient(circle at 8% 8%, rgba(255, 180, 84, 0.10), transparent 25%),
    radial-gradient(circle at 88% 15%, rgba(126, 226, 189, 0.08), transparent 28%),
    linear-gradient(180deg, #100b16, #181020 55%, #120d18);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.30;
  background-image:
    linear-gradient(rgba(255, 180, 84, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 180, 84, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
}

button { font: inherit; }
a { color: inherit; }

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 13, 24, 0.95);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 330px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #21130a;
  font-family: Consolas, monospace;
  font-weight: 900;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(255, 180, 84, 0.15);
}

.brand div { display: grid; gap: 3px; }
.brand strong { font-size: 1rem; }
.brand small { color: var(--muted); font-size: 0.72rem; }

.topnav {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.topnav-item {
  padding: 10px 14px;
  color: #c9b9ca;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  transition: 0.18s;
}

.topnav-item:hover,
.topnav-item.active {
  color: #fffaf3;
  border-color: rgba(255, 180, 84, 0.18);
  background: rgba(255, 180, 84, 0.08);
}

.mobile-menu-btn {
  display: none;
  margin-left: auto;
  width: 42px;
  height: 42px;
  color: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
}

/* ===== Layout ===== */
.app-shell {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - var(--topbar-h));
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: rgba(25, 16, 33, 0.95);
}

.sidebar-head {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(25, 16, 33, 0.98);
}

.sidebar-kicker {
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.sidebar h2 { margin: 6px 0 0; font-size: 1rem; }
.sidebar-close { display: none; }
.accordion { padding: 10px 10px 26px; }

.chapter {
  margin-bottom: 7px;
  border: 1px solid transparent;
  border-radius: 12px;
  overflow: hidden;
}

.chapter.open {
  border-color: rgba(255, 180, 84, 0.13);
  background: rgba(255, 180, 84, 0.025);
}

.chapter-button {
  width: 100%;
  padding: 13px 12px;
  display: grid;
  grid-template-columns: 42px 1fr 20px;
  gap: 8px;
  align-items: center;
  text-align: left;
  color: #eadfea;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.chapter-button:hover { background: rgba(255, 255, 255, 0.025); }

.chapter-no {
  color: var(--accent);
  font-family: Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 900;
}

.chapter-arrow { color: #a68ca9; transition: transform 0.18s; }
.chapter.open .chapter-arrow { transform: rotate(90deg); }

.submenu {
  display: none;
  padding: 4px 8px 10px 50px;
}

.chapter.open .submenu { display: block; }

.submenu button {
  width: 100%;
  margin: 2px 0;
  padding: 9px 10px;
  text-align: left;
  color: #bfaec2;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}

.submenu button:hover,
.submenu button.active {
  color: #fff;
  border-left-color: var(--accent);
  background: rgba(255, 180, 84, 0.07);
}

/* ===== Content ===== */
.content { padding: 28px; min-width: 0; }

.content-breadcrumb {
  max-width: 1060px;
  margin: 0 auto 12px;
  color: #9f8ba2;
  font-size: 0.78rem;
}

.content-card {
  max-width: 1060px;
  margin: 0 auto;
  padding: 34px 40px 56px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent),
    rgba(31, 20, 41, 0.90);
  box-shadow: 0 22px 65px rgba(0, 0, 0, 0.28);
}

.heading-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chapter-label,
.time-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.69rem;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.chapter-label {
  color: #2a1709;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.time-badge {
  color: var(--mint);
  border: 1px solid rgba(126, 226, 189, 0.18);
  background: rgba(126, 226, 189, 0.06);
}

.content-heading h1 {
  margin: 10px 0 12px;
  font-size: clamp(2rem, 4vw, 3.15rem);
  letter-spacing: -0.04em;
}

.content-heading p {
  max-width: 850px;
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
}

.lesson-content { margin-top: 38px; }

.lesson-block {
  padding: 26px 0;
  border-top: 1px solid var(--line);
}

.lesson-block:first-child { border-top: 0; padding-top: 0; }
.lesson-block h2 { margin: 0 0 14px; font-size: 1.28rem; }
.lesson-block h3 { margin: 28px 0 12px; color: #fff6ea; font-size: 1.06rem; }
.lesson-block p,
.content-list { color: #d3c6d3; line-height: 1.85; }

.content-list { padding-left: 1.3rem; }
.content-list li + li { margin-top: 6px; }

/* ===== Course overview / Cards ===== */
.course-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.summary-card,
.concept-card,
.practice-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.022);
}

.summary-card strong,
.concept-card strong,
.practice-card strong {
  display: block;
  color: #fff7ed;
  margin-bottom: 8px;
}

.summary-card span,
.concept-card p,
.practice-card p {
  color: var(--muted);
  line-height: 1.7;
  margin: 0;
}

.summary-number {
  display: inline-flex;
  margin-bottom: 12px;
  color: var(--accent);
  font-family: Consolas, monospace;
  font-weight: 900;
}

.concept-grid,
.practice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.component-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.component-tag {
  padding: 6px 9px;
  color: #ffe3b8;
  font-size: 0.78rem;
  border: 1px solid rgba(255, 180, 84, 0.18);
  border-radius: 999px;
  background: rgba(255, 180, 84, 0.06);
}

.notice,
.tip,
.goal-box {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 11px;
  line-height: 1.75;
}

.notice {
  color: #ffe1e1;
  border-left: 4px solid var(--danger);
  background: rgba(255, 143, 143, 0.07);
}

.tip {
  color: #d7fff0;
  border-left: 4px solid var(--mint);
  background: rgba(126, 226, 189, 0.07);
}

.goal-box {
  color: #ffe8c8;
  border-left: 4px solid var(--accent);
  background: rgba(255, 180, 84, 0.07);
}

/* ===== App Inventor block-like sample ===== */
.block-demo {
  margin: 16px 0;
  padding: 16px;
  border: 1px solid rgba(239, 145, 184, 0.16);
  border-radius: 14px;
  background: rgba(11, 8, 15, 0.55);
}

.block-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin: 8px 0;
}

.block-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 8px;
  font-family: Consolas, "Microsoft JhengHei", monospace;
  font-size: 0.88rem;
  font-weight: 700;
}

.block-event { color: #fff5dc; background: #9a6c22; }
.block-control { color: #fff; background: #8c5bb6; }
.block-variable { color: #fff; background: #cf7c2c; }
.block-text { color: #fff; background: #3f916a; }
.block-math { color: #fff; background: #4f83bd; }
.block-component { color: #fff; background: #aa4e70; }

pre {
  overflow-x: auto;
  margin: 16px 0;
  padding: 20px;
  border: 1px solid rgba(255, 180, 84, 0.12);
  border-radius: 14px;
  background: #0d0912;
}

code { font-family: Consolas, "Courier New", monospace; }

.resource-card {
  display: block;
  margin-top: 16px;
  padding: 18px 20px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 15px;
  background:
    linear-gradient(135deg, rgba(126, 226, 189, 0.05), transparent 55%),
    rgba(255, 255, 255, 0.02);
  transition: 0.18s;
}

.resource-card:hover {
  transform: translateY(-2px);
  border-color: rgba(126, 226, 189, 0.30);
}

.resource-card strong { color: var(--mint); }
.resource-card p { color: var(--muted); margin: 8px 0 0; line-height: 1.7; }

.tutorial-img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 18px 0 34px;
  border: 1px solid rgba(255, 180, 84, 0.16);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.26);
}

.sidebar-overlay { display: none; }

/* ===== Responsive ===== */
@media (max-width: 980px) {
  .course-summary { grid-template-columns: 1fr; }
  .brand { min-width: 0; }
  .brand small { display: none; }
  .topnav { display: none; }
  .mobile-menu-btn { display: block; }
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 150;
    width: min(86vw, 330px);
    height: calc(100vh - var(--topbar-h));
    transform: translateX(-105%);
    transition: transform 0.22s;
    box-shadow: 18px 0 50px rgba(0, 0, 0, 0.34);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .sidebar-close {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    color: #fff;
    font-size: 1.4rem;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
  }

  .sidebar-overlay {
    position: fixed;
    inset: var(--topbar-h) 0 0;
    z-index: 140;
    background: rgba(0, 0, 0, 0.52);
  }

  .sidebar-overlay.show { display: block; }
  .content { padding: 18px 14px 30px; }
  .content-card { padding: 26px 20px 42px; border-radius: 18px; }
}

@media (max-width: 680px) {
  .concept-grid,
  .practice-grid { grid-template-columns: 1fr; }
  .content-heading h1 { font-size: 2rem; }
}

@media (max-width: 520px) {
  :root { --topbar-h: 64px; }
  .topbar { padding: 0 14px; }
  .brand-logo { width: 36px; height: 36px; }
  .brand strong { font-size: 0.92rem; }
  .content-card { padding: 22px 16px 36px; }
}
