* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
html { background: var(--bg); color: var(--text); }
body {
  background: var(--bg-art), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: var(--label-weight) 16px/1.2 var(--font-body);
  display: flex; flex-direction: column;
  padding: var(--safe-top, env(safe-area-inset-top)) var(--safe-right, env(safe-area-inset-right)) var(--safe-bottom, env(safe-area-inset-bottom)) var(--safe-left, env(safe-area-inset-left));
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel) 85%, transparent), transparent);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 32px; height: 32px; color: var(--accent); flex: none; stroke-width: 2.5; filter: var(--icon-glow); }
.brand h1 {
  margin: 0; font: 400 19px/1 var(--font-display); letter-spacing: .14em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#status { display: flex; align-items: center; gap: 8px; margin-left: auto; font-size: 13px; color: var(--dim); white-space: nowrap; }
#dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); box-shadow: 0 0 10px var(--red); }
#dot.on { background: var(--green); box-shadow: 0 0 10px var(--green); }
.hbtn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: min(var(--key-radius), 10px); padding: 8px 12px; font-size: 13px;
  letter-spacing: .08em; text-transform: uppercase;
}
.hbtn svg { width: 16px; height: 16px; flex: none; color: var(--accent); stroke-width: 3; }

/* ---------- tabs ---------- */
nav { display: flex; gap: 6px; padding: 12px 18px 0; overflow-x: auto; scrollbar-width: none; }
nav button {
  flex: 0 0 auto; background: var(--panel); color: var(--dim);
  border: 1px solid var(--line); border-bottom: none; border-radius: var(--tab-radius);
  padding: 13px 24px; font: 400 15px/1 var(--font-display); letter-spacing: .1em; text-transform: uppercase;
}
nav button.active {
  color: var(--text); background: var(--panel-hi); border-color: var(--line-hi);
  box-shadow: inset 0 2px 0 var(--accent);
}

/* ---------- button grid ---------- */
main {
  flex: 1; min-height: 0; overflow-y: auto;
  border-top: 1px solid var(--line-hi); padding: 18px;
  display: grid; gap: 14px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 176px), 1fr));
}
body.offline main { opacity: .45; filter: saturate(.4); }

.key {
  --c: var(--accent);
  position: relative; overflow: hidden;
  min-height: 140px; padding: 18px 14px 12px 16px;
  display: grid; grid-template-rows: auto 1fr auto; gap: 8px;
  text-align: left; color: var(--text);
  background: var(--key-bg);
  border: 1px solid var(--line); border-left: var(--key-edge) solid var(--c);
  border-radius: var(--key-radius); clip-path: var(--key-clip);
  box-shadow: var(--key-shadow, none);
  touch-action: none; cursor: pointer;
  transition: transform .07s ease, background .07s ease, box-shadow .07s ease;
}
.key::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: var(--key-top-h);
  color: var(--c); background: var(--key-top);
}
.key::after {
  /* faint sweep so the face reads as glass/metal rather than flat */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(115deg, rgba(255,255,255,.05), transparent 38%);
}
.key[data-color="green"] { --c: var(--green); }
.key[data-color="amber"] { --c: var(--amber); }
.key[data-color="red"] { --c: var(--red); }
.key[data-color="blue"] { --c: var(--blue); }

.glyph { width: 46px; height: 46px; color: var(--c); filter: var(--icon-glow); }
.glyph svg { width: 100%; height: 100%; display: block; stroke-width: var(--icon-stroke); }
.label {
  align-self: end;
  font-size: 17px; font-weight: var(--label-weight);
  text-transform: var(--label-case); letter-spacing: var(--label-track); line-height: 1.15;
}
.foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.keycap {
  font: 600 11px/1 var(--font-body); letter-spacing: .08em; text-transform: uppercase;
  padding: 5px 7px; border-radius: 4px; color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 38%, transparent);
}
.mode {
  font: 600 10px/1 var(--font-body); letter-spacing: .14em; text-transform: uppercase; color: var(--dim);
}
.key.pressed {
  transform: scale(.965);
  background: radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--c) 40%, transparent), transparent 70%),
    color-mix(in srgb, var(--c) 22%, var(--panel));
  box-shadow: inset 0 0 0 1px var(--c), inset 0 0 28px color-mix(in srgb, var(--c) 40%, transparent);
}
.key.pressed .glyph { filter: drop-shadow(0 0 10px var(--c)); }

