:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --text: #e6edf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-dim: #1d4ed8;
  --cell: #243044;
  --cell-hover: #2d3d56;
  --rotary: #22c55e;
  --slider: #a855f7;
  --arduino-hw: #f59e0b;
  --mux-hw: #06b6d4;
  --border: #2d3b52;
  --font: "Segoe UI", system-ui, sans-serif;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1.25rem 1.5rem 2rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 600px at 20% 15%, rgba(59, 130, 246, 0.22), transparent 60%),
    radial-gradient(800px 520px at 80% 85%, rgba(168, 85, 247, 0.18), transparent 55%),
    linear-gradient(180deg, rgba(10, 14, 20, 0.92), rgba(10, 14, 20, 0.86));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 2rem 1.25rem;
  cursor: pointer;
}

.splash-card {
  width: min(520px, 92vw);
  border-radius: 16px;
  border: 1px solid rgba(59, 130, 246, 0.35);
  background: rgba(15, 20, 25, 0.72);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  padding: 1.25rem 1.25rem 1.1rem;
  text-align: left;
  animation: splashIn 420ms ease-out both;
}

.splash-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #c7d2fe;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: rgba(99, 102, 241, 0.12);
  margin-bottom: 0.75rem;
}

.splash-title {
  font-size: 1.55rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

.splash-subtitle {
  color: var(--muted);
  margin: 0 0 1rem;
  max-width: 60ch;
}

.splash-loader {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.splash-loader span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.85);
  animation: splashDot 1.05s ease-in-out infinite;
}
.splash-loader span:nth-child(2) { animation-delay: 0.12s; opacity: 0.85; }
.splash-loader span:nth-child(3) { animation-delay: 0.24s; opacity: 0.7; }

.splash.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}

@keyframes splashIn {
  from { transform: translateY(10px) scale(0.985); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes splashDot {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0 0 1.25rem;
  max-width: 65ch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.panel h2 {
  font-size: 1.05rem;
  margin: 0 0 0.75rem;
  font-weight: 600;
}

.panel-draggable {
  user-select: none;
}

.panel-handle[draggable="true"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 22px;
  margin-right: 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: grab;
  font-weight: 700;
  letter-spacing: -0.05em;
}

.panel-handle:active {
  cursor: grabbing;
}

.panel-dragging {
  opacity: 0.65;
  outline: 2px dashed rgba(59, 130, 246, 0.7);
  outline-offset: 4px;
}

.panel-drop-target {
  border-color: rgba(59, 130, 246, 0.8);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.22);
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}

.row.wrap {
  align-items: center;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="number"] {
  width: 4.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.inline-pins input {
  width: 2.8rem;
  margin-right: 0.25rem;
}

.check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.check input {
  width: auto;
}

.btn {
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--cell);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.btn:hover {
  background: var(--cell-hover);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent-dim);
  color: #fff;
}

.firmware-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.controller-name-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.75rem 0 0.5rem;
  max-width: 36rem;
}

.controller-name-label input {
  width: 100%;
  max-width: 28rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.75rem 0 0;
}

.hint code {
  background: var(--bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

.grid-host {
  overflow-x: auto;
  padding: 0.25rem 0;
}

.plate-wrap {
  --cell-size: 64px;
  display: inline-block;
  max-width: 100%;
}

.plate-grid {
  display: grid;
  gap: 6px;
  margin-top: 0.25rem;
  padding: 10px 12px 12px;
  background: linear-gradient(180deg, #131a24 0%, var(--bg) 100%);
  border-radius: 10px;
  border: 2px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.plate-grid-placed {
  position: relative;
  align-items: stretch;
  justify-items: stretch;
}

.plate-corner {
  min-width: 28px;
  min-height: 24px;
}

.plate-axis {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
}

.panel-workshop .hint {
  max-width: 72ch;
}

.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px dashed var(--border);
}

.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 110px;
  min-height: 88px;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--cell);
  color: var(--text);
  cursor: grab;
  font: inherit;
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.palette-item:hover {
  background: var(--cell-hover);
  border-color: #4a5f7a;
}

.palette-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.12);
}

.palette-item:active {
  cursor: grabbing;
}

.palette-item.rotary .palette-ico {
  color: #86efac;
}

.palette-item.slider .palette-ico {
  color: #d8b4fe;
}

.palette-item.clear .palette-ico {
  color: #f87171;
}

.palette-item.rotate .palette-ico {
  color: #38bdf8;
}

.palette-item.hw.arduino .palette-ico {
  color: #fbbf24;
}

.palette-item.hw.mux .palette-ico {
  color: #22d3ee;
}

.cell .cell-rotary-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  transition: transform 0.2s ease;
}

.palette-ico {
  font-size: 1.75rem;
  line-height: 1.2;
  margin-bottom: 0.2rem;
}

.palette-ico.ico-v {
  font-size: 0.7rem;
  line-height: 1.15;
  margin-bottom: 0.15rem;
  font-weight: 600;
  color: #c4b5fd;
}

.palette-txt {
  font-size: 0.85rem;
  font-weight: 600;
}

.palette-sub {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.cell {
  width: var(--cell-size, 64px);
  height: var(--cell-size, 64px);
  min-width: 48px;
  min-height: 48px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--cell);
  cursor: crosshair;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  text-align: center;
  line-height: 1.2;
  user-select: none;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
  padding: 4px;
}

