
/* ── Recessed key well: a carved bezel around the key area ─────────── */
/* container-type:size makes the well a query context so the grid can derive a
   perfectly square cap edge from its own content box (cqw/cqh) — no JS measuring. */
.deck-well {
  position: relative; flex: 1; min-height: 0; z-index: 1;
  container-type: size;
  border-radius: clamp(12px, var(--deck-radius), 18px); padding: var(--deck-gap);
  /* The recess fades IN PLACE instead of on its own layer, unlike the chassis
     above: both pseudo-elements of .deck-well are already taken by the comic
     theme's animated panel, and adding a real element would put a node between
     the well and .deck-well-bg for nothing. color-mix(<c> 100%, transparent) is
     exactly <c>, so with the knob untouched this is byte-identical to the paint
     it replaces. */
  --well-mix: calc(var(--deck-well-alpha, 1) * 100%);
  background: linear-gradient(180deg,
    color-mix(in srgb, #070810 var(--well-mix), transparent),
    color-mix(in srgb, #0a0c12 var(--well-mix), transparent));
  box-shadow:
    inset 0 3px 12px color-mix(in srgb, rgba(0, 0, 0, .85) var(--well-mix), transparent),   /* deep recess */
    inset 0 -1px 0 color-mix(in srgb, rgba(255, 255, 255, .04) var(--well-mix), transparent), /* lit lower lip of the groove */
    0 1px 0 color-mix(in srgb, rgba(255, 255, 255, .05) var(--well-mix), transparent);        /* highlight where the body meets the recess */
}
/* Optional free-form picture behind the key grid (below the caps, z 0). */
.deck-well-bg {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  border-radius: clamp(12px, var(--deck-radius), 18px);
  background-position: center;
}
.deck-well-bg::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  background: #05070d; opacity: var(--deck-well-dim, .3);
}

/* Square key caps (real Stream Deck). The cap edge is the largest square that fits
   the well at the current column/row count: we take the well's content box via
   container-query units, subtract the inter-key gaps, divide by the count on each
   axis, and pick the limiting axis with min(). The grid is then sized to those
   fixed square tracks and centred — so the caps are always square AND, because the
   now-playing screen reserves its space below, the cap size never shifts when music
   starts or stops. (A plain 1fr fallback keeps it sane on the rare browser without
   size container queries.) */
.deck-grid {
  position: relative; z-index: 1;
  width: 100%; height: 100%; display: grid; gap: var(--deck-gap); min-height: 0;
  --deck-cell: min(
    (100cqw - (var(--deck-cols, 3) - 1) * var(--deck-gap)) / var(--deck-cols, 3),
    (100cqh - (var(--deck-rows, 2) - 1) * var(--deck-gap)) / var(--deck-rows, 2)
  );
  grid-template-columns: repeat(var(--deck-cols, 3), var(--deck-cell, 1fr));
  grid-template-rows: repeat(var(--deck-rows, 2), var(--deck-cell, 1fr));
  justify-content: center; align-content: center;
}
@supports not (width: 1cqw) {
  .deck-grid {
    grid-template-columns: repeat(var(--deck-cols, 3), 1fr);
    grid-template-rows: repeat(var(--deck-rows, 2), 1fr);
  }
}

/* ── The LCD key cap ──────────────────────────────────────────────── */
.deck-key {
  position: relative; min-height: 0; min-width: 0;
  /* Own stacking context so the backdrop-image / animation layers (z-index:-1)
     paint ABOVE the cap's own background instead of falling behind it. Without
     this the cap face is opaque and the backdrop never shows. */
  isolation: isolate;
  border-radius: var(--deck-radius);
  border: 1px solid #000;
  /* Near-black LCD cap with a softly top-lit face. */
  background:
    radial-gradient(135% 90% at 50% -16%, rgba(255,255,255,.14), transparent 52%),
    linear-gradient(180deg, #1d212a, #14171f 58%, #0c0e14);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; padding: 6px; cursor: pointer;
  color: var(--text, #e7e9ee); text-align: center;
  font-size: max(8px, calc(var(--deck-cell, var(--deck-key-min, 76px)) * .135));
  overflow: hidden;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.14),
    inset 0 -7px 14px rgba(0,0,0,.55),
    0 3px 7px rgba(0,0,0,.55),
    0 1px 0 rgba(0,0,0,.7);
  transition: transform .11s cubic-bezier(.2,.8,.2,1), box-shadow .15s ease, filter .15s ease;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
/* Convex glass shine — a curved highlight pooled at the top of the cap. */
.deck-key::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background:
    radial-gradient(120% 75% at 50% -25%, rgba(255,255,255,.22), transparent 56%),
    linear-gradient(0deg, rgba(0,0,0,.28), transparent 42%);
  opacity: .9;
}
/* Specular glint: a light band sweeps across the glass as the cap springs back
   from a press (JS toggles .is-glint one-shot on release; cleared on
   animationend). Transform-only — same technique as the anim-shift ambient,
   clipped by the cap's overflow:hidden — and the pseudo-element exists ONLY
   while .is-glint is on, so idle keys carry no extra layer. It sits above
   every face layer (photo caps included) so the key reads as glazed. */
.deck-key.is-glint::after {
  content: ''; position: absolute; top: -30%; bottom: -30%; left: 0; width: 55%;
  z-index: 3; pointer-events: none;
  background: linear-gradient(105deg,
    transparent 0%, rgba(255, 255, 255, .26) 45%, rgba(255, 255, 255, .07) 60%, transparent 100%);
  transform: translateX(-220%) skewX(-14deg);   /* starts fully off the left — invisible */
  animation: deck-key-glint .5s cubic-bezier(.3, .55, .3, 1);
  will-change: transform;
}
@keyframes deck-key-glint {
  from { transform: translateX(-220%) skewX(-14deg); }
  to   { transform: translateX(400%)  skewX(-14deg); }  /* fully off the right — invisible */
}
/* Matte caps don't glaze: the flat theme strips the glass sheen, so it strips
   the glint too. Reduced-motion and Performance Mode kill it like every effect. */
.deck-root[data-capstyle="flat"] .deck-key.is-glint::after { display: none; }
@media (prefers-reduced-motion: reduce) { .deck-key.is-glint::after { display: none; } }
body.perf-mode .deck-key.is-glint::after { display: none; }
/* Icon + label paint above the optional backdrop-image / animation layers,
   which sit at z-index:-1 (above the cap face, below content) so the classic
   paint order — glyph and glass sheen over the label — is preserved untouched.
   --ico-scale is the per-key icon-size preset (S/M/L, set via data-icosize).

   Every size below is a FRACTION of the cap with a floor and no ceiling. The
   floor keeps a glyph legible on a tiny cap; the missing ceiling is the point.
   These used to be clamp(floor, fraction, ceiling) with ceilings (38/40/42/52px,
   and 12px for the label) tuned for the largest key-size preset — about a 104px
   cap. But .deck-grid sizes caps to FILL the well, so a deck given a lot of room
   goes well past that: on a large desktop display the cap measures ~178px, where
   every glyph-style icon is pinned at its ceiling and reads at 24% of the cap
   instead of 40%, while a full-bleed picture key (sized 100% of the cap, ceiling
   there is none) keeps its proportions. Same deck, same keys, two different
   looks side by side — reported from a Xeneon Edge (~86px caps, everything below
   the old ceilings) next to a desktop browser. Scaling with the cap all the way
   up is what makes one profile look like itself on every screen it lands on. */
.deck-key .deck-ico {
  font-size: calc(max(17px, calc(var(--deck-cell, var(--deck-key-min, 76px)) * .36)) * var(--ico-scale, 1));
  line-height: 1; filter: drop-shadow(0 1px 3px rgba(0,0,0,.7));
}
.deck-key .deck-ico img {
  width: calc(max(18px, calc(var(--deck-cell, var(--deck-key-min, 76px)) * .38)) * var(--ico-scale, 1));
  height: calc(max(18px, calc(var(--deck-cell, var(--deck-key-min, 76px)) * .38)) * var(--ico-scale, 1));
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.6));
}
/* Built-in vector icons tint to the cap's text colour and scale with the key. */
/* min-height:0 + max-height on the artwork is what lets the flex column take the
   icon's room back when the cap can't hold both it and the title: without it the
   svg's explicit height is the icon's min-content size, the icon refuses to give
   up a pixel, and the title is the only thing left to squeeze. */
.deck-key .deck-ico.is-builtin { display: flex; min-height: 0; }
.deck-key .deck-ico.is-builtin svg {
  width: calc(max(18px, calc(var(--deck-cell, var(--deck-key-min, 76px)) * .4)) * var(--ico-scale, 1));
  height: calc(max(18px, calc(var(--deck-cell, var(--deck-key-min, 76px)) * .4)) * var(--ico-scale, 1));
  max-width: 100%; max-height: 100%;
  fill: currentColor; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6));
}
.deck-key[data-icosize="sm"] { --ico-scale: .72; }
.deck-key[data-icosize="lg"] { --ico-scale: 1.35; }
/* The title is the fixed part of the cap and the icon is what yields. It is one
   nowrap line, so it never needs more than that line; flex-shrink would hand it
   a box shorter than the line and `overflow: hidden` would then slice the text
   in half — a key captioned "Work" reading "ork", or nothing at all. */
