/* ============================================================
   Editorial Modal System — Search, Search Results, Practice
   Darker "study mode" inverse of the landing/editorial palette
   (css/landing.css's --ep-* tokens): same navy/red/gold/serif+sans
   identity, inverted for a focused, low-glare working surface.
   Scoped to #searchModal / #searchResultsModal / #practiceModal only —
   does not touch topicSelectionModal or any other screen.
   Design approved via iterative mockup review, 2026-08-14.
   ============================================================ */

:root {
  --em-stage: #081B30;
  --em-surface: #0E2A49;
  --em-ink: #F7F0E3;       /* = --ep-paper */
  --em-ink-soft: #C9B99A;  /* muted --ep-tan-2 */
  --em-ink-faint: #7E92AC;
  --em-red: var(--ep-red, #C6242B);
  --em-red-hover: #DA3038;
  --em-gold: #C89A45;      /* legible variant of --ep-gold on a dark surface */
  --em-green: #4E9B6E;
  --em-green-bright: #6FBF8E;
  --em-line: rgba(247, 240, 227, 0.12);
  --em-line-strong: rgba(247, 240, 227, 0.24);
}

/* ---------- Shared modal shell (all three) ---------- */
#searchModal .search-container,
#searchResultsModal .results-container,
#practiceModal .practice-container {
  background: var(--em-surface) !important;
  background-image: none !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  border-color: var(--em-line-strong) !important;
  color: var(--em-ink);
  box-shadow: 0 24px 60px -24px rgba(0,0,0,0.6);
}
/* The backdrop itself: slightly deeper than the card so the card reads as
   a lit surface, not just a different grey. */
#searchModal.modal-backdrop, #searchModal:not(.hidden),
#searchResultsModal.modal-backdrop, #searchResultsModal:not(.hidden),
#practiceModal.modal-backdrop, #practiceModal:not(.hidden) {
  background-color: rgba(4, 12, 22, 0.72) !important;
}

#searchModal .em-head,
#searchResultsModal .em-head,
#practiceModal .em-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.em-head .em-titles h3 {
  font-family: var(--ep-serif); font-weight: 600; font-size: 22px; line-height: 1.1;
  color: var(--em-ink); margin: 0 0 5px;
}
.em-head .em-sub { font-size: 12.5px; color: var(--em-ink-faint); margin: 0; }

.em-icon-btn {
  width: 28px; height: 28px; flex-shrink: 0; display: inline-flex;
  align-items: center; justify-content: center; background: transparent;
  border: none; color: var(--em-ink-faint); cursor: pointer; border-radius: 6px;
}
.em-icon-btn:hover { color: var(--em-ink); }
.em-icon-btn:focus-visible { outline: 2px solid var(--em-gold); outline-offset: 2px; }

.em-label {
  display: block; font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em;
  color: var(--em-ink-faint); text-transform: uppercase; margin-bottom: 8px;
}

/* Subtle-border fields: no filled background, editorial form feel */
#searchModal select, #searchModal input[type="text"] {
  width: 100%; background: transparent !important; border: none !important;
  border-bottom: 1px solid var(--em-line-strong) !important; color: var(--em-ink) !important;
  border-radius: 0 !important; padding: 8px 2px; font-size: 15px;
}
#searchModal select::placeholder, #searchModal input::placeholder { color: var(--em-ink-faint); }
#searchModal select:focus, #searchModal input:focus {
  outline: none !important; border-bottom-color: var(--em-gold) !important; box-shadow: none !important;
}
#searchModal select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  /* The select's own background-color is what Chromium carries over into
     its OPEN dropdown list when no per-option color is set (option rule
     below reinforces this explicitly) -- transparent here would leave the
     open list with no color hint at all, falling back to browser-default
     white. This is the one field that needs a real fill, unlike the
     underline-style text inputs. */
  background-color: var(--em-surface) !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%237E92AC'%3E%3Cpath d='M5.5 7.5l4.5 5 4.5-5z'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 2px center !important;
  background-size: 15px !important;
  padding-right: 22px;
}
/* Chrome/Edge respect this for the non-hovered rows in the open list; the
   hovered/keyboard-focused row's highlight stays OS-controlled regardless
   (a real platform limit, not something missing here) -- Safari/mobile
   pickers ignore this entirely and show their own native UI either way. */
