/*
 * Component library. Class contracts are shared by the public site and the admin panel.
 * Depends on tokens.css + base.css. Every component is themed purely through tokens.
 */

/* ------------------------------------------------------------------ Icons */

.icon {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}

.icon--loader {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------------------------------------------------------- Buttons */

.btn {
  --btn-bg: var(--surface);
  --btn-bg-hover: var(--surface-hover);
  --btn-fg: var(--fg);
  --btn-border: var(--border-strong);
  --btn-h: var(--control-h);
  --btn-px: var(--space-4);

  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--btn-h);
  padding: 0 var(--btn-px);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  cursor: pointer;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.btn:hover {
  background: var(--btn-bg-hover);
  text-decoration: none;
}

.btn:active:not(:disabled):not([aria-disabled="true"]) {
  transform: translateY(1px) scale(0.985);
}

.btn:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.btn .icon {
  margin-inline: -2px;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn--primary {
  --btn-bg: var(--accent);
  --btn-bg-hover: var(--accent-hover);
  --btn-fg: var(--accent-fg);
  --btn-border: transparent;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 1px 2px rgba(0, 0, 0, 0.2);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-bg-hover: var(--surface-hover);
  --btn-border: transparent;
  --btn-fg: var(--fg-muted);
}

.btn--ghost:hover {
  color: var(--fg);
}

.btn--outline {
  --btn-bg: transparent;
  --btn-bg-hover: var(--surface);
  --btn-border: var(--border-strong);
}

.btn--outline:hover {
  border-color: var(--fg-subtle);
}

.btn--danger {
  --btn-bg: var(--danger-soft);
  --btn-bg-hover: var(--danger);
  --btn-fg: var(--danger);
  --btn-border: transparent;
}

.btn--danger:hover {
  color: #fff;
}

.btn--sm {
  --btn-h: var(--control-h-sm);
  --btn-px: var(--space-3);
  font-size: var(--text-xs);
  gap: 6px;
}

.btn--lg {
  --btn-h: var(--control-h-lg);
  --btn-px: var(--space-6);
  font-size: var(--text-base);
  border-radius: var(--radius-md);
}

.btn--icon {
  --btn-px: 0;
  width: var(--btn-h);
  flex-shrink: 0;
}

.btn--icon .icon {
  margin: 0;
}

.btn--block {
  display: flex;
  width: 100%;
}

.btn.is-loading {
  color: transparent !important;
  pointer-events: none;
}

.btn.is-loading > * {
  visibility: hidden;
}

.btn.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--btn-fg);
  border-right-color: transparent;
  opacity: 0.85;
  animation: spin 0.7s linear infinite;
}

@media (pointer: coarse) {
  .btn {
    --control-h: 44px;
    --control-h-sm: 40px;
  }
}

/* ------------------------------------------------------------------ Forms */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field__label {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--fg);
}

.field__optional {
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--fg-subtle);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--fg-subtle);
  line-height: 1.45;
}

.field__error {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  color: var(--danger);
  line-height: 1.45;
  animation: field-error-in var(--dur-base) var(--ease-out);
}

@keyframes field-error-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
}

.input,
.textarea,
.select {
  display: block;
  width: 100%;
  min-height: var(--control-h);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--bg-inset);
  color: var(--fg);
  font-size: var(--text-base);
  line-height: 1.4;
  appearance: none;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

@media (min-width: 720px) {
  .input,
  .textarea,
  .select {
    font-size: var(--text-sm);
  }
}

.input::placeholder,
.textarea::placeholder {
  color: var(--fg-subtle);
  opacity: 1;
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--fg-subtle);
}

.input:focus,
.textarea:focus,
.select:focus,
.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background-color: var(--bg-elev-1);
}

.input:disabled,
.textarea:disabled,
.select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input[readonly] {
  background: transparent;
}

.input[type="number"] {
  font-variant-numeric: tabular-nums;
}

.input[type="date"]::-webkit-calendar-picker-indicator {
  opacity: 0.6;
  cursor: pointer;
}

[data-theme="dark"] .input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

.textarea {
  min-height: 96px;
  padding: 10px var(--space-3);
  resize: vertical;
  line-height: var(--leading-normal);
}