#msg { padding: 40px 16px; color: var(--dim); text-align: center; grid-column: 1 / -1; }

/* ---------- pairing ---------- */
/* ---------- pairing ---------- */
/* Before pairing nothing on the deck works, so only the brand and the pairing card show. */
body.pairing header .hbtn, body.pairing #status, body.pairing nav { display: none; }
#pair {
  grid-column: 1 / -1; justify-self: center; position: relative;
  width: min(100%, 440px); margin: max(4vh, 16px) 0; padding: 28px 28px 24px;
  display: flex; flex-direction: column; align-items: stretch; gap: 12px; text-align: center;
  background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line);
  border-radius: min(var(--key-radius), 12px);
  box-shadow: 0 24px 60px rgba(0,0,0,.45), 0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent) inset;
}
/* HUD corner brackets */
#pair::before, #pair::after {
  content: ""; position: absolute; width: 22px; height: 22px; pointer-events: none;
  border: 2px solid var(--accent); opacity: .8;
}
#pair::before { left: -1px; top: -1px; border-right: 0; border-bottom: 0; }
#pair::after { right: -1px; bottom: -1px; border-left: 0; border-top: 0; }
.pair-emblem { align-self: center; width: 56px; height: 56px; color: var(--accent); filter: var(--icon-glow); }
.pair-emblem svg { width: 100%; height: 100%; }
#pair h2 {
  margin: 4px 0 0; font: 600 18px/1.2 var(--font-display); letter-spacing: .14em; text-transform: uppercase;
}
#pair h2 b { color: var(--accent); margin-right: 4px; }
#pair p { margin: 0; line-height: 1.45; }
.pair-help { color: var(--text); opacity: .85; font-size: 15px; }
.pair-help strong { color: var(--accent); font-weight: 600; }
#pair label {
  margin-top: 8px; text-align: left; color: var(--dim);
  font-size: 12px; letter-spacing: .14em; text-transform: uppercase;
}
#pair input {
  width: 100%; box-sizing: border-box; padding: 14px 16px; border-radius: 10px;
  border: 1px solid var(--line-hi); background: var(--bg); color: var(--text);
  font: 600 26px/1 var(--font-body); text-align: center; letter-spacing: .22em; text-transform: lowercase;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
#pair input::placeholder { color: var(--dim); opacity: .55; letter-spacing: .12em; font-size: 20px; }
#pair input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
#pair input.bad { border-color: var(--red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 25%, transparent); animation: pair-shake .3s; }
@keyframes pair-shake { 25% { translate: -6px 0; } 75% { translate: 6px 0; } }
.pair-error { color: var(--red); font-size: 14px; text-align: left; }
#pair button {
  margin-top: 6px; padding: 14px 32px; border-radius: 10px; border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, var(--panel)); color: var(--text);
  font: 600 16px/1 var(--font-body); letter-spacing: .14em; text-transform: uppercase;
}
#pair button:disabled { opacity: .6; }
.pair-hint { color: var(--dim); font-size: 13px; }
@media (prefers-reduced-motion: reduce) { #pair input.bad { animation: none; } }
/* An unpaired device is always "offline"; the card must not be dimmed like a lost connection. */
body.pairing.offline main { opacity: 1; filter: none; }
/* Landscape phones: drop the emblem and tighten up so Connect fits without scrolling. */
@media (max-height: 520px) {
  body.pairing main { padding: 8px 12px; }
  #pair { margin: 0; padding: 14px 18px 12px; gap: 7px; }
  .pair-emblem { display: none; }
  #pair h2 { margin: 0; font-size: 15px; }
  .pair-help { font-size: 13px; }
  #pair label { margin-top: 2px; }
  #pair input { padding: 9px 12px; font-size: 22px; }
  #pair button { margin-top: 2px; padding: 11px 24px; }
  .pair-hint { font-size: 12px; }
}

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom, env(safe-area-inset-bottom)) + 24px); z-index: 20;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 18px; border-radius: min(var(--key-radius), 10px);
  background: color-mix(in srgb, var(--panel) 92%, transparent); color: var(--text);
  border: 1px solid var(--amber); box-shadow: 0 0 18px color-mix(in srgb, var(--amber) 35%, transparent);
  font-size: 14px; letter-spacing: .12em; text-transform: uppercase; white-space: nowrap;
  transition: opacity .2s ease, transform .2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- hold-to-talk ---------- */
