.profile-menu { max-height: calc(100dvh - 90px); overflow-y: auto; }
#profileNightMode { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.profile-night-label { display: flex; align-items: center; gap: 10px; }
.profile-moon-icon { width: 20px; height: 20px; flex: 0 0 20px; background: currentColor; mask: url("assets/icons/moon.svg") center / contain no-repeat; }
.profile-theme-switch { position: relative; width: 38px; height: 22px; flex: 0 0 38px; border: 1px solid #7c898e; border-radius: 12px; background: #344044; }
.profile-theme-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #f4f7f4; }
#profileNightMode[aria-checked="true"] .profile-theme-switch { background: #cef43d; border-color: #cef43d; }
#profileNightMode[aria-checked="true"] .profile-theme-switch::after { transform: translateX(16px); background: #162014; }

html[data-theme="night"] {
  color-scheme: dark;
  --night-base: #101617;
  --night-surface: #192123;
  --night-raised: #232d30;
  --night-text: #eef3f1;
  --night-muted: #b0bebb;
  --night-line: #455350;
  --night-mint: #60dfc5;
  --night-green: #173c32;
  --night-red: #432524;
  --night-warning: #3b3420;
  --ink: var(--night-text);
  --muted: var(--night-muted);
  --panel: var(--night-surface);
  --soft: var(--night-raised);
  --line: var(--night-line);
}

html[data-theme="night"] body.template-v3 {
  --v3-paper: var(--night-base);
  --v3-white: var(--night-surface);
  --v3-ink: var(--night-text);
  --v3-muted: var(--night-muted);
  --v3-line: var(--night-line);
  background: #0b1011;
  color: var(--night-text);
}

html[data-theme="night"] .template-v3 :is(.app-header, .tool-row) {
  background: var(--night-surface);
  color: var(--night-text);
  border-color: var(--night-line);
}
html[data-theme="night"] .template-v3 :is(.chat-window, .tool-result) {
  background: var(--night-base);
  color: var(--night-text);
}
html[data-theme="night"] .template-v3 :is(.header-calc-button, .chat-room-button, .profile-button, .mobile-menu-button) {
  background: var(--night-raised);
  color: var(--night-text);
  border-color: var(--night-line);
}
html[data-theme="night"] .template-v3 :is(.header-calc-button, .chat-room-button, .profile-button, .mobile-menu-button):hover {
  border-color: var(--night-mint);
}
html[data-theme="night"] .template-v3 .mobile-menu-button span { background: var(--night-text); }
html[data-theme="night"] .template-v3 :is(.brand-copy small, .profile-copy small) { color: var(--night-muted); }

/* Shared study surfaces. Uploaded media and exported status images stay unchanged. */
html[data-theme="night"] .template-v3 :is(
  .assistant-message, .formula-card, .data-cell, .question-card, .trick-card,
  .mini-result, .trick-result, .quiz-summary, .quiz-topic-card, .quiz-set-panel,
  .quiz-set-card, .quiz-leaderboard, .quiz-question-card, .quiz-result-card,
  .quiz-review-summary, .quiz-review-question, .quiz-set-search-panel,
  .feedback-form, .feedback-login-card, .public-feedback-card, .hm-playlist-card
) {
  background: var(--night-surface);
  color: var(--night-text);
  border-color: var(--night-line);
  box-shadow: none;
}
html[data-theme="night"] .template-v3 :is(
  .tool-input, .tool-select, .tool-actions button.secondary, .trick-example,
  .quiz-topic-stats b, .quiz-option-list label, .quiz-option-list b,
  .quiz-review-options > div, .quiz-review-options > div > b,
  .quiz-report-panel select, .quiz-report-panel textarea, .quiz-report-panel button,
  .quiz-load-ranks, .quiz-status-download, .public-feedback button, .hm-video-back,
  .feedback-review-label textarea, .quiz-leaderboard-close
) {
  background: var(--night-raised);
  color: var(--night-text);
  border-color: var(--night-line);
}
html[data-theme="night"] :is(#quizSetSort, #quizSetSearch, #quizSetSearchToggle, #quizLeaderboardSearch, #closeQuizBtn) {
  background: var(--night-raised);
  color: var(--night-text);
  border-color: var(--night-line);
}
html[data-theme="night"] :is(#quizSetSearch, #quizLeaderboardSearch)::placeholder,
html[data-theme="night"] .template-v3 :is(.tool-input, .feedback-review-label textarea)::placeholder { color: var(--night-muted); }
html[data-theme="night"] .template-v3 :is(
  .quiz-set-panel > header, .quiz-leaderboard-head, .quiz-leaderboard li,
  .quiz-question-card > footer, .quiz-review-question > footer,
  .solver-solution-header, .solver-verification, .feedback-average
) { border-color: var(--night-line); }

html[data-theme="night"] .template-v3 :is(
  .quiz-set-card > div span, .quiz-set-card > div b, .quiz-breadcrumb strong,
  .quiz-active-strip strong, .quiz-active-strip b, .quiz-question-card > h3,
  .quiz-result-card > strong, .quiz-result-stats b, .quiz-empty-state strong,
  .trick-rule > strong, .trick-example h4, .feedback-average strong,
  .feedback-form-head h3, .feedback-login-card h3, .feedback-form legend,
  .feedback-review-label, .hm-video-progress-summary, .solver-thinking
) { color: var(--night-text); }
html[data-theme="night"] .template-v3 :is(
  .tool-row label, .quiz-library-note, .quiz-library-note span, .quiz-loading,
  .quiz-topic-copy small, .quiz-set-panel header small, .quiz-set-card dt,
  .quiz-set-card > div small, .quiz-set-sort, .quiz-leaderboard-head > small,
  .quiz-leaderboard li small, .quiz-leaderboard time, .quiz-no-ranks span,
  .quiz-active-strip em, .quiz-question-card > header button, .quiz-question-card > footer > span,
  .quiz-result-card > strong small, .quiz-result-card > p, .quiz-result-stats span,
  .quiz-review-question footer, .quiz-set-empty, .trick-rule, .trick-example p,
  .formula-card p, .mini-result p, .public-feedback-card > p, .public-feedback-card time,
  .feedback-average span, .feedback-summary-copy p, .feedback-form-head span,
  .feedback-login-card div > span, .feedback-form fieldset small, .feedback-review-label small,
  .feedback-loading, .hm-playlist-card-copy > span, .hm-playlist-card-copy em,
  .hm-playlist-state, .hm-video-toolbar a, .hm-video-progress-summary span,
  .solver-solution-section h4, .solver-answer-conclusion
) { color: var(--night-muted); }

html[data-theme="night"] .template-v3 :is(
  .quiz-set-panel header p, .quiz-leaderboard-head > span, .quiz-result-card > span,
  .quiz-breadcrumb small, .quiz-active-strip small, .quiz-review-summary small,
  .trick-example > span, .feedback-form-head p, .feedback-login-card p,
  .hm-playlist-card-copy small, .solver-short-trick h4
) { color: #d2ec75; }
html[data-theme="night"] .template-v3 :is(
  .big-number, .quiz-card-arrow, .trick-example > strong, .hm-playlist-card-copy i,
  .feedback-saved-badge, .feedback-submit-row p, .solver-topic-chip,
  .solver-final-label, .solver-final-value, .solver-option
) { color: var(--night-mint); }
html[data-theme="night"] .template-v3 :is(.solver-final-answer, .solver-method) { background: var(--night-green); }
html[data-theme="night"] .template-v3 .solver-short-trick { background: #2a3320; }
html[data-theme="night"] .template-v3 .solver-step-list li::before { background: var(--night-raised); color: var(--night-text); border-color: var(--night-line); }
html[data-theme="night"] .template-v3 .public-feedback { background: var(--night-base); border-color: var(--night-line); }
html[data-theme="night"] .template-v3 .public-feedback button.public-review-toggle { background: transparent; color: #80ddcd; }
html[data-theme="night"] .template-v3 .public-feedback-card .feedback-stars.is-readonly .feedback-star.is-selected { color: #e8c264; }

html[data-theme="night"] .template-v3 .quiz-set-card.is-selected { border-color: var(--night-mint); box-shadow: inset 0 3px 0 #28d7bd; }
html[data-theme="night"] .template-v3 .quiz-set-actions .quiz-rank-button { background: var(--night-raised); color: var(--night-text); border-color: var(--night-line); }
html[data-theme="night"] .template-v3 .quiz-set-actions .quiz-rank-button[aria-pressed="true"],
html[data-theme="night"] :is(#quizSetSearchToggle:hover, #quizSetSearchToggle[aria-expanded="true"], #quizSetSearchToggle.has-query) {
  background: var(--night-green); color: var(--night-mint); border-color: var(--night-mint);
}
html[data-theme="night"] .template-v3 .quiz-set-card .quiz-completed-label { background: #27332e; color: var(--night-muted); border-color: var(--night-line); }
html[data-theme="night"] .template-v3 .quiz-set-actions .quiz-review-button { background: var(--night-green) !important; color: var(--night-mint) !important; border-color: #458a75 !important; }
html[data-theme="night"] .template-v3 .quiz-option-list label:has(input:checked) { border-color: #d2ec75; }
html[data-theme="night"] .template-v3 :is(.quiz-option-list label.is-correct, .quiz-review-options > div.is-correct, .quiz-review-question > header > b.is-correct, .quiz-answer-feedback.is-correct) {
  background: var(--night-green); color: #a9f4d5; border-color: #458a75;
}
html[data-theme="night"] .template-v3 :is(.quiz-option-list label.is-wrong, .quiz-review-options > div.is-wrong, .quiz-review-question > header > b.is-wrong, .quiz-answer-feedback.is-wrong, .quiz-report-panel) {
  background: var(--night-red); color: #ffbbb5; border-color: #a36e65;
}
html[data-theme="night"] .template-v3 .quiz-answer-feedback.is-warning { background: var(--night-warning); color: #f3d48d; border-color: #a89558; }
html[data-theme="night"] .quiz-result-card {
  --result-ink: var(--night-text);
  --result-muted: var(--night-muted);
  --result-line: var(--night-line);
  --result-track: #34443e;
  --result-secondary: var(--night-raised);
}
html[data-theme="night"] .quiz-active-strip .quiz-complete-mark { background: var(--night-green); color: var(--night-mint); }
html[data-theme="night"] .quiz-result-stats .is-correct dd { color: #80dec0; }
html[data-theme="night"] .quiz-result-stats .is-wrong dd { color: #ffa8a0; }
html[data-theme="night"] .quiz-result-meter::-webkit-progress-value { background: #60dfc5; }
html[data-theme="night"] .quiz-result-meter::-moz-progress-bar { background: #60dfc5; }
html[data-theme="night"] :is(.quiz-question-card, .quiz-review-summary) .quiz-font-controls button,
html[data-theme="night"] .quiz-question-card > header #reportQuizQuestion { background: var(--night-raised); border-color: var(--night-line); color: var(--night-text); }
html[data-theme="night"] .quiz-font-controls output { color: var(--night-muted); }
html[data-theme="night"] .template-v3 :is(.quiz-report-panel small, .feedback-loading.is-error, #feedbackMessage.is-error) { color: #ffbbb5; }
html[data-theme="night"] .template-v3 .quiz-set-card .quiz-new-badge { background: #d7fb49; color: #23320b; }
html[data-theme="night"] :is(#quizLeaderboardDialog, .quiz-status-dialog) { background: var(--night-surface); color: var(--night-text); border-color: var(--night-line); }
html[data-theme="night"] .quiz-status-dialog :is(header p, #quizStatusMessage) { color: var(--night-muted); }
