:root {
  color-scheme: dark;
  --wall: #14110e;
  --paper: #f3ead7;
  --paper-edge: #e2d3b4;
  --ink: #241c14;
  --faded: #6d5e4c;
  --rule: #c9b89a;
  --accent: #8f2d1c;
  --ok: #1e6b3a;
  --ok-bg: #e4f0e2;
  --bezel: #2a241c;
  --face: #12110f;
  --led: #ff3b24;
  --led-dim: #3a1612;
  --cream: #f4efe4;
  --muted: #b7ab9a;
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 20% -10%, #3a2c22 0%, transparent 55%),
    var(--wall);
  color: var(--cream);
}

button, input { font: inherit; }

a { color: #e7c7a2; }

#app { max-width: 1240px; margin: 0 auto; padding: 28px 20px 48px; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 22px;
}

.kicker, .fiche-kicker, .coach-kicker {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-family: "Iowan Old Style", Georgia, serif;
  font-size: 0.72rem;
}

.kicker { color: #e0b089; }

h1 { margin: 4px 0 0; font-size: 2rem; font-weight: 600; letter-spacing: -0.03em; }

.progress { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 640px; }

.progress button {
  border: 1px solid #4a3d32;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.72rem;
  cursor: pointer;
}

.progress button.now { background: var(--cream); color: var(--ink); border-color: var(--cream); }
.progress button.done { color: #e7c7a2; border-color: #8a6244; }
.progress button:disabled { opacity: 0.35; cursor: default; }

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.fiche {
  background: linear-gradient(180deg, var(--paper), #efe2c8);
  color: var(--ink);
  padding: 22px 22px 18px;
  border-radius: 2px 10px 10px 2px;
  box-shadow: 8px 10px 28px rgba(0, 0, 0, 0.28), inset 0 0 0 1px var(--paper-edge);
}

.fiche h2 { margin: 6px 0 12px; font-size: 1.55rem; line-height: 1.15; font-weight: 600; }

.fiche p { margin: 0 0 10px; line-height: 1.45; font-size: 1.02rem; }

.fiche-kicker { color: var(--accent); }

#goal {
  border-left: 4px solid var(--accent);
  padding: 8px 0 8px 12px;
  margin: 14px 0;
  font-size: 1.12rem;
  line-height: 1.35;
}

#goal.success {
  border-left-color: var(--ok);
  background: var(--ok-bg);
  padding: 10px 12px;
}

.fiche-actions { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  background: var(--ink);
  color: var(--paper);
  border: 0;
  border-radius: 4px;
  padding: 8px 12px;
  cursor: pointer;
}

.ghost-btn, .fiche .ghost-btn {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule);
}

