#dialog[data-kind="workbench"] {
  --bench-ink: #273a46;
  --bench-paper: #fcf8eb;
  --bench-edge: #b8bdad;
  --bench-accent: #285b50;
  --bench-focus: #9b4f12;
  width: min(920px, calc(100% - max(16px, var(--phone-left, 16px)) - max(16px, var(--phone-right, 16px))));
  max-height: min(95dvh, calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 12px));
  background: var(--bench-paper);
  color: var(--bench-ink);
  border: 2px solid #354d55;
  border-radius: 18px;
  box-shadow: 0 4px 0 #354d55, 0 14px 54px #19263660;
  scrollbar-width: thin;
}

#dialog[data-kind="workbench"] .dialog-content { padding: 0; }
#dialog[data-kind="workbench"] .dialog-close {
  z-index: 2;
  right: 12px;
  top: 12px;
  width: 44px;
  height: 44px;
  padding: 0;
  color: #364943;
  background: #efeedd;
  border: 1px solid #b9c1b1;
}

.wb-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "figure heading" "figure controls";
  align-items: start;
  column-gap: clamp(16px, 2.5vw, 28px);
  row-gap: 12px;
  padding: 20px;
  color: var(--bench-ink);
}

.wb-heading { grid-area: heading; position: relative; display: flex; align-items: center; justify-content: space-between; align-self: end; padding-right: 45px; }
.wb-title { display: flex; align-items: center; gap: 9px; }
.wb-title > .glyph {
  width: 34px; height: 34px; padding: 6px; box-sizing: border-box;
  border: 1px solid #8faaa2; border-radius: 8px;
  color: #365f5a; background: linear-gradient(145deg, #ecf3db, #ccded3);
}
#dialog[data-kind="workbench"] .wb-heading h2 {
  font-size: clamp(23px, 3vw, 36px);
  line-height: 1.14;
  letter-spacing: -.045em;
  margin: 2px 0 0;
  color: #244448;
}
.wb-hint summary {
  display: grid; place-items: center; min-height: 44px; min-width: 44px; padding: 0 6px;
  color: #476751; font-size: 12px; font-weight: 800; cursor: pointer; list-style: none;
}
.wb-hint summary::-webkit-details-marker { display: none; }
.wb-hint summary:focus-visible { outline: 2px solid var(--bench-focus); }
#dialog[data-kind="workbench"] .wb-hint p {
  position: absolute; z-index: 3; right: 44px; top: 100%; max-width: 85%; width: 250px; padding: 10px 12px;
  margin: 0; color: #2a493a; border: 1px solid #6e8c70; border-radius: 8px; background: #f3f5df;
  box-shadow: 0 4px 12px #1d3e2c30; font-size: 13px;
}

