/* =====================================================================
   Meca-widgets — styles of the interactive figures of the MECENCLI course
   ---------------------------------------------------------------------
   Loaded only on the course pages (teaching/mecencli/_metadata.yml).
   Colours are CSS variables (section 1): change them here, nowhere else.
   Dark mode: Quarto adds `body.quarto-dark` when the toggle is on.

     1. Variables (colours)          5. Buttons & status line
     2. Widget frame                 6. Drawings (SVG)
     3. Symbols (σ_xx, vectors…)     7. Widget-specific bits
     4. Matrices & animated cells    8. Small screens
   ===================================================================== */

/* 1. VARIABLES -------------------------------------------------------- */
:root {
  --mw-ink: #031C59;          /* main text / outlines (site navy) */
  --mw-muted: #8a94ad;        /* zeros, reference shapes */
  --mw-grid: rgba(3, 28, 89, .12);
  --mw-bg: #ffffff;
  --mw-panel: #f4f8fc;
  --mw-pos: #D66547;          /* traction (> 0) — site red */
  --mw-neg: #008BD2;          /* compression (< 0) — site blue */
  --mw-shear: #8E44AD;        /* shear / off-diagonal terms */
  --mw-n: #D99A00;            /* normal vector n */
  --mw-T: #0F8B6E;            /* stress vector T */
  --mw-u: #E07B00;            /* displacements u */
  --mw-a: #0F8B6E;            /* material vector along E_x */
  --mw-b: #C2185B;            /* material vector along E_y */
  --mw-hl: #008BD2;           /* highlight */
  --mw-c1: #1f6fd1;           /* matrix-vector product: column 1 */
  --mw-c2: #1a9e5a;           /* column 2 */
  --mw-c3: #e0a100;           /* column 3 */
  --mw-radius: 14px;
  --mw-font-math: "STIX Two Math", "Cambria Math", "Latin Modern Math", "Times New Roman", serif;
}
body.quarto-dark {
  --mw-ink: #f3f3f3;
  --mw-muted: #9fb0d8;
  --mw-grid: rgba(153, 221, 255, .18);
  --mw-bg: #2d4180;
  --mw-panel: #24366f;
  --mw-pos: #ff8a6b;
  --mw-neg: #6cd0ff;
  --mw-shear: #d7a6f0;
  --mw-n: #ffd25e;
  --mw-T: #4fe0b4;
  --mw-u: #ffad5c;
  --mw-a: #4fe0b4;
  --mw-b: #ff8fbd;
  --mw-hl: #99ddff;
  --mw-c1: #8ab8ff;
  --mw-c2: #6fe0a0;
  --mw-c3: #ffd25e;
}

/* 2. FRAME ------------------------------------------------------------ */
.mw {
  margin: 1.6rem 0 1.8rem;
  border: 1px solid var(--mw-grid);
  border-left: 5px solid var(--mw-ink);
  border-radius: var(--mw-radius);
  background: var(--mw-bg);
  box-shadow: 0 6px 18px rgba(3, 28, 89, .08);
  text-align: left;
  overflow: hidden;
}
body.quarto-dark .mw { border-left-color: #99ddff; }
.mw-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .7rem 1rem .5rem; border-bottom: 1px solid var(--mw-grid);
}
.mw-title { font-weight: 600; color: var(--mw-ink); font-size: 1rem; }
.mw-hint { font-size: .82rem; opacity: .75; }
.mw-body { display: flex; flex-wrap: wrap; gap: 1rem; padding: .8rem 1rem; align-items: center; justify-content: center; }
.mw-body > .mw-draw { flex: 1 1 270px; max-width: 460px; }
.mw-body > .mw-panel { flex: 1 1 280px; }
.mw-panel {
  background: var(--mw-panel); border-radius: 10px; padding: .8rem 1rem;
  display: flex; flex-direction: column; gap: .7rem; align-items: center;
}
.mw-row { display: flex; align-items: center; justify-content: center; gap: .6rem; flex-wrap: wrap; }
.mw-foot { padding: .2rem 1rem .9rem; display: flex; flex-direction: column; gap: .5rem; }
.mw-caption { padding: 0 1rem .8rem; font-size: .92rem; opacity: .9; }
.mw-caption > :last-child { margin-bottom: 0; }
.mw-noscript { font-style: italic; opacity: .7; }