.select {
  padding-right: 36px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a39d92' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}

.select option {
  background: var(--bg-elev-2);
  color: var(--fg);
}

.field.has-error .input,
.field.has-error .textarea,
.field.has-error .select,
.input[aria-invalid="true"],
.textarea[aria-invalid="true"],
.select[aria-invalid="true"] {
  border-color: var(--danger);
}

.field.has-error .input:focus,
.field.has-error .textarea:focus,
.field.has-error .select:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}

@media (pointer: coarse) {
  .input,
  .select {
    min-height: 44px;
  }
}

/* Input group */
.input-group {
  display: flex;
  align-items: stretch;
  min-width: 0;
}

.input-group > .input,
.input-group > .select {
  flex: 1 1 auto;
  min-width: 0;
  border-radius: 0;
}

.input-group > :first-child {
  border-top-left-radius: var(--radius-sm);
  border-bottom-left-radius: var(--radius-sm);
}

.input-group > :last-child {
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
}

.input-group > * + * {
  margin-left: -1px;
}

.input-group > .input:focus,
.input-group > .select:focus {
  position: relative;
  z-index: 1;
}

.input-group > .select {
  flex: 0 0 auto;
  width: auto;
}

.input-group__addon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* Search field */
.search-field {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.search-field > .icon {
  position: absolute;
  left: 12px;
  color: var(--fg-subtle);
  pointer-events: none;
  transition: color var(--dur-fast) var(--ease-out);
}

.search-field > .input {
  padding-left: 38px;
  padding-right: 72px;
}

.search-field > .input::-webkit-search-cancel-button,
.search-field > .input::-webkit-search-decoration {
  appearance: none;
}

.search-field:focus-within > .icon {
  color: var(--fg);
}

.search-field > .kbd {
  position: absolute;
  right: 10px;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.search-field:focus-within > .kbd,
.search-field.has-value > .kbd {
  opacity: 0;
}

.search-field__clear {
  position: absolute;
  right: 4px;
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--fg-subtle);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.85);
  transition:
    opacity var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out),
    visibility 0s linear var(--dur-fast);
}

.search-field.has-value .search-field__clear,
.search-field:has(.input:not(:placeholder-shown)) .search-field__clear {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}

.search-field:has(.input:not(:placeholder-shown)) > .kbd {
  opacity: 0;
}

.search-field__clear:hover {
  color: var(--fg);
  background: var(--surface-hover);
}

/* Switch */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--control-h-sm);
  cursor: pointer;
  user-select: none;
  font-size: var(--text-sm);
}

.switch > input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.switch__track {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  box-shadow: inset 0 0 0 1px var(--border);
  transition: background-color var(--dur-base) var(--ease-out);
}

.switch__track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--fg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform var(--dur-base) var(--ease-spring), background-color var(--dur-base) var(--ease-out);
}

[data-theme="light"] .switch__track::after {
  background: #fff;
}

.switch > input:checked + .switch__track {
  background: var(--accent);
}

.switch > input:checked + .switch__track::after {
  transform: translateX(16px);
  background: var(--accent-fg);
}

[data-theme="light"] .switch > input:checked + .switch__track::after {
  background: #fff;
}

.switch:active .switch__track::after {
  width: 19px;
}

.switch > input:checked:active + .switch__track::after {
  transform: translateX(13px);
}

.switch > input:focus-visible + .switch__track {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.switch > input:disabled ~ * {
  opacity: 0.45;
  cursor: not-allowed;
}

.switch__label {
  color: var(--fg);
}

/* Checkbox + radio */
.checkbox,
.radio {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--control-h-sm);
  cursor: pointer;
  user-select: none;
  font-size: var(--text-sm);
}

.checkbox > input,
.radio > input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.checkbox__box,
.radio__box {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--fg-subtle);
  border-radius: 5px;
  background: var(--bg-inset);
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

.radio__box {
  border-radius: 50%;
}

.checkbox__box::after {
  content: '';
  width: 10px;
  height: 6px;
  margin-top: -2px;
  border-left: 2px solid var(--accent-fg);
  border-bottom: 2px solid var(--accent-fg);
  transform: rotate(-45deg) scale(0);
  transition: transform var(--dur-fast) var(--ease-spring);
}

