:root {
  --bg: #15161a;
  --fg: #e8e6e0;
  --muted: #a7a49c;
  --accent: #d9312f;
  --key: #262830;
  --key-edge: #0c0d10;
  --key-fg: #f2f0ea;
  --paper: #e4e4e0;
  --ink: #101010;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 0 16px 40px;
}
a { color: #8fb8ff; }
header { max-width: 900px; margin: 24px auto 12px; }
h1 { font-size: 1.6rem; font-weight: 600; margin: 0 0 6px; letter-spacing: .01em; }
.logo { font-weight: 800; color: #fff; }
.logo span { color: var(--accent); }
.sub { color: var(--muted); margin: 0; }
main { max-width: 900px; margin: 0 auto; }
kbd {
  font: 0.85em ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #2b2d35; border: 1px solid #3c3f49; border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; color: #fff; white-space: nowrap;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: #fff; }
.inv { background: #fff; color: #000; padding: 0 3px; font-family: ui-monospace, monospace; font-style: normal; }

/* Téléviseur */
.tv { margin: 0 auto; max-width: 840px; }
.bezel {
  background: #050505;
  border-radius: 14px;
  padding: 4%;
  box-shadow: 0 10px 40px rgba(0,0,0,.6), inset 0 0 0 2px #222;
}
#screen {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--paper);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 4px;
  outline: none;
}
.status {
  text-align: center; color: var(--muted); font-size: .85rem; margin: 8px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; min-height: 1.4em;
}

/* Barre d'outils */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center;
  margin: 14px auto 18px; max-width: 840px;
}
.toolbar button, .toolbar select {
  background: #2b2d35; color: #fff; border: 1px solid #40434e; border-radius: 6px;
  padding: 7px 14px; font: inherit; font-size: .95rem; cursor: pointer;
}
.toolbar button:hover { background: #363946; }
.toolbar button:active, .toolbar button.on { background: var(--accent); border-color: var(--accent); }
.toolbar .speed { color: var(--muted); font-size: .9rem; display: inline-flex; gap: 6px; align-items: center; }

/* Clavier ZX81 */
.keyboard {
  background: #0e0f12;
  border-radius: 12px;
  padding: 12px 10px 14px;
  margin: 0 auto;
  max-width: 840px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px 5px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.key {
  position: relative;
  aspect-ratio: 1 / 1.15;
  background: var(--key);
  border: 1px solid var(--key-edge);
  border-bottom-width: 3px;
  border-radius: 6px;
  color: var(--key-fg);
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  padding: 3px 4px 2px;
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  transition: background .05s;
}
.key.down { background: #4a4d5a; border-bottom-width: 1px; transform: translateY(2px); }
.key.sticky { background: var(--accent); }
.key .kw { font-size: clamp(7px, 1.15vw, 10px); color: #fff; letter-spacing: -.02em; line-height: 1; white-space: nowrap; overflow: hidden; }
.key .sh { font-size: clamp(7px, 1.15vw, 10px); color: #ff6b66; line-height: 1; text-align: right; white-space: nowrap; }
.key .top { display: flex; justify-content: space-between; align-items: start; gap: 2px; }
.key .main { font-size: clamp(14px, 2.6vw, 24px); font-weight: 700; text-align: center; line-height: 1; }
.key .main.small { font-size: clamp(8px, 1.4vw, 12px); font-weight: 600; }
.key .fn { font-size: clamp(7px, 1.15vw, 10px); color: #ff6b66; text-align: center; align-self: end; line-height: 1; white-space: nowrap; overflow: hidden; }
.key .g { display: inline-block; width: .9em; height: .9em; vertical-align: -0.1em; background:
  conic-gradient(from 0deg at 50% 50%, #fff 0 25%, #000 0 50%, #fff 0 75%, #000 0); }
.key .g[data-g="1"] { background: linear-gradient(to bottom, transparent 50%, #fff 50%) , linear-gradient(to right, #fff 50%, transparent 50%); background-size: 50% 50%; }

/* Aide */
.help { max-width: 900px; margin: 28px auto 0; color: #d4d2cc; }
.help h2 { font-size: 1.15rem; margin: 0 0 8px; }
.help h3 { font-size: 1rem; margin: 0 0 6px; color: #fff; }
.help .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.help p { margin: 0 0 10px; font-size: .95rem; }
.help table { border-collapse: collapse; font-size: .9rem; margin-bottom: 10px; }
.help td { padding: 3px 10px 3px 0; vertical-align: top; border-bottom: 1px solid #2a2c33; }
footer { max-width: 900px; margin: 30px auto 0; color: var(--muted); font-size: .8rem; }

@media (max-width: 480px) {
  .key .kw, .key .fn { display: none; }
  .key { aspect-ratio: 1 / 1.2; grid-template-rows: auto 1fr; }
  .toolbar button, .toolbar select { padding: 6px 10px; font-size: .85rem; }
}