.no-voice .js-talk, .no-voice .js-voice { display: none; }
.js-talk.listening {
  color: var(--red); border-color: var(--red);
  box-shadow: inset 0 0 0 1px var(--red), 0 0 18px color-mix(in srgb, var(--red) 55%, transparent);
  animation: talk-pulse 1s ease-in-out infinite;
}
.js-talk.listening .hud-ico { color: var(--red); }
@keyframes talk-pulse { 50% { box-shadow: inset 0 0 0 1px var(--red), 0 0 6px color-mix(in srgb, var(--red) 30%, transparent); } }

/* ---------- night mode ---------- */
/* Dims the deck for a dark room; sits under the theme picker and toasts so they stay readable. */
#night { position: fixed; inset: 0; z-index: 9; pointer-events: none; background: #000; opacity: 0; transition: opacity .3s ease; }
[data-night] #night { opacity: .5; }

/* ---------- large text and high contrast ---------- */
/* Both are switches in Deck settings (Display), kept per device like night mode. They sit on
   <html> and win over the theme and HUD styles by specificity, whatever the theme. */
/* The top bar, the small system tiles and mode switches keep their size: they're icons or
   one short word in a small box. */
html[data-large] .hud-btn:not(.s-top):not(.s-tile):not(.s-switch) { font-size: 18px; font-weight: 700; }
html[data-large] .s-wide { font-size: 19px; }
html[data-large] .hud-grid.compact .hud-btn { font-size: 15px; font-weight: 700; }
/* Phone layouts (compact) have the least room. */
html[data-large] .compact .hud-btn:not(.s-top):not(.s-tile):not(.s-switch) { font-size: 16px; }
html[data-large] .compact .hud-grid .hud-btn { font-size: 13.5px; font-weight: 700; }
html[data-large] .fx-state { font-size: 11px; }
html[data-large] .s-tile > .fx-state { font-size: 9px; }
html[data-large] .key > .fx-state { font-size: 12px; }
html[data-large] .hud-header { font-size: 13px; }
html[data-large] .hud-pager .title span { font-size: 19px; }
html[data-large] .label { font-size: 21px; font-weight: 700; }
html[data-large] .keycap { font-size: 13px; }

/* Black, white and strong colours; no glows, textures or see-through faces. The theme's
   layout (corners, case) stays, but its fonts give way to plain, easy-to-read ones. */