.radio__box::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-fg);
  transform: scale(0);
  transition: transform var(--dur-fast) var(--ease-spring);
}

.checkbox:hover .checkbox__box,
.radio:hover .radio__box {
  border-color: var(--fg-muted);
}

.checkbox > input:checked + .checkbox__box,
.checkbox > input:indeterminate + .checkbox__box,
.radio > input:checked + .radio__box {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox > input:checked + .checkbox__box::after,
.radio > input:checked + .radio__box::after {
  transform: rotate(-45deg) scale(1);
}

.radio > input:checked + .radio__box::after {
  transform: scale(1);
}

.checkbox > input:indeterminate + .checkbox__box::after {
  width: 10px;
  height: 0;
  margin: 0;
  border-left: 0;
  transform: none;
}

.checkbox > input:focus-visible + .checkbox__box,
.radio > input:focus-visible + .radio__box {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.checkbox > input:disabled ~ *,
.radio > input:disabled ~ * {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ------------------------------------------------------- Chips, tags, badges */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--fg-muted);
  font-size: var(--text-sm);
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

button.chip,
a.chip {
  cursor: pointer;
}

button.chip:hover,
a.chip:hover {
  border-color: var(--fg-subtle);
  color: var(--fg);
  background: var(--surface);
}

button.chip:active,
a.chip:active {
  transform: scale(0.97);
}

.chip:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.chip.is-active,
.chip[aria-pressed="true"] {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--fg-inverse);
}

.chip.is-active:hover,
.chip[aria-pressed="true"]:hover {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--fg-inverse);
  opacity: 0.9;
}

.chip:disabled,
.chip[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.chip__count {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--fg-subtle);
}

.chip.is-active .chip__count,
.chip[aria-pressed="true"] .chip__count {
  color: inherit;
  opacity: 0.65;
}

.chip__remove {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: -6px;
  border-radius: 50%;
  color: inherit;
  opacity: 0.6;
  transition: opacity var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}

.chip__remove:hover {
  opacity: 1;
  background: var(--surface-hover);
}

.chip.is-active .chip__remove:hover {
  background: rgba(127, 127, 127, 0.25);
}

.chip .icon {
  margin-left: -2px;
}

@media (pointer: coarse) {
  .chip {
    min-height: 40px;
    padding: 0 14px;
  }
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-xs);
  background: var(--surface-hover);
  color: var(--fg-muted);
  font-size: var(--text-xs);
  line-height: 1;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.badge .icon {
  width: 12px;
  height: 12px;
}

.badge--accent {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-fg);
}

.badge--success {
  border-color: transparent;
  background: var(--success-soft);
  color: var(--success);
}

.badge--warning {
  border-color: transparent;
  background: var(--warning-soft);
  color: var(--warning);
}

.badge--danger {
  border-color: transparent;
  background: var(--danger-soft);
  color: var(--danger);
}

.badge--muted {
  border-color: transparent;
  background: var(--surface-hover);
  color: var(--fg-subtle);
}

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-elev-1);
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-subtle);
}

.dot--accent {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.dot--success {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.dot--warning {
  background: var(--warning);
  box-shadow: 0 0 0 3px var(--warning-soft);
}

.dot--danger {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.dot.is-pulsing {
  animation: dot-pulse 1.6s var(--ease-in-out) infinite;
}

@keyframes dot-pulse {
  50% {
    opacity: 0.45;
  }
}

/* ------------------------------------------------------------- Segmented */

.segmented {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius-sm) + 3px);
  background: var(--bg-inset);
}

.segmented__item {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  min-width: 32px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--fg-subtle);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}

.segmented__item:hover {
  color: var(--fg);
}

.segmented__item[aria-pressed="true"],
.segmented__item[aria-checked="true"],
.segmented__item.is-active {
  color: var(--fg);
  background: var(--bg-elev-2);
  box-shadow: 0 0 0 1px var(--border-strong), var(--shadow-sm);
}

.segmented__item:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 1px;
}

.segmented__item:disabled {
  opacity: 0.4;
}

@media (pointer: coarse) {
  .segmented__item {
    min-height: 36px;
    min-width: 40px;
  }
}

