:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #66727d;
  --line: #dce2e8;
  --blue: #2563eb;
  --green: #178a55;
  --red: #c93d35;
  --yellow: #f4b942;
  --teal: #107980;
  --shadow: 0 14px 40px rgba(23, 32, 38, 0.08);
  --sidebar-bg: #0f1b24;
  --sidebar-fg: #f8fbfd;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111820;
  --panel: #1a2530;
  --ink: #e8f0f7;
  --muted: #8b949e;
  --line: #2a3a47;
  --blue: #4a8ff5;
  --green: #2aad70;
  --red: #e05a53;
  --yellow: #f4c14e;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.3);
  --sidebar-bg: #0a1118;
  --sidebar-fg: #d0dde8;
}

[data-theme="dark"] .readiness-panel,
[data-theme="dark"] .home-intro,
[data-theme="dark"] .topic-board,
[data-theme="dark"] .home-action,
[data-theme="dark"] .topic-card,
[data-theme="dark"] .stat-ring,
[data-theme="dark"] .last-progress article,
[data-theme="dark"] .progress-graph,
[data-theme="dark"] .category-report > div {
  background: var(--panel);
  border-color: var(--line);
}

[data-theme="dark"] .home-action.primary-action {
  background: #1a2e50;
  border-color: rgba(74, 143, 245, 0.4);
}

[data-theme="dark"] select,
[data-theme="dark"] input {
  background: #1a2530;
  color: var(--ink);
  border-color: var(--line);
}

[data-theme="dark"] .answer-option {
  background: var(--panel);
  border-color: var(--line);
}

[data-theme="dark"] .secondary {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}

[data-theme="dark"] .modal-dialog {
  background: var(--panel);
  color: var(--ink);
}

[data-theme="dark"] .modal-header {
  border-color: var(--line);
}

[data-theme="dark"] .account-dropdown-panel {
  background: var(--panel);
  color: var(--ink);
}

[data-theme="dark"] #accountEmail {
  color: var(--ink);
}

[data-theme="dark"] .license-status {
  background: #2a2300;
  color: #f0d070;
}

[data-theme="dark"] .ring {
  background:
    radial-gradient(circle at center, var(--panel) 58%, transparent 59%),
    conic-gradient(var(--ring-color) var(--percent), #2a3a47 0);
}

[data-theme="dark"] .how-to-grid article {
  background: #1e2d38;
}

[data-theme="dark"] #statsCanvas {
  background: var(--panel);
  border-color: var(--line);
}

[data-theme="dark"] .topic-number {
  background: #1e2d38;
  color: var(--muted);
}

[data-theme="dark"] .readiness-bar,
[data-theme="dark"] .topic-readiness {
  background: #2a3a47;
}

[data-theme="dark"] .readiness-legend span {
  background: var(--panel);
  border-color: var(--line);
}

[data-theme="dark"] .icon-button {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  padding: 24px;
  height: 100vh;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 30px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background: var(--yellow);
  color: #0f1b24;
  font-family: "Arial Black", Arial, sans-serif;
  font-weight: 900;
  font-size: 22px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
}

.brand p,
.metric small,
.eyebrow {
  margin: 0;
  color: var(--muted);
}

.sidebar .brand p,
.sidebar label {
  color: color-mix(in srgb, var(--sidebar-fg) 75%, transparent);
}

.nav-group {
  display: grid;
  gap: 8px;
  margin-bottom: 28px;
}

.nav-button {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #f8fbfd;
  text-align: left;
}

.nav-button.active {
  background: #f8fbfd;
  color: #0f1b24;
}

.controls {
  display: grid;
  gap: 16px;
}

.advanced-filters {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.advanced-filters summary {
  cursor: pointer;
  color: #f8fbfd;
  font-size: 14px;
  font-weight: 700;
}

.advanced-filters[open] {
  display: grid;
  gap: 0;
}

.advanced-filters label {
  gap: 12px;
  padding-top: 16px;
}

.advanced-filters select,
.advanced-filters input {
  min-height: 40px;
}

.advanced-filters summary + label {
  padding-top: 18px;
}

.controls .text-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: #dbe7ef;
  text-align: left;
}

