/* Final chapter + reader layout refinement.
   Presentation only: question IDs, answers, highlights, notes and stored progress remain untouched. */

/* ---------- Chapter strip controls ---------- */
.chapter-strip-head > .chapter-study-controls {
  display:flex !important;
  align-items:center !important;
  justify-content:flex-end !important;
  gap:8px !important;
  flex-wrap:nowrap !important;
}

.chapter-study-controls > :is(.chapter-shuffle-button,.study-session-timer,.chapter-reset-button,.chapter-reset-menu) {
  box-sizing:border-box !important;
  width:116px !important;
  min-width:116px !important;
  max-width:116px !important;
  height:38px !important;
  min-height:38px !important;
  max-height:38px !important;
  border-radius:9px !important;
  box-shadow:none !important;
  filter:none !important;
  transform:none !important;
  background-image:none !important;
  text-shadow:none !important;
}

.chapter-study-controls .chapter-shuffle-button,
.chapter-study-controls .chapter-reset-button {
  padding:0 8px !important;
  display:inline-flex !important;
  align-items:center !important;
  justify-content:center !important;
  gap:5px !important;
  white-space:nowrap !important;
  font-size:11px !important;
  line-height:1 !important;
}

.chapter-study-controls .chapter-shuffle-button:hover,
.chapter-study-controls .chapter-shuffle-button:active,
.chapter-study-controls .chapter-reset-button:hover,
.chapter-study-controls .chapter-reset-button:active {
  box-shadow:none !important;
  transform:none !important;
  filter:none !important;
}

.chapter-study-controls .chapter-reset-menu {
  position:relative;
}

.chapter-reset-menu > summary.chapter-reset-button {
  box-sizing:border-box;
  width:100%;
  height:100%;
  border:1px solid var(--line);
  border-radius:9px;
  background:var(--surface);
  color:var(--text);
  cursor:pointer;
  list-style:none;
}

.chapter-reset-menu > summary::-webkit-details-marker { display:none; }

.chapter-reset-options {
  position:absolute;
  z-index:25;
  top:calc(100% + 6px);
  right:0;
  box-sizing:border-box;
  width:238px;
  max-width:calc(100vw - 32px);
  padding:6px;
  border:1px solid var(--line);
  border-radius:10px;
  background:var(--surface);
  box-shadow:0 8px 24px rgb(0 0 0 / .15);
}

.chapter-reset-options > button {
  display:block;
  width:100%;
  min-height:42px;
  height:auto;
  padding:10px 12px;
  text-align:left;
  white-space:normal;
  color:var(--text);
  background:transparent;
  border:0;
  border-radius:6px;
  font-size:12px;
}

.chapter-reset-options > button:hover,
.chapter-reset-options > button:focus-visible { background:var(--accent-soft); }
.chapter-reset-menu > summary:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }

.chapter-answer-reset-dialog {
  box-sizing:border-box;
  width:460px;
  max-width:calc(100vw - 32px);
  max-height:calc(100dvh - 32px);
  padding:24px;
  border:1px solid var(--line);
  border-radius:14px;
  background:var(--surface);
  color:var(--text);
}
.chapter-answer-reset-dialog::backdrop { background:rgb(0 0 0 / .5); }
.chapter-answer-reset-dialog h2 { margin:0 0 14px; font-size:20px; }
.chapter-answer-reset-dialog p { margin:0 0 20px; white-space:pre-line; line-height:1.6; }
.chapter-answer-reset-dialog .dialog-actions { display:flex; justify-content:flex-end; gap:10px; flex-wrap:wrap; }

.chapter-study-controls .chapter-shuffle-button[aria-pressed="true"] {
  color:var(--accent) !important;
  border-color:var(--accent) !important;
  background:var(--accent-soft) !important;
  background-image:none !important;
}

.chapter-study-controls .study-session-timer {
  padding:2px 6px 2px 2px !important;
  display:inline-flex !important;
  align-items:center !important;
  justify-content:flex-start !important;
  gap:5px !important;
}