#searchModal select option {
  background-color: var(--em-surface) !important;
  color: var(--em-ink) !important;
}
#searchModal .em-field { margin-bottom: 22px; }

#searchModal .em-chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
#searchModal .search-suggestion,
#searchModal .em-chip {
  font-size: 12px !important; color: var(--em-ink-faint) !important; background: none !important;
  border: 1px solid var(--em-line) !important; border-radius: 999px !important; padding: 4px 11px !important;
}
#searchModal .search-suggestion:hover, #searchModal .em-chip:hover {
  border-color: var(--em-gold) !important; color: var(--em-ink) !important;
}

/* ---------- Buttons: red = forward action, everywhere ---------- */
#searchModal .em-btn-primary, #searchResultsModal .em-btn-primary, #practiceModal .em-btn-primary,
#searchModal #searchTopicsBtn, #searchResultsModal #startSearchReview,
#practiceModal #checkAnswerBtn, #practiceModal #nextQuestionBtn {
  background: var(--em-red) !important; color: var(--em-ink) !important;
  border: 1px solid transparent !important; border-radius: 9px !important;
  font-weight: 600 !important; min-height: 48px; transition: background 0.12s ease, transform 0.05s ease;
}
#searchModal #searchTopicsBtn:hover, #searchResultsModal #startSearchReview:hover,
#practiceModal #checkAnswerBtn:hover, #practiceModal #nextQuestionBtn:hover { background: var(--em-red-hover) !important; }
#searchModal #searchTopicsBtn:active, #searchResultsModal #startSearchReview:active,
#practiceModal #checkAnswerBtn:active, #practiceModal #nextQuestionBtn:active { transform: translateY(1px); }
#searchModal #searchTopicsBtn:disabled, #searchResultsModal #startSearchReview:disabled {
  background: var(--em-line-strong) !important; color: var(--em-ink-faint) !important;
}

#searchResultsModal #cancelSearchResults, #practiceModal #skipQuestionBtn {
  background: transparent !important; border: 1px solid var(--em-line-strong) !important;
  color: var(--em-ink-soft) !important; border-radius: 9px !important; font-weight: 600 !important; min-height: 48px;
}
#searchResultsModal #cancelSearchResults:hover, #practiceModal #skipQuestionBtn:hover {
  border-color: var(--em-ink-faint) !important; color: var(--em-ink) !important;
}

/* Ghost button: lighter-weight than em-btn-secondary, sits inline under the
   error message rather than as a full-width modal action. */
#searchResultsModal .em-btn-ghost {
  background: transparent !important; border: 1px solid var(--em-line-strong) !important;
  color: var(--em-ink-soft) !important; border-radius: 7px !important; font-weight: 600 !important;
  font-size: 12.5px; padding: 6px 14px; margin-top: 8px; cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease;
}
#searchResultsModal .em-btn-ghost:hover { border-color: var(--em-gold) !important; color: var(--em-ink) !important; }
#searchResultsModal .em-btn-ghost:focus-visible { outline: 2px solid var(--em-gold); outline-offset: 2px; }

/* ---------- Search Results specifics ---------- */
#searchResultsModal .em-headline { margin-bottom: 4px; }
#searchResultsModal .em-headline .em-num {
  font-family: var(--ep-serif); font-weight: 600; font-size: 40px; line-height: 1;
  color: var(--em-ink); font-variant-numeric: tabular-nums;
}
#searchResultsModal .em-headline .em-of { font-family: var(--ep-serif); font-size: 20px; color: var(--em-ink-soft); margin-left: 6px; }
/* Per-search context copy (buildResultsCopy, spec §8) directly under the
   match count -- more prominent than em-context's static placeholder line. */
#searchResultsModal .em-context-line { font-size: 13px; color: var(--em-ink-soft); margin: 2px 0 0; line-height: 1.4; }
#searchResultsModal .em-context { font-size: 13px; color: var(--em-ink-faint); margin: 8px 0 18px; }
#searchResultsModal .em-context b { color: var(--em-ink-soft); font-weight: 500; }
#searchResultsModal .em-note { font-size: 13px; color: var(--em-ink-soft); line-height: 1.6; margin: 0 0 4px; }