.deck-key .deck-label {
  flex: 0 0 auto;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 600; letter-spacing: .01em; text-shadow: 0 1px 2px rgba(0,0,0,.7);
}
/* Per-key label styling: weight, size preset, position (top / hidden). */
.deck-key .deck-label.is-bold { font-weight: 800; }
.deck-key[data-labelsize="sm"] .deck-label { font-size: .82em; }
.deck-key[data-labelsize="lg"] .deck-label { font-size: 1.24em; }
.deck-key[data-labelpos="top"] .deck-label { order: -1; }
.deck-key[data-labelpos="hidden"] .deck-label { display: none; }
/* Hover lift (pointer devices only) + press depression for tactile feel.
   Unlit empty slots stay inert — they're not pressable outside edit mode. */
@media (hover: hover) {
  .deck-key:hover { transform: translateY(-1px); filter: brightness(1.12); }
  .deck-key.is-empty:not(.is-add):hover { transform: none; filter: none; }
}
.deck-key:active, .deck-key.is-pressed {
  transform: translateY(2px) scale(.92);
  filter: brightness(.86);
  box-shadow:
    inset 0 3px 9px rgba(0,0,0,.7),
    inset 0 1px 0 rgba(255,255,255,.05),
    0 1px 2px rgba(0,0,0,.35);
}