/* ---------------------------------------------------------- Menu, popover */

.popover {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-dropdown);
  min-width: 200px;
  max-width: min(360px, calc(100vw - 16px));
  max-height: min(480px, calc(100vh - 16px));
  overflow: auto;
  overscroll-behavior: contain;
  padding: var(--space-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-elev-2);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(var(--popover-shift, -4px)) scale(0.98);
  transform-origin: var(--popover-origin, top left);
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.popover[data-side="top"] {
  --popover-shift: 4px;
}

.popover.is-open {
  opacity: 1;
  transform: none;
}

.popover.is-leaving {
  opacity: 0;
  transform: scale(0.98);
  pointer-events: none;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 180px;
  padding: 0;
  list-style: none;
}

.menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: var(--text-sm);
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.menu__item:hover,
.menu__item:focus-visible {
  outline: none;
  background: var(--surface-hover);
}

.menu__item:focus-visible {
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.menu__item.is-active {
  color: var(--fg);
  font-weight: 500;
}

.menu__item.is-active::after {
  content: '';
  width: 6px;
  height: 6px;
  margin-left: auto;
  border-radius: 50%;
  background: var(--accent);
}

.menu__item.is-danger {
  color: var(--danger);
}

.menu__item.is-danger:hover,
.menu__item.is-danger:focus-visible {
  background: var(--danger-soft);
}

.menu__item[aria-disabled="true"],
.menu__item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.menu__icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  color: var(--fg-muted);
}

.menu__item.is-danger .menu__icon {
  color: inherit;
}

.menu__text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu__hint {
  margin-left: auto;
  padding-left: var(--space-4);
  color: var(--fg-subtle);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.04em;
}

.menu__item.is-active .menu__hint {
  padding-right: var(--space-2);
}

.menu__sep {
  height: 1px;
  margin: var(--space-1) calc(var(--space-1) * -1);
  border: 0;
  background: var(--border);
}

.menu__label {
  padding: var(--space-2) 10px var(--space-1);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 500;
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  color: var(--fg-subtle);
}

@media (pointer: coarse) {
  .menu__item {
    min-height: 44px;
  }
}

/* --------------------------------------------------------------- Tooltip */

[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  z-index: var(--z-dropdown);
  width: max-content;
  max-width: 240px;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  background: var(--fg);
  color: var(--fg-inverse);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0;
  text-align: center;
  text-transform: none;
  white-space: normal;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, 4px);
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out), visibility 0s linear var(--dur-fast);
}

[data-tooltip][data-tooltip-pos="bottom"]::after {
  top: calc(100% + 8px);
  bottom: auto;
  transform: translate(-50%, -4px);
}

@media (hover: hover) {
  [data-tooltip]:hover::after {
    visibility: visible;
    opacity: 1;
    transform: translate(-50%, 0);
    transition-delay: 350ms;
  }
}

[data-tooltip]:focus-visible::after {
  visibility: visible;
  transition-delay: 0s;
  opacity: 1;
  transform: translate(-50%, 0);
}

[data-tooltip=""]::after {
  display: none;
}

/* ------------------------------------------------------------------ Tabs */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs__item {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0 var(--space-3);
  color: var(--fg-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out);
}

.tabs__item::after {
  content: '';
  position: absolute;
  left: var(--space-3);
  right: var(--space-3);
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--fg);
  transform: scaleX(0);
  transition: transform var(--dur-base) var(--ease-out);
}

.tabs__item:hover {
  color: var(--fg);
}

.tabs__item[aria-selected="true"],
.tabs__item.is-active {
  color: var(--fg);
}

.tabs__item[aria-selected="true"]::after,
.tabs__item.is-active::after {
  transform: scaleX(1);
}

.tabs__item:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

/* ----------------------------------------------------------------- Panel */

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elev-1);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 52px;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.panel__title {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0;
  color: var(--fg);
}

.panel__body {
  padding: var(--space-5);
}

@media (max-width: 559px) {
  .panel__header {
    padding: var(--space-3) var(--space-4);
  }

  .panel__body {
    padding: var(--space-4);
  }
}

/* ---------------------------------------------------------------- Toasts */