/* Opt-in disclosure: closed by default, no visual weight until opened */
#searchResultsModal .em-narrow-disclosure { margin: 18px 0 0; }
#searchResultsModal .em-narrow-disclosure summary {
  list-style: none; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--em-gold);
  padding: 6px 0; display: flex; align-items: center; gap: 7px;
}
#searchResultsModal .em-narrow-disclosure summary::-webkit-details-marker { display: none; }
#searchResultsModal .em-narrow-disclosure summary::before {
  content: ""; width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.15s ease; flex-shrink: 0;
}
#searchResultsModal .em-narrow-disclosure[open] summary::before { transform: rotate(45deg); }
#searchResultsModal .em-narrow-disclosure summary:hover { color: var(--em-ink); }
@keyframes em-narrow-reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
#searchResultsModal .em-narrow-disclosure[open] .em-subject-narrow { animation: em-narrow-reveal 0.16s ease-out; }

#searchResultsModal .em-subject-narrow { margin: 14px 0 4px; padding-top: 14px; border-top: 1px solid var(--em-line); }
#searchResultsModal .em-subject-narrow-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; min-height: 18px; }
#searchResultsModal .em-subject-narrow-head .em-n { font-size: 12px; color: var(--em-ink-faint); line-height: 1.4; }
#searchResultsModal .em-link-btn {
  background: none; border: none; color: var(--em-gold); font-size: 11.5px; font-weight: 600;
  cursor: pointer; padding: 2px; flex-shrink: 0;
}
#searchResultsModal .em-link-btn:hover { color: var(--em-ink); }

#searchResultsModal #subjectsSelection {
  display: flex; flex-direction: column; max-height: 150px; overflow-y: auto;
}
/* Per-facet group label ("Subject" / "Topic") above each block of checkbox
   rows in #facetContainer -- same small-caps treatment as .em-label. */
#searchResultsModal .em-facet-heading {
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--em-ink-faint); margin: 12px 0 4px; padding: 0 2px;
}
#searchResultsModal .em-facet-heading:first-child { margin-top: 0; }
#searchResultsModal .em-subject-row {
  display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--em-ink-soft);
  padding: 6px 2px; border-bottom: 1px solid var(--em-line); cursor: pointer; border-radius: 0;
  background: transparent !important;
}
#searchResultsModal .em-subject-row:last-child { border-bottom: none; }
#searchResultsModal .em-subject-row:hover { color: var(--em-ink); }
#searchResultsModal .em-subject-row input { accent-color: var(--em-red); width: 15px; height: 15px; flex-shrink: 0; }
#searchResultsModal .em-subject-row .em-count { margin-left: auto; font-size: 11px; color: var(--em-ink-faint); font-variant-numeric: tabular-nums; }

#searchResultsModal .em-summary-line { font-size: 12px; color: var(--em-ink-faint); padding: 10px 2px 0; }
#searchResultsModal .em-summary-line b { color: var(--em-gold); font-weight: 600; }

#searchResultsModal .em-no-results { font-size: 13px; color: var(--em-ink-soft); line-height: 1.6; }

/* Pinned header/footer, scrollable middle -- results-container is already
   flex (Tailwind classes on the element); we just redirect where the
   scroll happens. */
#searchResultsModal .results-container { display: flex !important; flex-direction: column !important; overflow: hidden !important; }
#searchResultsModal .em-fixed { flex-shrink: 0; }
#searchResultsModal .em-scroll { flex: 1 1 auto; overflow-y: auto; min-height: 0; }

/* ---------- Practice specifics ---------- */
#practiceModal .practice-container { display: flex !important; flex-direction: column !important; overflow-y: hidden !important; } /* the .em-scroll child handles scrolling now */
#practiceModal .em-fixed { flex-shrink: 0; }
#practiceModal .em-scroll { flex: 1 1 auto; overflow-y: auto; min-height: 0; }

#practiceModal #progressBar-track, #practiceModal .em-progress-track {
  height: 3px; background: var(--em-line-strong); border-radius: 999px; overflow: hidden; margin: 14px 0 20px;
}
#practiceModal .progress-bar { background: var(--em-gold) !important; }

