/* ICF Practice Simulator — themes and layout */

:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #6b7280;
  --border: #d4d4d8;
  --panel: #f5f5f5;
  --accent: #1e40af;
  --accent-soft: #dbeafe;
  --flag: #b45309;
  --flag-soft: #fef3c7;
  --shadow: 0 1px 2px rgba(0,0,0,.04);
  --radius: 4px;
  --font: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
  --serif: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
}

/* ─── Themes ─── */
/* Foreground / background only — UI scaffolding stays neutral within each. */

.theme-light          { --bg:#ffffff; --fg:#111111; --panel:#f5f5f5; --border:#d4d4d8; --muted:#6b7280; --accent:#1e40af; --accent-soft:#dbeafe; }
.theme-dark           { --bg:#0b0f14; --fg:#e5e7eb; --panel:#111827; --border:#334155; --muted:#9ca3af; --accent:#60a5fa; --accent-soft:#1e3a8a; }
.theme-cream          { --bg:#fbf5e3; --fg:#1f1a10; --panel:#f4ecd0; --border:#dcd1ad; --muted:#7a6a52; --accent:#7c4a1e; --accent-soft:#ead4a8; }
.theme-yellow         { --bg:#fff7c2; --fg:#1a1500; --panel:#fff09e; --border:#d8c97a; --muted:#5b4e16; --accent:#5b4002; --accent-soft:#ffeb84; }
.theme-pink           { --bg:#fde6ee; --fg:#1a0810; --panel:#facdda; --border:#e3a3b8; --muted:#6f3b4c; --accent:#7c1d3f; --accent-soft:#f4b8cb; }
.theme-green          { --bg:#e6f4ea; --fg:#0b1c10; --panel:#cde9d6; --border:#9bc8aa; --muted:#3e6a4d; --accent:#1f5132; --accent-soft:#b6dec3; }
.theme-blue           { --bg:#e3edff; --fg:#06112d; --panel:#cddafd; --border:#a6bcf0; --muted:#3f5478; --accent:#1e3a8a; --accent-soft:#bccdf9; }
.theme-grey           { --bg:#ebebeb; --fg:#1a1a1a; --panel:#dcdcdc; --border:#aeaeae; --muted:#555555; --accent:#0f172a; --accent-soft:#c8c8c8; }
.theme-sepia          { --bg:#f4ecd8; --fg:#3b2f1f; --panel:#ede1c4; --border:#d6c7a3; --muted:#7a6a52; --accent:#7c4a1e; --accent-soft:#e8d4ab; }
.theme-yellow-on-black{ --bg:#000000; --fg:#ffeb3b; --panel:#1a1a00; --border:#5a5a18; --muted:#bda74a; --accent:#fde047; --accent-soft:#3a3a08; }
.theme-green-on-black { --bg:#000000; --fg:#7fff7f; --panel:#001a00; --border:#1a5a1a; --muted:#5a9a5a; --accent:#aaffaa; --accent-soft:#063e06; }
.theme-amber          { --bg:#1a1308; --fg:#ffb74d; --panel:#241b0c; --border:#5a431f; --muted:#a68a55; --accent:#ffd180; --accent-soft:#3b2a14; }
.theme-high-contrast  { --bg:#fffae6; --fg:#000000; --panel:#fff4b8; --border:#000000; --muted:#4b3b00; --accent:#1a1a1a; --accent-soft:#ffe89a; }

/* ─── Plain / ASCII theme ─── */
/* Activates a monospaced, low-chrome appearance in addition to colour. */
.theme-plain {
  --bg: #f7f7f0; --fg: #111; --panel: #ecece2; --border: #888; --muted: #555;
  --accent: #111; --accent-soft: #d4d4c8; --radius: 0;
}
.theme-plain .option,
.theme-plain .zone { border-width: 1px; border-style: solid; box-shadow: none; }
.theme-plain .option-letter { border-radius: 0; background: transparent; border: 1px solid var(--fg); }
.theme-plain .clock { border-radius: 0; background: transparent; border: 1px solid var(--fg); }
.theme-plain button { border-radius: 0; box-shadow: none; }
.theme-plain .flag-btn { border-radius: 0; }
.theme-plain h1, .theme-plain h2, .theme-plain h3 { font-weight: 700; }
.theme-plain .topbar { border-bottom: 1px solid var(--fg); }
.theme-plain .actionbar { border-top: 1px solid var(--fg); }

/* ─── Reset / global ─── */

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
}
body { display: flex; flex-direction: column; }
main { background: var(--bg); }
.topbar, .actionbar { background: var(--panel); color: var(--fg); }

button, select, input, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
}

button {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s;
  color: var(--fg);
}
button:hover { background: var(--accent-soft); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
button.primary:hover { filter: brightness(1.1); background: var(--accent); }

select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
}

a { color: var(--accent); }

/* ─── Watermark bar (above topbar) ─── */
.watermark-bar {
  padding: 4px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 0.75em;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.watermark-bar:empty { display: none; }

/* ─── Tiled diagonal watermark ───
   Repeating SVG background painted across the viewport at -30° with the
   tester's email, IP (when available behind Cloudflare), and the date.
   pointer-events:none so it doesn't intercept drag/drop or clicks; z-index
   sits above page content but below modals (which use higher z-indices).
   The actual `background-image` is set from JS in paintTiledWatermark().
*/
.watermark-tile {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  background-repeat: repeat;
  background-position: top left;
  /* Faint by default; theme can tune via the CSS var below. */
}
.watermark-tile:empty { /* will still tile if background-image is set */ }
@media print {
  /* Make sure printouts / Save-As-PDF carry the watermark too. */
  .watermark-tile { z-index: 9999; }
}

/* ─── Floating Report-a-problem button ─── */
/* The action bar is fixed at bottom: 0 with padding 12+12 + button height ~32 ≈ 60px tall.
   We anchor the report button above it with breathing room, plus iOS safe-area insets. */
.report-btn {
  position: fixed;
  right: max(18px, env(safe-area-inset-right, 18px));
  bottom: calc(112px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--fg);
  font: inherit;
  font-size: 0.9em;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.report-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.report-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.report-btn:active { transform: translateY(1px); }
.report-icon { font-size: 1.05em; line-height: 1; }

/* When the action bar is hidden (setup / break / review-after-finalize / results),
   move the button down — no need to clear an action bar that isn't there.
   We rely on a body[data-actionbar-visible] flag set by app.js. */
body[data-actionbar-visible="false"] .report-btn {
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 720px) {
  /* Compact pill on narrow screens — just the bug icon, smaller pad. */
  .report-btn { padding: 9px 11px; gap: 0; font-size: 0.85em; }
  .report-btn .report-label { display: none; }
  /* The .actionbar wraps slightly tighter on mobile too; keep extra clearance. */
  .report-btn { bottom: calc(104px + env(safe-area-inset-bottom, 0px)); }
}

/* Report dialog content */
.report-modal h2 { margin-top: 0; }
.report-modal label { display: block; margin: 12px 0; font-size: 0.95em; }
.report-modal label > div:first-child { font-weight: 600; margin-bottom: 4px; }
.report-modal textarea {
  width: 100%;
  min-height: 56px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  resize: vertical;
}
.report-modal select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  background: var(--bg);
  color: var(--fg);
}
.report-modal .modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ─── Disclaimer footer ─── */
.disclaimer-footer {
  padding: 18px 32px 90px 32px;
  font-size: 0.78em;
  color: var(--muted);
  border-top: 1px dotted var(--border);
  width: 100%;
  line-height: 1.5;
}
.disclaimer-footer a { color: var(--accent); text-decoration: underline; }

/* ─── Topbar ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left, .topbar-right, .topbar-center {
  display: flex; align-items: center; gap: 12px;
}
#brand-home { cursor: pointer; border-radius: var(--radius); padding: 2px 6px; margin-left: -6px; transition: background 0.12s; }
#brand-home:hover { background: var(--accent-soft); }
#brand-home:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.vendor {
  font-size: 0.75em;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}
.brand { font-weight: 700; letter-spacing: 0.01em; }
.muted { color: var(--muted); font-size: 0.92em; }
#progress { font-weight: 600; font-variant-numeric: tabular-nums; }

.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  font-size: 1em;
  color: var(--fg);
  padding: 0;
  background: transparent;
  border: none;
  min-width: 60px;
  text-align: right;
}
.clock.warning { color: var(--flag); }
.clock.danger  { color: var(--flag); font-weight: 700; }

.flag-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 4px 10px;
  font-size: 0.9em;
  border-radius: var(--radius);
}
.flag-btn:hover { background: var(--flag-soft); border-color: var(--flag); color: var(--flag); }
.flag-btn.flagged {
  background: var(--flag-soft);
  border-color: var(--flag);
  color: var(--flag);
  font-weight: 600;
}

@media (max-width: 720px) {
  body { overflow-x: hidden; }
  .topbar {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    grid-template-areas: "brand progress tools";
    align-items: center;
    gap: 6px;
    min-height: 46px;
    padding: 6px 8px;
  }
  .topbar-left {
    grid-area: brand;
    width: 44px;
    min-width: 0;
    align-items: center;
    gap: 0;
  }
  .topbar-right {
    grid-area: tools;
    flex: 0 0 auto;
    min-width: 0;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 4px;
  }
  .topbar-center {
    grid-area: progress;
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    font-size: 0.92em;
    line-height: 1.15;
  }
  #brand-home { margin-left: 0; padding: 0; }
  .vendor {
    width: 38px;
    font-size: 0.58em;
    letter-spacing: 0.08em;
    line-height: 1.05;
  }
  .brand {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  #section-label {
    display: none;
  }
  #progress {
    display: block;
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .study-sheet-btn,
  .flag-btn {
    position: relative;
    width: 36px;
    height: 34px;
    padding: 0;
    overflow: hidden;
    white-space: nowrap;
    text-indent: 120%;
    font-size: 0;
    line-height: 1;
  }
  .study-sheet-btn::before,
  .flag-btn::before {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-indent: 0;
    font-size: 16px;
    line-height: 1;
  }
  .study-sheet-btn::before { content: "📖"; }
  .flag-btn::before { content: "⚑"; }
  .flag-btn.flagged::before {
    color: var(--flag);
  }
  #theme-select {
    width: 38px;
    min-width: 38px;
    height: 34px;
    padding: 0 16px 0 4px;
    color: transparent;
    font-size: 0;
  }
  #theme-select option {
    color: var(--fg);
    font-size: 16px;
  }
  .clock {
    min-width: 0;
    max-width: 54px;
    overflow: hidden;
    font-size: 0.84em;
    line-height: 1.15;
    white-space: nowrap;
  }
  .clock.no-timer {
    display: none;
  }
  main { padding: 12px 18px 110px 18px; }
  .setup-start-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px;
  }
  .setup-start-row .primary {
    width: 100%;
    padding: 12px 14px;
  }
  .setup-start-row .start-meta { flex: none; }
  label {
    align-items: flex-start;
    flex-wrap: wrap;
    margin-right: 0;
  }
}

/* ─── Main / layout ─── */
main {
  flex: 1;
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
  padding: 22px 28px 120px 28px;
}

h1 { font-size: 1.6em; margin: 0 0 16px 0; }
h2 { font-size: 1.25em; margin: 18px 0 10px 0; }
h3 { font-size: 1.05em; margin: 14px 0 6px 0; }
p { margin: 0 0 10px 0; }
ul, ol { margin: 0 0 10px 0; padding-left: 22px; }
li { margin: 4px 0; }

/* ─── Setup screen ─── */
.setup-main {
  max-width: 760px;
  margin: 14px 0 0 0;
}

.study-sheet {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.study-sheet > h2 { margin-top: 0; }
.study-sheet-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 10px;
}
@media (max-width: 900px) {
  .study-sheet-grid { grid-template-columns: 1fr; }
}
.study-sheet-grid .study-panel {
  margin: 0;
}

/* ─── Study-sheet drawer (slide-in from right; available from any screen) ─── */
.study-sheet-btn {
  font-size: 0.92em;
  padding: 6px 10px;
}
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 110;
  opacity: 0;
  transition: opacity 180ms ease;
}
.drawer-backdrop.open { opacity: 1; }
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  /* Roughly double the previous 460px so the full study sheet (six panels +
     headline) fits in one viewport on a desktop without scrolling. The 95vw
     cap keeps the drawer narrower than the screen on smaller laptops. */
  width: min(920px, 95vw);
  background: var(--bg);
  color: var(--fg);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0,0,0,0.28);
  z-index: 120;
  transform: translateX(100%);
  transition: transform 220ms ease;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky; top: 0;
  z-index: 1;
}
.drawer-header h2 { margin: 0; font-size: 1.15em; }
.drawer-close {
  border: 0; background: transparent;
  font-size: 1.6em; line-height: 1;
  cursor: pointer; padding: 2px 8px;
  color: var(--fg);
}
.drawer-body { padding: 16px 20px 28px; }
.drawer-body .study-panel {
  margin: 0 0 14px 0;
}
.drawer-body p.muted {
  font-size: 0.9em;
  margin-bottom: 14px;
}

/* Two-column study-sheet layout on wide drawers.
   The .study-cols wrapper holds two .study-col flex-stacks side-by-side.
   Each column packs its panels tightly top-to-bottom — short panels don't
   leave gaps when the neighbouring column is taller, which is the failure
   mode of CSS grid row-flow. The headline panel above the wrapper spans
   the full drawer width. On narrow screens the columns collapse to a
   single vertical flow. */
.drawer-body { padding: 18px 22px 32px; }
.drawer-body .study-cols {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}
.drawer-body .study-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.drawer-body > .study-panel-headline { margin: 0 0 4px 0; }

@media (min-width: 780px) {
  .drawer-body {
    padding: 18px 24px 32px;
  }
  .drawer-body .study-cols {
    flex-direction: row;
    align-items: flex-start;
    gap: 18px;
  }
  .drawer-body .study-col {
    flex: 1 1 0;
    min-width: 0;
  }
}

/* ─── Rationale reveal (drill / study mode only) ─── */
.rationale-reveal {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 18px 0 0 0;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.rationale-reveal #btn-reveal-rationale {
  font-weight: 600;
}
.rationale-reveal .muted { font-size: 0.88em; }

.setup-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 0 0 14px 0;
}
.setup-card h2 { margin-top: 0; margin-bottom: 10px; }

.mode-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.mode-option {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  background: var(--bg);
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}
.mode-option:hover { border-color: var(--accent); }
.mode-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.mode-option h3 { margin: 0 0 2px 0; font-size: 1em; }
.mode-option p { margin: 0; font-size: 0.88em; }

.setup-start-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  margin: 14px 0;
}
.setup-start-row .primary {
  font-size: 1.1em;
  padding: 12px 28px;
  font-weight: 700;
}
.setup-start-row .start-meta {
  flex: 1;
  font-size: 0.88em;
  color: var(--muted);
}

label { display: inline-flex; align-items: center; gap: 8px; margin-right: 16px; }
input[type="checkbox"], input[type="radio"] { transform: scale(1.1); }

textarea {
  width: 100%;
  min-height: 90px;
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: var(--radius);
  font: inherit;
  resize: vertical;
}

/* ─── Exam item ─── */
.item-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  gap: 28px;
}
@media (max-width: 920px) {
  .item-grid { grid-template-columns: 1fr; }
}

.scenario {
  grid-column: 1 / -1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-family: var(--serif);
  font-size: 1.05em;
  line-height: 1.65;
  margin-bottom: 4px;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-left: 44px;
  margin-bottom: 22px;
}

.option {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  align-items: start;
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: grab;
  transition: opacity 0.25s ease, background 0.15s, border-color 0.15s;
  user-select: none;
  position: relative;
}
.option:hover { border-color: var(--accent); }
.option:active { cursor: grabbing; }
.option.dragging { opacity: 0.4; }
.option.placed {
  opacity: 0.45;
  background: var(--panel);
}
.option.placed .option-letter {
  background: var(--border);
  color: var(--muted);
}
.option.placed::after {
  content: attr(data-placed-label);
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 0.7em;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.option-letter {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--fg);
  font-weight: 700;
}

.option-text { padding-top: 4px; }

/* Drop zones — right column */
.zones {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: start;
}
.zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: 130px;
  background: var(--panel);
  transition: background 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
}
.zone.has-answer { border-style: solid; border-color: var(--border); background: var(--bg); }
.zone.drag-over  { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.zone-label {
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: 0.8em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.zone-content { font-family: var(--serif); line-height: 1.45; flex: 1; }

.zone-content .placed-chip {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: start;
  cursor: grab;
  opacity: 0.65;
}
.zone-content .placed-chip:hover { opacity: 0.85; }
.zone-content .placed-chip:active { cursor: grabbing; }
.zone-content .placed-chip.dragging { opacity: 0.4; }
.zone-content .placed-chip .option-letter {
  width: 24px; height: 24px; font-size: 0.85em;
}

.zone-empty-hint {
  color: var(--muted);
  font-style: italic;
  font-family: var(--font);
  font-size: 0.92em;
}

.options-list.drag-over {
  background: var(--accent-soft);
  border-radius: var(--radius);
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

/* Custom drag system */
.option, .placed-chip { cursor: grab; }
.option:active, .placed-chip:active { cursor: grabbing; }
.source-dragging {
  opacity: 0.35;
  pointer-events: none;
}
.drag-ghost {
  /* Ghost inherits the visible look of whatever was picked up */
  background: var(--bg);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  cursor: grabbing;
  user-select: none;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  align-items: start;
}
.drag-ghost .option-letter {
  display: flex; justify-content: center; align-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--fg); font-weight: 700;
}
.drag-ghost .option-text { padding-top: 4px; }

/* ─── Action bar ─── */
.actionbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding: 12px 22px;
  z-index: 10;
}
.actionbar button { white-space: nowrap; }

/* Demo sign-up CTA inside the bottom action bar — sits between Previous
   and Next so every question screen carries a low-friction conversion
   path without taking layout space above the buttons. Hidden by default
   (the `hidden` attribute on the element); JS unhides it in demo mode.
   The two label spans (long / short) let the CTA collapse cleanly on
   narrow screens without re-rendering. */
.actionbar-cta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 9px 18px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.94em;
  white-space: nowrap;
  transition: filter 0.12s;
}
.actionbar-cta:hover { filter: brightness(1.08); }
.actionbar-cta strong { font-weight: 800; }
.actionbar-cta .actionbar-cta-short { display: none; }
@media (max-width: 720px) {
  .actionbar-cta { padding: 8px 12px; font-size: 0.9em; }
  .actionbar-cta .actionbar-cta-long { display: none; }
  .actionbar-cta .actionbar-cta-short { display: inline; }
}
@media (max-width: 420px) {
  /* Very narrow phone screens: collapse to icon-y / very short. */
  .actionbar-cta { padding: 7px 9px; font-size: 0.86em; }
}

/* ─── Review screen ─── */
.review-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 14px 0;
  background: var(--bg);
}
.review-row {
  display: grid;
  grid-template-columns: 56px 1fr 70px 36px 100px;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.review-row:last-child { border-bottom: 0; }
.review-row:hover { background: var(--accent-soft); }
.review-row .num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--muted);
}
.review-row .preview {
  font-family: var(--serif);
  line-height: 1.4;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.review-row .chosen {
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  letter-spacing: 0.04em;
}
.review-row .chosen .dash { color: var(--muted); font-weight: 400; }
.review-row .flag {
  text-align: center;
  color: var(--fg);
  font-weight: 700;
  font-size: 1.1em;
}
.review-row .review-btn {
  padding: 4px 12px;
  font-size: 0.88em;
}
.review-row.unanswered .preview { opacity: 0.75; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  overflow-y: auto;
  padding: 16px;
  z-index: 100;
}
.modal {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.modal h2 { margin-top: 0; }
.modal .count {
  font-size: 2.6em;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  margin: 14px 0;
  color: var(--flag);
}
@media (max-width: 720px) {
  .modal-backdrop { align-items: flex-start; }
  .modal {
    width: 100%;
    padding: 22px;
    text-align: left;
  }
}

/* ─── Break screen ─── */
.break-card {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 540px;
  margin: 36px auto;
}
.break-clock {
  font-size: 3em;
  font-variant-numeric: tabular-nums;
  margin: 18px 0;
}

/* ─── Results ─── */
.result-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat-value { font-size: 1.8em; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 0.85em; }

.competency-row {
  display: grid;
  grid-template-columns: 1fr 90px 1fr;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.bar-track { height: 10px; background: var(--accent-soft); border-radius: 5px; overflow: hidden; }
.bar-fill  { height: 100%; background: var(--accent); }

.result-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 10px 0;
}
.result-item.correct { border-left: 4px solid var(--accent); }
.result-item.partial { border-left: 4px solid var(--flag); }
.result-item.wrong   { border-left: 4px solid var(--border); }
.result-item summary { cursor: pointer; font-weight: 600; }
.result-item .option-line {
  display: flex; gap: 8px; padding: 4px 0; align-items: flex-start;
}
.result-item .option-line .tag {
  font-size: 0.75em; padding: 1px 6px; border-radius: 4px; white-space: nowrap;
  border: 1px solid var(--border);
}
.tag-best { background: var(--accent-soft); color: var(--fg); border-color: var(--accent); font-weight: 600; }
.tag-worst{ background: var(--panel); color: var(--fg); border-color: var(--muted); font-weight: 600; }
.tag-you  { background: var(--flag-soft); color: var(--flag); border-color: var(--flag); }

@media (max-width: 720px) {
  .review-row {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    grid-template-areas:
      "num preview review"
      "num chosen flag";
    gap: 6px 8px;
    padding: 10px;
  }
  .review-row .num { grid-area: num; }
  .review-row .preview {
    grid-area: preview;
    min-width: 0;
  }
  .review-row .chosen {
    grid-area: chosen;
    text-align: left;
  }
  .review-row .flag { grid-area: flag; }
  .review-row .review-btn {
    grid-area: review;
    padding: 4px 8px;
  }
  .competency-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .competency-row .muted { justify-self: start; }
  .result-item summary { overflow-wrap: anywhere; }
  .result-item .option-line {
    flex-wrap: wrap;
    gap: 5px 6px;
  }
  .result-item .option-line > div {
    flex: 1 1 180px;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .result-item .option-line .tag {
    white-space: normal;
    align-self: flex-start;
  }
}

.rationale {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: var(--radius);
  margin-top: 8px;
  font-family: var(--serif);
}
.rationale h4 { margin: 8px 0 4px 0; font-size: 0.95em; }
.rationale h4:first-child { margin-top: 0; }

/* ─── Results screen — walk-through entry ─── */
.results-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 14px 0 22px 0;
  padding: 14px 18px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}
.results-actions .primary { font-weight: 700; }
.results-actions .muted { flex: 1; font-size: 0.9em; }
@media (max-width: 720px) {
  .results-actions { flex-direction: column; align-items: stretch; gap: 8px; }
}

/* ─── Study mode (walkthrough) ─── */
.walkthrough-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.walkthrough-header h1 { margin: 0; }
.walkthrough-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.walkthrough-controls label { display: flex; align-items: center; gap: 6px; }
.walkthrough-controls select { padding: 4px 8px; }

.walkthrough-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 0.9em;
}
.walkthrough-meta .wt-id { font-weight: 700; font-family: ui-monospace, monospace; }
.walkthrough-meta .wt-result { font-weight: 600; }
.walkthrough-meta .wt-correct { color: var(--accent); }
.walkthrough-meta .wt-partial { color: var(--flag); }
.walkthrough-meta .wt-wrong { color: var(--fg); }
.walkthrough-meta .wt-flagged { color: var(--flag); font-weight: 600; }

.wt-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0 18px 0;
}
.wt-option {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  background: var(--bg);
}
.wt-option.is-best { border-color: var(--accent); }
.wt-option.is-worst { border-color: var(--muted); }
.wt-option.is-you { background: var(--accent-soft); }
.wt-option-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.wt-option-tags:empty { display: none; }
.wt-option-body { font-family: var(--serif); line-height: 1.5; }

.walkthrough-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  margin-top: 14px;
  border-top: 1px solid var(--border);
}
.walkthrough-nav .muted { font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .walkthrough-header {
    align-items: stretch;
    gap: 10px;
  }
  .walkthrough-controls {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .walkthrough-controls label {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }
  .walkthrough-controls select,
  .walkthrough-controls button {
    width: 100%;
    max-width: 100%;
  }
  .walkthrough-nav {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }
  .walkthrough-nav .muted {
    order: -1;
    flex: 1 0 100%;
    text-align: center;
  }
  .walkthrough-nav button { flex: 1 1 110px; }
}

/* ─── Study panel ─── */
.study-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 10px 0;
}
.study-panel h3 { margin-top: 0; }
/* The "signature method" headline panel — SCAN for TRUST, reject FIXES.
   Highlighted with an accent-coloured left border + soft accent fill so
   it reads as the load-bearing summary, not just one of many panels. */
.study-panel-headline {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft, var(--panel));
}
.study-panel table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92em;
}
.study-panel th, .study-panel td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.study-panel th { background: var(--accent-soft); font-weight: 600; }

