a {
  color: var(--color-primary);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.brand {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--color-primary);
  text-decoration: none;
  line-height: 1;
}

.brand-small {
  font-size: var(--text-xl);
}

.muted {
  color: var(--color-text-muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-8);
  width: min(100%, 440px);
}

.card-wide {
  width: 100%;
}

@media (max-width: 480px) {
  .card {
    padding: var(--space-6) var(--space-4);
  }
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.button-block {
  width: 100%;
}

.button-primary {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}

.button-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.button-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.button-secondary:hover:not(:disabled) {
  background: var(--color-surface-muted);
}

.button-danger {
  background: var(--color-danger);
  color: var(--color-primary-contrast);
}

.button-danger:hover:not(:disabled) {
  filter: brightness(0.92);
}

.button-ghost {
  background: transparent;
  color: var(--color-text-muted);
  min-height: 2.25rem;
  padding: 0 var(--space-3);
}

.button-ghost:hover {
  background: var(--color-surface-muted);
  color: var(--color-text);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1.05rem;
  cursor: pointer;
}

.link-button {
  align-self: center;
  border: none;
  background: none;
  padding: var(--space-1);
  color: var(--color-primary);
  font: inherit;
  font-size: var(--text-sm);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* Segmented control (language switch) */
.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
}

.segmented button {
  min-width: 2.5rem;
  height: 2rem;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}

.segmented-wide {
  display: flex;
  border-radius: var(--radius-md);
}

.segmented-wide button {
  flex: 1;
  height: 2.5rem;
  border-radius: calc(var(--radius-md) - 2px);
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.label {
  font-size: var(--text-sm);
  font-weight: 600;
}

.input {
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
}

.input:focus-visible {
  border-color: var(--color-primary);
}

.input[aria-invalid="true"] {
  border-color: var(--color-danger);
}

.input-code {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  letter-spacing: 0.3em;
  text-align: center;
}

.input-amount {
  font-size: var(--text-lg);
  font-variant-numeric: tabular-nums;
}

.hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

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

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  cursor: pointer;
}

.checkbox input {
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.15rem;
  accent-color: var(--color-primary);
}

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}

.alert-error {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}

.alert-warning {
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.alternatives {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2) var(--space-4);
}

.alternatives:empty {
  display: none;
}

/* Second-factor choice */
.option-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.option:hover:not(:disabled) {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.option-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
}

.badge {
  padding: 0.1rem var(--space-2);
  border-radius: var(--radius-full);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: 0.75rem;
  font-weight: 700;
}

.qr {
  align-self: center;
  width: 200px;
  height: 200px;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  /* The QR code needs a light background in both themes. */
  background: #ffffff;
}

.secret {
  font-family: var(--font-mono);
  font-size: var(--text-md);
  word-break: break-all;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-surface-muted);
  user-select: all;
}

.code-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2) var(--space-4);
  margin: 0;
  padding: var(--space-4) var(--space-4) var(--space-4) var(--space-8);
  border-radius: var(--radius-md);
  background: var(--color-surface-muted);
  font-family: var(--font-mono);
}

@media (max-width: 400px) {
  .code-list {
    grid-template-columns: 1fr;
  }
}

/* Balance */
.balance-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
}

.balance-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.balance {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* Shares */
.badge-muted {
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
}

.shares {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.share {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
}

.share:first-child {
  border-top: none;
}

.share-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  overflow-wrap: anywhere;
}

.share-own .share-name {
  font-weight: 700;
}

.share-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.share-bar {
  grid-column: 1 / -1;
  height: 0.375rem;
  border-radius: var(--radius-full);
  background: var(--color-surface-muted);
  overflow: hidden;
}

.share-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--color-text-muted);
}

.share-own .share-bar > span {
  background: var(--color-primary);
}