#practiceModal .em-stem-wrap { max-width: 46ch; }
#practiceModal #questionStem {
  font-family: var(--ep-serif) !important; font-size: 19px !important; line-height: 1.42 !important;
  font-weight: 500 !important; color: var(--em-ink) !important;
}

#practiceModal #answerOptions { max-width: 46ch; }
#practiceModal .em-option {
  display: flex; align-items: center; gap: 13px; width: 100%; min-height: 50px;
  text-align: left; background: transparent !important; border: 1px solid var(--em-line-strong) !important;
  border-radius: 9px !important; padding: 12px 15px; color: var(--em-ink-soft) !important;
  font-size: 14px; cursor: pointer; transition: border-color 0.12s ease, background 0.12s ease;
}
#practiceModal .em-option:hover { border-color: var(--em-ink-faint) !important; }
#practiceModal .em-option .em-letter {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--em-line-strong);
  display: flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 600; color: var(--em-ink-faint);
}
#practiceModal .em-option .em-mark { margin-left: auto; flex-shrink: 0; width: 18px; height: 18px; display: none; align-items: center; justify-content: center; }

#practiceModal .em-option.em-wrong { border-color: var(--em-red) !important; background: rgba(198,36,43,0.12) !important; color: var(--em-ink) !important; }
#practiceModal .em-option.em-wrong .em-letter { border-color: var(--em-red); color: var(--em-red-hover); }
#practiceModal .em-option.em-wrong .em-mark.em-x { display: inline-flex; color: var(--em-red-hover); }

#practiceModal .em-option.em-correct { border-color: var(--em-green) !important; background: rgba(78,155,110,0.1) !important; color: var(--em-ink) !important; }
#practiceModal .em-option.em-correct .em-letter { border-color: var(--em-green); color: var(--em-green-bright); }
#practiceModal .em-option.em-correct .em-mark.em-check { display: inline-flex; color: var(--em-green-bright); }

/* Pre-check selection (before Check Answer is pressed) -- distinct from the
   post-check wrong/correct states above. */
#practiceModal .em-option.selected { border-color: var(--em-gold) !important; background: rgba(200,154,69,0.14) !important; box-shadow: 0 0 0 1px var(--em-gold), 0 0 16px rgba(200,154,69,0.30) !important; }
#practiceModal .em-option.selected .em-letter { border-color: var(--em-gold); color: var(--em-gold); background: rgba(200,154,69,0.15); }
/* Post-check text labels (non-color feedback): "Correct answer" / "Your answer". */
.em-ans-tag { margin-left: 8px; font-size: 11px; font-weight: 700; letter-spacing: .02em; padding: 1px 7px; border-radius: 4px; white-space: nowrap; flex-shrink: 0; }
#practiceModal .em-option.em-correct .em-ans-tag.em-ans-correct { color: var(--em-green-bright); border: 1px solid var(--em-green); }
#practiceModal .em-option.em-wrong .em-ans-tag.em-ans-yours { color: var(--em-red-hover); border: 1px solid var(--em-red); }
/* Keep the pinned quiz actions clear of the mobile browser chrome / home indicator. */
#practiceActionRow { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
/* The results screen can be taller than the fixed-height practice container
   (overflow:hidden), so it must scroll ITSELF — otherwise the bottom actions
   ("Done") are clipped below the fold with no scrollbar. The Review Answers
   walkthrough is its sibling state and needs the identical treatment. */
#practiceModal #practiceSummary,
#practiceModal #reviewWalkthrough,
#practiceModal #examReviewScreen { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }

#practiceModal #explanationContent {
  background: transparent !important; border: none !important; border-left: 2px solid var(--em-gold) !important;
  border-radius: 0 !important; padding: 0 0 0 14px !important; max-width: 46ch;
}
#practiceModal #explanationContent h5 {
  font-size: 10.5px !important; font-weight: 700 !important; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--em-gold) !important; margin-bottom: 6px !important;
}
#practiceModal #explanationText { font-size: 13.5px !important; line-height: 1.6 !important; color: var(--em-ink-soft) !important; }