.cell:active {
  transform: scale(0.97);
}

.cell .cell-ico {
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0.9;
}

.cell .cell-ico.empty-ico {
  font-size: 1.4rem;
  font-weight: 300;
  color: #64748b;
  opacity: 0.5;
}

.cell .cell-hint {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 2px;
}

.cell .cell-size-hint {
  display: block;
  font-size: 0.5rem;
  color: #94a3b8;
  margin-top: 1px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.cell.slider-h-part .cell-ico,
.cell.slider-v-part .cell-ico {
  font-size: 1rem;
  line-height: 1.15;
}

.cell.slider-h-part,
.cell.slider-v-part {
  position: relative;
}

/* Piste de slider continue (sur 3 cases) */
.cell.slider-h-part::before {
  content: "";
  position: absolute;
  left: -1px; /* traverse la jointure des bordures */
  right: -1px;
  top: 50%;
  height: 4px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: rgba(216, 180, 254, 0.95);
  box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.35);
  z-index: 0;
}

.cell.slider-v-part::before {
  content: "";
  position: absolute;
  top: -1px; /* traverse la jointure des bordures */
  bottom: -1px;
  left: 50%;
  width: 4px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(216, 180, 254, 0.95);
  box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.35);
  z-index: 0;
}

/* Le contenu (texte/ico) au-dessus de la piste */
.cell.slider-h-part > *,
.cell.slider-v-part > * {
  position: relative;
  z-index: 1;
}

/* L'icone unicode sert de fallback, on la rend discrète */
.cell.slider-h-part .cell-ico.slider-ico,
.cell.slider-v-part .cell-ico.slider-ico {
  opacity: 0.25;
}

.cell.slider-v-part {
  padding: 0.35rem 0.2rem;
}

.cell.slider-h-part {
  padding: 0.35rem 0.2rem;
}

/* Relier visuellement les 3 cases d'un slider */
.cell.slider.slider-h-part.slider-part-start {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.cell.slider.slider-h-part.slider-part-mid {
  border-radius: 0;
}
.cell.slider.slider-h-part.slider-part-end {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.cell.slider.slider-v-part.slider-part-start {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
.cell.slider.slider-v-part.slider-part-mid {
  border-radius: 0;
}
.cell.slider.slider-v-part.slider-part-end {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.cell:hover {
  background: var(--cell-hover);
}

.cell.empty {
  color: var(--muted);
}

.cell.rotary {
  background: rgba(34, 197, 94, 0.2);
  border-color: var(--rotary);
  color: #86efac;
}

.cell.slider {
  background: rgba(168, 85, 247, 0.2);
  border-color: var(--slider);
  color: #d8b4fe;
}

.cell.hw.arduino-cell {
  background: rgba(245, 158, 11, 0.22);
  border-color: var(--arduino-hw);
  color: #fcd34d;
}

.cell.hw.mux-cell {
  background: rgba(6, 182, 212, 0.2);
  border-color: var(--mux-hw);
  color: #67e8f9;
}

.cell .cell-label {
  font-weight: 600;
  font-size: 0.6rem;
  text-transform: uppercase;
}

.mux-summary {
  font-size: 0.9rem;
  color: var(--muted);
}

.mux-need {
  margin: 0.5rem 0 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 0.9rem;
  white-space: pre-line;
}

.mux-need.ok {
  border-color: rgba(34, 197, 94, 0.55);
  background: rgba(34, 197, 94, 0.08);
  color: #bbf7d0;
}

.mux-need.warn {
  border-color: rgba(245, 158, 11, 0.65);
  background: rgba(245, 158, 11, 0.08);
  color: #fde68a;
}

.mux-summary strong {
  color: var(--text);
}

.mux-badge {
  display: inline-block;
  margin: 0.25rem 0.5rem 0.25rem 0;
  padding: 0.25rem 0.5rem;
  background: var(--bg);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.wiring-doc {
  font-size: 0.88rem;
  color: var(--muted);
}

.wiring-doc ol {
  margin: 0.5rem 0 0 1.25rem;
  padding: 0;
}

.wiring-doc li {
  margin-bottom: 0.5rem;
}

.wiring-doc .tag {
  display: inline-block;
  padding: 0.1em 0.45em;
  border-radius: 4px;
  font-size: 0.8em;
  margin-right: 0.35rem;
}

.wiring-doc .tag.rotary {
  background: rgba(34, 197, 94, 0.25);
  color: #86efac;
}

.wiring-doc .tag.slider {
  background: rgba(168, 85, 247, 0.25);
  color: #d8b4fe;
}

.panel-firmware .hint {
  margin-bottom: 0.75rem;
  max-width: 55ch;
}

.btn-firmware {
  padding: 0.65rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
}

.version-badge {
  display: inline-block;
  font-size: 0.55em;
  font-weight: 700;
  color: var(--muted);
  vertical-align: middle;
  letter-spacing: 0.04em;
}

.site-footer {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  padding: 1rem 1rem 2rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

.site-footer a {
  color: var(--accent);
}

@media print {
  .no-print {
    display: none !important;
  }

  body {
    background: #fff !important;
    color: #111 !important;
    padding: 12mm !important;
    max-width: none !important;
  }

  .panel {
    break-inside: avoid;
  }
}
