/*
 * Theme tokens, three-layer system (@belajarcarabelajar house look).
 *
 *  1. :root (light): derived neutral palette with a darker orange for AA on light grounds.
 *  2. :root[data-theme="dark"]: the house look (near-black frame, chalk text, iket orange).
 *  3. @media (prefers-color-scheme: dark) :root:not([data-theme]): auto fallback
 *     when no theme attribute is set. Once [data-theme] is set the @media block
 *     no longer applies.
 *
 * The two dark blocks below share identical declarations (CSS has no native way
 * to factor them without a preprocessor); keep them in sync. Ratios in the
 * comments are WCAG 2.x, checked by tests/house-look.test.js.
 */
:root {
  color-scheme: light dark;

  /* Brand */
  /* Yellow leads, orange supports. Yellow is never text on a light ground:
     text accents here are a dark amber. */
  --primary-color:       #854d0e;   /* text, borders, focus: 6.23:1 on --bg-page, 6.85:1 on white, 6.56:1 on elevated */
  --primary-hover:       #713f12;   /* 7.89:1 on --bg-page, 8.67:1 on white */
  --primary-fill:        #fec700;   /* button background (headline yellow) */
  --primary-fill-hover:  #eab308;
  --primary-on:          #111113;
  --text-on-primary:     #111113;   /* 12.02:1 on --primary-fill, 9.83:1 on --primary-fill-hover */
  --accent-orange:       #c2410c;   /* card headings, card hover, XP fill end: 5.18:1 on white, 4.96:1 on elevated */

  /* Surfaces */
  --bg-page:             #f4f4f5;
  --bg-surface:          #ffffff;
  --bg-surface-elevated: #fafafa;
  --bg-surface-muted:    #f4f4f5;
  --bg-inset:            #f4f4f5;

  /* Text */
  --text-color:          #111113;   /* 18.86:1 on white, 17.16:1 on --bg-page */
  --text-color-muted:    #52525b;   /* 7.73:1 on white, 7.03:1 on --bg-page */
  --text-on-dark:        #d6d6da;

  /* Borders */
  --border-color:        #e4e4e7;
  --border-color-strong: #d4d4d8;

  /* Semantic */
  --red:                 #b91c1c;   /* 6.47:1 on white, 5.91:1 on --red-bg */
  --red-bg:              #fef2f2;
  --green-bg:            #f4f4f5;
  --tip-card-bg:         #f4f4f5;
  --info-card-bg:        #fafafa;
  --info-border:         #52525b;
  --skeleton-base:       #f4f4f5;
  --skeleton-shine:      #e4e4e7;

  /* Toast (used by error-handler.js) */
  --toast-bg:            #b91c1c;
  --toast-fg:            #ffffff;   /* 6.47:1 */

  /* Back-compat aliases, kept for inline styles and JS modules that pre-date
     the rename. Safe to remove once all callers migrate. */
  --secondary-color:     var(--bg-inset);
  --light-gray:          var(--bg-page);
  --gray:                var(--text-color-muted);
  --white:               var(--bg-surface);
  --red-light:           var(--red-bg);
  --green-light:         var(--green-bg);

  /* Radius / shadow */
  --border-radius:       12px;
  --box-shadow:          0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.08);
  --shadow-sm:           0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md:           var(--box-shadow);
  --shadow-lg:           0 10px 25px -5px rgba(0, 0, 0, 0.15);
  --shadow-card-hover:   0 6px 12px -2px rgba(0, 0, 0, 0.18);

  /* Flashcards: --text-color on the faces is at least 16.46:1 */
  --flashcard-front-from: #fafafa;
  --flashcard-front-to:   #f4f4f5;
  --flashcard-back-from:  #fff7ed;
  --flashcard-back-to:    #ffedd5;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --primary-color:       #fec700;   /* headline yellow: 12.91:1 on page, 12.02:1 on surface, 10.59:1 on elevated */
  --primary-hover:       #ffd23f;   /* 14.03:1 on page, 11.50:1 on elevated */
  --primary-fill:        #fec700;
  --primary-fill-hover:  #ffd23f;
  --primary-on:          #060607;
  --text-on-primary:     #060607;   /* 12.91:1 on --primary-fill, 14.03:1 on --primary-fill-hover */
  --accent-orange:       #f97316;   /* iket orange: 6.73:1 on surface, 5.93:1 on elevated */

  --bg-page:             #060607;   /* ink */
  --bg-surface:          #111113;
  --bg-surface-elevated: #1e1e22;   /* ground */
  --bg-surface-muted:    #0c0c0e;   /* groundShade */
  --bg-inset:            #1e1e22;

  --text-color:          #d6d6da;   /* chalk: 13.98:1 on page, 13.01:1 on surface, 11.46:1 on elevated */
  --text-color-muted:    #a3a3a3;   /* slateLight: 7.48:1 on surface, 6.59:1 on elevated */
  --text-on-dark:        #d6d6da;

  --border-color:        #2a2a2e;
  --border-color-strong: #3a3a3c;   /* slate */

  --red:                 #f87171;   /* 6.82:1 on --bg-surface, 5.84:1 on --red-bg */
  --red-bg:              #450a0a;
  --green-bg:            #1e1e22;
  --tip-card-bg:         #1e1e22;
  --info-card-bg:        #1e1e22;
  --info-border:         #a3a3a3;
  --skeleton-base:       #1e1e22;
  --skeleton-shine:      #2a2a2e;

  --toast-bg:            #b91c1c;
  --toast-fg:            #fef2f2;   /* 5.91:1 */

  --shadow-sm:           0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md:           0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg:           0 10px 25px -5px rgba(0, 0, 0, 0.6);
  --shadow-card-hover:   0 6px 12px -2px rgba(0, 0, 0, 0.6);

  /* Chalk text on the faces: at least 10.39:1 */
  --flashcard-front-from: #1e1e22;
  --flashcard-front-to:   #26262b;
  --flashcard-back-from:  #2a1608;
  --flashcard-back-to:    #3b1d0a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;

    --primary-color:       #fec700;   /* headline yellow: 12.91:1 on page, 12.02:1 on surface, 10.59:1 on elevated */
    --primary-hover:       #ffd23f;   /* 14.03:1 on page, 11.50:1 on elevated */
    --primary-fill:        #fec700;
    --primary-fill-hover:  #ffd23f;
    --primary-on:          #060607;
    --text-on-primary:     #060607;   /* 12.91:1 on --primary-fill, 14.03:1 on --primary-fill-hover */
    --accent-orange:       #f97316;   /* iket orange: 6.73:1 on surface, 5.93:1 on elevated */

    --bg-page:             #060607;   /* ink */
    --bg-surface:          #111113;
    --bg-surface-elevated: #1e1e22;   /* ground */
    --bg-surface-muted:    #0c0c0e;   /* groundShade */
    --bg-inset:            #1e1e22;

    --text-color:          #d6d6da;   /* chalk: 13.98:1 on page, 13.01:1 on surface, 11.46:1 on elevated */
    --text-color-muted:    #a3a3a3;   /* slateLight: 7.48:1 on surface, 6.59:1 on elevated */
    --text-on-dark:        #d6d6da;

    --border-color:        #2a2a2e;
    --border-color-strong: #3a3a3c;   /* slate */

    --red:                 #f87171;   /* 6.82:1 on --bg-surface, 5.84:1 on --red-bg */
    --red-bg:              #450a0a;
    --green-bg:            #1e1e22;
    --tip-card-bg:         #1e1e22;
    --info-card-bg:        #1e1e22;
    --info-border:         #a3a3a3;
    --skeleton-base:       #1e1e22;
    --skeleton-shine:      #2a2a2e;

    --toast-bg:            #b91c1c;
    --toast-fg:            #fef2f2;   /* 5.91:1 */

    --shadow-sm:           0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md:           0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
    --shadow-lg:           0 10px 25px -5px rgba(0, 0, 0, 0.6);
    --shadow-card-hover:   0 6px 12px -2px rgba(0, 0, 0, 0.6);

    /* Chalk text on the faces: at least 10.39:1 */
    --flashcard-front-from: #1e1e22;
    --flashcard-front-to:   #26262b;
    --flashcard-back-from:  #2a1608;
    --flashcard-back-to:    #3b1d0a;
  }
}