@media (prefers-reduced-motion: reduce) {
  #searchModal *, #searchResultsModal *, #practiceModal * { transition: none !important; animation: none !important; }
}

/* ============================================================
   End-of-Explore conversion modal (Task 9, #exploreConvertModal)
   A different hybrid from the dark #em-* study-mode surface above: the
   wrapper keeps the old bg-black/50 + .modal-backdrop shell (blurred scrim,
   role="dialog" on the inner panel) but the panel itself uses the light
   ivory-on-navy-scrim language of .ep-modal-panel (editorial-app.css) via a
   NEW .ep-modal/.ep-convert component -- this modal is compact content, not
   a full study surface, so it gets its own small centered card rather than
   reusing .ep-modal-panel's mobile full-height sheet treatment.
   ============================================================ */
#exploreConvertModal.modal-backdrop, #exploreConvertModal:not(.hidden) {
  background-color: rgba(11, 41, 72, .55) !important;
}
#exploreConvertModal:not(.hidden) {
  display: flex; align-items: center; justify-content: center; padding: 16px;
}

.ep-modal.ep-convert {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: 90dvh;
  overflow-y: auto;
  margin: auto;
  background: var(--ep-paper, #F7F0E3);
  color: var(--ep-navy, #0B2948);
  border-radius: 16px;
  padding: 34px 28px 28px;
  text-align: center;
  font-family: var(--ep-sans, Inter, system-ui, sans-serif);
  box-shadow: 0 24px 60px -20px rgba(0,0,0,0.5);
}
.ep-convert .ep-modal-close {
  position: absolute; top: 8px; right: 8px;
}
.ep-convert .ep-modal-title {
  font-size: 22px;
  line-height: 1.25;
  margin: 4px 36px 12px 0; /* right margin clears the close button */
}
.ep-convert-sub {
  font-size: 13.5px; line-height: 1.5; color: rgba(11, 41, 72, .72); margin: 0 0 22px;
}
.ep-convert-ben {
  text-align: left; font-size: 13.5px; line-height: 1.55; color: rgba(11, 41, 72, .82);
  margin: 0 0 14px;
}
.ep-convert-ben span {
  display: inline-block; margin-right: 4px; color: var(--ep-gold, #B98228); font-weight: 700;
}
.ep-convert-ben strong { color: var(--ep-navy, #0B2948); font-weight: 700; }

.ep-convert-primary {
  display: block; width: 100%; text-align: center; margin-top: 20px;
}
.ep-convert-login {
  margin: 14px 0 0; font-size: 13px; color: rgba(11, 41, 72, .68);
}
.ep-convert-loginlink {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 4px; margin-left: 2px;
  background: none; border: 0;
  color: var(--ep-red, #C6242B); font-weight: 600; font-size: 13px;
  text-decoration: underline; cursor: pointer; transition: color .15s ease;
}
.ep-convert-loginlink:hover { color: var(--ep-red-2, #A81D23); }

.ep-convert-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 18px 0; font-size: 11px; letter-spacing: .05em; text-transform: uppercase;
  /* .45 measured ~2.64:1 against this same paper bg elsewhere in the codebase (see the
     ep-selection-summary contrast note in editorial-app.css) -- .7 is the value that
     codebase already relies on for AA-safe muted text (~5.3:1), reused here. */
  color: rgba(11, 41, 72, .7);
}
.ep-convert-divider::before, .ep-convert-divider::after {
  content: ""; flex: 1; height: 1px; background: rgba(11, 41, 72, .16);
}

.ep-convert-guest {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; width: 100%; padding: 10px 16px;
  background: transparent; border: 0; border-radius: 4px;
  color: var(--ep-red, #C6242B); font-family: var(--ep-sans, Inter, system-ui, sans-serif);
  font-weight: 600; font-size: 14px; cursor: pointer; transition: color .15s ease;
}
.ep-convert-guest:hover { color: var(--ep-red-2, #A81D23); }

.ep-convert .ep-modal-close:focus-visible,
.ep-convert-loginlink:focus-visible,
.ep-convert-guest:focus-visible,
.ep-convert-primary:focus-visible {
  outline: 2px solid var(--ep-red, #C6242B); outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .ep-convert * { transition: none !important; }
}