/* ─── Demo sign-up nudge ───────────────────────────────────────────────
   Three variants rendered by demoSignupCard(variant) in app.js:
   - default ("setup"): bottom of the setup screen, mid-density pitch
   - "between": compact one-liner injected under each question
   - "conversion": full pitch on the demo-conversion end screen
*/
.demo-signup {
  margin: 22px 0 10px;
  padding: 18px 20px;
  background: var(--panel);
  border: 1.5px solid var(--border-strong, var(--border));
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  position: relative;
  z-index: 105;
}
.demo-signup h3 { margin: 0 0 6px; font-size: 1.05em; }
.demo-signup p { margin: 0 0 8px; color: var(--muted); }
.demo-signup .demo-signup-price {
  font-size: 1.05em; color: var(--fg);
  margin: 8px 0 12px; font-variant-numeric: tabular-nums;
}
.demo-signup .demo-signup-price s { color: var(--muted); margin-right: 8px; font-weight: 400; }
.demo-signup .demo-signup-actions {
  display: flex; flex-wrap: wrap; gap: 10px;
}
.demo-signup .demo-signup-actions .primary,
.demo-signup .demo-signup-actions .secondary {
  display: inline-block; padding: 9px 16px; border-radius: 5px;
  text-decoration: none; font-weight: 600; font-size: 0.95em;
  border: 1px solid var(--accent);
}
.demo-signup .demo-signup-actions .primary {
  background: var(--accent); color: #fff;
}
.demo-signup .demo-signup-actions .secondary {
  background: transparent; color: var(--accent);
}
.demo-signup .demo-signup-actions .primary:hover,
.demo-signup .demo-signup-actions .secondary:hover { filter: brightness(1.07); }

