/* ============================================================
   MODEL PALETTE TOKENS
   The single source of colour for every model, in both normal and
   high-contrast mode. Model JS must read these (via ModelShell.palette)
   rather than hardcoding hex values — that is what keeps every model
   looking identical and makes high contrast genuinely black and white.
   ============================================================ */
.viz-container {
  --model-bg:        #fafafa;
  --model-fg:        #000000;
  --model-grid:      #cccccc;
  --model-muted:     #666666;
  --model-accent:    #CC0000;

  /* Ordered data series. Use series-1..5 in order; do not invent new hexes. */
  --model-series-1:  #1565C0;  /* e.g. activation  */
  --model-series-2:  #E65100;  /* e.g. ohmic       */
  --model-series-3:  #388E3C;  /* e.g. concentration */
  --model-series-4:  #424242;  /* e.g. ideal/reference */
  --model-series-5:  #CC0000;  /* e.g. overall/result  */

  --model-legend-bg: rgba(255,255,255,0.9);
  --model-title-size: 16;
  --model-axis-size:  14;
}

/* High contrast: pure black and white, no exceptions. Series are separated by
   dash pattern and line width instead of hue (see ModelShell.palette.dashes). */
.viz-container.high-contrast {
  --model-bg:        #000000;
  --model-fg:        #ffffff;
  --model-grid:      #ffffff;
  --model-muted:     #ffffff;
  --model-accent:    #ffffff;

  --model-series-1:  #ffffff;
  --model-series-2:  #ffffff;
  --model-series-3:  #ffffff;
  --model-series-4:  #ffffff;
  --model-series-5:  #ffffff;

  --model-legend-bg: #000000;
  --model-title-size: 20;
  --model-axis-size:  18;
}