.chapter-study-controls .study-session-timer time {
  min-width:0 !important;
  flex:1 1 auto !important;
  text-align:center !important;
  font-size:12px !important;
}

.chapter-study-controls .study-timer-toggle {
  box-sizing:border-box !important;
  width:32px !important;
  min-width:32px !important;
  height:32px !important;
  min-height:32px !important;
  padding:0 !important;
  border-radius:7px !important;
  box-shadow:none !important;
  filter:none !important;
  transform:none !important;
  background-image:none !important;
}

.chapter-study-controls .study-timer-toggle:hover,
.chapter-study-controls .study-timer-toggle:active,
.chapter-study-controls .study-timer-toggle[aria-pressed="true"] {
  box-shadow:none !important;
  transform:none !important;
  filter:none !important;
}

/* iPad/tablet: title + controls stay on one row. */
@media (min-width:768px) {
  .chapter-strip-head {
    display:flex !important;
    align-items:center !important;
    flex-wrap:nowrap !important;
    gap:12px !important;
  }

  .chapter-strip-head > div:first-child {
    min-width:0 !important;
    overflow:hidden !important;
    flex:1 1 auto !important;
  }

  .chapter-strip-head > div:first-child > :is(strong,span) {
    display:block !important;
    max-width:100% !important;
    overflow:hidden !important;
    text-overflow:ellipsis !important;
    white-space:nowrap !important;
  }

  .chapter-strip-head > .chapter-study-controls {
    margin-inline-start:auto !important;
    flex:0 0 auto !important;
    white-space:nowrap !important;
  }
}

/* Mobile: same three equal-width controls, fitted to available width. */
@media (max-width:767px) {
  .chapter-strip-head > .chapter-study-controls {
    width:100% !important;
    gap:6px !important;
  }

  .chapter-study-controls > :is(.chapter-shuffle-button,.study-session-timer,.chapter-reset-button,.chapter-reset-menu) {
    width:calc((100% - 12px) / 3) !important;
    min-width:0 !important;
    max-width:116px !important;
  }

  .chapter-study-controls .chapter-shuffle-button,
  .chapter-study-controls .chapter-reset-button {
    padding-inline:5px !important;
    font-size:10px !important;
  }
}

/* ---------- Inline source question number ---------- */
.reader-card.inline-question-number-enabled .reader-toolbar > .question-index,
.reader-card.inline-question-number-enabled .reader-toolbar .question-index-group > .question-index {
  display:none !important;
}

/* Number is true inline text: wrapped lines return beneath the number, not after a hanging indent. */
.reader-card.inline-question-number-enabled .question-stem {
  display:block !important;
  align-items:initial !important;
  gap:0 !important;
  white-space:pre-line !important;
}

.reader-card.inline-question-number-enabled .inline-question-number {
  display:inline !important;
  float:none !important;
  flex:none !important;
  margin:0 .38em 0 0 !important;
  padding:0 !important;
  font:inherit !important;
  line-height:inherit !important;
  white-space:nowrap !important;
  vertical-align:baseline !important;
}

.reader-card.inline-question-number-enabled .question-stem-text {
  display:inline !important;
  flex:none !important;
  min-width:0 !important;
  margin:0 !important;
  padding:0 !important;
  font:inherit !important;
  line-height:inherit !important;
  white-space:inherit !important;
  overflow-wrap:anywhere !important;
  word-break:normal !important;
}

/* ---------- Reader toolbar ---------- */
.reader-card.inline-question-number-enabled .reader-toolbar {
  --reader-tool-height:36px;
  --reader-tool-width:84px;
  --reader-edit-width:36px;
  display:flex !important;
  align-items:center !important;
  justify-content:space-between !important;
  gap:8px !important;
  min-width:0 !important;
}

/* Admin Edit alone at far left. */
.reader-card.inline-question-number-enabled .reader-toolbar .question-index-group {
  display:flex !important;
  align-items:center !important;
  flex:0 0 auto !important;
  margin-inline-end:auto !important;
  min-width:0 !important;
}