/* Smooth color transition when the user toggles; disabled for reduced-motion users. */
:root { transition: background-color 0.25s ease, color 0.25s ease; }
@media (prefers-reduced-motion: reduce) {
  :root { transition: none !important; }
}

body {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-weight: 400;
  margin: 0;
  background-color: var(--bg-page);
  color: var(--text-color);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; letter-spacing: -0.01em; }
button, input, select, textarea { font-family: inherit; }
button { font-weight: 500; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.container { width: 90%; max-width: 1200px; margin: 0 auto; padding: 16px; }

/* Header */
.header-block {
  position: relative;
  background-color: var(--bg-surface);
  padding: 16px 24px;
  margin-bottom: 20px;
  border-radius: var(--border-radius);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}
.header-block h1 {
  font-size: 1.8rem;
  margin: 0;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

.header-title-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  margin: 0 auto;
  width: 100%;
  max-width: 680px;
}

.home-header .header-title-group,
.home-header #progress-bar {
  pointer-events: none;
}

.home-header .header-right {
  z-index: 2;
  pointer-events: auto;
}

.home-header .header-right * {
  pointer-events: auto;
}
#progress-bar {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
}

/* .container is 90% wide and the header adds side padding; under the default
   content-box sizing that overflowed a 390px phone by 9px on every page. */
