:root {
  --bg: #edeff4;
  --primary: #1a1a2e;
  --secondary: #6b7280;
  --accent: #667eea;
  --accent-light: #764ba2;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow-light: #ffffff;
  --shadow-dark: #c9ccd4;
  --card-radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1e26;
    --primary: #f2f3f7;
    --secondary: #9aa0ac;
    --shadow-light: #262933;
    --shadow-dark: #121319;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--primary);
  font-family: -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: inherit; text-decoration: none; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 96px;
}

header.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

header.top-bar h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  box-shadow: 6px 6px 12px var(--shadow-dark), -6px -6px 12px var(--shadow-light);
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--accent);
}

.card {
  background: var(--bg);
  border-radius: var(--card-radius);
  box-shadow: 8px 8px 16px var(--shadow-dark), -8px -8px 16px var(--shadow-light);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--accent);
}

.today-course {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.today-course .title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 8px;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
}

.go-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  box-shadow: 6px 6px 12px var(--shadow-dark), -6px -6px 12px var(--shadow-light);
  color: var(--accent);
  font-size: 1.1rem;
  cursor: pointer;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 4px 12px;
}

.section-heading h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
}

.count-pill {
  font-weight: 700;
  color: var(--accent);
}

.category-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 12px;
  -webkit-overflow-scrolling: touch;
}

.category-chip {
  flex: 0 0 auto;
  padding: 8px 16px;
  border-radius: 999px;
  border: none;
  background: var(--bg);
  box-shadow: 4px 4px 8px var(--shadow-dark), -4px -4px 8px var(--shadow-light);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--secondary);
  cursor: pointer;
  white-space: nowrap;
}

.category-chip.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  box-shadow: none;
}

.course-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.course-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg);
  border-radius: 16px;
  /* A single lightweight shadow instead of the double neumorphic shadow —
     with 50+ of these on screen, two blurred shadows each was heavy enough
     to make scrolling and re-renders (toggling learned, switching category)
     visibly stutter on mobile. */
  box-shadow: 0 2px 6px var(--shadow-dark);
  padding: 14px 16px;
  cursor: pointer;
  contain: content;
}

.course-card .info { flex: 1; min-width: 0; }

.course-card .info .title {
  font-weight: 700;
  font-size: 0.98rem;
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.course-card .info .meta {
  font-size: 0.78rem;
  color: var(--secondary);
}

.course-card .check {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--shadow-dark);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: transparent;
}

.course-card.learned .check {
  border-color: var(--success);
  background: var(--success);
  color: #fff;
}

.learned-toggle {
  background: none;
  border: none;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px;
  cursor: pointer;
  color: var(--primary);
  font-family: inherit;
}

.learned-toggle .spacer { flex: 1; }

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--secondary);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  padding: 10px env(safe-area-inset-bottom) calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  box-shadow: 0 -4px 12px var(--shadow-dark);
}

.tab-bar nav {
  display: flex;
  gap: 40px;
}

.tab-bar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.7rem;
  color: var(--secondary);
  gap: 2px;
}

.tab-bar a.active { color: var(--accent); font-weight: 700; }
.tab-bar a .glyph { font-size: 1.3rem; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  border-bottom: 1px solid var(--shadow-dark);
}

.settings-row:last-child { border-bottom: none; }

.settings-row label { font-weight: 600; }

.switch {
  position: relative;
  width: 48px;
  height: 28px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--shadow-dark);
  border-radius: 999px;
  transition: .2s;
}

.switch .slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}

.switch input:checked + .slider {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

input[type="time"] {
  border: none;
  background: var(--bg);
  box-shadow: inset 3px 3px 6px var(--shadow-dark), inset -3px -3px 6px var(--shadow-light);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.95rem;
  color: var(--primary);
}

.primary-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 8px;
}

.install-banner {
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  box-shadow: 6px 6px 12px var(--shadow-dark), -6px -6px 12px var(--shadow-light);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 16px;
  font-size: 0.85rem;
}

.install-banner.show { display: flex; }

.detail-frame-wrap {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.detail-top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  box-shadow: 0 4px 10px var(--shadow-dark);
  background: var(--bg);
  z-index: 2;
}

.detail-top-bar h2 {
  flex: 1;
  min-width: 0;
  font-size: 1rem;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-frame-wrap iframe {
  flex: 1;
  border: none;
  width: 100%;
}

.offline-note {
  font-size: 0.75rem;
  color: var(--secondary);
  text-align: center;
  margin-top: -8px;
  margin-bottom: 16px;
}
