:root {
  --brand-red: #d20000;
  --brand-red-dark: #a80000;
  --brand-red-soft: #c41212;
  --bg: #ffffff;
  --bg-elevated: #f7f7f8;
  --bg-panel: #ffffff;
  --bg-input: #ffffff;
  --bg-muted: #f0f1f3;
  --ink: #1a1a1a;
  --ink-soft: #4a4a4e;
  --ink-muted: #6c6c6f;
  --line: rgba(0, 0, 0, 0.12);
  --line-strong: rgba(210, 0, 0, 0.35);
  --white: #ffffff;
  --ok: #15803d;
  --caution: #b45309;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sans: "Source Sans 3", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Oswald", "Arial Narrow", Impact, sans-serif;
  --radius: 3px;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
  --header-sticky: 0px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(ellipse 55% 35% at 0% 0%, rgba(210, 0, 0, 0.06), transparent 55%),
    radial-gradient(ellipse 40% 30% at 100% 0%, rgba(210, 0, 0, 0.04), transparent 50%),
    linear-gradient(180deg, #ffffff 0%, #fafafa 55%, #f5f5f5 100%);
  line-height: 1.45;
  overflow-x: hidden;
}

.bg-grid {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, black, transparent 75%);
  opacity: 0.7;
}

.bg-glow {
  position: fixed; width: min(38vw, 280px); height: min(38vw, 280px); top: -8%; right: -4%;
  border-radius: 50%; pointer-events: none; z-index: 0;
  background: radial-gradient(circle, rgba(210, 0, 0, 0.1), transparent 70%);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(-3%, 5%) scale(1.06); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.site-header, main, .site-footer { position: relative; z-index: 1; }

.site-header {
  padding: 1.1rem clamp(0.9rem, 3.5vw, 3rem) 0;
  max-width: 1200px; margin: 0 auto;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex; align-items: center; gap: 0.85rem;
  margin-bottom: 0.85rem; animation: rise 0.6s ease-out both;
  min-width: 0;
}

.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0; font-family: var(--display);
  font-size: clamp(1.65rem, 6vw, 3rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 0.95;
  color: var(--ink);
  word-break: break-word;
}
.brand-web {
  color: var(--brand-red);
  letter-spacing: 0.08em;
}

.brand-text p {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  font-size: clamp(0.78rem, 2.8vw, 0.9rem);
  font-weight: 500;
}

.brand-text a {
  color: var(--brand-red);
  text-decoration: none;
  font-weight: 700;
}
.brand-text a:hover { text-decoration: underline; }

.summary-bar {
  display: flex; flex-wrap: wrap; gap: 0.45rem 0.85rem;
  padding: 0.6rem 0.8rem; margin: 0.85rem 0 0.75rem;
  background: var(--bg-elevated);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand-red);
  border-radius: var(--radius);
  font-size: 0.8rem;
  animation: rise 0.6s ease-out 0.05s both;
}

.summary-bar span {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: baseline;
}

.summary-bar strong {
  color: var(--brand-red);
  font-family: var(--mono);
  font-weight: 500;
}

.tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.3rem;
  padding: 0 0 0.75rem;
  margin: 0 calc(-1 * clamp(0.9rem, 3.5vw, 3rem));
  padding-left: clamp(0.9rem, 3.5vw, 3rem);
  padding-right: clamp(0.9rem, 3.5vw, 3rem);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
  animation: rise 0.6s ease-out 0.1s both;
  scroll-snap-type: x proximity;
}

.tabs::-webkit-scrollbar { height: 4px; }
.tabs::-webkit-scrollbar-thumb {
  background: rgba(210, 0, 0, 0.35);
  border-radius: 4px;
}