/* Accent-tinted caps: JS sets --key-accent; we tint the face + add a rim glow
   so a coloured key reads as a lit LCD instead of a flat fill. */
.deck-key.has-accent {
  background:
    linear-gradient(180deg, rgba(255,255,255,.12), transparent 36%),
    linear-gradient(180deg,
      color-mix(in srgb, var(--key-accent, #2b6cff) 42%, #1b1f27),
      color-mix(in srgb, var(--key-accent, #2b6cff) 18%, #14171d));
  border-color: color-mix(in srgb, var(--key-accent, #2b6cff) 55%, #000);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.22),
    inset 0 -3px 8px rgba(0,0,0,.5),
    0 0 12px color-mix(in srgb, var(--key-accent, #2b6cff) 45%, transparent),
    0 2px 4px rgba(0,0,0,.45);
}

/* Two-colour caps: JS sets --key-accent2 + data-grad. The face gradient lives in
   --kg-face so the direction variants (and the cap-style themes below) can swap
   just the shape while the lit-LCD blend (darkened accents, sheen, rim) stays. */
.deck-key.has-gradient {
  --kg-c1: color-mix(in srgb, var(--key-accent, #2b6cff) 50%, #181b23);
  --kg-c2: color-mix(in srgb, var(--key-accent2, #7aa2ff) 46%, #10131a);
  --kg-face: linear-gradient(135deg, var(--kg-c1), var(--kg-c2));
  background:
    linear-gradient(180deg, rgba(255,255,255,.12), transparent 36%),
    var(--kg-face);
  border-color: color-mix(in srgb, var(--key-accent, #2b6cff) 45%, #000);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.22),
    inset 0 -3px 8px rgba(0,0,0,.5),
    0 0 10px color-mix(in srgb, var(--key-accent, #2b6cff) 30%, transparent),
    0 0 10px color-mix(in srgb, var(--key-accent2, #7aa2ff) 24%, transparent),
    0 2px 4px rgba(0,0,0,.45);
}
.deck-key.has-gradient[data-grad="v"] { --kg-face: linear-gradient(180deg, var(--kg-c1), var(--kg-c2)); }
.deck-key.has-gradient[data-grad="r"] { --kg-face: radial-gradient(135% 135% at 30% 18%, var(--kg-c1), var(--kg-c2)); }

/* Backdrop picture: a layer under the icon/label. The ::after scrim keeps the
   content readable (opacity = the user's dim setting); with an accent the scrim
   tints, so the photo reads as backlit by the key colour instead of just dark. */
.deck-key .deck-key-bgimg {
  position: absolute; inset: 0; z-index: -1; border-radius: inherit;
  overflow: hidden; pointer-events: none;
}
.deck-key .deck-key-bgimg img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  filter: blur(var(--key-blur, 0px));
}
/* When blurred, scale the image up a touch so the softened edges stay outside the
   cap instead of showing a faded halo against the border. */
.deck-key.has-bgblur .deck-key-bgimg img { transform: scale(1.09); }
.deck-key .deck-key-bgimg::after {
  content: ''; position: absolute; inset: 0;
  background: #06080c; opacity: var(--key-dim, .35);
}
.deck-key.has-accent .deck-key-bgimg::after {
  background: color-mix(in srgb, var(--key-accent, #2b6cff) 45%, #06080c);
}
.deck-key.has-gradient .deck-key-bgimg::after {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--key-accent, #2b6cff) 55%, #06080c),
    color-mix(in srgb, var(--key-accent2, #7aa2ff) 55%, #06080c));
}
/* A key whose face IS a photo keeps its title scrim readable over the picture. */
.deck-key.has-bgimg .deck-label { text-shadow: 0 1px 3px rgba(0, 0, 0, .9); }