@media (max-width: 767px) {
  .header-block {
    box-sizing: border-box;
  }
}

/* Header right rail (toggles + auth slot) */
.header-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

@media (min-width: 768px) {
  .header-block {
    position: relative;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: 18px 28px;
    min-height: 80px;
    text-align: center;
  }
  .header-block h1 {
    font-size: 1.8rem;
    text-align: center;
    margin: 0;
  }
  .header-right {
    position: absolute;
    right: 28px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    width: auto;
    gap: 16px;
  }
}

/* Auth slot */
html.is-authenticated #auth-slot .auth-login-btn { display: none !important; }
.auth-slot { display: flex; align-items: center; justify-content: center; }
.auth-login-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background-color: var(--bg-surface);
  color: var(--text-color);
  border: 1px solid var(--border-color-strong);
  border-radius: 8px;
  min-height: 44px;
  box-sizing: border-box;
  font-weight: 500;
  font-size: 0.9rem;
  text-decoration: none;
  box-shadow: var(--box-shadow);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.auth-login-btn:hover { border-color: var(--primary-color); transform: translateY(-1px); }
.auth-login-btn svg { display: block; }

.auth-user-dropdown {
  position: relative;
  display: inline-block;
}
.auth-avatar-btn {
  background: none;
  border: 2px solid var(--primary-color);
  padding: 2px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.auth-avatar-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color) 35%, transparent);
}
.auth-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.auth-avatar-fallback {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--primary-fill);
  color: var(--text-on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
}
.auth-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  min-width: 200px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}
.auth-dropdown-menu[hidden] {
  display: none !important;
}
.auth-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}
.auth-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-color);
}
.auth-email {
  font-size: 0.75rem;
  color: var(--gray);
}
.auth-logout {
  display: block;
  text-align: center;
  padding: 6px 12px;
  background-color: var(--red-light);
  color: var(--red);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s ease;
}
.auth-logout:hover {
  background-color: var(--red-bg);
  border-color: transparent;
  filter: brightness(0.97);
  opacity: 0.95;
}

.progress-bar-container {
  background-color: var(--border-color);
  border-radius: 999px;
  overflow: hidden;
  width: 100%;
  margin-bottom: 0;
  position: relative;
  height: 28px;
}
#xpProgressBar {
  background: linear-gradient(90deg, var(--primary-fill), var(--accent-orange));
  width: 0%;
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s ease-in-out;
}
#xpLabel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  /* Own chip so the label never sits on the orange fill directly
     (chalk on #f97316 is 1.93:1); text-color on bg-surface is a tested pair. */
  color: var(--text-color);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 2px 8px;
  line-height: 1.2;
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  pointer-events: none;
}