.toast-region {
  position: fixed;
  right: max(var(--space-4), env(safe-area-inset-right));
  bottom: calc(max(var(--space-4), env(safe-area-inset-bottom)) + var(--player-offset, 0px));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-2);
  width: min(380px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
  transition: bottom var(--dur-base) var(--ease-out);
}

body.has-player .toast-region {
  --player-offset: calc(var(--player-h) + var(--space-2));
}

@media (max-width: 639px) {
  .toast-region {
    right: 50%;
    transform: translateX(50%);
    align-items: stretch;
  }
}

.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
  padding: 12px 12px 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-elev-2);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  line-height: 1.45;
  pointer-events: auto;
  overflow: hidden;
  animation: toast-in var(--dur-slow) var(--ease-out) both;
}

.toast.is-leaving {
  animation: toast-out var(--dur-base) var(--ease-in-out) both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(24px) scale(0.97);
  }
}

@media (max-width: 639px) {
  @keyframes toast-out {
    to {
      opacity: 0;
      transform: translateY(12px) scale(0.97);
    }
  }
}

.toast__icon {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--fg-muted);
}

.toast--success .toast__icon {
  color: var(--success);
}

.toast--error .toast__icon {
  color: var(--danger);
}

.toast--warning .toast__icon {
  color: var(--warning);
}

.toast--info .toast__icon {
  color: var(--fg-muted);
}

.toast__body {
  flex: 1 1 auto;
  min-width: 0;
  padding-top: 1px;
  overflow-wrap: anywhere;
}

.toast__action {
  flex-shrink: 0;
  align-self: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  color: var(--fg);
  font-size: var(--text-xs);
  font-weight: 600;
  transition: background-color var(--dur-fast) var(--ease-out);
}

.toast__action:hover {
  background: var(--border-strong);
}

.toast__close {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin: -2px -2px 0 0;
  border-radius: var(--radius-sm);
  color: var(--fg-subtle);
  transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}

.toast__close:hover {
  color: var(--fg);
  background: var(--surface-hover);
}

.toast__progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  background: currentColor;
  opacity: 0.18;
  transform-origin: left center;
  animation: toast-progress linear forwards;
  animation-duration: var(--toast-duration, 4200ms);
}

.toast:hover .toast__progress,
.toast:focus-within .toast__progress {
  animation-play-state: paused;
}

@keyframes toast-progress {
  to {
    transform: scaleX(0);
  }
}

/* ---------------------------------------------------------- Modal, sheet */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-root--sheet {
  display: block;
  padding: 0;
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}

@supports (backdrop-filter: blur(1px)) {
  .modal-backdrop {
    backdrop-filter: blur(3px) saturate(0.9);
  }
}

.modal-backdrop.is-open {
  opacity: 1;
}

.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--modal-w, 520px);
  max-height: calc(100dvh - 2 * var(--space-4));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elev-1);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(10px) scale(0.975);
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-slow) var(--ease-out);
}

.modal.is-open {
  opacity: 1;
  transform: none;
}

.modal--sm {
  --modal-w: 400px;
}

.modal--md {
  --modal-w: 520px;
}

.modal--lg {
  --modal-w: 760px;
}

.modal--xl {
  --modal-w: 1080px;
}

.modal__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 60px;
  padding: var(--space-4) var(--space-4) var(--space-3) var(--space-6);
  flex-shrink: 0;
}

.modal__title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--text-md);
  font-weight: 600;
  line-height: var(--leading-snug);
}

.modal__close {
  margin-left: auto;
}

.modal__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--space-2) var(--space-6) var(--space-6);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal__header + .modal__body {
  padding-top: 0;
}

.modal__body:first-child {
  padding-top: var(--space-6);
}

.modal__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.modal__message {
  color: var(--fg-muted);
  white-space: pre-line;
}

@media (max-width: 559px) {
  .modal-root {
    align-items: end;
    padding: var(--space-2);
  }

  .modal {
    max-height: calc(100dvh - var(--space-4));
    transform: translateY(24px);
  }

  .modal__header {
    padding-left: var(--space-5);
  }

  .modal__body {
    padding-inline: var(--space-5);
  }

  .modal__footer {
    padding-inline: var(--space-5);
  }

  .modal__footer > .btn {
    flex: 1 1 0;
  }
}

