#sheet:has(#counter-pairing-setup) {
  left: var(--counter-sheet-left, 0px);
  right: var(--counter-sheet-right, 0px);
  bottom: var(--counter-sheet-bottom, 0px);
  max-height: min(88dvh, var(--counter-sheet-height, 88dvh));
}

#sheet:has(#counter-pairing-setup) #sheet-body { overflow-x: hidden; }

#sheet-body #counter-pairing-setup {
  --counter-paper: #f6ecd2;
  --counter-ink: #17251a;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  color: var(--counter-paper);
  font: 400 15px/1.45 system-ui, sans-serif;
  letter-spacing: normal;
  overflow-wrap: anywhere;
  padding-bottom: 6px;
}

#counter-pairing-setup h2 {
  font: 400 clamp(1.25rem, 5vw, 1.65rem)/1.2 var(--comicfont, var(--display));
  margin-bottom: -6px;
}

#counter-pairing-setup h3 { font-size: 1rem; }
#counter-pairing-setup .counter-pairing-hint { color: #c7d9c6; font-size: .875rem; }

.counter-pairing-field { display: grid; gap: 6px; min-width: 0; }
.counter-pairing-field label { font-weight: 650; }

#counter-pairing-setup :is(input, select, textarea) {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 2px solid #18291c;
  border-radius: 9px;
  background-color: var(--counter-paper);
  color: var(--counter-ink);
  -webkit-text-fill-color: var(--counter-ink);
  color-scheme: light;
  font: 500 1rem/1.35 system-ui, sans-serif;
}

#counter-pairing-setup select {
  padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, #344932 50%),
    linear-gradient(135deg, #344932 50%, transparent 50%);
  background-position: right 18px center, right 12px center;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

#counter-pairing-setup textarea {
  font-family: ui-monospace, Menlo, monospace;
  resize: vertical;
}

#counter-pairing-setup textarea::placeholder {
  color: #535e4e;
  -webkit-text-fill-color: #535e4e;
  opacity: 1;
}

#counter-pairing-setup :focus-visible { outline: 3px solid #ffe174; outline-offset: 2px; }
#counter-pairing-setup .counter-pairing-error { color: #ffc0b1; }
#counter-pairing-setup .counter-pairing-error:empty { display: none; }

#counter-pairing-setup .btn {
  min-height: 44px;
  font: 700 1rem/1.25 system-ui, sans-serif;
}

#counter-enable { width: 100%; }

#counter-pairing-result {
  padding: 12px 14px;
  border: 2px solid #18291c;
  border-radius: 10px;
  background: var(--counter-paper);
  color: var(--counter-ink);
}

.counter-pairing-code-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 10px;
  margin: 4px 0;
}

#counter-pairing-code {
  display: block;
  min-width: 0;
  font: 750 clamp(1.1rem, 5.4vw, 1.75rem)/1.25 ui-monospace, Menlo, monospace;
  letter-spacing: .045em;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
}

#counter-copy-code {
  min-height: 44px;
  padding: 6px 11px;
  border: 1px solid #0b3f15;
  border-radius: 7px;
  background: #0b3f15;
  color: var(--counter-paper);
  font-weight: 750;
  cursor: pointer;
}

#counter-copy-code:focus-visible { outline-color: #0b3f15; }
#counter-copy-status { margin-top: 4px; color: #0b3f15; font-size: .875rem; font-weight: 650; }
#counter-copy-status:empty { display: none; }
#counter-pairing-expiry { font-size: .875rem; color: #43543d; }
#counter-device-link { justify-self: start; color: #ffe174; text-underline-offset: .18em; }

.counter-pairing-stations {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line2);
}

.counter-pairing-station { padding: 8px 0; border-bottom: 1px solid var(--line2); }
.counter-pairing-station .btn { margin-top: 6px; }
#counter-stations-refresh { justify-self: start; }