/* 3. SYMBOLS ---------------------------------------------------------- */
.mw-m { font-family: var(--mw-font-math); font-size: 1.12em; white-space: nowrap; }
.mw-status .mw-m, .mw-lines .mw-m { white-space: normal; }
.mw-lines { display: flex; flex-direction: column; gap: .35rem; align-items: center; text-align: center; }
.mw-m i { font-style: italic; }
.mw-m sub, .mw-m sup { font-size: .68em; font-style: normal; }
.mw-m sub { vertical-align: -0.35em; }
.mw-vec { position: relative; display: inline-block; padding-top: .3em; }
.mw-vec::before {
  content: ""; position: absolute; left: 8%; right: 0; top: .16em; height: 0;
  border-top: 1.3px solid currentColor;
}
.mw-vec::after {
  content: ""; position: absolute; right: -1px; top: .16em; width: .28em; height: .28em;
  border-top: 1.3px solid currentColor; border-right: 1.3px solid currentColor;
  transform: translateY(-50%) rotate(45deg); transform-origin: center;
}
.mw-tens { border-bottom: 3px double currentColor; line-height: 1; display: inline-block; padding-bottom: 1px; }
.mw-frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.05; margin: 0 .08em; }
.mw-frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 .15em .2em; }
.mw-frac sub { vertical-align: -.18em; }
.mw-sqrt { display: inline-flex; align-items: stretch; vertical-align: bottom; }
.mw .mw-sqrt > svg { width: .5em; height: 1.22em; flex: none; overflow: visible; display: block; align-self: flex-end; }
.mw-sqrt > .mw-rad { border-top: 1.3px solid currentColor; padding: .06em .08em 0 .04em; line-height: 1.1; }
.mw-frac > span:last-child { padding: .12em .15em 0; }