/* Syllabus */
.syllabus-section {
  background-color: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  margin-bottom: 16px;
  padding: 16px;
}
.top-tabs {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 16px;
}
/* Tab chips: neutral when idle, inverted (text-colour fill) when active. */
.top-tab-button {
  min-height: 44px;
  padding: 10px 20px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface-elevated);
  color: var(--text-color);
  cursor: pointer;
  border-radius: 8px;
  font-weight: 500;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.top-tab-button:hover { border-color: var(--border-color-strong); }
.top-tab-button.active { background-color: var(--primary-fill); color: var(--text-on-primary); border-color: var(--primary-fill); font-weight: 700; }
.top-tab-content { display: none; }
.top-tab-content.active { display: block; }

.grid-container { display: grid; gap: 16px; }
.grid-item {
  background-color: var(--bg-inset);
  padding: 24px;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}
.grid-item h3 {
  margin-top: 0;
  color: var(--accent-orange);
  margin-bottom: 16px;
}
.grid-item ul { padding-left: 0; list-style: none; margin: 0; }
.grid-item li { margin-bottom: 8px; text-align: left; }


/* SMART Goals To-Do List */
#todo-list { list-style-type: none; padding: 0; }
#todo-list li {
  background-color: var(--white);
  margin-bottom: 8px; padding: 12px; border-radius: 8px;
  display: flex; align-items: center; border: 1px solid var(--border-color);
}
#todo-list input[type="checkbox"] { margin-right: 12px; }
#todo-list label { flex-grow: 1; }

/* Course Modules */
.course-layout { 
  display: flex; 
  flex-direction: column; 
  gap: 0; 
  background-color: var(--white); 
  border-radius: var(--border-radius); 
  box-shadow: var(--box-shadow); 
  overflow: hidden;
  margin-top: 16px;
}

.sidebar {
  padding: 24px 16px;
  width: 100%;
  box-sizing: border-box;
  background-color: var(--bg-surface-elevated);
}

.sidebar-nav { list-style: none; padding: 0; margin: 0; }
.sidebar-nav li a {
  display: block; padding: 12px 16px; text-decoration: none; color: var(--text-color);
  border-radius: 8px; font-weight: 500; transition: background-color 0.3s, color 0.3s; margin-bottom: 4px;
}
.sidebar-nav li a:hover { background-color: var(--secondary-color); }
.sidebar-nav li a.active { background-color: var(--primary-fill); color: var(--text-on-primary); }

.main-content {
  flex: 1; padding: 32px; min-width: 0;
  background-color: var(--white);
}
.module-container { display: block; }

.module-content-area .content-tab { display: none; }
.module-content-area .content-tab.active { display: block; }
.module-header h2 { text-align: center; font-size: 2rem; margin-bottom: 16px; }

.video-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; border-radius: var(--border-radius); margin-bottom: 16px; }
.video-container iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }

.completion-button {
  display: block; width: 100%; padding: 12px; border: none; border-radius: 8px;
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: background-color 0.3s; margin-bottom: 16px;
}
.mark-complete-btn { background-color: var(--primary-fill); color: var(--text-on-primary); }
.mark-complete-btn.completed { background-color: var(--bg-surface-elevated); color: var(--text-color); box-shadow: inset 0 0 0 1px var(--border-color-strong); }