.tab {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.55rem 0.85rem;
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
  scroll-snap-align: start;
  min-height: 2.5rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.tab:hover {
  background: rgba(210, 0, 0, 0.06);
  color: var(--ink);
  border-color: rgba(210, 0, 0, 0.35);
}

.tab.active {
  background: var(--brand-red);
  color: var(--white);
  border-color: var(--brand-red);
}

.tab:active { transform: scale(0.98); }

main {
  max-width: 1200px; margin: 0 auto;
  padding: 1.1rem clamp(0.9rem, 3.5vw, 3rem) calc(2rem + var(--safe-bottom));
}

.panel { animation: rise 0.35s ease-out both; }
.panel[hidden] { display: none !important; }

.panel-intro { margin-bottom: 1rem; max-width: 44rem; }
.panel-intro h2 {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: clamp(1.35rem, 4.5vw, 2rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  border-left: 3px solid var(--brand-red);
  padding-left: 0.65rem;
}
.panel-intro p { margin: 0.45rem 0 0; color: var(--ink-soft); font-size: 0.95rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 1rem; align-items: start;
}
.layout.wide { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); }

.form, .results {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}

.form { padding: 1rem 1.05rem 1.15rem; }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 0.9rem;
  padding: 0.75rem 0.8rem 0.9rem;
  background: var(--bg-elevated);
}
fieldset:last-of-type { margin-bottom: 0; }
legend {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brand-red);
  padding: 0 0.3rem;
}

.field { display: flex; flex-direction: column; gap: 0.28rem; margin-bottom: 0.8rem; }
.field:last-child { margin-bottom: 0; }
.field span { font-size: 0.8rem; font-weight: 600; color: var(--ink-soft); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; }
.row.gears { grid-template-columns: repeat(5, minmax(0, 1fr)); }

input, select, textarea {
  font-family: var(--mono);
  font-size: 1rem; /* évite le zoom iOS */
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--ink);
  width: 100%;
  max-width: 100%;
  min-height: 2.75rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px rgba(210, 0, 0, 0.18);
}
input[readonly] {
  background: var(--bg-muted);
  color: var(--ink-muted);
}
option { background: var(--white); color: var(--ink); }

.hint { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--ink-muted); }

.results {
  padding: 1.1rem 1.15rem 1.25rem;
  background:
    linear-gradient(165deg, #ffffff 0%, #fff8f8 55%, #fff5f5 100%);
  border-color: var(--line-strong);
  color: var(--ink);
  min-height: 11rem;
}
.results h3 {
  margin: 0 0 0.85rem;
  font-family: var(--display);
  font-size: clamp(1.15rem, 3.5vw, 1.35rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand-red);
}

.result-grid { display: grid; gap: 0.5rem; }
.result-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--line);
}
.result-item:last-child { border-bottom: none; }
.result-item .label { font-size: 0.86rem; color: var(--ink-soft); flex: 1 1 auto; min-width: 0; }
.result-item .value {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: right;
  color: var(--ink);
  word-break: break-word;
}
.result-item.highlight .value {
  color: var(--brand-red);
  font-size: 1.15rem;
}