/* Shared model chrome so every model page opens the same way */
.model-backbar {
  background: #CC0000;
  padding: 15px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.model-backbar a {
  color: #fff;
  text-decoration: none;
  font-size: 16px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.high-contrast .model-backbar { background: #000; border-bottom: 3px solid #fff; }

.model-title { color: #CC0000; margin: 20px 0 10px; font-size: clamp(1.6rem, 3.5vw, 2.1rem); font-weight: 700; line-height: 1.2; }
.model-intro { margin-bottom: 20px; }

/* Container must fill the page or high contrast leaves a white margin around
   a black box instead of reading as a black-and-white page. */
.viz-container { padding: 20px; }
.viz-container.high-contrast { min-height: 100vh; }

/* Shared "model shell" styles: accessibility + feedback + focus mode helpers */

/* Accessibility icon - using "A" instead of emoji */
.accessibility-icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  background: #CC0000;
  color: white;
  border-radius: 50%;
  text-align: center;
  line-height: 24px;
  font-weight: bold;
  font-size: var(--fs-small, 0.9375rem);
}
.accessibility-icon::before { content: "A"; }

/* Dyslexia-friendly formatting */
.dyslexic-font {
  font-family: Arial, Verdana, sans-serif !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
  line-height: 1.5 !important;
}
.dyslexic-font * {
  font-family: Arial, Verdana, sans-serif !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
  line-height: 1.5 !important;
}

/* High contrast mode */
.high-contrast {
  background: #000 !important;
  color: #fff !important;
}
.high-contrast * { color: #fff !important; }

.high-contrast .info-box,
.high-contrast .bv-controls,
.high-contrast .loss-panel,
.high-contrast .accessibility-panel,
.high-contrast .model-feedback {
  background: #000 !important;
  color: #fff !important;
  border: 3px solid #fff !important;
}

.high-contrast .info-box h4 {
  color: #fff !important;
  border-bottom: 2px solid #fff !important;
}
.high-contrast .info-box h2,
.high-contrast .info-box p,
.high-contrast .info-box li,
.high-contrast .info-box strong {
  color: #fff !important;
}

.high-contrast .loss-panel h3,
.high-contrast .loss-toggle label,
.high-contrast .loss-description {
  color: #fff !important;
  font-weight: bold !important;
}

.high-contrast .loss-toggle {
  background: #000 !important;
  border: 2px solid #fff !important;
}

.high-contrast .control-label,
.high-contrast .value-display,
.high-contrast .hint-text,
.high-contrast .slider-container span {
  color: #fff !important;
  font-weight: bold !important;
}

.high-contrast .value-display {
  background: #000 !important;
  border: 2px solid #fff !important;
  color: #fff !important;
}

.high-contrast .model-feedback h4,
.high-contrast .model-feedback p,
.high-contrast .feedback-status {
  color: #fff !important;
}

.high-contrast .feedback-btn {
  background: #000 !important;
  color: #fff !important;
  border: 3px solid #fff !important;
  box-shadow: none !important;
}
.high-contrast .feedback-btn:hover { background: #333 !important; }
.high-contrast .feedback-btn.selected {
  background: #fff !important;
  color: #000 !important;
}

.high-contrast .feedback-comment-section {
  background: #000 !important;
  border: 2px solid #fff !important;
}
.high-contrast .feedback-comment {
  background: #000 !important;
  color: #fff !important;
  border: 2px solid #fff !important;
}
.high-contrast .feedback-submit-btn {
  background: #000 !important;
  color: #fff !important;
  border: 3px solid #fff !important;
}
.high-contrast .feedback-submit-btn:hover { background: #333 !important; }

.high-contrast .accessibility-panel h3,
.high-contrast .accessibility-option label {
  color: #fff !important;
  font-weight: bold !important;
}
.high-contrast .accessibility-icon {
  background: #fff !important;
  color: #000 !important;
  border: 2px solid #fff !important;
}

.high-contrast input[type="range"] { background: #fff !important; }
.high-contrast input[type="range"]::-webkit-slider-thumb {
  background: #fff !important;
  border: 2px solid #000 !important;
}
.high-contrast input[type="range"]::-moz-range-thumb {
  background: #fff !important;
  border: 2px solid #000 !important;
}
.high-contrast input[type="radio"] { accent-color: #fff !important; }
.high-contrast #modeDescription {
  color: #fff !important;
  font-weight: bold !important;
}

/* Focus mode: hide only elements explicitly marked */
.focus-mode .hide-in-focus { display: none !important; }

/* Feedback widget styles */
.model-feedback {
  background: #fafafa;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 20px;
  margin: 20px 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.model-feedback h4 {
  color: #CC0000;
  margin-bottom: 15px;
  font-size: 1.1rem;
}
.feedback-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 15px;
}
.feedback-btn {
  flex: 1;
  min-width: 100px;
  min-height: 44px;
  padding: 10px 15px;
  background: #fff;
  color: #1f2328;
  border: 2px solid #8a9099;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.feedback-btn:hover { border-color: #1f2328; background: #f3f4f6; }
.feedback-btn.selected { border-color: #CC0000; color: #A80000; background: #fdecec; }

.feedback-comment-section {
  margin-top: 15px;
  padding: 15px;
  background: white;
  border-radius: 8px;
}
.feedback-comment {
  width: 100%;
  min-height: 80px;
  padding: 10px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  resize: vertical;
  margin-bottom: 10px;
}
.feedback-submit-btn {
  background: #CC0000;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.feedback-status {
  margin-top: 10px;
  font-size: var(--fs-small, 0.9375rem);
  color: #666;
  font-style: italic;
}

/* Model-specific layout pieces that are likely reusable */
.plot-loss-container {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 20px;
  margin: 20px 0;
  align-items: start;
}
@media (max-width: 1024px) {
  .plot-loss-container { grid-template-columns: 1fr; }
}
.loss-panel {
  background: #ffffff;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  height: fit-content;
  position: sticky;
  top: 20px;
}
.loss-panel h3 {
  color: #CC0000;
  margin: 0 0 15px 0;
  font-size: 1.2rem;
  text-align: center;
}
.loss-toggle {
  margin: 15px 0;
  padding: 15px;
  background: #f9f9f9;
  border-radius: 8px;
  border: 2px solid #e0e0e0;
}
.loss-toggle label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}
.loss-toggle input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}
.loss-description {
  margin-top: 8px;
  font-size: var(--fs-small, 0.9375rem);
  color: #666;
  line-height: 1.4;
}

/* Legend swatch colours in page markup, driven by the same tokens as the plot */
.viz-container .series-1 { color: var(--model-series-1); font-weight: 600; }
.viz-container .series-2 { color: var(--model-series-2); font-weight: 600; }
.viz-container .series-3 { color: var(--model-series-3); font-weight: 600; }

/* ============================================================
   COMPACT MODE - small screens
   The model reshapes itself; it is never replaced by a cut-down
   variant. Secondary controls are deferred into <details>, not removed.
   ============================================================ */

/* Secondary controls: a plain block on desktop, a disclosure on mobile. */
.model-secondary { border: none; margin: 0; padding: 0; }
.model-secondary > summary { display: none; }

.compact-mode .model-secondary {
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 14px 0;
  background: #fafafa;
}
.compact-mode .model-secondary > summary {
  display: list-item;
  cursor: pointer;
  font-weight: 600;
  color: #CC0000;
  padding: 6px 0;
  min-height: 44px;          /* touch target */
  line-height: 32px;
}
.high-contrast .model-secondary { background: #000 !important; border-color: #fff !important; }
.high-contrast .model-secondary > summary { color: #fff !important; }

/* Guidance notice */
.model-notice {
  background: #FFF8E1;
  border: 2px solid #CC0000;
  border-left-width: 6px;
  border-radius: 8px;
  padding: 14px 16px;
  margin: 0 0 18px;
}
.model-notice p { margin: 0 0 10px; font-size: 0.95rem; line-height: 1.5; }
.model-notice-btn {
  font-family: inherit;
  font-size: var(--fs-small, 0.9375rem);
  background: #CC0000;
  color: #fff;
  border: 2px solid #CC0000;
  border-radius: 6px;
  padding: 10px 14px;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
  margin-right: 8px;
}
.model-notice-dismiss { background: #fff; color: #CC0000; }
.high-contrast .model-notice {
  background: #000 !important;
  border-color: #fff !important;
}
.high-contrast .model-notice-btn {
  background: #000 !important; color: #fff !important; border-color: #fff !important;
}

/* Layout + touch targets */
.compact-mode .plot-loss-container { grid-template-columns: 1fr; gap: 12px; }
.compact-mode .loss-panel { position: static; padding: 14px; }
.compact-mode { padding: 12px; }
.compact-mode .model-title { font-size: 1.35rem; }

.compact-mode input[type="range"] { height: 44px; }
.compact-mode input[type="range"]::-webkit-slider-thumb { width: 28px; height: 28px; }
.compact-mode input[type="range"]::-moz-range-thumb { width: 28px; height: 28px; }
.compact-mode .feedback-btn { min-height: 44px; flex: 1 1 100%; }
.compact-mode .loss-toggle input[type="checkbox"] { width: 26px; height: 26px; }

/* Complex models often include figures alongside the plot */
.viz-container img { max-width: 100%; height: auto; }

/* The title is now the first visible thing in the container (the accessibility
   button is fixed in the corner), so it needs no extra space above it. */
.viz-container > .model-title { margin-top: 0; }

/* Feedback now sits at the bottom of the page, after the model. */
.viz-container > .model-feedback { margin-top: 40px; }


/* ============================================================
   ACCESSIBILITY PULL-OUT PANEL
   A fixed "Accessibility" button in the bottom-right corner opens the
   options panel above it. To move it to another corner, change the
   right/bottom values on .a11y-toggle and .a11y-drawer together
   (e.g. left: 16px instead of right: 16px).
   ============================================================ */
.a11y-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2000;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 16px 8px 10px;
  background: #fff;
  color: #CC0000;
  border: 2px solid #CC0000;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
.a11y-toggle:hover { background: #fdecec; }

/* Fades out for good once the student starts using the page; model-shell.js
   adds .is-tucked. It stays in the page (not display:none) so screen readers
   and the Tab key still find it, and it reappears while it has keyboard focus
   or while its panel is open. */
.a11y-toggle {
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.a11y-toggle.is-tucked {
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
}
.a11y-toggle.is-tucked:focus-visible,
.a11y-toggle.is-tucked[aria-expanded="true"] {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
@media (prefers-reduced-motion: reduce) {
  .a11y-toggle { transition: none; }
}
.a11y-toggle[aria-expanded="true"] { background: #CC0000; color: #fff; }
.a11y-toggle[aria-expanded="true"] .accessibility-icon { background: #fff; color: #CC0000; }

.a11y-drawer {
  position: fixed;
  right: 16px;
  bottom: 72px;
  z-index: 2000;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}
/* Some site-wide styles set display on panels, which would beat the hidden
   attribute. This makes sure a closed panel really is closed. */
.a11y-drawer[hidden] { display: none !important; }

.a11y-drawer .accessibility-panel {
  margin: 0;
  background: #fff;
  border: 2px solid #CC0000;
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.2);
}
.a11y-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.a11y-drawer-head h3 { margin: 0; color: #CC0000; font-size: 1.1rem; }

.a11y-close {
  background: #fff;
  color: #1f2328;
  border: 2px solid #8a9099;
  border-radius: 8px;
  padding: 6px 14px;
  min-height: 44px;
  font-family: inherit;
  font-size: var(--fs-small, 0.9375rem);
  font-weight: 600;
  cursor: pointer;
}
.a11y-close:hover { border-color: #1f2328; background: #f3f4f6; }

/* styles.css lays the options out in a row for the old top-of-page panel and
   gives each checkbox a 44px box. Inside the pull-out panel they stack in a
   single column instead, and the whole line (label + box) is the touch target. */
.a11y-drawer .accessibility-options {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 0;
}
.a11y-drawer .accessibility-option { margin: 2px 0; width: 100%; }
.a11y-drawer .accessibility-option label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;          /* touch target */
  padding: 0;
  cursor: pointer;
}
.a11y-drawer .accessibility-option input[type="checkbox"] {
  flex: none;
  width: 20px;
  height: 20px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

.a11y-toggle:focus-visible,
.a11y-close:focus-visible,
.a11y-drawer input:focus-visible {
  outline: 3px solid #0066cc;
  outline-offset: 2px;
}

/* High contrast: black and white like everything else. */
.high-contrast .a11y-toggle,
.high-contrast .a11y-close {
  background: #000 !important;
  color: #fff !important;
  border: 3px solid #fff !important;
  box-shadow: none !important;
}
.high-contrast .a11y-toggle:hover,
.high-contrast .a11y-close:hover { background: #333 !important; }
.high-contrast .a11y-drawer .accessibility-panel { box-shadow: none !important; }
.high-contrast .a11y-toggle:focus-visible,
.high-contrast .a11y-close:focus-visible,
.high-contrast .a11y-drawer input:focus-visible { outline-color: #fff; }

/* Never print the button or panel. */
@media print {
  .a11y-dock { display: none !important; }
}


/* ---------- Reusable model panels (usable by any future model) ---------- */
.model-card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}
.model-card--controls { border-color: #CC0000; }
.model-card--results  { border-color: #0066cc; }

.model-card-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 14px;
}
.model-card--results .model-card-title { color: #0066cc; }

.model-readout {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px;
  margin: 8px 0;
  background: #f8f8f8;
  border-radius: 4px;
}
.model-readout-label { font-weight: 600; font-size: var(--fs-small, 0.9375rem); }
.model-readout-value { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.model-readout-note {
  margin: -4px 0 8px;
  padding: 0 10px;
  font-size: var(--fs-small, 0.9375rem);
  font-style: italic;
  line-height: 1.4;
  color: #4a4f57;
}

.model-note {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1.55;
}
.model-note p { margin: 0; }
.model-note--warn { background: #fff3cd; border: 1px solid #ffc107; color: #6b5003; }
.model-note--info { background: #e8f1fb; border: 1px solid #5b9bd5; color: #0b3d78; }

/* A quiet secondary button: green read as "correct", but these are resets
   and ordinary actions. The one main action on a page uses the accent. */
.model-reset-btn {
  background: #fff;
  color: #1f2328;
  border: 2px solid #8a9099;
  border-radius: 8px;
  padding: 10px 18px;
  min-height: 44px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.model-reset-btn:hover { border-color: #1f2328; background: #f3f4f6; }
.model-reset-btn:disabled { opacity: 0.5; cursor: default; }
.model-reset-btn:focus-visible { outline: 3px solid #0066cc; outline-offset: 2px; }

/* Text colour helpers (darkened so they pass WCAG AA on white) */
.is-red    { color: #CC0000; }
.is-orange { color: #a65200; }
.is-blue   { color: #0066cc; }
.is-green  { color: #1e7e44; }

/* High contrast for the panels above */
.high-contrast .model-card,
.high-contrast .model-readout,
.high-contrast .model-note,
.high-contrast .model-reset-btn {
  background: #000 !important;
  color: #fff !important;
  border: 2px solid #fff !important;
  box-shadow: none !important;
}
.high-contrast .model-reset-btn:hover { background: #333 !important; }

@media (max-width: 560px) {
  .model-card { padding: 14px; }
}