.content-tabs {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px;
  border-bottom: 1px solid var(--border-color); padding-bottom: 16px;
}
.content-tab-button {
  min-height: 44px; padding: 10px 20px; border: 1px solid var(--border-color);
  background-color: var(--bg-surface-elevated); color: var(--text-color);
  cursor: pointer; border-radius: 8px; font-weight: 500;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.content-tab-button:hover { border-color: var(--border-color-strong); }
.content-tab-button.active { background-color: var(--primary-fill); color: var(--text-on-primary); border-color: var(--primary-fill); font-weight: 700; }

/* Highlights */
.highlights-container { display: flex; flex-direction: column; gap: 12px; }
.highlight-card { padding: 16px; border-radius: var(--border-radius); border: 1px solid var(--border-color); }
.highlight-card p { margin: 0; }
.highlight-card strong { display: inline-block; margin-right: 8px; }

/* Quiz & Boolean */
.quiz-container { text-align: center; }
.quiz-navigation { display: flex; justify-content: center; gap: 10px; margin-bottom: 20px; }
.quiz-navigation button {
  padding: 10px 20px; border: 1px solid var(--primary-color); background-color: var(--white);
  color: var(--primary-color); border-radius: 8px; cursor: pointer; font-weight: 700; min-height: 44px;
}
.quiz-navigation button:hover { background-color: var(--secondary-color); }
.quiz-question { margin-bottom: 20px; font-size: 1.2rem; }
.quiz-options, .boolean-options { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.quiz-options li button, .boolean-options li button {
  width: 100%; padding: 15px; text-align: left; border: 2px solid var(--border-color);
  background-color: var(--bg-surface); color: var(--text-color);
  font-family: inherit; font-size: 1rem; font-weight: 600;
  border-radius: 8px; cursor: pointer; transition: all 0.2s;
}
.quiz-options li button:hover, .boolean-options li button:hover { border-color: var(--primary-color); }
.quiz-options li button:focus-visible,
.boolean-options li button:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  border-color: var(--primary-color);
}
.quiz-options li button.correct, .boolean-options li button.correct {
  background-color: var(--green-light); border-color: var(--primary-color); color: var(--primary-color); font-weight: bold;
}
.quiz-options li button.incorrect, .boolean-options li button.incorrect {
  background-color: var(--red-light); border-color: var(--red); color: var(--red); font-weight: bold;
}
.quiz-explanation { margin-top: 15px; padding: 15px; background-color: var(--secondary-color); border-radius: 8px; }
.quiz-results { padding: 20px; background-color: var(--secondary-color); border-radius: var(--border-radius); }
.restart-btn { padding: 12px 24px; margin-top: 20px; cursor: pointer; border: none; background-color: var(--primary-fill); color: var(--text-on-primary); border-radius: 8px; font-size: 1rem; font-weight: 700; }
.restart-btn:hover { background-color: var(--primary-fill-hover); }

/* Flashcards */
.flashcard-container { perspective: 1000px; width: 100%; height: 250px; margin: 0 auto; }
.flashcard { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.6s; cursor: pointer; }
.flashcard.is-flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; width: 100%; height: 100%; backface-visibility: hidden;
  display: flex; justify-content: center; align-items: center; padding: 20px; box-sizing: border-box;
  border-radius: var(--border-radius); box-shadow: var(--box-shadow); text-align: center;
}
.flashcard-front { background: linear-gradient(135deg, var(--flashcard-front-from), var(--flashcard-front-to)); }
.flashcard-back { background: linear-gradient(135deg, var(--flashcard-back-from), var(--flashcard-back-to)); transform: rotateY(180deg); }
.flashcard-status { margin-top: 16px; text-align: center; }

/* PDF Viewer */
.pdf-container { width: 100%; height: 80vh; border: 1px solid var(--border-color); border-radius: var(--border-radius); }

/* Assignment */
.assignment-section {
  background-color: var(--white); padding: 24px; border-radius: var(--border-radius);
  box-shadow: var(--box-shadow); margin-top: 16px; margin-bottom: 16px;
}
.assignment-section h2 { text-align: center; margin-bottom: 24px; }
.assignment-section p, .assignment-section ol { text-align: left; }

#upload-form {
  margin-top: 24px; padding: 24px; border: 2px dashed var(--border-color-strong);
  border-radius: var(--border-radius); text-align: center;
}
#file-upload-area {
  padding: 40px; border: 2px dashed var(--primary-color); border-radius: var(--border-radius);
  background-color: var(--secondary-color); cursor: pointer;
}
#submit-assignment {
  margin-top: 16px; padding: 12px 24px; background-color: var(--primary-fill);
  color: var(--text-on-primary); border: none; border-radius: 8px; cursor: pointer;
  font-weight: 700; min-height: 44px;
}
#submit-assignment:hover { background-color: var(--primary-fill-hover); }
#file-upload-area.is-dragover {
  border-style: solid;
  border-color: var(--primary-color);
  background-color: color-mix(in srgb, var(--primary-color) 12%, var(--bg-surface));
}
#upload-status, #submission-result { margin-top: 16px; }
#upload-status[data-state="error"] { color: var(--red); }
#upload-status[data-state="pending"] { color: var(--text-color-muted); }
#upload-status[data-state="success"] { color: var(--text-color); font-weight: 500; }