.badge {
  display: inline-block;
  margin-top: 0.85rem;
  padding: 0.3rem 0.65rem;
  border-radius: 2px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.badge.ok { background: rgba(22, 163, 74, 0.12); color: var(--ok); }
.badge.caution { background: rgba(249, 174, 0, 0.18); color: var(--caution); }
.badge.hot { background: rgba(210, 0, 0, 0.12); color: var(--brand-red); }

.speed-table, .recap-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: 0.86rem;
}
.speed-table th, .speed-table td,
.recap-table th, .recap-table td {
  padding: 0.4rem 0.3rem;
  text-align: right;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  color: var(--ink);
}
.speed-table th:first-child, .speed-table td:first-child,
.recap-table th:first-child, .recap-table td:first-child {
  text-align: left;
  font-family: var(--sans);
  font-weight: 600;
}
.speed-table th, .recap-table th {
  color: var(--ink-muted);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.aac-specs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.aac-chip {
  background: rgba(210, 0, 0, 0.04);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.55rem;
}
.aac-chip .k {
  display: block;
  font-size: 0.68rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.aac-chip .v {
  font-family: var(--mono);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
}

.needles-block {
  margin-top: 1rem;
  min-width: 0;
}
.needles-block > fieldset {
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  margin-bottom: 0;
}
.needles-grid {
  display: grid;
  grid-template-columns: minmax(200px, 280px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
.needles-catalog,
.needles-compare { min-width: 0; }
.catalog-list {
  width: 100%;
  min-height: 11rem;
  font-size: 0.9rem;
}
.needle-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: 2.2rem;
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-muted);
}
.needle-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.45rem 0.35rem 0.55rem;
  border-radius: 4px;
  border: 1px solid currentColor;
  background: var(--white);
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  min-height: 2.2rem;
}
.needle-chip .swatch {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 2px;
  background: currentColor;
  flex-shrink: 0;
}
.needle-chip button {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0.15rem 0.25rem;
  min-width: 1.75rem;
  min-height: 1.75rem;
}
.needle-chip button:hover { opacity: 1; }
.needle-chips-empty {
  color: var(--ink-muted);
  font-size: 0.82rem;
  padding: 0.2rem 0.25rem;
}

.chart-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem;
  margin-bottom: 0.85rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.check-field {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin: 0 0 0.85rem;
  font-size: 0.86rem;
  color: var(--ink-soft);
  cursor: pointer;
  line-height: 1.35;
}
.check-field input {
  width: auto;
  min-height: auto;
  margin-top: 0.15rem;
  accent-color: var(--brand-red);
  flex-shrink: 0;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.5rem 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 100%;
}
.needle-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  white-space: nowrap;
}
.needle-table th,
.needle-table td {
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  text-align: right;
}
.needle-table th:first-child,
.needle-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--bg-panel);
  font-family: var(--sans);
  font-weight: 700;
  z-index: 1;
}
.needle-table th {
  color: var(--ink-muted);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
}
.needle-table .richer { color: #15803d; }
.needle-table .leaner { color: #b91c1c; }
.setup-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.setup-table th,
.setup-table td {
  padding: 0.65rem 0.7rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.35;
}
.setup-table thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  background: var(--bg-muted);
}
.setup-table tbody th {
  font-family: var(--sans);
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  width: 28%;
}
.setup-table tbody td {
  color: var(--ink-soft);
}
.setup-table tbody tr:hover td,
.setup-table tbody tr:hover th {
  background: rgba(210, 0, 0, 0.04);
}
#chart-courbe { display: block; width: 100%; max-width: 100%; height: auto; }


.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0; }
.btn, .file-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  background: var(--brand-red);
  color: var(--white);
  transition: transform 0.15s, background 0.15s;
  min-height: 2.75rem;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover, .file-btn:hover { background: var(--brand-red-dark); }
.btn:active, .file-btn:active { transform: scale(0.97); }
.btn.secondary, .file-btn { background: #4b5563; }
.btn.secondary:hover, .file-btn:hover { background: #374151; }
.btn.danger { background: #7f1d1d; }

.site-footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.1rem clamp(0.9rem, 3.5vw, 3rem) calc(1.6rem + var(--safe-bottom));
  border-top: 1px solid var(--line);
}
.site-footer p { margin: 0; font-size: 0.8rem; color: var(--ink-muted); }
.site-footer a { color: var(--brand-red); text-decoration: none; font-weight: 700; }
.site-footer a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .layout, .layout.wide { grid-template-columns: 1fr; }
  .needles-grid { grid-template-columns: 1fr; }
  .row.gears { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .site-header {
    padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
  }
  .summary-bar {
    font-size: 0.74rem;
    gap: 0.35rem 0.65rem;
  }
  .form { padding: 0.9rem; }
  .results { padding: 0.95rem; }
  .btn, .file-btn { width: 100%; }
  .btn-row .btn { flex: 1 1 calc(50% - 0.25rem); width: auto; min-width: 8rem; }
  .catalog-list { min-height: 9rem; }
  .chart-wrap { margin-left: -0.15rem; margin-right: -0.15rem; }
}

@media (max-width: 540px) {
  .row { grid-template-columns: 1fr; }
  .row.gears { grid-template-columns: 1fr 1fr; }
  .result-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
  }
  .result-item .value { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