.legacy-account-panel {
  display: none;
}

.account-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 26px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.account-panel.legacy-account-panel {
  display: none;
}

.account-panel h2 {
  margin: 0;
  color: #f8fbfd;
  font-size: 16px;
}

.account-panel input,
.account-panel select {
  min-height: 38px;
}

.account-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.account-panel button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #f8fbfd;
  color: #0f1b24;
}

.account-panel .text-button {
  border: 0;
  background: transparent;
  color: #dbe7ef;
  text-align: left;
  padding: 0;
}

#signedOutPanel,
#signedInPanel,
#resetPanel {
  display: grid;
  gap: 8px;
}

#accountEmail {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.license-status {
  border-left: 3px solid var(--yellow);
  padding: 8px 10px;
  background: #fff8df;
  color: #554315;
  font-size: 13px;
}

.account-message {
  min-height: 18px;
  margin: 0;
  color: #f4d889;
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  font-size: 13px;
}

select,
input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}

.main-panel {
  display: grid;
  align-content: start;
  gap: 20px;
  height: 100vh;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
  overscroll-behavior: contain;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 12px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.top-account {
  position: static;
  min-width: 0;
  margin: 0 0 24px;
}

.topbar .top-account {
  display: none !important;
}

.signed-out-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.signed-out-actions .primary,
.signed-out-actions .secondary {
  min-width: 0;
  padding: 10px 14px;
}

.signed-out-actions .secondary {
  border-color: #d99c18;
  background: var(--yellow);
  color: #111;
}

.signed-out-actions .primary {
  border-color: rgba(255, 255, 255, 0.18);
  background: #f8fbfd;
  color: #0f1b24;
}

.account-dropdown {
  position: relative;
}

.account-dropdown summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fbfd;
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: none;
  cursor: pointer;
  list-style: none;
}

.account-dropdown summary::-webkit-details-marker {
  display: none;
}

.account-dropdown summary::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
}

.account-dropdown[open] summary::after {
  transform: rotate(225deg) translateY(-2px);
}

#accountMenuLabel {
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-dropdown-panel {
  position: static;
  z-index: 20;
  display: grid;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  box-shadow: none;
}

.account-name {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 27, 36, 0.52);
}

.modal-dialog {
  width: min(480px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 27, 36, 0.32);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
}

.modal-close:hover {
  background: #eef2f5;
  color: var(--ink);
}

.modal-body,
.auth-form-panel,
#resetPanel {
  display: grid;
  gap: 12px;
}

.modal-body {
  padding: 18px;
}

.modal-body .text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  text-align: left;
}

.metric,
.question-workspace,
.details-grid article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  font-size: 28px;
  font-weight: 700;
}

.question-workspace {
  padding: 22px;
}

.home-view {
  display: grid;
  gap: 20px;
}

.readiness-panel,
.home-intro,
.topic-board {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.home-intro {
  display: flex;
  flex-direction: column;
}

.home-intro-copy {
  padding: 20px 24px;
}

.home-intro-copy h2 {
  max-width: 760px;
  margin: 0 0 10px;
  font-size: 24px;
  line-height: 1.2;
}

.home-intro-copy p {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.home-intro-how-to {
  border-top: 1px solid var(--line);
  padding: 18px 24px;
}

.home-intro-how-to h3 {
  margin: 0 0 14px;
  font-size: 17px;
  color: var(--ink);
}

.readiness-panel {
  display: grid;
  grid-template-columns: minmax(260px, 0.7fr) minmax(320px, 1.3fr);
  gap: 24px;
  align-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafb 100%);
  border-color: rgba(37, 99, 235, 0.24);
}

.readiness-copy {
  display: grid;
  gap: 8px;
}

.readiness-copy h2 {
  margin: 0;
  font-size: 58px;
  line-height: 1;
  letter-spacing: 0;
}

.readiness-visual {
  display: grid;
  gap: 14px;
}

.readiness-bar,
.topic-readiness {
  display: flex;
  width: 100%;
  overflow: hidden;
  background: #e6ebef;
}

.readiness-bar {
  height: 34px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(23, 32, 38, 0.08);
}

.readiness-bar span,
.topic-readiness i {
  min-width: 0;
}

.ready {
  background: var(--green);
}

.building {
  background: var(--yellow);
}

.risk {
  background: var(--red);
}

.readiness-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.readiness-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  background: #fff;
}