/* Highlight card data-type colors (older API; new renderers use accent classes below). */
.highlight-card[data-type="tip"] { background-color: var(--tip-card-bg); border-color: var(--primary-color); }
.highlight-card[data-type="warning"] { background-color: var(--red-bg); border-color: var(--red); }
.highlight-card[data-type="info"] { background-color: var(--info-card-bg); border-color: var(--info-border); }

/* Module navigation */
.module-nav {
  display: flex;
  justify-content: space-between;
  padding: 16px 0;
  border-top: 1px solid var(--border-color);
  margin-top: 24px;
}
.module-nav a {
  padding: 10px 20px;
  background-color: var(--light-gray);
  color: var(--text-color);
  text-decoration: none;
  border-radius: 8px;
  font-weight: 500;
}
.module-nav a:hover { background-color: var(--primary-fill); color: var(--text-on-primary); }

/* Footer */
.footer {
  text-align: center;
  padding: 24px;
  color: var(--gray);
  font-size: 0.9rem;
}

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shine) 50%, var(--skeleton-base) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 8px;
}
@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Mobile Sidebar Toggle */
.mobile-sidebar-toggle {
  display: block; width: 100%; padding: 16px; background-color: var(--primary-fill);
  color: var(--text-on-primary); border: none; border-radius: 8px; font-size: 1.1rem;
  font-weight: 700; cursor: pointer; margin-bottom: 8px; text-align: left;
}
.mobile-sidebar-toggle::after { content: '▼'; float: right; transition: transform 0.3s; }
.mobile-sidebar-toggle.active::after { transform: rotate(180deg); }

.sidebar-content { display: none; margin-top: 16px; }
.sidebar-content.active { display: block; }

/* Responsive */
@media (min-width: 768px) { .grid-container { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { 
  .course-layout { flex-direction: row; align-items: stretch; min-height: 800px; } 
  .sidebar { width: 350px; flex-shrink: 0; border-right: 1px solid var(--border-color); overflow-y: auto; position: sticky; top: 0; max-height: 100vh; } 
  .main-content { padding: 40px; }
  .mobile-sidebar-toggle { display: none; }
  .sidebar-content { display: block; margin-top: 0; }
}

/* Auth card (login / signup / unauthorized) */
.auth-card {
  max-width: 460px;
  margin: 32px auto 48px;
  background: var(--white);
  padding: 32px 28px;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  border: 1px solid var(--border-color);
}

.auth-card-error { border-color: var(--red); }

.auth-card-title {
  margin: 0 0 8px;
  font-size: 1.6rem;
  color: var(--accent-orange);
  font-weight: 700;
  text-align: center;
}

.auth-card-subtitle {
  margin: 0 0 20px;
  font-size: 0.95rem;
  color: var(--gray);
  text-align: center;
}

.auth-card-email {
  margin: 0 0 16px;
  padding: 10px 14px;
  background: var(--red-light);
  color: var(--red);
  border-radius: 8px;
  font-weight: 600;
  text-align: center;
  word-break: break-all;
}

.auth-card-secondary-link {
  display: block;
  margin-top: 14px;
  text-align: center;
  color: var(--gray);
  text-decoration: none;
  font-size: 0.9rem;
}

.auth-card-secondary-link:hover { color: var(--primary-color); }

.auth-card-foot {
  margin: 20px 0 0;
  font-size: 0.95rem;
  color: var(--gray);
  text-align: center;
}

.auth-card-foot a {
  color: var(--primary-color);
  font-weight: 600;
  text-decoration: none;
}

.auth-card-foot a:hover { text-decoration: underline; }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-form-field label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-color);
}

