/* ============================================================
   PyMaster TW Pro — style.css
   Complete 25-chapter Python Tutorial Site
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --bg: #080e20;
  --bg2: #0f1830;
  --text: #edf3ff;
  --muted: #8fa3c8;
  --panel: rgba(255,255,255,0.07);
  --panel2: rgba(255,255,255,0.11);
  --border: rgba(255,255,255,0.11);
  --primary: #5cabff;
  --secondary: #8a6eff;
  --accent: #25d8be;
  --success: #3fd48c;
  --danger: #ff6b82;
  --warning: #ffbe5c;
  --code-bg: #0a1025;
  --radius: 22px;
  --shadow: 0 20px 48px rgba(0,0,0,0.3);
  --gradient: linear-gradient(135deg, #4aa6ff 0%, #7b5fff 50%, #1fccb0 100%);
}

body.light {
  --bg: #f0f5ff;
  --bg2: #e7efff;
  --text: #152040;
  --muted: #5a6e8e;
  --panel: rgba(255,255,255,0.75);
  --panel2: rgba(255,255,255,0.9);
  --border: rgba(20,36,67,0.09);
  --primary: #2060dd;
  --secondary: #6b4fcc;
  --accent: #00a99c;
  --success: #1a9c55;
  --danger: #d43a5a;
  --warning: #b07600;
  --code-bg: #101e3a;
  --shadow: 0 16px 40px rgba(50,80,130,0.14);
  --gradient: linear-gradient(135deg, #2060dd 0%, #6b4fcc 50%, #00a99c 100%);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.72;
  overflow-x: hidden;
  position: relative;
}
a { text-decoration: none; color: inherit; }
code, pre { font-family: Consolas, Monaco, "Courier New", monospace; }
button, input { font-family: inherit; }

/* ---------- Background Orbs ---------- */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(88px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.55;
}
.orb-1 { width: 500px; height: 500px; top: -120px; left: -140px; background: rgba(74,166,255,0.22); }
.orb-2 { width: 420px; height: 420px; top: 30%; right: -100px; background: rgba(123,95,255,0.18); }
.orb-3 { width: 360px; height: 360px; bottom: 0; left: 30%; background: rgba(31,204,176,0.15); }

/* ---------- Layout ---------- */
.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 28px;
  position: relative;
  z-index: 1;
}

/* ---------- Topbar / Nav ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 900;
  backdrop-filter: blur(18px);
  background: rgba(8,14,32,0.6);
  border-bottom: 1px solid var(--border);
}
body.light .topbar { background: rgba(255,255,255,0.76); }

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 28px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  flex-shrink: 0;
}
.brand-logo {
  width: 46px; height: 46px;
  border-radius: 14px;
  background: var(--gradient);
  display: grid; place-items: center;
  color: #fff; font-weight: 900; font-size: 1.1rem;
  box-shadow: 0 10px 28px rgba(74,166,255,0.28);
}
.brand strong { display: block; font-size: 1rem; }
.brand span { display: block; color: var(--muted); font-size: .8rem; }

.nav-links {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
  justify-content: center;
}
.nav-links a {
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--muted);
  transition: .22s;
  font-size: .95rem;
}
.nav-links a:hover { background: var(--panel2); color: var(--text); }

.nav-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.primary-btn, .ghost-btn {
  border: none; cursor: pointer; border-radius: 13px;
  padding: 11px 18px; font-weight: 700; font-size: .95rem;
  transition: .22s;
}
.primary-btn {
  background: var(--gradient);
  color: #fff;
  box-shadow: 0 10px 24px rgba(74,166,255,0.22);
}
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 28px rgba(74,166,255,0.3); }
.ghost-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}
.ghost-btn:hover { background: var(--panel2); transform: translateY(-2px); }
.full-width { width: 100%; }
.hidden { display: none !important; }

/* ---------- Glass Cards ---------- */
.glass {
  background: var(--panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Hero ---------- */
.hero {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 24px;
  padding-top: 60px;
  padding-bottom: 28px;
  align-items: start;
}
.hero-card {
  padding: 44px;
  position: relative;
  overflow: hidden;
}
.hero-card::after {
  content: "";
  position: absolute;
  right: -80px; bottom: -80px;
  width: 240px; height: 240px; border-radius: 50%;
  background: radial-gradient(circle, rgba(74,166,255,0.25), transparent 68%);
}
.eyebrow {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  font-size: .9rem;
  margin-bottom: 18px;
}
.hero-card h1 {
  font-size: clamp(1.9rem, 3.5vw, 3.6rem);
  line-height: 1.1;
  letter-spacing: -.03em;
  margin-bottom: 14px;
}
.hero-card > p { color: var(--muted); margin-bottom: 22px; max-width: 760px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 26px; }
.hero-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 20px;
}
.metric-card {
  padding: 18px;
  border-radius: 18px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
}
.metric-card strong { display: block; font-size: 1.5rem; }
.metric-card span { color: var(--muted); font-size: .9rem; }

.hero-side { display: flex; flex-direction: column; gap: 18px; }
.panel { padding: 24px; }
.panel h3 { margin: 0 0 10px; font-size: 1rem; }
.inline-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

.search-box { margin-top: 12px; }
.search-box input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.08);
  color: var(--text);
  outline: none;
  font-size: .97rem;
}

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip {
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .86rem;
  cursor: pointer;
  transition: .2s;
  font-weight: 600;
}
.chip.active, .chip:hover {
  background: var(--gradient);
  color: #fff;
  border-color: transparent;
}

