/* Polices du portfolio Omni-système (thème « Violet Nuit »), copiées dans
   l'application : elles marchent sans internet, aucun site n'est contacté.
   Licence : SIL Open Font License 1.1 (fichier POLICES-OFL.txt). */
@font-face {
  font-family: "Oxanium";
  src: url("./oxanium.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Literata";
  src: url("./literata.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("./jetbrains-mono.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

:root,
:root[data-theme="clair"] {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #edf1f8;
  --key: #ffffff;
  --key-hover: #e6ebf5;
  --text: #172033;
  --muted: #596579;
  --border: #d5dcea;
  --accent: #3155c6;
  --accent-contrast: #ffffff;
  --equal-bg: #3155c6;
  --equal-text: #ffffff;
  --danger: #a91d24;
  --shadow: 0 12px 35px rgb(32 48 80 / 10%);
}

:root[data-theme="sombre"] {
  color-scheme: dark;
  --bg: #0f141b;
  --surface: #171e28;
  --surface-2: #202936;
  --key: #222d3b;
  --key-hover: #2c3949;
  --text: #f2f5fa;
  --muted: #b0bdcd;
  --border: #344255;
  --accent: #a9c1ff;
  --accent-contrast: #101828;
  --equal-bg: #4269c8;
  --equal-text: #ffffff;
  --danger: #ffaaa5;
  --shadow: 0 14px 40px rgb(0 0 0 / 28%);
}

/*
 * « Violet Nuit » : mêmes couleurs et mêmes polices que le portfolio
 * Omni-système (fond #14111d, surfaces #1d1929, violet du logo #a777ff).
 */
:root[data-theme="nuit"] {
  color-scheme: dark;
  --bg: #14111d;
  --surface: #1d1929;
  --surface-2: #14111d;
  --key: #262036;
  --key-hover: #302945;
  --text: #e9e4f2;
  --muted: #a59cbb;
  --border: #332c47;
  --accent: #a777ff;
  --accent-contrast: #140d24;
  --halo: #d6c2ff;
  --equal-bg: #a777ff;
  --equal-text: #140d24;
  --danger: #ff8fa3;
  --shadow: 0 16px 45px rgb(0 0 0 / 40%);
  --f-titre: "Oxanium", "Trebuchet MS", system-ui, sans-serif;
  --f-texte: "Literata", Georgia, "Times New Roman", serif;
  --f-chiffres: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 280px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at top right, color-mix(in srgb, var(--accent) 9%, transparent), transparent 38%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  width: min(920px, calc(100% - 16px));
  margin: 0 auto;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0;
}

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

.brand-logo {
  display: grid;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1.65rem;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.15rem, 4vw, 1.55rem);
  line-height: 1.15;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.header-actions,
.theme-control {
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-actions {
  flex-wrap: wrap;
}

.theme-control label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

select,
input {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
}

select {
  padding: 0 34px 0 11px;
}

input {
  padding: 0 13px;
}

.theme-control select {
  width: auto;
  max-width: 270px;
  min-height: 44px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
}

.tab {
  min-width: 0;
  min-height: 48px;
  padding: 8px 4px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}

.tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
}

.panel {
  padding: clamp(12px, 3vw, 24px);
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.calculator-layout {
  display: grid;
  gap: 22px;
}

.calculator {
  min-width: 0;
}

.calculator-screen {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  margin-bottom: 12px;
  padding: 15px 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-2);
  color: var(--text);
  text-align: right;
  cursor: copy;
  -webkit-tap-highlight-color: transparent;
}

.calculator-screen:active {
  border-color: var(--accent);
}

.copy-hint {
  position: absolute;
  top: 8px;
  left: 12px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0.75;
  text-transform: uppercase;
}

.calc-expression {
  display: block;
}

.calc-expression {
  min-height: 1.5em;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.95rem;
}

.calc-display {
  display: block;
  max-width: 100%;
  min-height: 1.25em;
  overflow-x: auto;
  color: var(--text);
  font-size: clamp(2rem, 9vw, 3.4rem);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  scrollbar-width: thin;
}

.scientific-keys,
.keypad {
  display: grid;
  gap: 7px;
}

.scientific-keys {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 7px;
}

.keypad {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.key {
  min-width: 0;
  min-height: 57px;
  padding: 7px 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--key);
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.key.scientific {
  min-height: 48px;
  background: var(--surface-2);
  font-size: 0.95rem;
}

.key.utility {
  color: var(--muted);
}

.key.operator {
  color: var(--accent);
  font-size: 1.35rem;
}

.key.danger {
  color: var(--danger);
}

.key.equal {
  border-color: transparent;
  background: var(--equal-bg);
  color: var(--equal-text);
  font-size: 1.45rem;
}

.key:active {
  transform: scale(0.965);
}

@media (hover: hover) {
  .key:hover {
    background: var(--key-hover);
  }

  .key.equal:hover {
    background: var(--equal-bg);
    filter: brightness(1.08);
  }
}

.history {
  min-width: 0;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.history-header {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.history h2,
.converter h2 {
  margin: 14px 0 4px;
  font-size: 1.15rem;
}

.history-help,
.section-intro,
.small-note {
  color: var(--muted);
  font-size: 0.87rem;
}

.history-help {
  margin: 5px 0;
}

.text-button {
  min-width: 48px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

.history-list {
  max-height: 330px;
  margin: 6px 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.history-list li {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
}

.history-list li.history-empty {
  display: list-item;
  border-bottom: 0;
}

.history-copy {
  flex: 0 0 48px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
}

@media (hover: hover) {
  .history-copy:hover {
    color: var(--accent);
  }
}

.history-entry {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  min-height: 58px;
  padding: 9px 6px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.history-entry span,
.history-entry strong {
  display: block;
  overflow-wrap: anywhere;
}

.history-entry span {
  color: var(--muted);
  font-size: 0.82rem;
}

.history-entry strong {
  margin-top: 2px;
  color: var(--accent);
  font-size: 1.05rem;
}

.history-empty {
  padding: 18px 4px;
  color: var(--muted);
  list-style: none;
}

.converter {
  max-width: 650px;
  margin: 0 auto;
}

.converter h2 {
  margin-top: 2px;
  font-size: 1.45rem;
}

.section-intro {
  margin-top: 4px;
}

.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
}

.field label,
.field legend,
.field-label {
  font-size: 0.9rem;
  font-weight: 750;
}

.field-head {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
}

.star-button {
  min-width: 36px;
  min-height: 30px;
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: 1.25rem;
  line-height: 1;
}

.favorite-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.copyable {
  cursor: copy;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}

.copyable:active {
  opacity: 0.7;
}

/* Interrupteur « Vibrer à chaque touche » */
.switch {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
}

.switch input {
  width: 22px;
  min-height: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

.currency-selects {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.swap-button {
  width: 48px;
  min-width: 48px;
  height: 50px;
  margin-bottom: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 1.35rem;
}

#unit-result {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: var(--accent);
  font-size: clamp(1.5rem, 6.5vw, 2.4rem);
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

/* ------------------------------------------------------------------
   Outils
------------------------------------------------------------------ */

.tools {
  display: grid;
  gap: 18px;
  max-width: 650px;
  margin: 0 auto;
}

.tool {
  padding: 4px 0 20px;
  border-bottom: 1px solid var(--border);
}

.tool:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.tool h2 {
  margin: 2px 0 0;
  font-size: 1.25rem;
}

.tool .section-intro {
  margin: 4px 0 0;
}

fieldset.field {
  margin-inline: 0;
  padding: 0;
  border: 0;
}

fieldset.field legend {
  margin-bottom: 6px;
  padding: 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  min-width: 56px;
  min-height: 42px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
}

.chip[aria-pressed="true"] {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-contrast);
}

.inline-field {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.inline-field input {
  width: 6em;
  min-height: 42px;
}

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

.stepper-button {
  width: 48px;
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 700;
}

#people-count {
  min-width: 2.5ch;
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  text-align: center;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.tool-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin: 16px 0 0;
}

.tool-results div {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.tool-results dt {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.tool-results dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.tool-results .main-result dd {
  color: var(--accent);
  font-size: 1.45rem;
}

.tool-question {
  margin: 16px 0 0;
  line-height: 2.6;
}

.mini-input {
  display: inline-block;
  width: 5.5em;
  min-height: 42px;
  padding: 0 8px;
  text-align: center;
}

.tool-answer {
  margin: 2px 0 0;
}

.tool-answer output {
  display: inline-block;
  padding: 2px 4px;
  color: var(--accent);
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

/* ------------------------------------------------------------------
   Message « Copié » et bandeau de mise à jour
------------------------------------------------------------------ */

.toast {
  position: fixed;
  z-index: 20;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.92rem;
  font-weight: 700;
  pointer-events: none;
  transform: translateX(-50%);
  box-shadow: var(--shadow);
}

.toast.visible {
  animation: toast-in 0.18s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

.update-banner {
  position: fixed;
  z-index: 30;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.update-banner button {
  min-height: 42px;
  padding: 6px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 750;
}

/* Bouton rond « i » à côté du thème, et fenêtre « À propos » */
.about-button {
  display: grid;
  width: 44px;
  min-height: 44px;
  padding: 0;
  place-items: center;
}


.about-dialog {
  width: min(460px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Marge sur le formulaire : un appui sur le fond (hors formulaire) ferme. */
.about-dialog form {
  padding: 24px;
}

.about-dialog::backdrop {
  background: rgb(0 0 0 / 45%);
}

.about-dialog h2 {
  margin: 14px 0 2px;
  font-size: 1.35rem;
}

.about-dialog p {
  color: var(--muted);
  line-height: 1.55;
}

.about-dialog .about-version {
  margin-top: 0;
  font-size: 0.88rem;
  font-weight: 700;
}

.about-credit {
  margin: 18px 0;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface-2);
}

.about-credit p {
  margin: 0 0 10px;
  color: var(--text);
}

.about-credit a {
  color: inherit;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}

.about-credit .about-link {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  text-align: center;
  text-decoration: none;
}

.about-close {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 750;
}

.conversion-card {
  margin-top: 22px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-2);
}

.conversion-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

#conversion-result {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: var(--accent);
  font-size: clamp(1.65rem, 7vw, 2.6rem);
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.unit-rate {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.rate-actions {
  display: flex;
  margin-top: 16px;
}

.button-secondary {
  min-height: 46px;
  padding: 8px 15px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
}

.rate-status {
  min-height: 2.8em;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.small-note {
  margin-bottom: 0;
}

footer {
  padding: 18px 8px 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.noscript-message {
  margin: 20px;
  padding: 16px;
  border: 2px solid #a91d24;
  background: #ffffff;
  color: #172033;
}

@media (min-width: 760px) {
  .calculator-layout {
    grid-template-columns: minmax(0, 1.45fr) minmax(240px, 0.8fr);
    gap: 26px;
  }

  .history {
    padding-top: 0;
    padding-left: 22px;
    border-top: 0;
    border-left: 1px solid var(--border);
  }

  .history h2 {
    margin-top: 2px;
  }

  .keypad,
  .scientific-keys {
    gap: 9px;
  }

  .key {
    min-height: 62px;
  }
}

/*
 * Téléphones : « De » et « Vers » l'un sous l'autre, pour lire le nom
 * entier des devises et des unités ; le bouton d'inversion passe à droite.
 */
@media (max-width: 520px) {
  .currency-selects {
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 10px;
    row-gap: 0;
  }

  .currency-selects .field:first-child {
    grid-row: 1;
    grid-column: 1;
  }

  .currency-selects .field:last-child {
    grid-row: 2;
    grid-column: 1;
  }

  .currency-selects .swap-button {
    grid-row: 1 / span 2;
    grid-column: 2;
    align-self: center;
    margin-top: 40px;
    transform: rotate(90deg);
  }
}

@media (max-width: 380px) {
  .tab {
    font-size: 0.88rem;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .theme-control label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .brand p {
    display: none;
  }

  .key {
    min-height: 54px;
  }

  .currency-selects {
    gap: 5px;
  }
}

/* ------------------------------------------------------------------
   Violet Nuit : typographie du portfolio
   Oxanium pour les titres et commandes, Literata pour les textes,
   JetBrains Mono pour les nombres.
------------------------------------------------------------------ */

:root[data-theme="nuit"] body {
  background:
    radial-gradient(circle at top right, color-mix(in srgb, var(--accent) 7%, transparent), transparent 38%),
    var(--bg);
  font-family: var(--f-texte);
}

:root[data-theme="nuit"] h1,
:root[data-theme="nuit"] h2,
:root[data-theme="nuit"] button,
:root[data-theme="nuit"] select,
:root[data-theme="nuit"] label,
:root[data-theme="nuit"] .conversion-label {
  font-family: var(--f-titre);
}

:root[data-theme="nuit"] .brand-logo {
  border: 2px solid var(--accent);
  background: radial-gradient(circle at 50% 45%, #2b1f4d, var(--bg) 70%);
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--halo);
}

:root[data-theme="nuit"] .calc-display,
:root[data-theme="nuit"] .calc-expression,
:root[data-theme="nuit"] #conversion-result,
:root[data-theme="nuit"] #unit-result,
:root[data-theme="nuit"] #people-count,
:root[data-theme="nuit"] .tool-results dd,
:root[data-theme="nuit"] .tool-answer output,
:root[data-theme="nuit"] .history-entry strong,
:root[data-theme="nuit"] input {
  font-family: var(--f-chiffres);
}

:root[data-theme="nuit"] .history-entry strong,
:root[data-theme="nuit"] #conversion-result,
:root[data-theme="nuit"] #unit-result,
:root[data-theme="nuit"] .tool-results .main-result dd,
:root[data-theme="nuit"] .tool-answer output {
  color: var(--halo);
}

:root[data-theme="nuit"] .tool h2,
:root[data-theme="nuit"] .field legend,
:root[data-theme="nuit"] .field-label,
:root[data-theme="nuit"] .tool-results dt,
:root[data-theme="nuit"] .copy-hint,
:root[data-theme="nuit"] .toast {
  font-family: var(--f-titre);
}

:root[data-theme="nuit"] .tab[aria-selected="true"] {
  letter-spacing: 0.04em;
}

:root[data-theme="nuit"] button:focus-visible,
:root[data-theme="nuit"] input:focus-visible,
:root[data-theme="nuit"] select:focus-visible {
  outline-color: var(--halo);
}

@media (hover: hover) {
  :root[data-theme="nuit"] .key.equal:hover {
    background: var(--halo);
    filter: none;
  }
}

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