/* ==========================================================================
   Ohm Calc - feuille de styles

   Themes clair et sombre definis une seule fois grace a light-dark() :
   la page suit le systeme, et data-theme="light|dark" sur <html> force
   un theme (bouton de l'en-tete).
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Fond et surfaces */
  /* Theme clair "papier millimetre" : fond kraft clair, quadrillage orange a
     deux pas, cartes blanches en relief (bordures et ombres marquees) */
  --bg: light-dark(#f1eadf, #0c0f14);
  --bg-grid: light-dark(rgb(195 100 40 / 0.14), rgb(255 255 255 / 0.045));
  --bg-grid-fine: light-dark(rgb(195 100 40 / 0.05), transparent);
  --bg-glow: light-dark(rgb(205 105 45 / 0.06), rgb(227 162 90 / 0.07));
  --surface: light-dark(#ffffff, #141920);
  --surface-2: light-dark(#f7f1e8, #1a2029);
  --field: light-dark(#fdfbf8, #10141a);
  --border: light-dark(#dccfbd, #252c37);
  --border-strong: light-dark(#bfab92, #364050);

  /* Texte */
  --text: light-dark(#13100d, #e7eaf0);
  --text-2: light-dark(#463e35, #9ba4b4);
  --text-3: light-dark(#5c5349, #818999);

  /* Accent cuivre (marque) et etats */
  --accent: light-dark(#b0541a, #e3a25a);
  --danger: light-dark(#c0392b, #f28b7a);
  --ring: light-dark(rgb(30 26 22 / 0.35), rgb(231 234 240 / 0.4));

  /* Une couleur par grandeur, reprise par les cartes, le detail et la roue.
     Teintes claires choisies pour un contraste d'au moins 4,5:1 sur leurs pastilles. */
  --q-U: light-dark(#7d5800, #e6b450);
  --q-I: light-dark(#22609f, #6aa7f0);
  --q-R: light-dark(#1b6b4c, #5cc49e);
  --q-P: light-dark(#7044b5, #b79af2);

  /* Ombres. Sur fond sombre une ombre noire se voit peu : le relief y vient
     d'une ombre plus dense et d'un fin reflet clair sur le bord superieur. */
  --shadow-color: light-dark(rgb(70 45 20 / 0.14), rgb(0 0 0 / 0.55));
  --shadow-highlight: light-dark(transparent, rgb(255 255 255 / 0.05));
  --shadow: inset 0 1px 0 var(--shadow-highlight), 0 1px 2px var(--shadow-color), 0 10px 30px -18px var(--shadow-color);

  /* Typographie : polices du systeme, aucune dependance externe */
  --font-ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-math: "Cambria Math", "STIX Two Math", "Latin Modern Math", Cambria, Georgia, serif, math;

  /* Formes */
  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 9px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/*
 * Navigateurs sans light-dark() (Chrome < 123, Firefox < 120, Safari < 17.5) :
 * les couleurs ci-dessus y seraient invalides. Theme clair seulement, et le
 * bouton de theme est masque puisqu'il n'aurait aucun effet.
 */
@supports not (color: light-dark(#000, #fff)) {
  :root,
  :root[data-theme] {
    color-scheme: light;
    --bg: #f1eadf;
    --bg-grid: rgb(195 100 40 / 0.14);
    --bg-grid-fine: rgb(195 100 40 / 0.05);
    --bg-glow: rgb(205 105 45 / 0.06);
    --surface: #ffffff;
    --surface-2: #f7f1e8;
    --field: #fdfbf8;
    --border: #dccfbd;
    --border-strong: #bfab92;
    --text: #13100d;
    --text-2: #463e35;
    --text-3: #5c5349;
    --accent: #b0541a;
    --danger: #c0392b;
    --ring: rgb(30 26 22 / 0.35);
    --q-U: #7d5800;
    --q-I: #22609f;
    --q-R: #1b6b4c;
    --q-P: #7044b5;
    --shadow-color: rgb(70 45 20 / 0.14);
    --shadow-highlight: transparent;
  }

  /* Deux classes : doit l'emporter sur .icon-btn, defini plus bas */
  .icon-btn.theme-toggle {
    display: none;
  }
}

/* Couleur courante de chaque grandeur */
.q-U { --q: var(--q-U); }
.q-I { --q: var(--q-I); }
.q-R { --q: var(--q-R); }
.q-P { --q: var(--q-P); }

/* ----------------------------------------------------------------- Base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 50% -12%, var(--bg-glow), transparent 70%) fixed,
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  isolation: isolate;
}

/* Quadrillage facon papier millimetre, estompe vers le bas : traits forts
   tous les 32px, traits fins tous les 8px (transparents en theme sombre) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px),
    linear-gradient(var(--bg-grid-fine) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid-fine) 1px, transparent 1px);
  background-size: 32px 32px, 32px 32px, 8px 8px, 8px 8px;
  background-position: center top;
  -webkit-mask-image: radial-gradient(ellipse 90% 70% at 50% 0%, #000 25%, transparent 100%);
  mask-image: radial-gradient(ellipse 90% 70% at 50% 0%, #000 25%, transparent 100%);
}

button,
input,
select,
output {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:where(button, select, a):focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

svg {
  flex: none;
}

.page {
  width: min(1160px, 100% - 32px);
  margin-inline: auto;
  padding-block: 36px 40px;
}

@media (min-width: 640px) {
  .page {
    width: min(1160px, 100% - 64px);
    padding-block: 48px 48px;
  }
}

.noscript {
  padding: 14px 18px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
}

/* -------------------------------------------------------------- En-tete */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand__logo {
  display: grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 11%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--border));
  box-shadow: var(--shadow);
}

.brand__logo svg {
  width: 30px;
  height: 30px;
}

/* Chevron du menu Barbatools, colle au logo */
.brand barba-nav {
  margin-left: -12px;
}

.brand__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.65rem, 1.25rem + 1.3vw, 2.2rem);
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.brand__tagline {
  margin: 4px 0 0;
  color: var(--text-2);
  font-size: 0.95rem;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-2);
  box-shadow: var(--shadow);
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

/* Bouton de theme a trois etats : l'icone montre le mode en cours (A = auto) */
.theme-toggle svg {
  display: none;
}

.theme-toggle[data-mode="auto"] .icon-auto,
.theme-toggle[data-mode="light"] .icon-sun,
.theme-toggle[data-mode="dark"] .icon-moon {
  display: block;
}

/* ----------------------------------------------------------- Mise en page */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "calc"
    "details"
    "wheel";
  gap: 20px;
}

.calc { grid-area: calc; }
.details { grid-area: details; }
.wheel-panel { grid-area: wheel; }

@media (min-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1.4fr) minmax(340px, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "calc wheel"
      "details wheel";
    align-items: start;
    gap: 24px;
  }

  .wheel-panel {
    position: sticky;
    top: 24px;
  }
}

.panel {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.panel__title {
  margin: 0 0 16px;
  color: var(--text-2);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.panel__note {
  margin: 14px auto 0;
  max-width: 34ch;
  color: var(--text-3);
  font-size: 0.82rem;
  text-align: center;
}

/* Pastille de grandeur (cartes et detail) */
.symbol {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  color: var(--q);
  background: color-mix(in srgb, var(--q) 14%, transparent);
  font-family: var(--font-math);
  font-size: 1.15rem;
  font-style: italic;
  line-height: 1;
  transition: color 0.2s, background-color 0.2s;
}

/* --------------------------------------------------------------- Cartes */

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

@media (max-width: 420px) {
  .cards {
    grid-template-columns: minmax(0, 1fr);
  }
}

.card {
  padding: 14px 16px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: border-color 0.2s var(--ease);
}

.card[data-mode="input"] {
  border-color: color-mix(in srgb, var(--q) 38%, var(--border));
}

.card[data-mode="input"] .symbol {
  color: var(--surface);
  background: var(--q);
}

.card__head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  margin-bottom: 12px;
}

.card__label {
  font-weight: 600;
  font-size: 0.95rem;
}

.card__badge {
  margin-left: auto;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.card__badge:empty {
  display: none;
}

.card[data-mode="input"] .card__badge {
  color: var(--text-2);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
}

.card[data-mode="computed"] .card__badge {
  color: var(--q);
  background: color-mix(in srgb, var(--q) 14%, transparent);
}

/* Cadenas : une seule valeur verrouillee a la fois */
.card__lock {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  margin-right: -4px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-3);
  transition: color 0.15s, background-color 0.15s, border-color 0.15s, opacity 0.15s;
}

.card__badge:empty + .card__lock {
  margin-left: auto;
}

.card__lock svg {
  width: 17px;
  height: 17px;
}

.card__lock:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.card__lock .icon-locked,
.card__lock[aria-pressed="true"] .icon-unlocked {
  display: none;
}

.card__lock[aria-pressed="true"] .icon-locked {
  display: block;
}

.card__lock[aria-pressed="true"] {
  color: var(--q);
  background: color-mix(in srgb, var(--q) 14%, transparent);
  border-color: color-mix(in srgb, var(--q) 35%, transparent);
}

.card__lock[aria-disabled="true"] {
  opacity: 0.4;
  cursor: default;
}

.card__lock[aria-disabled="true"]:hover {
  color: var(--text-3);
  background: none;
  border-color: transparent;
}

.card[data-locked] {
  border-color: color-mix(in srgb, var(--q) 65%, var(--border));
  box-shadow: var(--shadow), 0 0 0 1px color-mix(in srgb, var(--q) 30%, transparent);
}

.card__field {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 58px;
  padding: 0 6px 0 14px;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.2s;
}

.card__field:hover {
  border-color: var(--border-strong);
}

.card__field:focus-within {
  border-color: var(--q);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--q) 22%, transparent);
}

.card__input {
  flex: 1;
  min-width: 0;
  padding: 10px 0;
  border: 0;
  outline: none;
  background: none;
  font-size: clamp(1.35rem, 1.1rem + 0.8vw, 1.7rem);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* Exemple de saisie : discret mais lisible (contraste 4,5:1), le "ex." le distingue d'une valeur */
.card__input::placeholder {
  color: var(--text-3);
  font-weight: 400;
  opacity: 1;
}

.card__unit {
  position: relative;
  flex: none;
  color: var(--text-2);
}

/* Chevron du menu d'unite */
.card__unit::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 11px;
  width: 6px;
  height: 6px;
  margin-top: -5px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.7;
  pointer-events: none;
}

.card__select {
  appearance: none;
  padding: 8px 27px 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  font-size: 1.05rem;
  font-weight: 500;
  transition: background-color 0.15s, color 0.15s;
}

.card__select:hover {
  background: var(--surface-2);
  color: var(--text);
}

.card__select:focus-visible {
  outline: 2px solid var(--q);
  outline-offset: 0;
}

.card__select option {
  color: var(--text);
  background: var(--surface);
}

/* Valeur calculee : champ teinte, chiffres dans la couleur de la grandeur */
.card[data-mode="computed"] .card__field {
  background: color-mix(in srgb, var(--q) 7%, var(--surface));
  border-color: color-mix(in srgb, var(--q) 26%, transparent);
}

.card[data-mode="computed"] .card__input,
.card[data-mode="computed"] .card__unit {
  color: var(--q);
}

.card[data-mode="computed"] .card__input {
  font-weight: 600;
}

/* L'exemple de saisie n'a pas de sens sur une valeur calculee (en erreur) */
.card[data-mode="computed"] .card__input::placeholder {
  color: transparent;
}

.card__message {
  min-height: 1.45em;
  margin: 6px 2px 0;
  color: var(--text-3);
  font-size: 0.8rem;
  line-height: 1.45;
}

.card[data-error] .card__message {
  color: var(--danger);
}

.card[data-hint] .card__message {
  color: var(--text-2);
}

.card[data-mode="input"][data-error] .card__field {
  border-color: var(--danger);
}

.card[data-mode="input"][data-error] .card__field:focus-within {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent);
}

/* ------------------------------------------------- Reglages et astuces */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-top: 14px;
  padding: 10px 10px 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stepper__label {
  color: var(--text-2);
  font-size: 0.9rem;
}

.stepper__control {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stepper__btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-2);
  transition: background-color 0.15s, color 0.15s, opacity 0.15s;
}

.stepper__btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.stepper__btn[aria-disabled="true"] {
  opacity: 0.35;
  cursor: default;
  background: none;
}

.stepper__btn svg {
  width: 16px;
  height: 16px;
}

/* Largeur de "10 chiffres" : les boutons ne bougent pas quand la valeur change */
.stepper__value {
  min-width: 6.6em;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.stepper__number {
  font-weight: 600;
}

.stepper__unit {
  color: var(--text-2);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.btn svg {
  width: 16px;
  height: 16px;
}

.hint {
  margin: 12px 6px 0;
  color: var(--text-3);
  font-size: 0.8rem;
  line-height: 1.9;
}

kbd {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-2);
  font-family: inherit;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* ----------------------------------------------------- Detail du calcul */

math {
  font-family: var(--font-math);
}

.details__list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 14px;
}

.details__list:empty {
  display: none;
}

/* Formules trop larges pour deux colonnes (voir fitDerivations dans assets/js/app.js) */
.details__list.is-stacked {
  grid-template-columns: minmax(0, 1fr);
}

.details__empty {
  margin: 0;
  padding: 22px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-3);
  font-size: 0.9rem;
  text-align: center;
}

.derivation {
  min-width: 0;
  padding: 14px 16px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.derivation__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.derivation__name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

/*
 * Lignes d'egalites alignees : R | = U / I, puis = valeurs, puis = resultat.
 * Pas de zone de defilement : les formules MathML depassent souvent d'un ou
 * deux pixels en hauteur, ce qui suffirait a faire apparaitre des barres.
 * Une ligne trop large est mise a l'echelle par assets/js/app.js (fitDerivations).
 */
.derivation__rows {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 0.3em;
  font-size: 1.2rem;
}

.derivation__rows math {
  justify-self: start;
}

.qvar {
  color: var(--q);
}

.derivation__result {
  color: var(--q);
}

.derivation__error {
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
}

.derivation__origin {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--text-2);
  font-size: 0.82rem;
}

.derivation__origin math {
  font-size: 1.1em;
}

.derivation__origin .qvar {
  color: inherit;
}

/* ------------------------------------------------------------------ Roue */

.wheel {
  max-width: 400px;
  margin-inline: auto;
}

.wheel__svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.wheel__sector {
  transition: opacity 0.25s var(--ease);
}

.wheel__sector path {
  fill: var(--surface-2);
  stroke: var(--surface);
  stroke-width: 3;
  transition: fill 0.25s var(--ease);
}

.wheel__formula {
  fill: var(--text-2);
  font-family: var(--font-math);
  font-size: 17px;
  text-anchor: middle;
  dominant-baseline: central;
  transition: fill 0.25s var(--ease);
}

.wheel__var {
  font-style: italic;
}

.wheel__svg.is-active .wheel__sector:not(.is-used) {
  opacity: 0.4;
}

.wheel__sector.is-used path {
  fill: color-mix(in srgb, var(--q) 22%, var(--surface));
}

.wheel__sector.is-used .wheel__formula {
  fill: var(--q);
}

.wheel__core {
  cursor: pointer;
}

.wheel__core path {
  fill: color-mix(in srgb, var(--q) 10%, var(--surface));
  stroke: var(--surface);
  stroke-width: 3;
  transition: fill 0.25s var(--ease);
}

.wheel__core:hover path {
  fill: color-mix(in srgb, var(--q) 18%, var(--surface));
}

.wheel__core[data-mode="computed"] path {
  fill: color-mix(in srgb, var(--q) 22%, var(--surface));
}

.wheel__core[data-mode="input"] path {
  fill: var(--q);
}

.wheel__letter {
  fill: var(--q);
  font-family: var(--font-math);
  font-size: 30px;
  font-style: italic;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  transition: fill 0.25s var(--ease);
}

.wheel__core[data-mode="input"] .wheel__letter {
  fill: var(--surface);
}

.wheel__lock {
  display: none;
  fill: none;
  stroke: var(--surface);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.wheel__core.is-locked .wheel__lock {
  display: inline;
}

.wheel__hub {
  fill: var(--surface);
  stroke: var(--border-strong);
  stroke-width: 1.5;
}

/* ---------------------------------------------------------- Pied de page */

.site-footer {
  margin-top: 28px;
  color: var(--text-3);
  font-size: 0.8rem;
  text-align: center;
}

.site-footer p {
  margin: 0;
}

/* Premier affichage et changement de theme : tout bascule d'un coup (voir assets/js/theme.js) */
.no-transitions *,
.no-transitions *::before,
.no-transitions *::after {
  transition: none !important;
}

/* --------------------------------------------------------- Accessibilite */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
