form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.input-row {
  display: flex;
  gap: var(--space-2);
  align-items: stretch;
}

input[type="text"] {
  min-width: 0;
  flex: 1;
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-panel);
  outline: none;
  background: rgb(25 29 23 / 72%);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 16px;
  transition: border-color var(--transition), background-color var(--transition), box-shadow var(--transition);
}

input[type="text"]::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

input[type="text"]:focus {
  border-color: var(--primary);
  background: var(--surface-raised);
  box-shadow: 0 0 0 3px rgb(162 211 152 / 14%);
}

input[type="text"]:read-only {
  cursor: wait;
  opacity: 0.8;
}

.btn {
  position: relative;
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 20px;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1px;
  line-height: 20px;
  transition: box-shadow var(--transition), background-color var(--transition), color var(--transition), transform var(--transition);
}

.btn::after {
  position: absolute;
  inset: 0;
  background: currentColor;
  content: "";
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.btn:hover:not(:disabled)::after,
.btn:focus-visible:not(:disabled)::after {
  opacity: 0.08;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.btn-label {
  position: relative;
  z-index: 1;
}

.btn-generate {
  flex: 0 0 auto;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 1px 2px rgb(0 0 0 / 30%);
}

.btn-random {
  width: 100%;
  border: 1px solid var(--outline-variant);
  background: var(--surface-variant);
  color: var(--text);
}

.btn-random:hover:not(:disabled) {
  box-shadow: 0 2px 6px rgb(0 0 0 / 24%);
}

/* Export actions: 下载 PNG is the primary one, the two copy actions are equal
   secondaries. Adapted from the reference system's tonal/outlined patterns —
   the reference ships no outlined button variant, so this is a local adaptation. */
.action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.btn-action {
  border: 1px solid color-mix(in srgb, var(--outline) 45%, transparent);
  background: transparent;
  color: var(--text);
}

.btn-action.btn-dl {
  grid-column: 1 / -1;
  border-color: transparent;
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.btn-action:hover:not(:disabled) {
  box-shadow: 0 1px 2px rgb(0 0 0 / 30%);
}

/* Holds more than one setting, so labels need a wider column gap than the 8px
   each label already puts between its own box and text — at that spacing two
   adjacent settings read as one. */
.switch-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: var(--space-5);
  row-gap: var(--space-2);
}

.switch-label {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}

/* Switch. The checkbox itself is the track, so keyboard operation, the
   `.checked` reads in ui/handlers.js and the focus ring from reset.css all keep
   working untouched; only its rendering changes. The thumb is the ::before. */
.switch-label input {
  position: relative;
  flex: none;
  width: 52px;
  height: 32px;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--surface-variant);
  cursor: pointer;
  transition: background-color var(--transition);
}

.switch-label input::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  /* --text-muted rather than the MD3 off-thumb token (--outline), which sits at
     3.89:1 on this track; this reads at 7.20:1 and keeps the thumb bright in
     both states, as it is on iOS. */
  background: var(--text-muted);
  /* The thumb is the raised element, so it carries the shadow. */
  box-shadow: 0 1px 3px rgb(0 0 0 / 45%);
  transition: transform var(--transition), background-color var(--transition);
}

.switch-label input:checked {
  background: var(--primary);
}

.switch-label input:checked::before {
  /* 52 − 4 − 24 − 4 = 20 travels the thumb to the far edge, keeping the 4px
     inset identical at both ends. */
  transform: translateX(20px);
  /* Not white as on iOS: --primary is a pale green, and a light thumb on it
     would sit at about 1.9:1. --on-primary is the token for content placed on
     --primary, so the thumb keeps its contrast in both states. */
  background: var(--on-primary);
}

/* Border width. 添加边框 turns the slider off instead of removing it, so the row
   keeps its place and the readout keeps reporting the size the export will have. */
.border-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* The text dims as a group so the inert handle does not sit under a label that
   still reads as active. 0.6 leaves the readout above 4.5:1 on the panel. */
.border-row.is-disabled .border-label,
.border-row.is-disabled .border-value,
.border-row.is-disabled .section-hint {
  opacity: 0.6;
}

.border-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}

.border-label {
  color: var(--text);
  font-size: 14px;
}

.border-value {
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* Styled native range input, adapted from the reference system's slider: a 4px
   track with a primary handle that grows on hover, focus and drag. The filled
   share is passed in as --range-progress because a native range cannot style it. */
.border-range {
  width: 100%;
  min-width: 0;
  height: 20px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

/* Chromium: filled portion drawn as a gradient up to --range-progress. */
.border-range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: linear-gradient(
    to right,
    var(--primary) 0 var(--range-progress, 0%),
    var(--surface-variant) var(--range-progress, 0%) 100%
  );
}

.border-range::-moz-range-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface-variant);
}

/* Firefox has a native progress pseudo-element for the filled portion. */
.border-range::-moz-range-progress {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--primary);
}

.border-range::-webkit-slider-thumb {
  width: 12px;
  height: 12px;
  /* (4px track − 12px thumb) / 2 keeps the thumb centered on the track. */
  margin-top: -4px;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: var(--radius-pill);
  background-color: var(--primary);
  transition: transform var(--transition);
}

.border-range::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: var(--radius-pill);
  background-color: var(--primary);
  transition: transform var(--transition);
}

.border-range:hover:not(:disabled)::-webkit-slider-thumb,
.border-range:focus-visible:not(:disabled)::-webkit-slider-thumb {
  transform: scale(1.2);
}

.border-range:hover:not(:disabled)::-moz-range-thumb,
.border-range:focus-visible:not(:disabled)::-moz-range-thumb {
  transform: scale(1.2);
}

.border-range:active::-webkit-slider-thumb {
  transform: scale(1.4);
}

.border-range:active::-moz-range-thumb {
  transform: scale(1.4);
}

/* Disabled while 添加边框 is unchecked. The handle needs its own muted colors
   rather than the group opacity above: a faded track would sink into the panel
   and leave the thumb looking unattached. Both the fill and the thumb go neutral
   so an inert slider cannot be read as a green, active one. */
.border-range:disabled {
  cursor: not-allowed;
}

.border-range:disabled::-webkit-slider-runnable-track {
  background: var(--outline-variant);
}

.border-range:disabled::-moz-range-progress {
  background: var(--outline-variant);
}

.border-range:disabled::-webkit-slider-thumb,
.border-range:disabled::-moz-range-thumb {
  background-color: var(--outline);
}

.status {
  min-height: 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.status[data-state="success"] {
  color: var(--primary);
}

.status[data-state="error"] {
  color: var(--error);
}

@media (max-width: 420px) {
  .input-row {
    flex-direction: column;
  }

  /* Stacked, the input must keep its 44px height: `flex: 1` sets a 0 flex-basis,
     which overrides `height` along the column axis and collapses the field. */
  .input-row input[type="text"] {
    flex: none;
  }

  .btn-generate {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn:active:not(:disabled) {
    transform: none;
  }

  .border-range:hover:not(:disabled)::-webkit-slider-thumb,
  .border-range:focus-visible:not(:disabled)::-webkit-slider-thumb,
  .border-range:active::-webkit-slider-thumb,
  .border-range:hover:not(:disabled)::-moz-range-thumb,
  .border-range:focus-visible:not(:disabled)::-moz-range-thumb,
  .border-range:active::-moz-range-thumb {
    transform: none;
  }
}