.reader-card.inline-question-number-enabled .reader-toolbar .question-index-group > .inline-question-edit-button {
  box-sizing:border-box !important;
  width:var(--reader-edit-width) !important;
  min-width:var(--reader-edit-width) !important;
  max-width:var(--reader-edit-width) !important;
  height:var(--reader-tool-height) !important;
  min-height:var(--reader-tool-height) !important;
  max-height:var(--reader-tool-height) !important;
  padding:0 6px !important;
  display:inline-flex !important;
  align-items:center !important;
  justify-content:center !important;
  gap:4px !important;
  border-radius:8px !important;
  box-shadow:none !important;
  filter:none !important;
  transform:none !important;
  background-image:none !important;
  text-shadow:none !important;
  font-size:16px !important;
  white-space:nowrap !important;
}

/* Book chapters keep equal, narrower action buttons; the edit icon stays square. */
.reader-card.chapter-reader-controls .reader-toolbar {
  --reader-tool-width:72px;
}

.reader-card.chapter-reader-controls .reader-toolbar .inline-question-edit-button > span {
  display:inline !important;
}

/* Section practice labels need their intrinsic width, especially Remove the flag.
   This scope excludes chapter, random-exam, comparison and removed-feature controls. */
.reader-card.inline-question-number-enabled.practice-reader-controls .reader-toolbar .marker-row {
  flex-wrap:wrap !important;
  max-width:100% !important;
}

.reader-card.inline-question-number-enabled.practice-reader-controls .reader-toolbar .marker-row > button {
  width:auto !important;
  min-width:var(--reader-tool-height) !important;
  max-width:100% !important;
  height:auto !important;
  max-height:none !important;
  padding:8px 10px !important;
  flex:0 1 auto !important;
  white-space:normal !important;
  overflow-wrap:anywhere !important;
  line-height:1.3 !important;
}

