:root {
  --bg: #ffffff;
  --fg: #14161a;
  --muted: #5d6470;
  --line: #e3e6ea;
  --panel: #f7f8fa;
  --accent: #d97757;
  --accent-fg: #ffffff;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --fg: #e7e9ec;
    --muted: #99a1ad;
    --line: #262b33;
    --panel: #161a20;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --fg: #e7e9ec; --muted: #99a1ad; --line: #262b33; --panel: #161a20;
}
:root[data-theme="light"] {
  --bg: #ffffff; --fg: #14161a; --muted: #5d6470; --line: #e3e6ea; --panel: #f7f8fa;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 24px; }

header.hero {
  border-bottom: 1px solid var(--line);
  padding: 56px 0 40px;
}
.hero h1 { font-size: 2.1rem; line-height: 1.2; margin: 0 0 12px; letter-spacing: -0.02em; }
.hero p { color: var(--muted); margin: 0; max-width: 62ch; }
.hero .tag {
  display: inline-block; font: 600 11px/1 var(--mono); letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 14px;
}

nav.toc {
  display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 16px 0;
  border-bottom: 1px solid var(--line); font-size: 14px;
}
nav.toc a { color: var(--muted); text-decoration: none; }
nav.toc a:hover { color: var(--accent); }

section { padding: 44px 0; border-bottom: 1px solid var(--line); }
section h2 { font-size: 1.4rem; margin: 0 0 8px; letter-spacing: -0.01em; }
section h3 { font-size: 1.03rem; margin: 28px 0 8px; }
section > p { color: var(--muted); max-width: 68ch; }

a { color: var(--accent); }

code, kbd {
  font-family: var(--mono);
  font-size: 0.87em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}
pre {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; overflow-x: auto; font-family: var(--mono); font-size: 13px;
}
pre code { background: none; border: 0; padding: 0; }

.note {
  border-left: 3px solid var(--accent);
  background: var(--panel);
  padding: 12px 16px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 20px 0;
  font-size: 14.5px;
}
.note strong { color: var(--fg); }

/* ---- device previews ---- */

.grid-keypad, .grid-dialpad {
  display: grid; gap: 6px; width: 216px;
}
.grid-keypad { grid-template-columns: repeat(3, 1fr); }
.grid-dialpad { grid-template-columns: repeat(2, 1fr); }

.key {
  /* Grid items default to min-width:auto, which lets a wide glyph push the
     track past the body. */
  min-width: 0;
  aspect-ratio: 1; border-radius: 8px; background: #24262c; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 4px; gap: 2px; border: 0; cursor: default;
  font-family: inherit;
}
.key .glyph { font-size: 20px; line-height: 1; max-width: 100%; overflow: hidden; }
.key .label { font-size: 9.5px; line-height: 1.15; opacity: .95; word-break: break-word; }
.key.empty { background: var(--panel); border: 1px dashed var(--line); color: var(--muted); }

.profiles { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-top: 24px; }
.card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
  background: var(--panel); display: flex; flex-direction: column; gap: 14px;
}
.card h3 { margin: 0; font-size: 1.05rem; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.card .previews { display: flex; gap: 16px; flex-wrap: wrap; }
.card .dl { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }

button, .btn {
  font: 500 14px/1 var(--sans); padding: 9px 14px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
  cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
button.primary, .btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-fg);
}
button.primary:hover, .btn.primary:hover { filter: brightness(1.06); color: var(--accent-fg); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---- builder ---- */

.builder { display: grid; grid-template-columns: 240px 1fr; gap: 28px; margin-top: 24px; align-items: start; }
@media (max-width: 720px) { .builder { grid-template-columns: 1fr; } }

.builder .key { cursor: pointer; transition: outline-color .12s; outline: 2px solid transparent; }
.builder .key:hover { outline-color: var(--muted); }
.builder .key[aria-current="true"] { outline-color: var(--accent); }

.controls { display: grid; gap: 14px; }
.row { display: grid; gap: 6px; }
.row label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.row-inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

input[type="text"], select {
  font: 14px var(--sans); padding: 8px 10px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); width: 100%;
}
input[type="color"] { width: 42px; height: 34px; padding: 2px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); }
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 13.5px; color: var(--fg); }

.steps { display: grid; gap: 8px; }
.step {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--bg);
}
.step .mods { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.step-body { display: grid; gap: 6px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }

.encoded {
  font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  word-break: break-all; background: var(--panel); border: 1px solid var(--line);
  border-radius: 7px; padding: 8px 10px;
}

table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.scroll-x { overflow-x: auto; }

footer { padding: 32px 0 60px; color: var(--muted); font-size: 14px; }
footer .tip { max-width: 64ch; margin: 0 0 18px; }
footer .tip-note { display: block; margin-top: 4px; font-size: 12.5px; opacity: .75; }

/* ---- device shells ----
   Proportions traced from Logitech's own labelled diagram of the hardware,
   so the builder matches what is actually under your hands. */

.device {
  position: relative;
  background: #303338;
  border: 1px solid #1c1e22;
  border-radius: 16px;
  padding: 10px;
  /* A definite width, not a percentage: the dialpad body's children are all
     absolutely positioned, so it has no intrinsic width and would collapse to
     nothing as a shrink-to-fit flex item. */
  width: 250px;
  max-width: 100%;
}
.device-keypad { padding: 12px; }
.device-dialpad { aspect-ratio: 386 / 327; padding: 0; }

.device .ctrl {
  position: absolute;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; overflow: hidden;
  border: 0; padding: 2px; cursor: pointer;
  font-family: inherit; color: #fff;
  background: #4a4e55;
  outline: 2px solid transparent; outline-offset: 2px;
  transition: outline-color .12s;
}
.device .ctrl.round { border-radius: 50%; }
.device .ctrl.roller { border-radius: 5px; background: #23262a; border: 1px solid #55595f; }
.device .ctrl:hover { outline-color: rgba(255, 255, 255, .55); }
.device .ctrl[aria-current="true"] { outline-color: var(--accent); }
.device .ctrl.unassigned { background: #3c4046; color: #9aa1ab; box-shadow: inset 0 0 0 1px #4e535a; }

.device .ctrl .t { font-size: 8.5px; font-weight: 600; line-height: 1.1; word-break: break-word; }
.device .ctrl .g { font-size: 15px; line-height: 1; }
.device .ctrl.dial-main .t { font-size: 11px; }
.device .ctrl.dial-main .g { font-size: 22px; }

.device-caption {
  font-size: 11.5px; color: var(--muted); margin: 6px 0 0; text-align: center;
}

.slot { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.slot > h4 {
  margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.slot + .slot { margin-top: 10px; }

.slot { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.slot > h4 {
  margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.slot + .slot { margin-top: 10px; }

.theme-toggle { position: fixed; top: 14px; right: 14px; z-index: 10; padding: 6px 10px; font-size: 13px; }