.readiness-legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.readiness-legend b {
  color: var(--ink);
}

.readiness-hint {
  margin: 0;
  color: #34414c;
  font-size: 14px;
  line-height: 1.45;
}

.home-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.home-action,
.topic-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
}

.home-action {
  display: grid;
  gap: 5px;
  min-height: 88px;
  padding: 16px;
}

.home-action span {
  font-size: 17px;
  font-weight: 700;
}

.home-action small,
.topic-card small,
.topic-meta {
  color: var(--muted);
}

.home-action.primary-action {
  border-color: rgba(37, 99, 235, 0.35);
  background: #eff5ff;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 0;
}

.section-heading h3,
.how-to-panel h3 {
  margin: 0;
  font-size: 20px;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
}

.topic-card {
  display: grid;
  gap: 8px;
  min-height: 168px;
  padding: 15px;
}

.topic-card:hover {
  border-color: rgba(37, 99, 235, 0.45);
}

.topic-number {
  width: fit-content;
  border-radius: 6px;
  padding: 4px 7px;
  background: #eef2f5;
  color: #34414c;
  font-size: 12px;
  font-weight: 700;
}

.topic-card strong {
  font-size: 16px;
  line-height: 1.25;
}

.topic-readiness {
  height: 8px;
  border-radius: 2px;
}

.how-to-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.how-to-grid article {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafb;
}

.how-to-grid strong {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #0f1b24;
  color: #fff;
}

html[dir="rtl"] .sidebar {
  border-right: 0;
  border-left: 1px solid var(--line);
}

html[dir="rtl"] .nav-button,
html[dir="rtl"] .home-action,
html[dir="rtl"] .topic-card,
html[dir="rtl"] .controls .text-button,
html[dir="rtl"] .account-panel .text-button {
  text-align: right;
}

/* The mobile bottom-nav stays centered in RTL (overrides the rule above) */
html[dir="rtl"] .bottom-nav .nav-button {
  text-align: center;
}

html[dir="rtl"] .notice {
  border-left: 0;
  border-right: 4px solid var(--yellow);
}

/* ── Exam page: RTL mirroring ───────────────────────────────────────────── */
html[dir="rtl"] .exam-points {
  float: left;
  margin-left: 0;
  margin-right: 24px;
}

html[dir="rtl"] body.exam-mode .question-toolbar {
  padding: 0 15px 0 0;
}

html[dir="rtl"] body.exam-mode .icon-button {
  border-left: 0;
  border-right: 1px solid #006000;
}

/* Desktop only: mirror the floating Next button and the count/Submit footer
   to the left edge. Mobile keeps its full-width fixed bottom bar. */
@media (min-width: 769px) {
  html[dir="rtl"] .exam-footer { right: auto; left: 230px; }
  html[dir="rtl"] body.exam-mode .action-row { right: auto; left: 42px; }
}

.question-toolbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  font-size: 13px;
  margin-bottom: 8px;
}

#questionTitle {
  margin: 0;
  font-size: 24px;
  line-height: 1.35;
}

.icon-button {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #111;
  font-size: 25px;
  line-height: 1;
}

.icon-button.saved {
  background: var(--yellow);
}

.notice {
  margin-top: 16px;
  border-left: 4px solid var(--yellow);
  background: #fff8df;
  padding: 12px;
  color: #554315;
}

.hidden {
  display: none !important;
}

.media-panel {
  margin-top: 18px;
}

.exam-body {
  display: contents;
}

.answer-column {
  display: block;
}

.media-panel img,
.media-panel video {
  display: block;
  width: min(100%, 760px);
  max-height: 430px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
  object-fit: contain;
}