.terminal-panel pre {
  background: var(--code-bg);
  border-radius: 14px;
  padding: 16px;
  margin-top: 12px;
  overflow: auto;
  font-size: .9rem;
  color: #d0e4ff;
}

/* ---------- Section Headings ---------- */
.section-block { padding: 60px 28px; }
.section-heading {
  margin-bottom: 28px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
}
.section-heading.compact { margin-bottom: 22px; }
.section-kicker {
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 6px;
}
.section-heading h2 { font-size: 1.8rem; line-height: 1.15; }
.muted { color: var(--muted); font-size: .98rem; margin-top: 6px; }

/* ---------- Dashboard ---------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.stat-panel {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.panel-label { font-size: .83rem; color: var(--muted); font-weight: 600; }
.stat-panel strong { font-size: 1.7rem; }
.stat-panel small { font-size: .84rem; color: var(--muted); }

.progress-card {
  padding: 28px;
}
.progress-text-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.progress-percentage {
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 1;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.progress-bar-shell {
  width: 100%;
  height: 16px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--gradient);
  border-radius: 999px;
  transition: width 0.6s ease;
}

/* ---------- Chapters Layout ---------- */
.chapters-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: start;
  padding: 60px 28px;
}
.sidebar-panel {
  position: sticky;
  top: 90px;
  padding: 20px 14px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}
.sidebar-head { padding: 0 8px 12px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.sidebar-head h3 { font-size: 1rem; }
.chapter-nav { display: flex; flex-direction: column; gap: 4px; }
.chapter-nav a {
  padding: 10px 13px;
  border-radius: 13px;
  color: var(--muted);
  font-size: .9rem;
  transition: .2s;
  display: block;
}
.chapter-nav a:hover, .chapter-nav a.active {
  background: var(--panel2);
  color: var(--text);
}

.chapter-content-area { flex: 1; }
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}