/* Conversion variant — bigger, more prominent on the end screen */
.demo-signup.demo-signup-conversion {
  border-left-width: 4px;
  padding: 22px 24px;
}
.demo-signup.demo-signup-conversion h3 { font-size: 1.25em; }

/* Compact one-liner under each question. Sits below the rationale reveal
   button if any. Single row on desktop; stacks vertically on narrow. */
.demo-signup-compact {
  margin: 16px 0 0;
  padding: 10px 14px;
  border-left-width: 3px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px;
  font-size: 0.94em;
}
.demo-signup-compact span { color: var(--muted); }
.demo-signup-compact span strong { color: var(--fg); }
.demo-signup-compact .demo-signup-cta {
  flex-shrink: 0;
  display: inline-block; padding: 7px 14px; border-radius: 5px;
  background: var(--accent); color: #fff;
  text-decoration: none; font-weight: 600; font-size: 0.92em;
  border: 1px solid var(--accent);
}
.demo-signup-compact .demo-signup-cta:hover { filter: brightness(1.07); }

/* ─── Mobile swipe input ─────────────────────────────────────────────
   On phones, drag-and-drop is awkward — the long-press fights with
   browser scroll. Mobile (≤720px) renders swipe cards instead: flick
   right for BEST, left for WORST. Desktop is unaffected. */