.wb-figure { grid-area: figure; align-self: center; min-width: 0; width: 100%; margin: 0; }
.wb-board {
  position: relative;
  isolation: isolate;
  aspect-ratio: 1;
  width: 100%;
  background: radial-gradient(ellipse at 35% 12%, #304c59, #1b303f 68%, #152936);
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px #567580, inset 0 0 0 4px #203841, inset 0 0 0 5px #5c787665;
}
.wb-shell[data-profile="day"] .wb-board {
  background: radial-gradient(ellipse at 0 35%, #424e4e, transparent 51%),
    linear-gradient(145deg, #344951, #203543 62%, #172c39);
  box-shadow: inset 0 0 0 1px #91a39b, inset 0 0 0 4px #263b40, inset 0 0 0 5px #d6b98775;
}
.wb-shell[data-profile="night"] .wb-board {
  background: radial-gradient(ellipse at 100% 45%, #344d6a, transparent 52%),
    linear-gradient(145deg, #334358, #202d47 62%, #1a283d);
  box-shadow: inset 0 0 0 1px #93acbe, inset 0 0 0 4px #283549, inset 0 0 0 5px #9db6cb75;
}
.wb-board::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 9px;
  pointer-events: none;
  background:
    radial-gradient(circle at 4px 4px, #afc1b8 1px, transparent 2px),
    radial-gradient(circle at calc(100% - 4px) 4px, #afc1b8 1px, transparent 2px),
    radial-gradient(circle at 4px calc(100% - 4px), #afc1b8 1px, transparent 2px),
    radial-gradient(circle at calc(100% - 4px) calc(100% - 4px), #afc1b8 1px, transparent 2px);
}
.wb-board canvas, .wb-sockets { position: absolute; inset: 0; width: 100%; height: 100%; }
.wb-board canvas { display: block; border-radius: inherit; }
.wb-sockets button {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  width: clamp(44px, calc(100% / 7), 62px);
  height: clamp(44px, calc(100% / 7), 62px);
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  touch-action: manipulation;
}
.wb-sockets button::before, .wb-sockets button::after { position: absolute; content: ""; }
.wb-sockets button::before {
  inset: 16%;
  border: 1.5px dashed #c5d9cc;
  border-radius: 24%;
  background: #c5d9cc0b;
}
.wb-sockets button[data-filled="no"]::after {
  width: 24%;
  height: 24%;
  background: linear-gradient(#dcead9, #dcead9) center / 65% 1.5px no-repeat,
    linear-gradient(#dcead9, #dcead9) center / 1.5px 65% no-repeat;
}
.wb-sockets button[data-filled="yes"]::before { border-color: #acb9b64d; border-style: solid; }
.wb-sockets button[aria-pressed="true"]::before { inset: 11%; border: 2px solid #ffdf91; background: #ffdf9110; box-shadow: 0 0 0 1.5px #25333d; }
.wb-sockets button:focus-visible { outline: 2px solid white; outline-offset: -4px; }
.wb-figure figcaption { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 9px; color: #53655f; }
.wb-figure figcaption span { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 750; }
.wb-figure figcaption i { width: 11px; height: 11px; display: inline-block; }
.wb-key-source { background: #45786c; clip-path: polygon(50% 3%, 100% 80%, 75% 97%, 25% 97%, 0 80%); }
.wb-key-receiver { border: 2px solid #45786c; border-radius: 50%; }
.wb-key-socket { border: 1.5px dashed #53655f; border-radius: 3px; }
.wb-standby-key i { border: 1.5px dashed #71847b; border-radius: 50%; }

.wb-controls { grid-area: controls; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.wb-shell button { cursor: pointer; font-family: inherit; font-weight: 800; }
.wb-shell button:disabled { cursor: default; }
.wb-controls button { color: var(--bench-ink); min-height: 44px; border: 1px solid var(--bench-edge); }
.wb-controls button:focus-visible, #dialog[data-kind="workbench"] .dialog-close:focus-visible {
  outline: 2px solid var(--bench-focus);
  outline-offset: 2px;
}
.wb-orders, .wb-stock, .wb-edit { display: flex; align-items: stretch; gap: 6px; }
.wb-orders { padding: 3px; border: 1px solid #bec6b5; border-radius: 11px; background: #ebeede; }
.wb-orders button { flex: 1; padding: 3px 5px; background: none; border-color: transparent; border-radius: 7px; color: #53645a; font-size: 14px; }
.wb-orders button[aria-pressed="true"] { color: #fffef0; border-color: #245448; background: #326458; }
.wb-seal { margin-left: 4px; font-size: 11px; font-style: normal; }
.wb-shell [hidden] { display: none !important; }
#dialog[data-kind="workbench"] .wb-brief { margin: 0; font-size: 14px; line-height: 1.55; font-weight: 640; color: #44544e; }
.wb-test { display: grid; gap: 8px; }
.wb-profiles {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px;
  padding: 3px; border: 1px solid #a8b4a8; border-radius: 10px; background: #e0e4d8;
}
.wb-profiles button {
  --switch-ink: #7d4c29; --switch-edge: #ab8962; --switch-face: #faebc9;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 3px 8px; color: #51635d; border: 1px solid transparent; border-radius: 7px;
  background: transparent; font-size: 14px; white-space: nowrap;
}
.wb-profiles button[data-profile="night"] { --switch-ink: #2f4968; --switch-edge: #8b9fae; --switch-face: #dce8f3; }
.wb-profiles button[aria-pressed="true"] {
  color: var(--switch-ink); background: var(--switch-face); border-color: var(--switch-edge);
  box-shadow: inset 0 1px #ffffffa1, 0 1px 2px #34453c24;
}
.wb-profiles b {
  display: inline-grid; place-items: center; min-width: 24px; height: 17px;
  box-sizing: border-box; border: 1px solid #74898068; border-radius: 4px;
  font-size: 10px; line-height: 1; font-variant-numeric: tabular-nums;
}
.wb-profiles [data-lit="true"] b { color: #ecffe8; background: #35634e; border-color: #35634e; }
.wb-phase-icon { display: inline-block; width: 17px; height: 17px; position: relative; flex: none; }
.wb-phase-icon::before, .wb-phase-icon::after { content: ""; position: absolute; }
[data-profile="day"] > .wb-phase-icon::before {
  inset: 27%; border-radius: 50%; background: currentColor;
}
[data-profile="day"] > .wb-phase-icon::after {
  inset: 0; background: repeating-conic-gradient(from -5deg, currentColor 0 10deg, transparent 10deg 45deg);
  mask: radial-gradient(circle, transparent 47%, #000 49% 63%, transparent 65%);
}
[data-profile="night"] > .wb-phase-icon::before {
  inset: 0; border-radius: 50%; background: currentColor;
  mask: radial-gradient(circle at 77% 25%, transparent 45%, #000 48%);
}
.wb-readout { background: #e7efe1; border-left: 3px solid #6c9c82; border-radius: 0 8px 8px 0; padding: 8px 10px; }
.wb-result { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.wb-reward { padding: 1px 5px; color: #6c4819; font-size: 11px; font-weight: 800; background: #ffdf99; border-radius: 4px; white-space: nowrap; }
.wb-lamps { display: inline-flex; align-items: center; gap: 5px; font-size: 15px; color: #2d5c4c; line-height: 1.3; }
.wb-lamps::before { content: ""; width: 9px; height: 9px; border: 2px solid #5c8b72; border-radius: 50%; }
[data-solved="true"] > .wb-controls .wb-lamps::before { background: #a6dc9f; border-color: #3a7955; }
.wb-metrics { display: flex; flex-wrap: wrap; gap: 2px 11px; margin-top: 3px; font-size: 11px; line-height: 1.35; font-weight: 720; color: #52665a; }
#dialog[data-kind="workbench"] .wb-selection { margin: 0; color: #365b51; font-size: 13px; line-height: 1.4; font-weight: 800; }
.wb-stock button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1;
  padding: 4px 6px;
  border-radius: 8px;
  background: #dceece;
  border-color: #83a68a;
  font-size: 13px;
  white-space: nowrap;
}
.wb-stock button:disabled { color: #637169; background: #eeeee2; border-color: #c8cebe; }
.wb-stock b { font-size: 12px; font-variant-numeric: tabular-nums; }
.wb-stock .glyph, .wb-edit .glyph { width: 17px; height: 17px; flex: 0 0 auto; }
.wb-mirror-icon { position: relative; width: 14px; height: 17px; }
.wb-mirror-icon::after { content: ""; position: absolute; top: 45%; left: -1px; width: 17px; height: 3px; border-radius: 2px; background: currentColor; transform: rotate(-45deg); }
.wb-edit button { flex: 1; display: inline-flex; gap: 4px; justify-content: center; align-items: center; padding: 4px 6px; border-radius: 7px; background: #f5f0dd; color: #455044; font-size: 13px; }
.wb-edit [data-action="workbench-reset"] { background: transparent; }
.wb-edit button:disabled { border-color: #d4d1c3; color: #73746b; background: transparent; }

.wb-receivers { display:grid; grid-auto-columns:minmax(0,1fr); grid-auto-flow:column; gap:4px; }
.wb-receivers button {
  display:flex; justify-content:center; align-items:center; gap:5px; min-width:44px; min-height:44px;
  padding:3px 4px; border:1px solid #99b0a4; border-radius:7px; color:#29423f; background:#f0f1e5;
  text-align:left; touch-action:manipulation;
}
.wb-receivers button[aria-pressed="true"] { border-color:#64796b; background:#e0ead7; box-shadow:inset 0 0 0 1px #64796b; }
.wb-receivers button > span { display:grid; gap:2px; min-width:0; line-height:1.15; }
.wb-receivers button b { font-size:12px; }
.wb-receivers button small { font-size:10px; font-weight:720; color:#4e5d55; }
.wb-receivers button[data-state="mismatch"] small { color:#90492e; }
.wb-receiver-glyph { display:grid; place-items:center; width:17px; height:17px; flex:none; border:2px solid var(--socket-goal); border-radius:50%; background:#30454a; box-shadow:0 0 0 1px #53665e; }
.wb-receiver-glyph::before { content:''; width:7px; height:7px; border-radius:50%; border:1px solid #9daaa8; }
[data-state="match"] > .wb-receiver-glyph::before,[data-state="mismatch"] > .wb-receiver-glyph::before { display:grid; place-content:center; width:10px; height:10px; border:0; background:var(--socket-read); color:#293c3e; font:900 9px/1 system-ui,sans-serif; }
[data-state="match"] > .wb-receiver-glyph::before { content:'✓'; }
[data-state="mismatch"] > .wb-receiver-glyph::before { content:'≠'; }
.wb-device { display:grid; gap:4px; }
.wb-compact-metrics { display:none; }
.wb-receiver-reading { padding:3px 6px; border-left:3px solid #b08e55; background:#f3ecd9; color:#584b39; font-size:12px; line-height:1.35; font-weight:720; }
.wb-directions { display:grid; gap:2px; }
.wb-directions > div { display:flex; flex-wrap:wrap; align-items:center; gap:1px 5px; font-size:11px; font-weight:720; line-height:1.3; color:#4a5a5a; }
.wb-directions > div[data-active] { color:#254a49; }
.wb-directions b { padding:1px 3px; font-size:10px; background:#e8e8db; border-radius:3px; }
.wb-directions i { color:#6d8477; font-style:normal; }

@media (hover: hover) {
  .wb-stock button:not(:disabled):hover, .wb-edit button:not(:disabled):hover { border-color: #4b7767; background: #e4edd4; }
  .wb-sockets button:hover::before { border-color: #ffedba; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #dialog[data-kind="workbench"] {
    width: min(845px, calc(100% - var(--phone-left, 10px) - var(--phone-right, 10px)));
    max-height: calc(100dvh - var(--top, 6px) - var(--bottom, 6px));
    border-radius: 12px;
  }
  .wb-shell {
    grid-template-columns: minmax(288px, min(44vw, max(308px, calc(100dvh - 52px)))) minmax(0, 1fr);
    column-gap: 14px;
    row-gap: 5px;
    padding: 7px 11px;
  }
  #dialog[data-kind="workbench"] .dialog-close { top: 4px; right: 6px; }
  #dialog[data-kind="workbench"] .wb-heading h2 { font-size: 24px; }
  .wb-heading { min-height: 36px; display: flex; align-items: center; }
  .wb-figure figcaption { margin-top: 3px; line-height: 1.1; }
  .wb-controls { gap: 6px; align-self: center; }
  .wb-orders { padding: 0; }
  .wb-orders button { min-height: 44px; }
  #dialog[data-kind="workbench"] .wb-brief { font-size: 12px; line-height: 1.35; }
  .wb-readout { padding: 4px 8px; }
  .wb-lamps { font-size: 13px; }
  .wb-metrics { margin-top: 1px; font-size: 10px; }
  #dialog[data-kind="workbench"] .wb-selection { font-size: 12px; }
}

@media (orientation: landscape) and (max-height: 500px) and (min-width: 650px) {
  .wb-test { gap: 5px; }
  .wb-shell[data-profile]:not([data-profile=""]) .wb-test {
    grid-template-columns: auto minmax(0, 1fr); align-items: stretch;
  }
  .wb-profiles { padding: 0; gap: 1px; border-radius: 7px; }
  .wb-profiles button { gap: 4px; padding: 2px 6px; font-size: 12px; }
  .wb-profiles b { min-width: 19px; font-size: 9px; }
  .wb-phase-icon { width: 14px; height: 14px; }
}

@media (orientation: landscape) and (max-height: 360px) and (min-width: 650px) {
  #dialog[data-kind="workbench"] {
    inset: max(2px, env(safe-area-inset-top)) var(--phone-right, 8px) max(2px, env(safe-area-inset-bottom)) var(--phone-left, 8px);
    max-height: calc(100dvh - max(2px, env(safe-area-inset-top)) - max(2px, env(safe-area-inset-bottom)));
  }
  .wb-shell {
    grid-template-columns: minmax(0, min(45vw, calc(100dvh - max(2px, env(safe-area-inset-top)) - max(2px, env(safe-area-inset-bottom)) - 10px))) minmax(0, 1fr);
    padding: 3px 6px 3px 3px; column-gap: 10px; row-gap: 3px;
  }
  .wb-heading { align-self: center; }
  .wb-figure figcaption { display: none; }
  .wb-controls { align-self: start; gap: 5px; }
  .wb-readout { align-content: center; padding: 2px 5px; }
  .wb-result { gap: 2px 4px; }
  .wb-metrics { gap: 1px 6px; }
}

@media (orientation: portrait) and (max-width: 640px) {
  #dialog[data-kind="workbench"] { width: calc(100% - var(--phone-left, 8px) - var(--phone-right, 8px)); }
  .wb-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas: "heading" "figure" "controls";
    padding: 7px 5px 12px;
    gap: 7px;
  }
  .wb-heading { min-height: 40px; display: flex; align-items: center; }
  #dialog[data-kind="workbench"] .wb-heading h2 { font-size: 25px; }
  #dialog[data-kind="workbench"] .dialog-close { top: 3px; right: 5px; }
  .wb-figure { max-width: min(100%, 47dvh); justify-self: center; }
  .wb-figure figcaption { margin-top: 4px; }
  .wb-controls { gap: 7px; }
  #dialog[data-kind="workbench"] .wb-brief { font-size: 12px; }
  .wb-readout { padding: 5px 8px; }
  .wb-lamps { font-size: 14px; }
  .wb-stock button { padding-inline: 2px; }
}

@media (orientation:landscape) and (max-height:500px) and (min-width:650px) {
  .wb-controls { gap:4px; }
  .wb-test { gap:3px; }
  .wb-test:has(.wb-receivers > button:only-child) { grid-template-columns:minmax(0,1.3fr) minmax(0,1fr); }
  .wb-shell[data-profile]:not([data-profile=""]) .wb-test {
    grid-template-columns:auto minmax(72px,1fr) minmax(75px,1fr); gap:3px;
  }
  .wb-profiles button { padding-inline:4px; gap:2px; }
  .wb-receivers { gap:3px; }
  .wb-receivers button { gap:4px; padding-inline:2px; }
  .wb-receivers button b { font-size:11px; }
  .wb-receivers button small { font-size:10px; }
  .wb-receiver-glyph { width:14px; height:14px; }
  .wb-device { gap:2px; }
  .wb-receiver-reading,.wb-directions > div { font-size:10px; }
  .wb-receiver-reading { padding-block:1px; }
  .wb-shell[data-inspecting] .wb-brief { display:none; }
  .wb-shell:not([data-installing]) .wb-stock button { min-height:18px; padding-block:0; background:transparent; border-color:transparent; font-size:11px; }
  .wb-shell:not([data-installing]) .wb-stock :is(.glyph,.wb-mirror-icon) { display:none; }
  .wb-shell:not([data-installing]) .wb-stock b { font-size:10px; }
}
@media (orientation:landscape) and (max-height:360px) and (min-width:650px) {
  .wb-compact-metrics { display:grid; gap:2px; text-align:right; line-height:1.12; font-size:11px; font-weight:750; color:#3e5c50; }
  .wb-compact-metrics small { color:#516257; font-size:10px; }
  .wb-readout .wb-metrics { display:none; }
  .wb-readout { display:grid; align-content:center; }
  .wb-shell[data-profile]:not([data-profile=""]) .wb-lamps { font-size:12px; gap:3px; white-space:nowrap; }
}
