:root {
  color-scheme: dark;
  --ground: #171918;
  --ink: #efefeb;
  --muted: #a8aea8;
  --surface: #222623;
  --line: #393f3a;
  --key: #e7e8e2;
  --key-ink: #252923;
  --accent: #91d5bd;
  --accent-deep: #297864;
  --warning: #ebc38a;
  --hold-duration: 850ms;
  font: 16px/1.5 system-ui, sans-serif;
  color: var(--ink);
  background: var(--ground);
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: var(--ground); }

.shell {
  width: min(100%, 488px);
  margin-inline: auto;
  padding: max(26px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
.masthead { display: flex; align-items: center; gap: 9px; border-bottom: 1px solid var(--line); padding-bottom: 18px; }
.masthead img { flex: none; margin-left: -7px; border-radius: 8px; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.375rem; font-weight: 680; letter-spacing: -.03em; }
h2 { font-size: 1.75rem; line-height: 1.17; font-weight: 660; letter-spacing: -.035em; }
.connection {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 7px;
  margin-inline-start: auto;
  color: var(--muted);
  font-size: .8125rem;
  line-height: 1.25;
  text-align: end;
}
.signal { width: 7px; height: 7px; flex: none; border-radius: 50%; background: currentColor; }
.connection[data-online="true"] { color: var(--accent); }

.activation, .remote { margin-top: 38px; }
.activation > p, #instruction { margin-top: 9px; color: var(--muted); }
.activation strong { color: var(--ink); }
.controls { display: grid; gap: 12px; margin-top: 23px; }

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, h2:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}
.trigger {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 101px;
  padding: 15px 17px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.trigger[data-target="gate"] { background: var(--key); color: var(--key-ink); border-color: var(--key); }
.trigger:disabled { background: var(--surface); color: var(--muted); border-color: var(--line); }
.trigger-label { font-size: 1.375rem; font-weight: 680; letter-spacing: -.025em; }
.trigger-hint { font-size: .75rem; opacity: .86; text-align: right; }
.trigger.holding { border-color: var(--accent-deep); }
.trigger[data-target="barrier"].holding { border-color: var(--accent); }
.trigger.ready .trigger-hint { font-weight: 750; opacity: 1; }
.progress {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  pointer-events: none;
}
.trigger[data-target="gate"] .progress { background: var(--accent-deep); }
.trigger.holding .progress { transform: scaleX(1); transition: transform var(--hold-duration) linear; }
@media (prefers-reduced-motion: reduce) {
  .trigger.holding .progress { transform: scaleX(0); }
  .trigger.ready .progress { transform: scaleX(1); }
}
@media (hover: hover) {
  .trigger[data-target="gate"]:enabled:hover { background: #f2f3ed; }
  .trigger[data-target="barrier"]:enabled:hover { background: #2b302c; }
  .text-button:enabled:hover { color: var(--ink); }
}

/* Two silhouettes keep the physical controls identifiable at a glance. */
.glyph { display: block; position: relative; width: 38px; height: 30px; }
.glyph-gate { border-inline: 2px solid; border-radius: 2px; }
.glyph-gate::before {
  content: '';
  position: absolute;
  inset: 6px 2px 4px;
  border-block: 2px solid;
}
.glyph-gate span { position: absolute; inset: 8px 10px 6px; border-inline: 2px solid; }
.glyph-barrier::before { content: ''; position: absolute; left: 3px; bottom: 1px; width: 8px; height: 25px; border: 2px solid; border-radius: 2px; }
.glyph-barrier::after { content: ''; position: absolute; left: 11px; top: 7px; width: 25px; height: 5px; border: 2px solid; border-left: 0; border-radius: 0 2px 2px 0; }

.feedback {
  min-height: 48px;
  margin-top: 15px;
  display: flex;
  align-items: baseline;
  gap: 9px;
  color: var(--muted);
  font-size: .875rem;
  overflow-wrap: anywhere;
}
.feedback:not(:empty)::before { content: ''; width: 7px; height: 7px; border: 1px solid; border-radius: 50%; flex: none; }
.feedback[data-tone="success"] { color: var(--accent); }
.feedback[data-tone="success"]::before { background: currentColor; }
.feedback[data-tone="warning"], .feedback[data-tone="hint"] { color: var(--warning); }
footer { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 11px; }
.text-button { min-height: 44px; padding: 0; background: none; color: var(--muted); border: 0; text-decoration: underline; text-underline-offset: 4px; font-size: .875rem; }

.steps { display: grid; gap: 15px; margin: 23px 0 0; padding: 0 0 0 23px; }
.steps li { padding-inline-start: 6px; }
.steps li::marker { color: var(--accent); font-weight: 650; }
.steps p { margin-top: 3px; color: var(--muted); }
.steps button { display: block; margin-top: 8px; }
#activate { display: grid; gap: 8px; margin-top: 23px; }
#activate label { font-size: .875rem; font-weight: 650; }
#activate button { margin-top: 5px; }
input { min-height: 50px; min-width: 0; padding: 9px 12px; background: var(--surface); color: var(--ink); border: 1px solid #606a61; border-radius: 8px; caret-color: var(--accent); }
.primary, .secondary { min-height: 46px; padding: 8px 15px; border-radius: 8px; font-weight: 650; }
.primary { background: var(--key); color: var(--key-ink); border: 1px solid var(--key); }
.secondary { background: var(--surface); color: var(--ink); border: 1px solid #606a61; }
.primary:disabled, .secondary:disabled, .text-button:disabled { opacity: .65; }
dialog { width: min(calc(100% - 40px), 400px); border: 1px solid var(--line); border-radius: 12px; padding: 24px; background: var(--surface); color: var(--ink); }
dialog h2 { font-size: 1.375rem; }
dialog::backdrop { background: #101310b3; }
.dialog-actions { display: flex; justify-content: end; gap: 8px; margin-top: 21px; }
@media (min-width: 640px) { .shell { padding-top: max(70px, env(safe-area-inset-top)); } }
@media (max-width: 370px) {
  .shell { padding-inline: 18px; }
  .trigger { padding-inline: 13px; gap: 8px; grid-template-columns: 38px minmax(0, 1fr) auto; }
}