/* Semantic colors for best/worst — kept theme-independent so the
   affordance reads on every backdrop. */
:root {
  --best-mark: #2e7d32;
  --best-mark-soft: #d6efd9;
  --worst-mark: #b22222;
  --worst-mark-soft: #f7d8d6;
}

/* ─── Swipe cards ─── */
.swipe-block { padding: 0; margin: 0 0 22px; }
.swipe-instructions {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 4px 10px;
  font-size: 0.78em; font-weight: 600; letter-spacing: 0.04em;
  color: var(--muted); text-transform: uppercase;
}
.swipe-hint.left  { color: var(--worst-mark); }
.swipe-hint.right { color: var(--best-mark); }

.swipe-options {
  display: flex; flex-direction: column; gap: 10px;
}
.swipe-option {
  position: relative;
  border-radius: var(--radius); overflow: hidden;
  background: var(--bg);
  border: 2px solid var(--border);
  transition: border-color 0.2s, background 0.2s;
  touch-action: pan-y; /* allow vertical scroll, capture horizontal */
}
.swipe-option.is-best  { border-color: var(--best-mark); background: var(--best-mark-soft); }
.swipe-option.is-worst { border-color: var(--worst-mark); background: var(--worst-mark-soft); }

/* Reveal panels behind the card. As .swipe-inner translates, one of
   these becomes visible. Right-swipe → BEST (green, on the left edge);
   left-swipe → WORST (red, on the right edge). */
