/* Reusable controls: buttons, switch, segmented, cards, slider, select, issues, toast. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 var(--sp-2);
  border: 1px solid var(--key-edge);
  border-radius: var(--radius-s);
  background: var(--key);
  box-shadow: inset 0 1px 0 var(--key-hi), var(--key-drop);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  transition: transform var(--press), box-shadow var(--press), background var(--press);
}
.btn:hover:not(:disabled) { background: var(--key-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: inset 0 1px 0 var(--key-hi); }
.btn:disabled { box-shadow: none; color: var(--muted); cursor: not-allowed; }
/* Program key: the one amber raised key. */
.btn-primary { background: var(--accent); border-color: var(--accent-edge); color: var(--on-accent); box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.35), 0 1px 0 var(--accent-edge), 0 2px 3px var(--drop-2); }
.btn-primary:hover:not(:disabled) { background: var(--accent); }
.btn-primary:active:not(:disabled) { box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.35); }
.btn-primary:disabled { background: var(--key); border-color: var(--key-edge); color: var(--muted); }
/* The Program screen keeps its flat buttons: the raised-key look stays off the always-dark programming flow. */
.program .btn, .program .btn:active:not(:disabled) { box-shadow: none; transform: none; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost:active:not(:disabled) { box-shadow: none; }
.btn-outline { background: var(--surface); border-color: var(--line); box-shadow: none; }
.btn-outline:hover:not(:disabled) { background: var(--surface-2); }
.btn-icon { padding: 0; width: var(--tap); }
.btn-danger { color: var(--danger); }
.btn-small { font-size: var(--fs-small); padding: 0 12px; }
/* On phones the topbar keys show only their icon, and shrink to the 44 px tap size so the wordmark and the language key fit beside them. */
@media (max-width: 399px) { .btn-label { display: none; } #btn-presets, #btn-saved { padding: 0; } }

.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--sp-2);
  display: grid;
  gap: var(--sp-1);
  min-width: 0;
}
.card-title { font-size: var(--fs-body); line-height: var(--lh-body); font-weight: 600; }
.hint { color: var(--muted); font-size: var(--fs-small); line-height: var(--lh-small); }
.note { color: var(--muted); font-size: var(--fs-body); }
.field-label { font-size: var(--fs-small); line-height: var(--lh-small); font-weight: 500; color: var(--muted); padding: 0; margin-bottom: 4px; }

/* Switch */
.switch {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: var(--tap);
  cursor: pointer;
}
.switch input { position: absolute; opacity: 0; width: var(--tap); height: var(--tap); margin: 0; cursor: pointer; }
.switch-track {
  flex: none;
  position: relative;
  width: 44px;
  height: 24px;
  margin-top: 10px;
  border-radius: 12px;
  background: var(--well);
  border: 1px solid var(--well-edge);
  box-shadow: var(--well-shade);
}
/* Amber fill bar: only the exposed part of the track (left of the thumb) when the switch is on. */
.switch-track::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 14px;
  height: 14px;
  border-radius: 7px;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--press);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--key);
  border: 1px solid var(--key-edge);
  box-shadow: inset 0 1px 0 var(--key-hi), var(--key-drop);
  transition: transform 0.15s;
}
.switch input:checked + .switch-track::before { opacity: 1; }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.switch-text { display: grid; padding-top: 8px; min-width: 0; }
.switch-label { font-weight: 500; line-height: 28px; }

/* Segmented control and option cards */
.seg-field { display: grid; min-width: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; background: var(--well); border: 1px solid var(--well-edge); box-shadow: var(--well-shade); border-radius: var(--radius-s); padding: 4px; }
.seg-opt { position: relative; flex: 1 1 auto; display: flex; min-width: 0; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-opt > span {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--muted);
  transition: transform var(--press), box-shadow var(--press), background var(--press);
}
.seg-opt::before { content: ""; position: absolute; inset: -4px 0; } /* extends the tap area to 44px */
/* Checked: a raised key face, bold ink and a 2 px amber bar, so it is not told by colour alone. */
.seg-opt input:checked + span { background: var(--key); border-color: var(--key-edge); box-shadow: inset 0 1px 0 var(--key-hi), var(--key-drop); color: var(--text); font-weight: 600; }
.seg-opt input:checked + span::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 3px; height: 2px; border-radius: 1px; background: var(--accent-strong); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.seg-opt:hover input:not(:checked) + span { color: var(--text); background: var(--surface-2); }
.seg-opt:active input + span { transform: translateY(1px); }

