/* Labeled icon button — icon + visible label + screen-reader span.
   Overrides the circular-grid rule in buttons.css that fires on any .btn
   containing both an icon and a .for-screen-reader span. Without these
   overrides, our icon and label would stack at grid-area 1/1 and overlap. */

.btn.btn--labeled {
  /* Override .btn:where(:has(.for-screen-reader):has(img, svg)) defaults */
  aspect-ratio: auto;
  block-size: auto;
  inline-size: auto;
  display: inline-flex;

  /* Labeled-button shape */
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.4rem 0.55rem;
  border-radius: 1rem;
  min-inline-size: 3.5rem;
}

.btn--labeled > * {
  /* Defeat `> * { grid-area: 1/1 }` — children stack vertically again */
  grid-area: auto;
}

.btn--labeled .icon-label {
  font-size: 0.72rem;
  line-height: 1.1;
  font-weight: 500;
  color: var(--color-ink);
  text-align: center;
  white-space: nowrap;
}

.btn--labeled img,
.btn--labeled svg {
  inline-size: 1.4em;
  block-size: 1.4em;
}

@media (max-width: 600px) {
  .btn--labeled .icon-label { font-size: 0.62rem; }
  .btn--labeled            { padding: 0.3rem 0.4rem; gap: 0.15rem; }
}

@media (max-width: 380px) {
  .btn--labeled .icon-label { display: none; }
}

.btn--labeled .icon-flag {
  font-size: 1.4em;
  line-height: 1;
}

/* Circle toggle — icon inside a circle with label below as plain text.
   Used for sidebar toolbar checkboxes/radios where the wrapping <label>
   contains the input. The wrapper itself is shapeless; only the inner
   .circle-toggle__icon span carries the visible circular border. */

.circle-toggle {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  font-weight: 600;
}

.circle-toggle input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.circle-toggle__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: var(--btn-size);
  block-size: var(--btn-size);
  border-radius: 50%;
  border: 1px solid var(--color-subtle-dark);
  background: transparent;
  transition: background-color 300ms ease, border-color 300ms ease;
}

.circle-toggle__icon img,
.circle-toggle__icon svg {
  inline-size: 1.4em;
  block-size: 1.4em;
  transition: filter 300ms ease;
}

.circle-toggle__label {
  font-size: 0.72rem;
  line-height: 1.1;
  font-weight: 500;
  color: var(--color-ink);
  text-align: center;
  white-space: nowrap;
}

.circle-toggle:has(input:checked) .circle-toggle__icon,
.circle-toggle--primary .circle-toggle__icon {
  background: var(--color-ink);
  border-color: var(--color-ink);
}

.circle-toggle:has(input:checked) .circle-toggle__icon img,
.circle-toggle--primary .circle-toggle__icon img {
  filter: invert(1);
}

a.circle-toggle,
button.circle-toggle {
  /* link_to / button_to default styling — undo browser/btn defaults */
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  color: inherit;
}

form.button_to {
  /* button_to wraps a <form>; keep it as an inline-flex item so it sits
     on the toolbar row like the link_to neighbors. */
  display: inline-flex;
  margin: 0;
}

@media (max-width: 600px) {
  .circle-toggle__label { font-size: 0.62rem; }
}