.own-share {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* History */
.timeline {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline:empty {
  display: none;
}

.entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
}

.entry:first-child {
  border-top: none;
}

.entry-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.entry-note {
  overflow-wrap: anywhere;
}

.entry-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.entry-amount {
  flex-shrink: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.credit {
  color: var(--color-success);
}

.debit {
  color: var(--color-danger);
}

/* Donator: grantee cards */
.search {
  max-width: 420px;
}

.grantee-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.grantee-grid:empty {
  display: none;
}

.grantee-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  height: 100%;
  padding: var(--space-6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  color: var(--color-text);
  text-decoration: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.grantee-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.grantee-name {
  font-size: var(--text-lg);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.grantee-username {
  font-size: var(--text-sm);
}

.grantee-balance {
  margin-top: var(--space-3);
  font-size: var(--text-xl);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  text-align: center;
  padding: var(--space-12) var(--space-6);
}

/* Donator: grantee detail */
.back-link {
  align-self: flex-start;
  font-weight: 600;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.detail-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4) var(--space-8);
}

.detail-balance {
  display: flex;
  flex-direction: column;
  margin-left: auto;
  text-align: right;
}

@media (max-width: 640px) {
  .detail-balance {
    margin-left: 0;
    text-align: left;
  }

  .detail-header .button {
    width: 100%;
  }
}

/* Password strength */
.strength {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.strength-bar {
  flex: 1;
  height: 0.5rem;
  appearance: none;
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-surface-muted);
  overflow: hidden;
}

.strength-bar::-webkit-meter-bar {
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-surface-muted);
}

.strength-weak::-webkit-meter-optimum-value,
.strength-weak::-webkit-meter-suboptimum-value,
.strength-weak::-webkit-meter-even-less-good-value {
  background: var(--color-danger);
}

.strength-fair::-webkit-meter-optimum-value,
.strength-fair::-webkit-meter-suboptimum-value,
.strength-fair::-webkit-meter-even-less-good-value {
  background: var(--color-warning);
}

.strength-strong::-webkit-meter-optimum-value,
.strength-strong::-webkit-meter-suboptimum-value,
.strength-strong::-webkit-meter-even-less-good-value {
  background: var(--color-success);
}

.strength-weak::-moz-meter-bar {
  background: var(--color-danger);
}

.strength-fair::-moz-meter-bar {
  background: var(--color-warning);
}

.strength-strong::-moz-meter-bar {
  background: var(--color-success);
}

.strength-text {
  min-width: 9rem;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Settings */
.settings .card {
  max-width: 720px;
}

.setting-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
}

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--space-1) var(--space-4);
  margin: 0;
}

.facts dt {
  font-weight: 600;
}

.facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.item-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
}

.item:first-child {
  border-top: none;
}

.item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 14rem;
}

.item-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.item-grow {
  flex: 1 1 100%;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-2) var(--space-3);
}

.inline-form .field {
  flex: 1 1 14rem;
}

.skeleton-row {
  height: 3rem;
}

/* Skeleton loaders */
.skeleton {
  display: block;
  border-radius: var(--radius-md);
  background: linear-gradient(
    90deg,
    var(--color-surface-muted) 25%,
    var(--color-border) 50%,
    var(--color-surface-muted) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.skeleton-list .skeleton {
  height: 3rem;
}

.skeleton-balance {
  width: 12rem;
  height: 2.75rem;
}

.skeleton-card {
  height: 9.5rem;
  border-radius: var(--radius-lg);
}

.skeleton-header {
  height: 7rem;
  border-radius: var(--radius-lg);
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

/* Dialog */
.dialog {
  width: min(calc(100% - 2 * var(--space-4)), 420px);
  padding: var(--space-6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
}

.dialog[open] {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.dialog::backdrop {
  background: rgb(10 12 20 / 0.55);
}

.dialog-wide {
  width: min(calc(100% - 2 * var(--space-4)), 560px);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* Toast */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: var(--space-6);
  transform: translateX(-50%);
  z-index: 100;
  width: max-content;
  max-width: calc(100% - 2 * var(--space-4));
}

.toast {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-text);
  color: var(--color-bg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
}

/* Loading */
.spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