html[data-contrast][data-theme] {
  --bg: #000; --bg-art: none; --panel: #000; --panel-hi: #262626;
  --line: #bdbdbd; --line-hi: #fff;
  --text: #fff; --dim: #e0e0e0;
  --accent: #ffd60a; --green: #3dff8b; --amber: #ffb000; --red: #ff5c5c; --blue: #5cc8ff;
  --font-display: "Exo 2", system-ui, sans-serif; --font-body: "Exo 2", system-ui, sans-serif;
  --label-weight: 700; --label-track: .04em;
  --key-bg: #000; --key-top: none; --key-top-h: 0; --key-shadow: none; --key-edge: 4px;
  --icon-glow: none; --label-shadow: none; --state-shadow: none;
  color-scheme: dark;
}
html[data-contrast] #canvas { --hud-line: #bdbdbd; --hud-face: #000; --hud-face-hi: #000; background: #000; }
html[data-contrast] .hud-btn, html[data-contrast] .key { border-width: 2px; }
html[data-contrast] body { background: #000; }

/* Button lights off: buttons that switch something keep no ON/OFF and no lit look, since
   the deck only knows what was tapped, not the game. Other status (HOLD TO ENGAGE) stays. */
html[data-no-lights] [data-state-group] > .fx-state { display: none; }

/* ---------- theme picker and voice commands list (full-screen sheets) ---------- */
#picker, #voiceHelp {
  position: fixed; inset: 0; z-index: 10; display: none; flex-direction: column;
  background: rgba(2, 4, 8, .82); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#picker.open, #voiceHelp.open { display: flex; }
#picker .bar, #voiceHelp .bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; color: #e8eef5; font: 600 14px/1 "Segoe UI", system-ui, sans-serif;
  letter-spacing: .16em; text-transform: uppercase;
}
#picker .bar-btns, #voiceHelp .bar-btns { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 10px; }

/* Deck settings: sections on one scrolling page. The sheet is always dark, whatever the
   theme, so it uses the house colours rather than theme tokens. */