.bench .ghost-btn, footer .ghost-btn { color: var(--cream); border-color: #5c5146; }

.listing {
  list-style: none;
  margin: 0 0 8px;
  padding: 8px;
  background: #2a241c;
  color: #f3e6cf;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.55;
}

.listing li.ok { color: #b7e2b4; }
.listing li.miss { color: #f0c7a4; }

.challenge {
  border-top: 1px solid var(--rule);
  margin-top: 12px;
  padding-top: 10px;
}

.challenge h3 { margin: 0 0 6px; font-size: 1.05rem; }
.challenge.solved h3::after { content: "  · fait"; color: var(--ok); font-weight: 500; }
.chal-note { min-height: 1.2em; color: var(--faded); font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; }
.speed { display: block; margin: 8px 0; font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; }

.bezel {
  background: var(--bezel);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.plaque {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px 10px;
  color: #c8b49a;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
}

.face {
  background: var(--face);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
}

.lamp-head, .switch-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-family: ui-monospace, Menlo, monospace;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-size: 0.75rem;
}

.lamp-head strong, .switch-head strong {
  letter-spacing: 0.08em;
  color: #ffb4a4;
  font-size: 1.35rem;
  font-weight: 600;
}

.groups {
  display: flex;
  gap: 14px;
  margin: 8px 0;
  min-width: 640px;
}

.group { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bits { display: flex; gap: 5px; }
.digit { font-family: ui-monospace, Menlo, monospace; color: #ffb4a4; font-size: 1.05rem; min-height: 1.2em; }
.digit.live { font-size: 1.6rem; color: #ffe1af; }
.place { font-family: ui-monospace, Menlo, monospace; color: #8d8274; font-size: 0.68rem; }

.led {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--led-dim);
  box-shadow: inset 0 0 0 1px #000;
  display: block;
}

.led.on {
  background: var(--led);
  box-shadow: 0 0 10px 2px rgba(255, 59, 36, 0.85);
}

.caption, .hint, .status-text {
  margin: 0 0 10px;
  color: var(--muted);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.78rem;
}

.status-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 12px; }

.pill, .flag {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  border: 1px solid #3a3128;
  color: #6a6158;
  border-radius: 999px;
  padding: 3px 8px;
}

.pill.on, .flag.on {
  color: #2a0906;
  background: var(--led);
  border-color: var(--led);
  box-shadow: 0 0 10px rgba(255, 59, 36, 0.7);
}

.status-text { flex: 1; margin: 0; text-align: right; }

.bit { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.weight, .bitno { font-family: ui-monospace, Menlo, monospace; color: #8d8274; font-size: 0.68rem; }

.sw {
  width: 28px;
  height: 52px;
  border-radius: 4px;
  border: 1px solid #000;
  background: #070707;
  position: relative;
  padding: 0;
}

.sw i {
  position: absolute;
  left: 4px;
  right: 4px;
  height: 20px;
  top: 26px;
  border-radius: 2px;
  background: linear-gradient(#f7f4ee, #c9c2b6);
}

.sw.on i { top: 4px; background: linear-gradient(#ff6a52, #b42316); }

.sw.want-up { outline: 2px dashed #ffb089; outline-offset: 2px; }
.sw.want-down { outline: 2px dashed #f4efe4; outline-offset: 2px; }
.sw.cursor { box-shadow: 0 0 0 2px #e6c27a; }

.keys { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 8px; min-width: 640px; }

.keys button, .knob button {
  background: #24211c;
  color: var(--cream);
  border: 1px solid #5a5044;
  font-family: ui-monospace, Menlo, monospace;
  letter-spacing: 0.06em;
  font-size: 0.82rem;
}

.keys .dep { background: #3a2218; }
.enable.armed { background: #6d1d12; border-color: #ff6a52; }

.is-next {
  animation: pulse 1s ease-in-out infinite;
  box-shadow: 0 0 0 2px #e6c27a;
}

@keyframes pulse {
  50% { box-shadow: 0 0 0 4px rgba(230, 194, 122, 0.25); }
}

.knob { display: flex; justify-content: space-between; gap: 12px; align-items: center; color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 0.78rem; min-width: 640px; }
.knob-keys { display: flex; gap: 6px; }
.knob button.chosen { background: #f4efe4; color: #241c14; }

.coach {
  margin-top: 12px;
  padding: 12px 4px 0;
}

.coach p { line-height: 1.4; }
#decode-text { font-family: ui-monospace, Menlo, monospace; color: #e7c7a2; min-height: 1.2em; }

.reg-grid { display: flex; flex-wrap: wrap; gap: 8px 14px; font-family: ui-monospace, Menlo, monospace; color: #f4efe4; font-size: 0.85rem; }

footer { margin-top: 22px; color: var(--muted); font-size: 0.92rem; }
footer p { line-height: 1.45; }

.shake { animation: shake 0.35s linear; }
@keyframes shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

@media (prefers-reduced-motion: reduce) {
  .is-next, .shake { animation: none; }
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .top { flex-direction: column; align-items: start; }
  .progress { justify-content: flex-start; }
}