.answers {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.answer-option {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.answer-option.correct {
  border-color: rgba(23, 138, 85, 0.5);
  background: #ecf8f1;
}

.answer-option.wrong {
  border-color: rgba(201, 61, 53, 0.5);
  background: #fff0ee;
}

.answer-option input {
  width: 20px;
  min-height: 20px;
  margin-top: 1px;
}

.number-answer {
  max-width: 280px;
}

.feedback {
  margin-top: 18px;
  border-radius: 8px;
  padding: 14px;
}

.feedback.good {
  background: #ecf8f1;
  color: #0f5b38;
}

.feedback.bad {
  background: #fff0ee;
  color: #8d2b25;
}

.action-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.primary,
.secondary {
  min-width: 104px;
  border-radius: 8px;
  padding: 12px 16px;
}

.primary {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
}

.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.exam-panel {
  margin-top: 20px;
}

.exam-tabs {
  display: flex;
  align-items: end;
  gap: 2px;
}

.exam-tab {
  border: 1px solid #006000;
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
  padding: 10px 14px;
  background: #fff;
  color: #000;
}

.exam-tab.active {
  background: #008000;
  color: #fff;
}

.exam-index-wrap {
  min-height: 90px;
  border-radius: 0 3px 3px 3px;
  background: #008000;
  padding: 12px 26px;
}

.exam-index-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.exam-index {
  position: relative;
  display: grid;
  place-items: center;
  width: 66px;
  height: 40px;
  border: 2px solid #000;
  background: #fff;
  color: #000;
  font-weight: 600;
  font-size: 18px;
}

.exam-index.current {
  border-width: 3px;
  font-weight: 700;
}

.exam-index.done {
  border-color: #fff;
  background: #008000;
  color: #fff;
}

.exam-index.correct {
  border-color: #fff;
  background: #008000;
  color: #fff;
}

.exam-index.wrong {
  border-color: #fff;
  background: #d01818;
  color: #fff;
}

.exam-video-dot {
  position: absolute;
  right: 4px;
  bottom: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f5ab00;
}

.exam-footer {
  position: absolute;
  right: 230px;
  bottom: 122px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 24px;
  padding-top: 0;
}

.exam-left {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #000;
}

.exam-left-count {
  font-weight: 700;
}

.exam-submit {
  min-width: 160px;
  height: 35px;
  border: 1px solid #000;
  border-radius: 1px;
  background: #d01818;
  color: #fff;
  font-size: 18px;
}

.exam-question-text {
  max-width: 980px;
  margin: 0;
  font-size: 22px;
  line-height: 1.35;
  color: #000;
}

.exam-points {
  float: right;
  margin-left: 24px;
  font-size: 16px;
  font-weight: 500;
}

body.exam-mode {
  background: #ddf6df;
  overflow: hidden;
}

body.exam-mode .app-shell {
  display: block;
  height: 100vh;
  overflow: hidden;
}

body.exam-mode .sidebar {
  display: none;
}

body.exam-mode .main-panel {
  gap: 0;
  height: 100vh;
  overflow: hidden;
  padding: 0;
}

body.exam-mode .topbar,
body.exam-mode .details-grid {
  display: none;
}

body.exam-mode .question-workspace {
  position: relative;
  min-height: 100vh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  background: #ddf6df;
}

body.exam-mode .question-toolbar {
  width: 100%;
  min-height: 55px;
  align-items: center;
  border-bottom: 1px solid #004d00;
  background: #008000;
  color: #fff;
  padding: 0 0 0 15px;
}

body.exam-mode .question-toolbar > div {
  flex: 1 1 auto;
  min-width: 0;
}

body.exam-mode .question-toolbar .eyebrow {
  display: none;
}

body.exam-mode #questionTitle {
  width: auto;
  font-size: 18px;
  font-weight: 500;
}

body.exam-mode .icon-button {
  align-self: stretch;
  width: 78px;
  height: 55px;
  border: 0;
  border-left: 1px solid #006000;
  border-radius: 0;
  background: #fff;
  color: #000;
  font-size: 0;
  font-weight: 700;
}

body.exam-mode .icon-button::before {
  content: "X";
  font-size: 18px;
}

body.exam-mode .notice,
body.exam-mode .feedback {
  margin: 12px 18px 0;
}

body.exam-mode .exam-body {
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(300px, 1fr);
  align-items: start;
  column-gap: 35px;
  max-width: calc(100vw - 50px);
  margin: 54px 30px 0 20px;
}

body.exam-mode .exam-body.no-media {
  grid-template-columns: minmax(0, 1fr);
  max-width: calc(100vw - 116px);
  margin: 32px 58px 0;
}

body.exam-mode .media-panel {
  width: 560px;
  max-width: 100%;
  margin: 0;
}

body.exam-mode .media-panel img,
body.exam-mode .media-panel video {
  width: 560px;
  max-width: 100%;
  max-height: 340px;
  border-radius: 0;
}

body.exam-mode .answers {
  min-height: 0;
  margin: 24px 0 0;
  padding: 0;
  gap: 0;
}

body.exam-mode .exam-body.no-media .answers {
  margin-top: 0;
}

body.exam-mode .answer-option {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  max-width: 900px;
  border: 0;
  border-radius: 0;
  padding: 5px 0 18px;
  background: transparent;
  font-size: 20px;
  line-height: 1.25;
}

body.exam-mode .answer-option input {
  width: 40px;
  min-height: 40px;
  margin: 0 12px 0 0;
  appearance: none;
  border: 0;
  border-radius: 0;
  background: transparent url("./assets/ui/unchecked.png") center / contain no-repeat;
}

body.exam-mode .answer-option input:checked {
  background-image: url("./assets/ui/checked.png");
}

body.exam-mode .answer-option.correct {
  border-left: 5px solid #008000;
  background: #fff;
  padding-left: 8px;
}

body.exam-mode .answer-option.wrong {
  border-left: 5px solid #d01818;
  background: #fff;
  padding-left: 8px;
}

body.exam-mode .action-row {
  position: fixed;
  right: 42px;
  bottom: 122px;
  justify-content: flex-end;
  margin: 0;
  z-index: 4;
}

body.exam-mode .primary,
body.exam-mode .secondary {
  min-width: 160px;
  height: 35px;
  border: 1px solid #000;
  border-radius: 1px;
  padding: 6px 10px;
  font-size: 18px;
}

body.exam-mode .primary {
  background: #008000;
  color: #fff;
}

body.exam-mode #prevButton {
  display: none;
}