.sheet {
  position: fixed;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev-1);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
  transition: transform var(--dur-slow) var(--ease-out);
  will-change: transform;
}

.sheet--bottom {
  left: 0;
  right: 0;
  bottom: 0;
  max-height: calc(100dvh - var(--space-12));
  border-top: 1px solid var(--border-strong);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(100%);
}

.sheet--right {
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  border-left: 1px solid var(--border-strong);
  transform: translateX(100%);
}

.sheet.is-open {
  transform: none;
}

.sheet.is-dragging {
  transition: none;
}

.sheet__handle {
  flex-shrink: 0;
  width: 100%;
  height: 22px;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
}

.sheet__handle::before {
  content: '';
  width: 36px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
}

.sheet__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-2) var(--space-4) var(--space-2) var(--space-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sheet--bottom .sheet__header {
  padding-top: 0;
}

.sheet__title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--text-md);
  font-weight: 600;
}

.sheet__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--space-5);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sheet--bottom .sheet__footer > .btn {
  flex: 1 1 0;
}

/* ------------------------------------------------- Skeleton, spinner */

.skeleton {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--skeleton-base);
  color: transparent !important;
  user-select: none;
  pointer-events: none;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, var(--skeleton-shine) 50%, transparent 100%);
  transform: translateX(-100%);
  animation: skeleton-shimmer 1.6s var(--ease-in-out) infinite;
}

.skeleton--text {
  height: 0.8em;
  margin: 0.3em 0;
  border-radius: var(--radius-xs);
}

.skeleton--circle {
  border-radius: 50%;
}

@keyframes skeleton-shimmer {
  to {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton::after {
    animation: none;
    display: none;
  }
}

.spinner {
  display: inline-block;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--fg);
  animation: spin 0.75s linear infinite;
}

.spinner--sm {
  width: 14px;
  height: 14px;
  border-width: 1.5px;
}

.spinner--lg {
  width: 32px;
  height: 32px;
  border-width: 2.5px;
}

/* ------------------------------------------------------------ Empty state */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  max-width: 440px;
  margin-inline: auto;
  padding: var(--space-16) var(--space-4);
  text-align: center;
}

.empty-state__art {
  width: 120px;
  margin-bottom: var(--space-3);
  color: var(--fg-subtle);
}

.empty-state__art > * {
  margin-inline: auto;
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: var(--leading-snug);
  text-wrap: balance;
}

.empty-state__text {
  color: var(--fg-muted);
  text-wrap: pretty;
}

.empty-state__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

/* ---------------------------------------------------------- Cover images */

.cover-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background-color: var(--record-color, var(--surface));
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease-out);
}

.cover-img.is-loaded {
  opacity: 1;
}

.cover-fallback {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 60%),
    var(--bg-elev-2);
  color: var(--fg-subtle);
  container-type: inline-size;
}

.cover-fallback::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--grain);
  opacity: var(--grain-opacity);
  pointer-events: none;
}

.cover-fallback__disc {
  position: absolute;
  width: 72%;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--bg-elev-2) 0 4%, transparent 4.5%),
    radial-gradient(circle, var(--record-color, var(--fg-subtle)) 0 30%, transparent 30.5%),
    repeating-radial-gradient(circle, transparent 0 2px, var(--border) 2px 3px),
    var(--bg-inset);
  box-shadow: inset 0 0 0 1px var(--border);
  opacity: 0.85;
}

.cover-fallback__initials {
  position: relative;
  font-weight: 600;
  font-size: clamp(12px, 10cqi, 32px);
  line-height: 1;
  color: var(--fg);
  letter-spacing: 0.02em;
  mix-blend-mode: normal;
}

/* ----------------------------------------------------------------- Vinyl */

.vinyl {
  --vinyl-size: 100%;
  position: relative;
  width: var(--vinyl-size);
  aspect-ratio: 1;
  flex-shrink: 0;
  border-radius: 50%;
  pointer-events: none;
}

.vinyl__disc {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, transparent 0 33%, rgba(0, 0, 0, 0.55) 33.4%, transparent 35%),
    radial-gradient(circle at 50% 50%, transparent 0 96%, rgba(255, 255, 255, 0.07) 96.6%, transparent 97.4%),
    var(--vinyl-black);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    0 10px 30px -10px rgba(0, 0, 0, 0.6);
}