.swipe-reveal {
  position: absolute; top: 0; bottom: 0; width: 50%;
  display: flex; align-items: center; padding: 0 18px;
  font-weight: 700; font-size: 0.86em; letter-spacing: 0.04em;
  color: white; opacity: 0; transition: opacity 0.1s;
}
.swipe-reveal-left  { left: 0; background: var(--best-mark); justify-content: flex-start; }
.swipe-reveal-right { right: 0; background: var(--worst-mark); justify-content: flex-end; }
.swipe-option.swipe-right .swipe-reveal-left  { opacity: 1; }
.swipe-option.swipe-left  .swipe-reveal-right { opacity: 1; }

.swipe-inner {
  position: relative; z-index: 2;
  background: var(--bg);
  padding: 13px 14px;
  transform: translateX(0);
  transition: transform 0.18s ease-out, background 0.2s;
  cursor: grab; user-select: none;
  display: flex; align-items: flex-start; gap: 10px;
  font-family: var(--serif);
}
.swipe-option.is-best  .swipe-inner { background: var(--best-mark-soft); }
.swipe-option.is-worst .swipe-inner { background: var(--worst-mark-soft); }
.swipe-inner.dragging { transition: none; cursor: grabbing; }

.swipe-letter {
  flex: 0 0 26px;
  display: inline-block; width: 26px; height: 26px;
  border-radius: 50%; background: var(--panel);
  font-family: var(--font-mono, monospace); font-weight: 700;
  text-align: center; line-height: 26px; font-size: 0.92em;
  color: var(--fg);
}
.swipe-option.is-best  .swipe-letter { background: var(--best-mark); color: white; }
.swipe-option.is-worst .swipe-letter { background: var(--worst-mark); color: white; }
.swipe-text { flex: 1; font-size: 0.95em; line-height: 1.45; }

.swipe-badge {
  flex: 0 0 auto; align-self: center;
  font-size: 0.66em; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 7px; border-radius: 999px; color: white;
}
.swipe-option.is-best  .swipe-badge { background: var(--best-mark); }
.swipe-option.is-best  .swipe-badge::after { content: "BEST"; }
.swipe-option.is-worst .swipe-badge { background: var(--worst-mark); }
.swipe-option.is-worst .swipe-badge::after { content: "WORST"; }

/* Telegraph the swipe gesture on the first card if nothing's been picked. */
@keyframes swipe-peek {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(28px); }
  40%      { transform: translateX(0); }
  60%      { transform: translateX(-22px); }
  80%      { transform: translateX(0); }
}
.swipe-option.peek .swipe-inner {
  animation: swipe-peek 2.4s ease-in-out 0.5s 1;
}

/* Collapse the grid when swipe is active (zones aren't rendered). */
.item-grid.ui-swipe { grid-template-columns: 1fr; }