body.exam-mode #submitButton {
  display: none;
}

body.exam-mode .exam-panel {
  display: block;
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  margin: 0;
  z-index: 3;
}

.details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

.details-grid article {
  padding: 18px;
}

.details-grid h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.rich-text {
  color: #34414c;
  line-height: 1.55;
}

.rich-text p {
  margin: 0 0 10px;
}

.stats-view {
  display: grid;
  gap: 20px;
}

.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.stats-header h2 {
  margin: 0;
  font-size: 28px;
}

.stat-rings {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-ring,
.last-progress article,
.progress-graph {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.stat-ring {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 18px;
  --percent: 0%;
  --ring-color: var(--green);
}

.stat-ring.wrong {
  --ring-color: var(--red);
}

.stat-ring.practiced {
  --ring-color: var(--yellow);
}

.stat-ring.not-seen {
  --ring-color: #8b949e;
}

.ring {
  display: grid;
  place-items: center;
  width: 136px;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #fff 58%, transparent 59%),
    conic-gradient(var(--ring-color) var(--percent), #d7dde3 0);
}

.ring span {
  font-size: 24px;
  font-weight: 700;
}

.stat-ring strong {
  font-size: 28px;
}

.stat-ring > span,
.last-progress span,
.stats-legend {
  color: var(--muted);
}

.last-progress {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.last-progress article {
  display: grid;
  gap: 4px;
  padding: 18px;
}

.last-progress strong {
  font-size: 42px;
}

.progress-graph {
  padding: 18px;
}

.progress-graph h3,
.category-report h3 {
  margin: 0 0 14px;
}

#statsCanvas {
  display: block;
  width: 100%;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.stats-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  font-size: 14px;
}

.stats-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.stats-legend i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.legend-mastered {
  background: var(--green);
}

.legend-practiced {
  background: var(--yellow);
}

.legend-wrong {
  background: var(--red);
}

.legend-not-seen {
  background: #8b949e;
}

.category-report {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}

.category-report > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
  box-shadow: var(--shadow);
}

.category-row {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.category-label {
  font-size: 14px;
  color: #34414c;
}

.category-bar {
  display: flex;
  width: 100%;
  height: 18px;
  overflow: hidden;
  border-radius: 3px;
  background: #eef2f5;
}

.category-bar span {
  min-width: 0;
}

.category-bar .mastered {
  background: var(--green);
}

.category-bar .practiced {
  background: var(--yellow);
}

.category-bar .wrong {
  background: var(--red);
}

.category-bar .not-seen {
  background: #8b949e;
}

@media (max-width: 920px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    border-right: 0;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .main-panel {
    height: auto;
    overflow: visible;
  }

  .details-grid,
  .stat-rings,
  .last-progress,
  .category-report,
  .readiness-panel,
  .home-actions,
  .topic-grid,
  .how-to-grid {
    grid-template-columns: 1fr 1fr;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .metric-row {
    grid-template-columns: 1fr 1fr;
  }

  .signed-out-actions {
    justify-content: flex-start;
  }

  .top-account {
    position: static;
    z-index: auto;
    min-width: 0;
    margin: 0 0 24px;
  }

  .signed-out-actions .primary {
    border-color: rgba(255, 255, 255, 0.18);
    background: #f8fbfd;
    color: #0f1b24;
  }

  .account-dropdown summary {
    background: rgba(255, 255, 255, 0.08);
    color: #f8fbfd;
    border-color: rgba(255, 255, 255, 0.16);
    box-shadow: none;
  }

  .account-dropdown-panel {
    position: static;
    width: 100%;
    margin-top: 8px;
    box-shadow: none;
  }

  body.exam-mode .exam-question-text {
    max-width: 100%;
    margin: 0;
  }

  body.exam-mode .exam-body,
  body.exam-mode .exam-body.no-media {
    grid-template-columns: minmax(0, 1fr);
    max-width: calc(100vw - 40px);
    margin: 28px 20px 0;
  }

  body.exam-mode .answers {
    margin-top: 18px;
  }
}

@media (max-width: 620px) {
  .main-panel,
  .sidebar {
    padding: 16px;
  }

  .details-grid,
  .stat-rings,
  .last-progress,
  .category-report,
  .readiness-panel,
  .home-intro,
  .home-actions,
  .topic-grid,
  .how-to-grid {
    grid-template-columns: 1fr;
  }

  .metric-row {
    grid-template-columns: 1fr;
  }

  .signed-out-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .home-intro {
    padding: 18px;
  }

  .readiness-panel {
    padding: 18px;
  }

  .readiness-copy h2 {
    font-size: 46px;
  }

  .home-intro h2 {
    font-size: 24px;
  }

  .question-toolbar,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  #questionTitle {
    font-size: 20px;
  }

  body.exam-mode .main-panel {
    padding: 0;
  }

  body.exam-mode .question-toolbar {
    align-items: center;
    flex-direction: row;
  }

  body.exam-mode #questionTitle {
    font-size: 18px;
  }

  body.exam-mode .action-row {
    align-items: center;
    flex-direction: row;
    right: 20px;
  }
}

/* ── Upgrade button ─────────────────────────────────────────────────────── */

.upgrade-button {
  width: 100%;
  min-height: 40px;
  border: 1px solid #d99c18;
  border-radius: 8px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #f4c14e 0%, #e8a800 100%);
  color: #1a0e00;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  cursor: pointer;
  transition: filter 0.15s;
}

.upgrade-button:hover {
  filter: brightness(1.08);
}

[data-theme="dark"] .upgrade-button {
  background: linear-gradient(135deg, #c9960a 0%, #a67800 100%);
  color: #fff8e1;
  border-color: #a67800;
}

/* ── Ad slots ───────────────────────────────────────────────────────────── */

.ad-slot {
  width: 100%;
  text-align: center;
  overflow: hidden;
}

.ad-slot-home {
  min-height: 90px;
  border-radius: 8px;
  border: 1px dashed var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-slot-question {
  min-height: 90px;
  border-radius: 8px;
  border: 1px dashed var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.ad-placeholder {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ── Cookie consent banner ──────────────────────────────────────────────── */

.cookie-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 220;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  max-width: 960px;
  margin: 0 auto;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.cookie-text { flex: 1; min-width: 240px; }
.cookie-text strong { display: block; margin-bottom: 4px; font-size: 15px; }
.cookie-text p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; }
.cookie-text a { color: var(--blue); }

.cookie-actions { display: flex; gap: 10px; flex-shrink: 0; }

/* ── Sidebar legal footer ───────────────────────────────────────────────── */

.sidebar-legal {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid color-mix(in srgb, var(--sidebar-fg) 12%, transparent);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.sidebar-legal a {
  color: color-mix(in srgb, var(--sidebar-fg) 70%, transparent);
  font-size: 13px;
  text-decoration: none;
}

.sidebar-legal a:hover { color: var(--sidebar-fg); text-decoration: underline; }

@media (max-width: 768px) {
  /* Keep the banner clear of the mobile bottom-nav */
  .cookie-banner { bottom: 72px; left: 12px; right: 12px; padding: 16px; }
  .cookie-actions { width: 100%; }
  .cookie-actions button { flex: 1; }
}

/* Mobile header ──────────────────────────────────────────────────────────── */

.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 56px;
  padding: 0 16px;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  position: sticky;
  top: 0;
  z-index: 200;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.mobile-brand h1 {
  font-size: 18px;
  margin: 0;
}

.mobile-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-menu-toggle {
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  padding: 8px 14px;
  background: rgba(255,255,255,0.08);
  color: var(--sidebar-fg);
  font-size: 14px;
}

.dark-toggle {
  font-size: 18px;
  line-height: 1;
}

/* Desktop dark toggle in sidebar brand */
.sidebar-brand {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.sidebar-brand .brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sidebar-brand .brand-row h1 {
  flex: 1;
  min-width: 0;
}

.sidebar-brand p {
  width: 100%;
  margin: 0;
}

.desktop-dark-toggle {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-color: rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.08);
  color: var(--sidebar-fg);
  font-size: 16px;
}

/* ── Due badge ──────────────────────────────────────────────────────────── */

.due-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  border-radius: 6px;
  padding: 5px 10px;
  background: #fff3cd;
  color: #664d03;
  font-size: 13px;
  font-weight: 600;
}

[data-theme="dark"] .due-badge {
  background: #3d2e00;
  color: #f0c040;
}

/* ── Bottom nav (mobile only) ───────────────────────────────────────────── */

.bottom-nav {
  display: none;
}

/* ── Sidebar overlay (mobile) ──────────────────────────────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 149;
  background: rgba(0,0,0,0.45);
}

/* ── Mobile layout (≤768px) ─────────────────────────────────────────────── */

@media (max-width: 768px) {
  body {
    overflow: auto;
    padding-bottom: 64px; /* space for bottom nav */
  }

  .mobile-header {
    display: flex;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: min(320px, 88vw);
    height: 100vh;
    z-index: 150;
    border-right: 1px solid rgba(255,255,255,0.12);
    transition: left 0.25s ease;
    overflow-y: auto;
  }

  /* Sidebar brand: hide the desktop dark toggle (mobile header has it) */
  .desktop-dark-toggle {
    display: none;
  }

  body.sidebar-open .sidebar {
    left: 0;
  }

  body.sidebar-open .sidebar-overlay {
    display: block;
  }

  .main-panel {
    height: auto;
    overflow: visible;
    padding: 16px;
  }

  /* Hide topbar account area on mobile (sidebar has it) */
  .topbar .top-account {
    display: none !important;
  }

  /* Bottom nav stays pinned to the screen edge. In the Android app the native
     banner is rendered above it, and modules/native-app.js reserves enough
     page space for both. */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--sidebar-bg);
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 0;
    height: 60px;
  }

  .bottom-nav .nav-button {
    flex: 1;
    min-width: 0;
    height: 60px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: color-mix(in srgb, var(--sidebar-fg) 55%, transparent);
    font-size: 11px;
    text-align: center;
    padding: 6px 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .bottom-nav .nav-button.active {
    background: rgba(255,255,255,0.1);
    color: var(--sidebar-fg);
    font-weight: 700;
  }

  /* Hide the sidebar nav group on mobile (bottom nav replaces it) */
  .sidebar .nav-group {
    display: none;
  }

  /* Responsive grids on mobile */
  .details-grid,
  .stat-rings,
  .last-progress,
  .category-report,
  .readiness-panel,
  .home-intro,
  .home-actions,
  .topic-grid,
  .how-to-grid,
  .metric-row {
    grid-template-columns: 1fr;
  }

  .home-actions {
    grid-template-columns: 1fr 1fr;
  }

  .stat-rings,
  .last-progress {
    grid-template-columns: 1fr 1fr;
  }

  /* ── Exam mode: mobile layout ─────────────────────────────────────────── */
  /* On phones the exam scrolls naturally and the controls become a single
     fixed bottom bar so nothing stacks on top of each other. */
  body.exam-mode {
    padding-bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    height: auto;
  }

  /* The exam has its own top toolbar — hide the app's mobile chrome. */
  body.exam-mode .mobile-header,
  body.exam-mode .bottom-nav,
  body.exam-mode .sidebar,
  body.exam-mode .sidebar-overlay {
    display: none;
  }

  body.exam-mode .app-shell,
  body.exam-mode .main-panel,
  body.exam-mode .question-workspace {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  /* Keep the green question header pinned while scrolling. */
  body.exam-mode .question-toolbar {
    position: sticky;
    top: 0;
    z-index: 6;
    min-height: 48px;
  }

  body.exam-mode #questionTitle {
    font-size: 16px;
  }

  body.exam-mode .icon-button {
    width: 56px;
    height: 48px;
  }

  /* Question content: single column, natural flow. */
  body.exam-mode .exam-body,
  body.exam-mode .exam-body.no-media {
    display: block;
    max-width: none;
    margin: 14px 16px 0;
  }

  body.exam-mode .media-panel,
  body.exam-mode .media-panel img,
  body.exam-mode .media-panel video {
    width: 100%;
    max-height: none;
  }

  body.exam-mode .exam-question-text {
    margin: 0 0 12px;
    font-size: 18px;
  }

  body.exam-mode .answers {
    margin-top: 14px;
  }

  body.exam-mode .answer-option {
    grid-template-columns: 40px minmax(0, 1fr);
    padding: 4px 0 14px;
    font-size: 17px;
  }

  body.exam-mode .answer-option input {
    width: 32px;
    min-height: 32px;
    margin-right: 8px;
  }

  /* The question index navigator now flows in the document instead of
     floating, and leaves room for the fixed Next bar. */
  body.exam-mode .exam-panel {
    position: static;
    margin: 18px 0 0;
    padding-bottom: 96px;
  }

  body.exam-mode .exam-tabs {
    padding: 0 12px;
  }

  body.exam-mode .exam-index-wrap {
    border-radius: 0;
    padding: 12px;
  }

  body.exam-mode .exam-index {
    width: 42px;
    height: 34px;
    font-size: 15px;
  }

  /* "Questions left" + Submit now sit inline at the end of the panel. */
  body.exam-mode .exam-footer {
    position: static;
    right: auto;
    bottom: auto;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    padding: 0 2px;
  }

  body.exam-mode .exam-submit {
    min-width: 130px;
  }

  /* Next becomes a full-width sticky bar so it never overlaps content. */
  body.exam-mode .action-row {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 10px 16px;
    gap: 10px;
    background: #fff;
    border-top: 1px solid #006000;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.12);
    z-index: 8;
  }

  body.exam-mode .action-row .primary,
  body.exam-mode .action-row .secondary,
  body.exam-mode #nextButton {
    flex: 1;
    min-width: 0;
    width: 100%;
    height: 44px;
  }
}