#picker .sheet-body { flex: 1; overflow-y: auto; padding: 0 20px 24px; }
#picker .sheet-top {
  display: grid; gap: 14px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 270px), 1fr));
}
#picker .sheet-section { display: flex; flex-direction: column; gap: 10px; color: #e8eef5; }
#picker .sheet-top .sheet-section {
  padding: 14px; border: 1px solid rgba(138,160,184,.25); border-radius: 12px; background: rgba(11,23,38,.6);
}
#picker h3 {
  margin: 0; font: 600 12px/1 "Exo 2", system-ui, sans-serif; letter-spacing: .16em; text-transform: uppercase; color: #8aa0b8;
}
#picker h3 b { color: #4fb3ff; margin-right: 2px; }
#picker .sheet-note { margin: 0; color: #8aa0b8; font: 13px/1.4 "Exo 2", system-ui, sans-serif; }
#picker .sheet-foot { margin: 22px 0 0; text-align: center; color: #8aa0b8; font: 13px/1.4 "Exo 2", system-ui, sans-serif; }
#picker .sheet-foot a { color: #4fb3ff; }
#layoutPick {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 8px; font: 600 15px "Exo 2", system-ui, sans-serif;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.25); color: #e8eef5;
}
#layoutPick option { background: #0b1726; }
/* An on/off row: the whole row is the switch, so it's easy to hit. */
.sheet-switch {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 8px 12px; text-align: left;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.14); border-radius: 10px; color: #e8eef5;
}
.sheet-switch .sw-text, .sheet-action .sw-text { flex: 1; display: flex; flex-direction: column; gap: 3px; }
/* A one-off action in the same style as the switch rows. */
.sheet-action {
  display: flex; align-items: center; width: 100%; min-height: 56px; padding: 8px 12px; text-align: left;
  background: rgba(255,255,255,.04); border: 1px dashed rgba(255,255,255,.22); border-radius: 10px; color: #e8eef5;
}
.sheet-action:active { background: rgba(79,179,255,.15); }
.sw-text b { font: 600 15px/1.2 "Exo 2", system-ui, sans-serif; letter-spacing: .04em; }
.sw-text span { color: #8aa0b8; font: 13px/1.35 "Exo 2", system-ui, sans-serif; }
.sw-knob {
  position: relative; flex: none; width: 50px; height: 28px; border-radius: 999px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.3); transition: background .2s, border-color .2s;
}
.sw-knob::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #8aa0b8; transition: transform .2s, background .2s;
}
.sheet-switch[aria-checked="true"] { border-color: rgba(79,179,255,.6); }
.sheet-switch[aria-checked="true"] .sw-knob { background: rgba(79,179,255,.3); border-color: #4fb3ff; }
.sheet-switch[aria-checked="true"] .sw-knob::after { transform: translateX(22px); background: #4fb3ff; box-shadow: 0 0 10px rgba(79,179,255,.6); }
@media (prefers-reduced-motion: reduce) { .sw-knob, .sw-knob::after { transition: none; } }
#picker .bar button, #voiceHelp .bar button {
  background: none; border: 1px solid rgba(255,255,255,.25); color: #e8eef5;
  border-radius: 8px; padding: 9px 16px; letter-spacing: .1em; text-transform: uppercase; font-size: 13px;
}
#voiceHelp .vh-intro, #voiceHelp .vh-note { margin: 0 20px 12px; color: rgba(232,238,245,.72); font: 13px/1.45 "Segoe UI", system-ui, sans-serif; }
#voiceHelp .vh-note { margin: 4px 0; }
#voiceSearch {
  margin: 0 20px 14px; padding: 10px 12px; border-radius: 8px; font: 15px "Segoe UI", system-ui, sans-serif;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.25); color: #e8eef5;
}
#voiceList {
  flex: 1; overflow-y: auto; padding: 0 20px 24px;
  display: grid; gap: 10px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
}
.vh-card {
  padding: 10px 12px; color: var(--text);
  background: var(--bg-art), var(--bg); border: 1px solid var(--line); border-radius: min(var(--key-radius), 12px);
}
.vh-label { margin-bottom: 7px; color: var(--accent); font: 400 15px/1.1 var(--font-display); letter-spacing: .06em; text-transform: uppercase; }
.vh-phrases { display: flex; flex-wrap: wrap; gap: 6px; }
.vh-phrases span { padding: 4px 9px; border: 1px solid var(--line); border-radius: 999px; font: 13px/1.2 var(--font-body); }
#picker .pc-links[hidden] { display: none; }
#pcLinkBtns { display: flex; flex-wrap: wrap; gap: 10px; }
#pcLinkBtns button {
  min-height: 44px; background: rgba(79,179,255,.1); border: 1px solid rgba(79,179,255,.55); color: #e8eef5;
  border-radius: 8px; padding: 9px 16px; font: 600 14px "Exo 2", system-ui, sans-serif; letter-spacing: .06em;
}
#picker .cards {
  display: grid; gap: 16px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
}
.card {
  position: relative; overflow: hidden; text-align: left;
  display: flex; flex-direction: column; gap: 14px; padding: 18px;
  min-height: 210px;
  background: var(--bg-art), var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: min(var(--key-radius), 16px);
}
.card.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 0 30px color-mix(in srgb, var(--accent) 35%, transparent); }
.card .top { display: flex; align-items: center; gap: 12px; }
.card .emblem {
  width: 64px; height: 64px; padding: 6px; flex: none; color: var(--accent);
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%);
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--accent) 35%, transparent));
}
.card .emblem svg { width: 100%; height: 100%; stroke-width: 2.5; }
.card .name { font: 400 20px/1.05 var(--font-display); letter-spacing: .08em; text-transform: uppercase; }
.card .tag { font-size: 12px; color: var(--dim); letter-spacing: .04em; margin-top: 4px; font-family: var(--font-body); }
.card .swatches { display: flex; gap: 6px; margin-top: auto; }
.card .swatches i { width: 22px; height: 8px; border-radius: 2px; }
.card .sample { min-height: 0; padding: 10px 12px; grid-template-rows: auto; grid-template-columns: auto 1fr; align-items: center; gap: 10px; pointer-events: none; }
.card .sample .glyph { width: 28px; height: 28px; }
.card .sample .label { font-size: 13px; align-self: center; }