.auth-form-field input {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  min-height: 44px;
  box-sizing: border-box;
  border: 1px solid var(--border-color-strong);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-color);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-form-field input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color) 35%, transparent);
}

.auth-form-error {
  background: var(--red-light);
  color: var(--red);
  font-size: 0.9rem;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 500;
}

.auth-form-submit {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  min-height: 44px;
  background: var(--primary-fill);
  color: var(--text-on-primary);
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
}

.auth-form-submit:hover:not(:disabled) {
  background: var(--primary-fill-hover);
}

.auth-form-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-divider {
  display: flex;
  align-items: center;
  margin: 22px 0 16px;
  color: var(--gray);
  font-size: 0.85rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.auth-divider span {
  padding: 0 12px;
}

.auth-google-slot {
  display: flex;
  justify-content: center;
}

.auth-google-slot .auth-google-btn {
  width: 100%;
  justify-content: center;
}

/* ─── Theme toggle (header) ──────────────────────────────────────────────── */
.theme-toggle-slot {
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-color);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s, transform 0.15s, box-shadow 0.15s;
}
.theme-toggle-btn:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}
.theme-toggle-btn:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  border-color: var(--primary-color);
}
.theme-toggle-btn:active { transform: scale(0.96); }
.theme-toggle-icon { display: inline-flex; }
.theme-toggle-icon svg {
  width: 20px;
  height: 20px;
  display: block;
}
@media (prefers-reduced-motion: reduce) {
  .theme-toggle-btn { transition: none; }
  .theme-toggle-btn:active { transform: none; }
}

/* ─── Language toggle (header) ───────────────────────────────────────────── */
.language-toggle-slot {
  display: flex;
  align-items: center;
  justify-content: center;
}
.language-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-color);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s, transform 0.15s, box-shadow 0.15s;
}
.language-toggle-btn:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}
.language-toggle-btn:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  border-color: var(--primary-color);
}
.language-toggle-btn:active { transform: scale(0.96); }
.language-toggle-icon {
  display: inline-flex;
  width: 24px;
  height: 16px;
  border-radius: 2px;
  overflow: hidden;
  flex: 0 0 auto;
}
.language-toggle-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
.language-toggle-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
@media (prefers-reduced-motion: reduce) {
  .language-toggle-btn { transition: none; }
  .language-toggle-btn:active { transform: none; }
}

/* ─── Module list card (homepage module list, replaces inline JS styles) ── */
.module-list-card {
  display: block;
  padding: 12px 14px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-color);
  transition: border-color 0.2s, transform 0.2s;
}
.module-list-card:hover,
.module-list-card:focus-visible {
  border-color: var(--accent-orange);
  transform: translateY(-1px);
}
.module-list-card:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .module-list-card { transition: none; }
  .module-list-card:hover,
  .module-list-card:focus-visible { transform: none; }
}

/* ─── Highlight card accent variants (replaces inline hsl()) ────────────── */
.highlight-card--accent-0 { background-color: var(--tip-card-bg);  border-color: var(--primary-color); }
.highlight-card--accent-1 { background-color: var(--info-card-bg); border-color: var(--info-border); }
.highlight-card--accent-2 { background-color: var(--bg-surface-elevated); border-color: var(--border-color-strong); }
.highlight-card--accent-3 { background-color: var(--bg-inset);     border-color: var(--primary-color); }

/* Highlights tab: locale-mismatch notice (shown when prose is in a
   language other than the active locale). Reuses the info-card palette
   already used by highlight-card--accent-1. */
.highlights-locale-notice {
  padding: 12px 16px;
  border-radius: var(--border-radius);
  background-color: var(--info-card-bg);
  border: 1px solid var(--info-border);
  color: var(--text-color);
  font-size: 0.95rem;
  line-height: 1.5;
}
.highlights-locale-notice strong { display: block; margin-bottom: 4px; }
.highlights-locale-notice span { color: var(--text-color-muted); }

/* ─── Global error toast (set by src/error-handler.js) ─────────────────── */
.global-error-toast { background: var(--toast-bg); color: var(--toast-fg); }