/* A light wash and a clear label replace the solid highlight rectangle in chapters. */
html[data-theme] body:has(#app > .app-header) .reader-card.chapter-reader-controls .reader-toolbar .highlight-brush,
html[data-theme] body:has(#app > .app-header) .reader-card.chapter-reader-controls .explanation-highlight-wrap .highlight-brush {
  border-color:var(--line) !important;
  background:color-mix(in srgb,var(--text) 5%,transparent) !important;
  background-image:none !important;
  color:var(--text) !important;
  box-shadow:none !important;
}

/* Reader actions are one compact group pinned to the far right. */
.reader-card.inline-question-number-enabled .reader-toolbar .marker-row {
  display:flex !important;
  align-items:center !important;
  justify-content:flex-end !important;
  flex:0 1 auto !important;
  flex-wrap:nowrap !important;
  margin-inline-start:auto !important;
  min-width:0 !important;
  gap:5px !important;
}

.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > button {
  box-sizing:border-box !important;
  width:var(--reader-tool-width) !important;
  min-width:var(--reader-tool-width) !important;
  max-width:var(--reader-tool-width) !important;
  height:var(--reader-tool-height) !important;
  min-height:var(--reader-tool-height) !important;
  max-height:var(--reader-tool-height) !important;
  padding:0 6px !important;
  display:inline-flex !important;
  align-items:center !important;
  justify-content:center !important;
  gap:4px !important;
  border-radius:8px !important;
  box-shadow:none !important;
  filter:none !important;
  transform:none !important;
  background-image:none !important;
  text-shadow:none !important;
  font-size:10.5px !important;
  line-height:1 !important;
  white-space:nowrap !important;
  margin-inline-start:0 !important;
  margin-inline-end:0 !important;
}

.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > button:hover,
.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > button:active,
.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > button.active,
.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > button.speaking {
  box-shadow:none !important;
  filter:none !important;
  transform:none !important;
  text-shadow:none !important;
}

/* Required visual order, left -> right: Speaker, Highlight, Compare, Flag, Skip.
   Therefore from the user's requested far-right direction it reads Skip, Flag, Compare, Highlight, Speaker. */
.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > [data-action="read-question"] { order:1 !important; }
.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > [data-action="highlight-menu"] { order:2 !important; }
.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > .comparison-tool { order:3 !important; }
.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > [data-marker="flagged"] { order:4 !important; }
.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > .skip-tool { order:5 !important; }
/* Keep the existing per-question reset available after answering without disturbing the requested right edge. */
.reader-card.inline-question-number-enabled .reader-toolbar .marker-row > .reset-tool { order:0 !important; }

/* Keep current hues, but flatten the previously dimensional states. */
.reader-card.inline-question-number-enabled .reader-toolbar .comparison-tool.active {
  color:#fff !important;
  background:#2f7df5 !important;
  border-color:#1458c3 !important;
  background-image:none !important;
}

.reader-card.inline-question-number-enabled .reader-toolbar .tool-icon {
  display:inline-flex !important;
  place-items:initial !important;
}

.reader-card.inline-question-number-enabled .reader-toolbar .tool-icon > span {
  display:inline-flex !important;
  align-items:center !important;
  justify-content:center !important;
  line-height:1 !important;
}

/* ---------- Plain inline answer choices ---------- */
/* The choice letter is ordinary text in the same line and color as the answer.
   Unanswered choices have no card, border, fill or hover highlight in any theme/book mode. */
.reader-card.inline-question-number-enabled .reader-content .options {
  gap:6px !important;
}

.reader-card.inline-question-number-enabled .reader-content .option {
  display:block !important;
  width:100% !important;
  max-width:100% !important;
  min-height:0 !important;
  margin:0 !important;
  padding:7px 4px !important;
  border:0 !important;
  border-radius:0 !important;
  outline:0 !important;
  background:transparent !important;
  background-image:none !important;
  box-shadow:none !important;
  filter:none !important;
  transform:none !important;
  color:inherit !important;
  line-height:1.42 !important;
  white-space:normal !important;
  overflow:visible !important;
  overflow-wrap:anywhere !important;
  word-break:normal !important;
}

.reader-card.inline-question-number-enabled .reader-content .option:not(.correct):not(.incorrect):not(.skipped-correct):hover,
.reader-card.inline-question-number-enabled .reader-content .option:not(.correct):not(.incorrect):not(.skipped-correct):focus,
.reader-card.inline-question-number-enabled .reader-content .option[aria-disabled="true"]:not(.correct):not(.incorrect):not(.skipped-correct):hover,
.reader-card.inline-question-number-enabled .reader-content .option[aria-disabled="true"]:not(.correct):not(.incorrect):not(.skipped-correct):focus {
  border:0 !important;
  outline:0 !important;
  background:transparent !important;
  background-image:none !important;
  box-shadow:none !important;
  filter:none !important;
  transform:none !important;
}

/* Keyboard focus remains visible without adding a box or fill. */
.reader-card.inline-question-number-enabled .reader-content .option:not(.correct):not(.incorrect):focus-visible {
  text-decoration:underline !important;
  text-decoration-thickness:1px !important;
  text-underline-offset:.12em !important;
}

/* Multi-answer selection remains legible before Submit without creating a card. */
.reader-card.inline-question-number-enabled .reader-content .option.active:not(.correct):not(.incorrect) {
  border:0 !important;
  background:transparent !important;
  background-image:none !important;
  box-shadow:none !important;
  color:inherit !important;
  text-decoration:underline !important;
  text-decoration-thickness:1px !important;
  text-underline-offset:.12em !important;
}

.reader-card.inline-question-number-enabled .reader-content .option-letter,
.reader-card.inline-question-number-enabled .reader-content .option.active .option-letter,
.reader-card.inline-question-number-enabled .reader-content .option.correct .option-letter,
.reader-card.inline-question-number-enabled .reader-content .option.incorrect .option-letter,
.reader-card.inline-question-number-enabled .reader-content .option.skipped-correct .option-letter {
  box-sizing:content-box !important;
  width:auto !important;
  min-width:0 !important;
  max-width:none !important;
  height:auto !important;
  min-height:0 !important;
  max-height:none !important;
  margin:0 .42em 0 0 !important;
  padding:0 !important;
  display:inline !important;
  vertical-align:baseline !important;
  float:none !important;
  border:0 !important;
  border-radius:0 !important;
  outline:0 !important;
  background:transparent !important;
  background-image:none !important;
  box-shadow:none !important;
  color:inherit !important;
  font:inherit !important;
  font-weight:inherit !important;
  line-height:inherit !important;
  text-shadow:none !important;
}

.reader-card.inline-question-number-enabled .reader-content .option-text {
  display:inline !important;
  flex:none !important;
  min-width:0 !important;
  max-width:none !important;
  margin:0 !important;
  padding:0 !important;
  color:inherit !important;
  white-space:normal !important;
  overflow-wrap:anywhere !important;
  word-break:normal !important;
  vertical-align:baseline !important;
}

/* Grading keeps the established correct/incorrect feedback, but without borders or shadows.
   All untouched alternatives stay plain text. */
.reader-card.inline-question-number-enabled .reader-content .option.correct,
.reader-card.inline-question-number-enabled .reader-content .option.skipped-correct {
  border:0 !important;
  outline:0 !important;
  background:var(--correct-soft) !important;
  background-image:none !important;
  box-shadow:none !important;
}

.reader-card.inline-question-number-enabled .reader-content .option.incorrect {
  border:0 !important;
  outline:0 !important;
  background:var(--wrong-soft) !important;
  background-image:none !important;
  box-shadow:none !important;
}

.reader-card.inline-question-number-enabled .reader-content .option.correct:hover,
.reader-card.inline-question-number-enabled .reader-content .option.skipped-correct:hover {
  background:var(--correct-soft) !important;
  border:0 !important;
  box-shadow:none !important;
}

.reader-card.inline-question-number-enabled .reader-content .option.incorrect:hover {
  background:var(--wrong-soft) !important;
  border:0 !important;
  box-shadow:none !important;
}

/* Keep the existing result mark inline with the sentence instead of dropping it to a new row. */
.reader-card.inline-question-number-enabled .reader-content .option.correct::after,
.reader-card.inline-question-number-enabled .reader-content .option.incorrect::after {
  display:inline !important;
  position:static !important;
  float:none !important;
  margin-inline-start:.42em !important;
  vertical-align:baseline !important;
}

/* ---------- Narrow mobile fitting ---------- */
@media (max-width:767px) {
  .reader-card.inline-question-number-enabled .reader-toolbar {
    --reader-tool-height:34px;
    --reader-tool-width:60px;
    --reader-edit-width:34px;
    gap:5px !important;
  }

  .reader-card.chapter-reader-controls .reader-toolbar {
    --reader-tool-width:52px;
  }

  .reader-card.inline-question-number-enabled .reader-toolbar .marker-row {
    gap:3px !important;
  }

  .reader-card.inline-question-number-enabled .reader-toolbar .marker-row > button {
    padding-inline:3px !important;
    gap:2px !important;
    font-size:9.5px !important;
  }

  .reader-card.inline-question-number-enabled .reader-toolbar .question-index-group > .inline-question-edit-button {
    padding-inline:4px !important;
    font-size:16px !important;
  }
}

@media (max-width:430px) {
  .reader-card.inline-question-number-enabled .reader-toolbar {
    --reader-tool-width:56px;
    --reader-edit-width:34px;
    gap:3px !important;
  }

  .reader-card.chapter-reader-controls .reader-toolbar {
    --reader-tool-width:48px;
  }

  .reader-card.chapter-reader-controls .reader-toolbar .marker-row {
    flex-wrap:wrap !important;
  }

  .reader-card.inline-question-number-enabled .reader-toolbar .marker-row {
    gap:2px !important;
  }

  .reader-card.inline-question-number-enabled .reader-toolbar .marker-row > button {
    font-size:9px !important;
  }

  .reader-card.inline-question-number-enabled .reader-toolbar .marker-row > .reset-tool {
    width:34px !important;
    min-width:34px !important;
    max-width:34px !important;
  }

  .reader-card.inline-question-number-enabled .reader-toolbar .marker-row > .reset-tool span {
    display:none !important;
  }
}