/* 4. MATRICES --------------------------------------------------------- */
.mw-eq { display: inline-flex; align-items: center; gap: .45rem; flex-wrap: wrap; justify-content: center; }
.mw-eq > .mw-op { font-family: var(--mw-font-math); font-size: 1.25em; }
.mw-mat {
  position: relative; display: inline-grid; gap: .25rem .35rem; padding: .3rem .75rem;
  font-family: var(--mw-font-math);
}
.mw-mat::before, .mw-mat::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: .45rem;
  border: 2px solid var(--mw-ink); border-radius: 2px;
}
.mw-mat::before { left: 0; border-right: none; }
.mw-mat::after { right: 0; border-left: none; }
.mw-mat.paren::before { border-radius: 1rem 0 0 1rem; border-top-color: transparent; border-bottom-color: transparent; }
.mw-mat.paren::after { border-radius: 0 1rem 1rem 0; border-top-color: transparent; border-bottom-color: transparent; }
.mw-cell {
  position: relative; min-width: 3.6em; min-height: 2.3em; padding: .25em .35em;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 8px; font-size: 1.08em; color: var(--mw-ink);
  transition: background-color .35s, color .35s, box-shadow .35s, transform .35s, opacity .35s;
  cursor: default; user-select: none;
}
.mw-mat.small .mw-cell { min-width: 2.6em; min-height: 1.9em; font-size: 1em; }
.mw-cell .mw-badge { font-size: .6em; font-family: system-ui, sans-serif; opacity: .85; line-height: 1; margin-top: .35em; }
.mw-cell .mw-badge:empty { display: none; }
.mw-cell[data-state="zero"] { color: var(--mw-muted); }
.mw-cell[data-state="one"]  { color: var(--mw-muted); }
.mw-cell[data-state="plain"]{ color: var(--mw-ink); }
.mw-cell[data-state="on"]   { color: var(--mw-hl);    background: color-mix(in srgb, var(--mw-hl) 14%, transparent); }
.mw-cell[data-state="pos"]  { color: var(--mw-pos);   background: color-mix(in srgb, var(--mw-pos) 15%, transparent); }
.mw-cell[data-state="neg"]  { color: var(--mw-neg);   background: color-mix(in srgb, var(--mw-neg) 15%, transparent); }
.mw-cell[data-state="shear"]{ color: var(--mw-shear); background: color-mix(in srgb, var(--mw-shear) 15%, transparent); }
.mw-cell[data-state="c1"] { color: var(--mw-c1); }
.mw-cell[data-state="c2"] { color: var(--mw-c2); }
.mw-cell[data-state="c3"] { color: var(--mw-c3); }
.mw-cell.clickable { cursor: pointer; }
.mw-cell.clickable:hover { box-shadow: 0 0 0 2px var(--mw-grid) inset; }
.mw-cell.focus { box-shadow: 0 0 0 2.5px currentColor; transform: scale(1.08); z-index: 1; }
.mw-cell.dim { opacity: .35; }
.mw-cell.ring { outline: 2px dashed currentColor; outline-offset: 1px; }
.mw-cell.flip { animation: mw-flip .45s ease; }
@keyframes mw-flip { 0% { transform: scale(.6); opacity: .2; } 60% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
.mw-cell.pulse { animation: mw-pulse .9s ease; }
@keyframes mw-pulse { 0%,100% { box-shadow: 0 0 0 0 currentColor; } 40% { box-shadow: 0 0 0 5px color-mix(in srgb, currentColor 30%, transparent); } }
.mw-matlabel { font-family: var(--mw-font-math); font-size: 1.15em; white-space: nowrap; }
.mw-fly {
  position: absolute; z-index: 5; pointer-events: none; font-family: var(--mw-font-math);
  padding: .1em .3em; border-radius: 6px; background: var(--mw-bg); box-shadow: 0 2px 8px rgba(0,0,0,.18);
  transition: transform .7s cubic-bezier(.45,.05,.3,1), opacity .3s;
}
.mw-sum { display: inline-flex; gap: .25em; align-items: center; flex-wrap: nowrap; }
.mw-term { padding: 0 .1em; border-radius: 4px; }
.mw-term.new { animation: mw-flip .45s ease; }

/* 5. BUTTONS & STATUS ------------------------------------------------- */
.mw-btns { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }
.mw-btn {
  border: 1px solid var(--mw-grid); background: var(--mw-bg); color: var(--mw-ink);
  border-radius: 999px; padding: .22rem .75rem; font-size: .84rem; cursor: pointer;
  transition: background-color .2s, border-color .2s, transform .15s;
}
.mw-btn:hover { border-color: var(--mw-hl); transform: translateY(-1px); }
.mw-btn.active { background: var(--mw-ink); color: var(--mw-bg); border-color: var(--mw-ink); }
body.quarto-dark .mw-btn.active { background: #99ddff; color: #031C59; }
.mw-btn:disabled { opacity: .4; cursor: default; transform: none; }
.mw-status {
  min-height: 2.6em; font-size: .93rem; text-align: center; line-height: 1.45;
  padding: .35rem .6rem; border-radius: 8px; background: color-mix(in srgb, var(--mw-hl) 8%, transparent);
  width: 100%;
}
.mw-status b { color: var(--mw-ink); }
.mw-toast {
  font-size: .85rem; padding: .35rem .7rem; border-radius: 8px; text-align: center;
  background: color-mix(in srgb, var(--mw-shear) 14%, transparent); color: var(--mw-ink);
  opacity: 0; transform: translateY(4px); transition: opacity .3s, transform .3s; width: 100%;
}
.mw-toast.show { opacity: 1; transform: none; }
.mw-legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; justify-content: center; font-size: .8rem; opacity: .9; }
.mw-legend > span::before { content: ""; display: inline-block; width: .8em; height: .8em; border-radius: 3px; margin-right: .3em; vertical-align: -.08em; background: var(--c); }
.mw-switch { display: inline-flex; align-items: center; gap: .35rem; font-size: .84rem; cursor: pointer; user-select: none; }
.mw-slider { width: 100%; max-width: 320px; accent-color: var(--mw-hl); }

/* 6. DRAWINGS --------------------------------------------------------- */
.mw svg { width: 100%; height: auto; display: block; overflow: visible; font-family: var(--mw-font-math); }
.mw svg text { fill: var(--mw-ink); font-size: 15px; paint-order: stroke; stroke: var(--mw-bg); stroke-width: 3px; stroke-linejoin: round; }
.mw svg text.small { font-size: 12px; }
.mw svg text.ui { font-family: system-ui, sans-serif; font-size: 11px; opacity: .8; }
.mw svg .axis { stroke: var(--mw-ink); stroke-width: 1.4; fill: none; }
.mw svg .ref { stroke: var(--mw-muted); stroke-width: 1.5; stroke-dasharray: 5 4; fill: none; }
.mw svg .body { stroke: var(--mw-ink); stroke-width: 2; fill: color-mix(in srgb, var(--mw-hl) 10%, transparent); }
.mw svg .face { stroke: transparent; stroke-width: 14; cursor: pointer; }
.mw svg .face:hover { stroke: color-mix(in srgb, var(--mw-hl) 25%, transparent); }
.mw svg .arrow { stroke-width: 2.6; fill: none; stroke-linecap: round; }
.mw svg .arrow.thin { stroke-width: 1.6; stroke-dasharray: 4 3; }
.mw svg .handle { cursor: grab; touch-action: none; }
.mw svg .handle:active { cursor: grabbing; }
.mw svg .handle circle.hit { fill: transparent; }
.mw svg .handle circle.dot { stroke: var(--mw-bg); stroke-width: 2; transition: r .15s; }
.mw svg .handle:hover circle.dot { r: 8; }
.mw svg .ghost { opacity: .35; }
.mw svg .glow { filter: drop-shadow(0 0 3px var(--mw-hl)); }
.mw svg .hint-ring { fill: none; stroke: var(--mw-hl); stroke-width: 2; opacity: 0; animation: mw-ring 2.4s ease-out 1s 3; pointer-events: none; }
@keyframes mw-ring { 0% { r: 8; opacity: .9; } 100% { r: 26; opacity: 0; } }
.mw svg .fiber { fill: none; stroke: var(--mw-pos); stroke-width: 2; }
.mw svg .wall { fill: url(#mw-hatch); stroke: var(--mw-ink); stroke-width: 1.5; }
.mw svg .hatch-line { stroke: var(--mw-ink); stroke-width: 1; }

/* 7. WIDGET-SPECIFIC -------------------------------------------------- */
.mw-steps { display: flex; gap: .35rem; justify-content: center; flex-wrap: wrap; font-size: .8rem; }
.mw-steps span { padding: .1rem .55rem; border-radius: 999px; border: 1px solid var(--mw-grid); opacity: .6; }
.mw-steps span.on { opacity: 1; border-color: var(--mw-hl); color: var(--mw-hl); font-weight: 600; }
.mw-pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; font-family: system-ui, sans-serif; border: 1px solid currentColor; }
.mw-pill.ok { color: var(--mw-T); }
.mw-pill.warn { color: var(--mw-pos); }

/* Playground (pg-* widgets, page playground.qmd): numbers typed in the matrices */
.mw[data-widget^="pg-"] { scroll-margin-top: 4.5rem; }   /* « Envoyer … » scrolls here, below the navbar */
.mw-mat.pg-edit .mw-cell { padding: .12em .2em; user-select: auto; cursor: text; }
.mw .pg-in {
  width: 4.7em; min-width: 0; margin: 0; padding: .12em 0;
  border: none; border-bottom: 1.5px dashed currentColor; border-radius: 0; box-shadow: none; outline: none;
  background: transparent; color: inherit; font: inherit; font-family: var(--mw-font-math); text-align: center;
}
.mw .pg-in:focus { border-bottom-style: solid; }
.mw-mat.pg-edit .mw-cell:focus-within { box-shadow: 0 0 0 2px var(--mw-hl) inset; }
.mw .mw-cell.pg-bad, .mw .pg-field.pg-bad { box-shadow: 0 0 0 2px var(--mw-pos) inset; border-radius: 8px; }
.pg-field { display: inline-flex; align-items: baseline; gap: .35em; padding: .1em .35em; font-size: .95rem; cursor: text; }
.pg-field .pg-in { width: 5.4em; }
.pg-unit { font-family: system-ui, sans-serif; font-size: .78rem; opacity: .75; }
.pg-val { font-size: .93rem; padding: .05em .35em; border-radius: 6px; }
.pg-val:empty { display: none; }
.pg-val.clickable, .pg-out .mw-cell.clickable { cursor: help; }
.pg-val.clickable:hover { background: color-mix(in srgb, var(--mw-hl) 12%, transparent); }
.pg-out .mw-cell { min-width: 3.9em; }
.pg-sec {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: .45rem;
  padding-top: .55rem; border-top: 1px solid var(--mw-grid);
}
.mw-panel > .pg-sec:first-child { border-top: none; padding-top: 0; }
.pg-sec-title { align-self: flex-start; font-size: .8rem; font-weight: 600; opacity: .8; }
.pg-sec-title:empty { display: none; }
.pg-rowlab { align-self: center; margin-right: .15rem; font-size: .8rem; opacity: .75; }
.pg-mohr { width: 100%; max-width: 380px; margin: .3rem auto 0; }

/* Long display equations: on a narrow screen they scroll sideways
   instead of running under the table of contents */
.math.display, mjx-container[display="true"] { max-width: 100%; overflow-x: auto; overflow-y: hidden; }

/* Course pages: menus and table of contents read better left-aligned */
#quarto-sidebar .sidebar-item-text, #TOC a, .breadcrumb { text-align: left !important; hyphens: manual !important; }

/* Static "flow" diagram (chapter 1), on a fixed grid so that it never wraps badly:
     Forces appliquées     →  Contraintes σ
                                 ⇅ loi de comportement
     Déplacements imposés  →  Déformations C, ε                                */
.mw-flow {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-areas: "f a1 s" ". . law" "d a2 e";
  gap: .35rem .6rem; align-items: center; max-width: 540px; margin: 1.4rem auto .4rem;
  text-align: center; hyphens: none;
}
.mw-flow > p { display: contents; }
.mw-flow .f { grid-area: f; } .mw-flow .a1 { grid-area: a1; } .mw-flow .s { grid-area: s; }
.mw-flow .law { grid-area: law; }
.mw-flow .d { grid-area: d; } .mw-flow .a2 { grid-area: a2; } .mw-flow .e { grid-area: e; }
.mw-flow .box { border: 1.5px solid var(--mw-ink); border-radius: 10px; padding: .5rem .7rem; background: var(--mw-panel); line-height: 1.25; text-align: center; }
.mw-flow small { display: block; font-size: .75em; opacity: .75; }
.mw-flow .s { border-color: var(--mw-pos); }
.mw-flow .e { border-color: var(--mw-T); }
.mw-flow .arr { font-size: 1.35rem; color: var(--mw-ink); line-height: 1; }
.mw-flow .law { display: flex; align-items: center; justify-content: center; gap: .45rem; font-size: .85rem; line-height: 1.2; text-align: left; color: var(--mw-ink); }
.mw-flow .law .arr { font-size: 1.35rem; }
.mw-flow .law small { opacity: .7; }
.mw-flow-cap { display: block; text-align: center; font-size: .85rem; opacity: .75; margin-bottom: 1rem; }

/* 8. SMALL SCREENS ---------------------------------------------------- */
@media (max-width: 576px) {
  .mw-body { padding: .6rem .5rem; }
  .mw-cell { min-width: 2.9em; font-size: .98em; }
  .mw-panel { padding: .6rem .5rem; }
}