.cards { display: grid; gap: var(--sp-1); }
.cards .seg { display: grid; gap: var(--sp-1); background: none; border: 0; box-shadow: none; padding: 0; }
.cards .seg-opt > span {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  text-align: left;
  gap: 2px;
  min-height: var(--tap);
  padding: 12px 48px 12px var(--sp-2);
  border: 1px solid var(--key-edge);
  background: var(--key);
  box-shadow: inset 0 1px 0 var(--key-hi), var(--key-drop);
  color: var(--text);
  border-radius: var(--radius);
  font-size: var(--fs-body);
  font-weight: 500;
}
.cards .seg-opt::before { display: none; }
.cards .seg-opt:hover input:not(:checked) + span { background: var(--key-hover); color: var(--text); }
.cards .seg-opt:active input + span { box-shadow: inset 0 1px 0 var(--key-hi); }
.cards .seg-opt input:checked + span { background: var(--key); border-color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--accent-strong), var(--key-drop); color: var(--text); font-weight: 500; }
.cards .seg-opt input:checked + span::after { left: auto; right: var(--sp-2); top: 50%; bottom: auto; width: 10px; height: 6px; margin-top: -5px; border: solid var(--accent-strong); border-width: 0 0 2px 2px; border-radius: 0; background: none; transform: rotate(-45deg); }
.opt-desc { font-weight: 400; color: var(--muted); font-size: var(--fs-small); line-height: var(--lh-small); }

/* Slider */
.slider-field { display: grid; gap: 0; min-width: 0; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-1); flex-wrap: wrap; }
.slider-head label { font-size: var(--fs-small); font-weight: 500; color: var(--muted); }
.slider-out { font-weight: 500; font-variant-numeric: tabular-nums; }
.slider-field input[type=range] {
  width: 100%;
  height: var(--tap);
  margin: 0;
  accent-color: var(--accent-strong);
  background: none;
  cursor: pointer;
}
.slider-ends { display: flex; justify-content: space-between; gap: var(--sp-1); color: var(--muted); font-size: var(--fs-caption); line-height: var(--lh-caption); }
.slider-note { margin-top: var(--sp-1); }

/* Select */
.select-field { display: grid; min-width: 0; }
.select-field select {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  background: var(--key);
  border: 1px solid var(--key-edge);
  box-shadow: inset 0 1px 0 var(--key-hi), var(--key-drop);
  border-radius: var(--radius-s);
  color: var(--text);
}
.select-field select:hover { background: var(--key-hover); }

/* Inline issues */
.issues:empty { display: none; }
.issues { display: grid; gap: 4px; }
.issue {
  font-size: var(--fs-small);
  line-height: var(--lh-small);
  padding: 8px 12px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--raised);
}
.issue b { font-weight: 600; margin-right: 4px; }
.issue-error { border-color: var(--danger); }
.issue-error b { color: var(--danger); }
.issue-warning { border-color: var(--accent-strong); }
.issue-warning b { color: var(--accent-strong); }
.issue-info { border-color: var(--muted); }
.issue-info b { color: var(--muted); }

/* Toast. The host is a popover so it is drawn above open dialogs; below 1200 px it clears the sticky bar. */
.toasts {
  position: fixed;
  inset: auto var(--sp-2) calc(var(--bar-h) + var(--sp-2)) var(--sp-2);
  width: auto;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  overflow: visible;
  z-index: 50;
  display: grid;
  gap: var(--sp-1);
  justify-items: center;
  pointer-events: none;
}
.toasts:empty { display: none; }
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: 480px;
  padding: 4px 4px 4px var(--sp-2);
  background: var(--key);
  color: var(--text);
  border: 1px solid var(--key-edge);
  border-radius: var(--radius-s);
  box-shadow: inset 0 1px 0 var(--key-hi), 0 8px 24px var(--shadow);
}
.toast-text { padding: 8px 0; }
@media (min-width: 1200px) { .toasts { bottom: var(--sp-3); } }
/* A toast placed inside an open dialog (see toast.js) sits under the dialog header. */
.toast-inline { margin: var(--sp-1) var(--sp-2) 0; max-width: none; justify-content: space-between; }