/* ---------- Chapter Card ---------- */
.chapter-card {
  padding: 24px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  transition: .24s;
  position: relative;
}
.chapter-card:hover { transform: translateY(-3px); background: var(--panel2); }
.chapter-card.completed { border-color: rgba(63,212,140,0.4); }
.chapter-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.chapter-top h4 { font-size: 1.05rem; flex: 1; }
.level-badge {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 800;
  background: rgba(92,171,255,0.15);
  color: #b0d4ff;
  border: 1px solid rgba(92,171,255,0.25);
  white-space: nowrap;
}
.level-badge.intermediate { background: rgba(138,110,255,0.14); color: #cdbfff; border-color: rgba(138,110,255,0.25); }
.level-badge.advanced { background: rgba(255,107,130,0.14); color: #ffb0bc; border-color: rgba(255,107,130,0.25); }
.level-badge.project { background: rgba(255,190,92,0.14); color: #ffe0a8; border-color: rgba(255,190,92,0.25); }

.code-block {
  margin-top: 14px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}
.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.dots { display: flex; gap: 7px; }
.dots span { width: 10px; height: 10px; border-radius: 50%; display: block; }
.dots span:nth-child(1){ background: #ff6b6b; }
.dots span:nth-child(2){ background: #ffd166; }
.dots span:nth-child(3){ background: #06d6a0; }
.code-block pre {
  background: var(--code-bg);
  padding: 16px;
  margin: 0;
  overflow: auto;
  color: #d0e0ff;
  font-size: .89rem;
  max-height: 240px;
}

.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.fav-btn, .done-btn {
  padding: 9px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  font-size: .88rem;
  font-weight: 700;
  transition: .2s;
}
.fav-btn:hover { background: rgba(255,190,92,0.14); color: var(--warning); }
.fav-btn.active { background: rgba(255,190,92,0.14); color: var(--warning); border-color: rgba(255,190,92,0.35); }
.done-btn:hover { background: rgba(63,212,140,0.12); color: var(--success); }
.done-btn.active { background: rgba(63,212,140,0.14); color: var(--success); border-color: rgba(63,212,140,0.35); }

.chapter-card.hidden { display: none; }

/* ---------- Favorites ---------- */
.favorite-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.fav-card {
  padding: 20px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--warning);
}
.fav-card h4 { margin: 0 0 6px; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 52px;
  color: var(--muted);
}

/* ---------- Quiz ---------- */
.quiz-layout { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.quiz-main { padding: 32px; }
.quiz-meta-row { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.quiz-chip {
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(92,171,255,0.12);
  color: var(--primary);
  border: 1px solid rgba(92,171,255,0.25);
  font-size: .85rem;
  font-weight: 700;
}
.quiz-chip.secondary {
  background: rgba(138,110,255,0.12);
  color: var(--secondary);
  border-color: rgba(138,110,255,0.25);
}
.quiz-question { font-size: 1.28rem; line-height: 1.5; margin-bottom: 18px; }
.quiz-options { display: grid; gap: 10px; margin-bottom: 20px; }
.option {
  padding: 14px 18px;
  border-radius: 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: .2s;
  font-size: .97rem;
}
.option:hover { background: rgba(255,255,255,0.09); }
.option.selected { border-color: rgba(92,171,255,0.55); background: rgba(92,171,255,0.12); color: var(--primary); }
.option.correct { border-color: rgba(63,212,140,0.55); background: rgba(63,212,140,0.12); }
.option.wrong { border-color: rgba(255,107,130,0.55); background: rgba(255,107,130,0.12); }
.quiz-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.quiz-feedback { margin-top: 14px; min-height: 28px; }

.quiz-side { padding: 24px; }
.quiz-side h3 { margin: 0 0 16px; }
.quiz-side-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.quiz-side-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.quiz-side-item strong { font-size: 1.35rem; }

/* ---------- Resources ---------- */
.resource-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.resource-card { padding: 24px; }
.resource-card h3 { margin: 0 0 10px; font-size: 1.05rem; }
.resource-card p { color: var(--muted); font-size: .94rem; }
.resource-card code { background: rgba(255,255,255,0.08); padding: 2px 7px; border-radius: 6px; font-size: .9em; }

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  padding: 38px 28px;
  color: var(--muted);
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}
.footer-inner strong { color: var(--text); font-size: 1rem; }

/* ---------- Back to Top ---------- */
.back-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999;
  width: 50px; height: 50px;
  border: none;
  border-radius: 15px;
  background: var(--gradient);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(74,166,255,0.28);
  display: grid; place-items: center;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  background: #111e3b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  opacity: 0;
  pointer-events: none;
  transition: .3s;
  z-index: 9999;
  font-size: .96rem;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 9000;
}
.modal-card {
  width: 100%;
  max-width: 440px;
  padding: 36px;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  display: grid; place-items: center;
}
.modal-tabs { display: flex; gap: 10px; margin-bottom: 22px; }
.tab-btn {
  flex: 1;
  padding: 11px;
  border-radius: 13px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 700;
  font-size: .96rem;
  cursor: pointer;
  transition: .2s;
}
.tab-btn.active { background: var(--gradient); color: #fff; border-color: transparent; }

.auth-pane { display: none; }
.auth-pane.active { display: block; }
.auth-pane h3 { margin: 0 0 6px; }
.auth-pane .muted { margin-bottom: 18px; }

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: .88rem; font-weight: 700; color: var(--muted); }
.form-group input {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.07);
  color: var(--text);
  outline: none;
  font-size: .96rem;
}
.form-group input:focus { border-color: var(--primary); }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 99px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .hero { grid-template-columns: 1fr; }
  .chapters-layout { grid-template-columns: 1fr; }
  .sidebar-panel { position: relative; top: 0; max-height: none; }
  .chapter-nav { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .chapter-nav a { padding: 8px 12px; font-size: .84rem; }
  .dashboard-grid, .hero-metrics { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .chapter-grid { grid-template-columns: 1fr; }
  .quiz-layout { grid-template-columns: 1fr; }
  .favorite-grid { grid-template-columns: 1fr; }
  .resource-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .hero-metrics { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .nav { padding: 12px 16px; }
  .nav-links { display: none; }
  .section-block { padding: 40px 16px; }
  .chapters-layout { padding: 40px 16px; }
  .hero { padding: 40px 16px 18px; }
  .hero-card { padding: 28px; }
  .hero-metrics, .dashboard-grid { grid-template-columns: 1fr; }
  .resource-grid { grid-template-columns: 1fr; }
  .quiz-layout { grid-template-columns: 1fr; }
}