/* ============================================================
   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; }
.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: 14px;
}
.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: #f9f1f1;
  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;
  padding: 10px 15px;
  background: #CC0000;
  color: white;
  border: 2px solid #CC0000;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.feedback-btn:hover {
  background: #B71C1C;
  transform: translateY(-2px);
}
.feedback-btn.selected { background: #8B0000; }

.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: 0.9rem;
  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: 0.9rem;
  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 {
  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; }

/* Accessibility panel now sits above the model title, so it needs a little
   breathing room beneath it rather than above. */
.viz-container > .accessibility-panel { margin: 0 0 18px; }
.viz-container > .model-title { margin-top: 0; }


/* ---------- 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.2rem;
  margin: 0 0 16px;
}
.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: 0.9rem; }
.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: 0.75rem;
  font-style: italic;
  line-height: 1.3;
  color: #595959;
}

.model-note {
  margin-top: 12px;
  padding: 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.4;
}
.model-note p { margin: 0; }
.model-note--warn { background: #fff3cd; border: 1px solid #ffc107; color: #6b5003; }
.model-note--info { background: #e3f2fd; border: 1px solid #2196f3; color: #0d47a1; }

.model-reset-btn {
  background: #1e7e44;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.model-reset-btn:hover { background: #196b3a; }
.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; }
}

/* ---------- Battery Capacity and C-Rate Explorer ---------- */
.battery-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}
.battery-canvas { display: block; width: 100%; }

.battery-control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 24px;
  align-items: end;
}
.battery-control label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.95rem;
}
.battery-control input[type="range"] { width: 100%; }
.battery-control-value {
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  margin-top: 6px;
}
.battery-control-sub {
  text-align: center;
  font-size: 0.95rem;
  color: #595959;
  margin-top: 2px;
}
.battery-control-sub span { font-weight: 600; }

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

@media (max-width: 900px) {
  .battery-layout { grid-template-columns: 1fr; }
  .battery-control-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .battery-columns { grid-template-columns: 1fr; gap: 0; }
}
@media (max-width: 560px) {
  .battery-control-grid { grid-template-columns: 1fr; gap: 18px; }
}

/* ===== EDLC model (edlc-animation.html) ===== */
.edlc-grid { display: grid; grid-template-columns: 1fr; gap: 20px; margin: 20px 0; }
@media (min-width: 1200px) { .edlc-grid { grid-template-columns: 1fr 1fr; } }
.edlc-grid > * { min-width: 0; }
.edlc-canvas { display: block; width: 100%; border-radius: 8px; }
.edlc-canvas--molecular { height: 580px; }
.edlc-canvas--energy { height: 350px; }
@media (min-width: 1200px) { .edlc-canvas--energy { height: 500px; } }
.edlc-state { text-align: center; font-weight: 600; min-height: 80px; display: flex;
  flex-direction: column; align-items: center; justify-content: center; margin: 16px 0; }
.edlc-buttons { display: flex; gap: 10px; }
.edlc-buttons .edlc-btn { flex: 1; }
.edlc-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.edlc-dashboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px; margin-top: 15px; }
@media (max-width: 600px) { .edlc-dashboard { grid-template-columns: 1fr; } }
.edlc-equation { text-align: center; font-size: 1.1rem; font-weight: 600; }
.edlc-slider input[type="range"] { width: 100%; touch-action: none; }