.vinyl__grooves {
  position: absolute;
  inset: 3%;
  border-radius: 50%;
  background:
    conic-gradient(from 20deg, transparent 0 40%, rgba(255, 255, 255, 0.025) 48%, transparent 56% 100%),
    repeating-radial-gradient(circle at 50% 50%,
      transparent 0,
      var(--vinyl-groove) 1.5px,
      transparent 3px),
    radial-gradient(circle at 50% 50%, transparent 0 62%, rgba(0, 0, 0, 0.35) 62.4%, transparent 63.5%),
    radial-gradient(circle at 50% 50%, transparent 0 80%, rgba(0, 0, 0, 0.3) 80.4%, transparent 81.5%);
  -webkit-mask: radial-gradient(circle, transparent 0 34%, #000 34.5%);
  mask: radial-gradient(circle, transparent 0 34%, #000 34.5%);
  animation: vinyl-spin 1.8s linear infinite paused;
}

.vinyl__shine {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    conic-gradient(from 0deg at 50% 50%,
      transparent 0deg,
      var(--vinyl-sheen) 28deg,
      transparent 62deg,
      transparent 180deg,
      rgba(255, 255, 255, 0.1) 208deg,
      transparent 242deg,
      transparent 360deg);
  -webkit-mask: radial-gradient(circle, transparent 0 33%, #000 36%, #000 95%, transparent 97%);
  mask: radial-gradient(circle, transparent 0 33%, #000 36%, #000 95%, transparent 97%);
  mix-blend-mode: screen;
  opacity: 0.55;
  pointer-events: none;
}

.vinyl__label {
  position: absolute;
  inset: 33%;
  overflow: hidden;
  border-radius: 50%;
  background: var(--label-color, var(--signal));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25), inset 0 0 12px rgba(0, 0, 0, 0.25);
  animation: vinyl-spin 1.8s linear infinite paused;
}

.vinyl__label::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, transparent 0 58%, rgba(0, 0, 0, 0.18) 60%, transparent 62%);
}

.vinyl__label img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.vinyl__hole {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3.2%;
  min-width: 3px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--vinyl-hole, var(--bg));
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.08);
  transform: translate(-50%, -50%);
}

.vinyl.is-spinning .vinyl__grooves,
.vinyl.is-spinning .vinyl__label {
  animation-play-state: running;
}

@keyframes vinyl-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .vinyl__grooves,
  .vinyl__label {
    animation: none;
  }
}

/* ------------------------------------------------------------- Equalizer */

.eq {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  width: 14px;
  height: 12px;
  flex-shrink: 0;
  color: var(--signal);
}

.eq > span,
.eq__bar {
  flex: 1 1 0;
  height: 100%;
  border-radius: 1px;
  background: currentColor;
  transform-origin: bottom center;
  animation: eq-bounce 0.9s var(--ease-in-out) infinite alternate;
}

.eq > span:nth-child(1) {
  animation-duration: 0.82s;
}

.eq > span:nth-child(2) {
  animation-duration: 0.61s;
  animation-delay: -0.3s;
}

.eq > span:nth-child(3) {
  animation-duration: 0.97s;
  animation-delay: -0.55s;
}

.eq.is-paused > span,
.eq.is-paused .eq__bar {
  animation-play-state: paused;
}

@keyframes eq-bounce {
  0% {
    transform: scaleY(0.2);
  }

  50% {
    transform: scaleY(1);
  }

  100% {
    transform: scaleY(0.45);
  }
}

@media (prefers-reduced-motion: reduce) {
  .eq > span,
  .eq__bar {
    animation: none;
    transform: scaleY(0.6);
  }

  .eq > span:nth-child(2) {
    transform: scaleY(1);
  }

  .eq > span:nth-child(3) {
    transform: scaleY(0.4);
  }
}

/* ------------------------------------------------------------ Grain layer */

.grain {
  position: relative;
  isolation: isolate;
}

.grain::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: var(--grain);
  opacity: var(--grain-opacity);
  pointer-events: none;
}
