/*
 * /settings/ — laid out like a system settings page: a sidebar of sections
 * that follows the reader, and sections of rows with the label on the left and the
 * control on the right. The controls are the system's own kinds — a
 * segmented control, a switch — moved on lazer's curves.
 */

.settings-layout {
  display: grid;
  grid-template-columns: minmax(11rem, 13rem) minmax(0, 1fr);
  gap: clamp(1.25rem, 3vw, 2.5rem);
  align-items: start;
}

/* ------------------------------------------------------------ sidebar */

.settings-nav {
  position: sticky;
  top: calc(var(--header-height) + 1rem);
  display: grid;
  gap: 2px;
}

.settings-nav a {
  position: relative;
  display: flex;
  gap: var(--space-3);
  align-items: center;
  min-height: 2.75rem;
  padding: 0.3rem var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-weight: 600;
  text-decoration: none;
  transition: background-color 600ms var(--ease-out-quint), color 500ms var(--ease-out-quint);
}

.settings-nav a:hover {
  background: color-mix(in srgb, var(--color-text) 6%, transparent);
  color: var(--color-text);
  transition-duration: 100ms;
}

.settings-nav a[aria-current="true"] {
  color: var(--color-accent);
}

.settings-nav a::before {
  content: "";
  position: absolute;
  top: 0.6rem;
  bottom: 0.6rem;
  left: 0;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--color-accent);
  transform: scaleY(0);
  transition: transform 500ms var(--ease-out-quint);
}

.settings-nav a[aria-current="true"]::before {
  transform: scaleY(1);
}

.settings-nav svg {
  flex: none;
  width: 1.2rem;
  height: 1.2rem;
}

/* ------------------------------------------------------------ sections */

/* Sections are divided by rules, not boxed: a heading, a sentence, then
 * the rows. */
.settings-content {
  display: grid;
  min-width: 0;
}

.settings-section {
  padding-block: clamp(1.5rem, 3vw, 2.25rem);
  border-top: 1px solid var(--color-line);
  scroll-margin-top: calc(var(--header-height) + 1rem);
}

.settings-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.settings-section__head {
  margin-bottom: var(--space-2);
}

.settings-section__head h2 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-2xl);
}

.settings-section__head p {
  max-width: 44rem;
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.setting {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-5);
  align-items: center;
  justify-content: space-between;
  padding-block: var(--space-4);
  border-bottom: 1px solid var(--color-line);
}

.setting:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.setting--stacked {
  flex-direction: column;
  align-items: stretch;
}

/* In a column the text's basis would be a height, not a width. */
.setting--stacked > .setting__text {
  flex: none;
}

.setting--switch {
  cursor: pointer;
}

.setting__text {
  display: grid;
  flex: 1 1 14rem;
  gap: 0.2rem;
  min-width: 0;
}

.setting__label {
  margin: 0;
  color: var(--color-text);
  font-weight: 600;
}

.setting__help,
.setting .form-status {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.setting .form-status:empty {
  display: none;
}

/* ----------------------------------------------------- segmented choice */

/*
 * A system segmented control: a grey track and a raised white thumb behind
 * the chosen option, the label staying dark. The thumb slides between
 * options on lazer's tab timing, 500ms OutQuint (OsuTabControl).
 */
.choice {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  align-self: flex-start;
  max-width: 100%;
  padding: 2px;
  border-radius: 0.6rem;
  background: var(--color-band-strong);
}

.setting:not(.setting--stacked) > .choice {
  align-self: center;
}

.choice__indicator {
  position: absolute;
  z-index: -1;
  top: 0;
  left: 0;
  width: var(--w, 0);
  height: var(--h, 0);
  border-radius: 0.5rem;
  background: var(--color-surface-strong);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12), 0 3px 8px rgb(0 0 0 / 0.08);
  opacity: 0;
  transform: translate(var(--x, 0), var(--y, 0));
  transition:
    transform 500ms var(--ease-out-quint),
    width 500ms var(--ease-out-quint),
    height 500ms var(--ease-out-quint),
    opacity 200ms var(--ease-out-quint);
}

.choice__indicator[data-ready] {
  opacity: 1;
}

.choice__indicator[data-instant] {
  transition: none;
}

.choice__option {
  position: relative;
  display: inline-flex;
  cursor: pointer;
}

.choice__option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.choice__option span {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding-inline: 1rem;
  border-radius: 0.5rem;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: color 600ms var(--ease-out-quint);
}

.choice__option:hover span {
  color: var(--color-text);
  transition-duration: 100ms;
}

.choice__option input:checked + span {
  color: var(--color-text);
  font-weight: 600;
}

.choice__option input:focus-visible + span {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* ---------------------------------------------------------------- switch */

/*
 * A system switch — track and round knob — moved the way lazer moves its
 * Nub (osu.Game/Graphics/UserInterface/Nub.cs): switching on is a gain, so
 * the knob lands on a half elastic; switching off settles on OutQuint.
 */
.nub {
  --knob: 1.6rem;
  position: relative;
  flex: none;
  width: 3.1rem;
  height: 1.85rem;
  margin: 0 0 0 auto;
  border: 0;
  border-radius: 999px;
  background: var(--color-rule);
  cursor: pointer;
  appearance: none;
  transition: background-color 300ms var(--ease-out-quint);
}

.nub::before {
  content: "";
  position: absolute;
  top: calc((1.85rem - var(--knob)) / 2);
  left: calc((1.85rem - var(--knob)) / 2);
  width: var(--knob);
  height: var(--knob);
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  transition: transform 300ms var(--ease-out-quint);
}

.nub:checked {
  background: var(--color-accent);
}

.nub:checked::before {
  transform: translateX(calc(3.1rem - 1.85rem));
  transition: transform 450ms var(--ease-out-elastic-half);
}

.nub:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

.nub:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ------------------------------------------------------ motion section */

.motion-levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: var(--space-2) var(--space-5);
  margin: var(--space-4) 0 0;
}

.motion-levels div {
  display: flex;
  gap: var(--space-3);
  align-items: baseline;
}

.motion-levels dt {
  flex: none;
  min-width: 2.5rem;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 700;
}

.motion-levels dd {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.motion-preview {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  min-height: 9rem;
  margin-top: var(--space-5);
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--color-band);
}

.motion-preview__label {
  position: absolute;
  top: var(--space-3);
  left: var(--space-4);
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
}

/* ---------------------------------------------------------------- phone */

@media (max-width: 48rem) {
  .settings-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .settings-nav {
    position: static;
    display: flex;
    gap: var(--space-1);
    margin-inline: calc(-1 * var(--gutter));
    padding: var(--space-2) var(--gutter);
    overflow-x: auto;
    border-bottom: 1px solid var(--color-line);
    background: var(--color-bg);
    scrollbar-width: none;
  }

  .settings-nav a {
    flex: none;
    min-height: 2.4rem;
  }

  .settings-nav a::before {
    top: auto;
    right: 0.75rem;
    bottom: 0;
    left: 0.75rem;
    width: auto;
    height: 3px;
    border-radius: 3px 3px 0 0;
    transform: scaleX(0);
  }

  .settings-nav a[aria-current="true"]::before {
    transform: scaleX(1);
  }
}

html.motion-none :is(.choice__indicator, .nub, .nub::before, .settings-nav a, .settings-nav a::before) {
  transition: none;
}
