.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  color: var(--text);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
}
.brand__mark { width: 1.55em; height: 1.55em; flex: none; color: var(--text); }
.brand__word {
  font-family: var(--font-mono);
  font-size: 1.02em;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  font-weight: var(--weight-medium);
}
.brand--lg .brand__mark { width: 2em; height: 2em; }

.btn {
  --btn-h: 42px;
  --btn-px: var(--space-5);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--btn-h);
  padding-inline: var(--btn-px);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  border: 1px solid transparent;
  transition: background 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),
              box-shadow var(--dur-fast) var(--ease-out),
              opacity var(--dur-fast) var(--ease-out);
}
.btn:active { transform: translateY(0.5px) scale(0.994); }
.btn svg { width: 1.15em; height: 1.15em; }

.btn--primary {
  background: var(--primary);
  color: var(--primary-text);
  box-shadow: var(--shadow-xs);
}
.btn--primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-sm); }

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn--secondary:hover { background: var(--surface-hover); border-color: var(--border-strong); }

.btn--ghost { background: transparent; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn--danger {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn--danger:hover {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.btn--lg { --btn-h: 50px; --btn-px: var(--space-7); font-size: var(--text-sm); border-radius: var(--radius-lg); }
.btn--sm { --btn-h: 34px; --btn-px: var(--space-4); font-size: var(--text-xs); }
.btn--block { display: flex; width: 100%; }

.btn--icon {
  --btn-px: 0;
  width: var(--btn-h);
  min-height: var(--btn-h);
  padding: 0;
  color: var(--text-secondary);
}
.btn--icon.btn--ghost:hover { color: var(--text); }
.btn--icon svg { width: 1.25rem; height: 1.25rem; }

.btn:disabled,
.btn[aria-disabled="true"],
.btn.is-loading {
  pointer-events: none;
  opacity: 0.55;
}
.btn.is-loading { color: transparent !important; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 1.05em; height: 1.05em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--primary-text);
  animation: spin 0.6s linear infinite;
}
.btn--secondary.is-loading::after,
.btn--ghost.is-loading::after { color: var(--text); }

.link {
  color: var(--text);
  font-weight: var(--weight-medium);
  text-decoration: none;
  background-image: linear-gradient(var(--border-strong), var(--border-strong));
  background-size: 100% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size var(--dur) var(--ease-out), color var(--dur-fast);
  padding-bottom: 1px;
}
.link:hover { background-image: linear-gradient(var(--text), var(--text)); }
.link--muted { color: var(--text-muted); }
.link--muted:hover { color: var(--text); }

.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}
.field-label .optional { font-weight: var(--weight-regular); color: var(--text-subtle); font-size: var(--text-xs); }

.input,
.textarea,
.select {
  width: 100%;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
  appearance: none;
}
.input::placeholder,
.textarea::placeholder { color: var(--text-subtle); }
.input:hover,
.textarea:hover,
.select:hover { border-color: var(--border-strong); }
.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--surface-hover), 0 0 0 4px var(--border);
}
.textarea { min-height: 120px; resize: vertical; line-height: var(--leading-normal); }
.input.mono, .textarea.mono { font-family: var(--font-mono); }

.select {
  padding-right: var(--space-10);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23767d8b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  cursor: pointer;
}

.field-hint { font-size: var(--text-xs); color: var(--text-muted); line-height: var(--leading-snug); }
.field-error {
  display: none;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text);
}
.field-error svg { width: 14px; height: 14px; flex: none; }
.field.has-error .input,
.field.has-error .textarea { border-color: var(--text); box-shadow: 0 0 0 3px var(--surface-active); }
.field.has-error .field-error { display: flex; }
.field.has-error .field-hint { display: none; }

.input-affix { position: relative; display: flex; align-items: stretch; }
.input-affix .input { flex: 1; }
.input-affix--suffix .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.affix {
  display: inline-flex;
  align-items: center;
  padding-inline: var(--space-4);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  white-space: nowrap;
}
.input-reveal { position: absolute; right: var(--space-2); top: 50%; transform: translateY(-50%); }

.check {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-snug);
}
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check__box {
  flex: none;
  width: 20px; height: 20px;
  margin-top: 1px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface);
  display: grid;
  place-items: center;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast);
}
.check input[type="radio"] ~ .check__box { border-radius: var(--radius-full); }
.check__box::after {
  content: "";
  width: 11px; height: 11px;
  background: var(--primary-text);
  clip-path: polygon(14% 44%, 0 65%, 43% 100%, 100% 16%, 84% 2%, 41% 74%);
  transform: scale(0);
  transition: transform var(--dur-fast) var(--ease-spring);
}
.check input[type="radio"] ~ .check__box::after { clip-path: circle(50%); width: 8px; height: 8px; }
.check input:checked ~ .check__box { background: var(--primary); border-color: var(--primary); }
.check input:checked ~ .check__box::after { transform: scale(1); }
.check input:focus-visible ~ .check__box { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 42px; height: 24px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  transition: background var(--dur) var(--ease-out);
  position: relative;
}
.switch__track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease-spring);
}
.switch input:checked ~ .switch__track { background: var(--primary); }
.switch input:checked ~ .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible ~ .switch__track { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.segment {
  display: inline-flex;
  padding: 3px;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  gap: 2px;
}
.segment button {
  padding: var(--space-2) var(--space-4);
  border-radius: calc(var(--radius-md) - 3px);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  transition: color var(--dur-fast), background var(--dur-fast), box-shadow var(--dur-fast);
}
.segment button:hover { color: var(--text-secondary); }
.segment button.active {
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}
.segment button:disabled { opacity: 0.4; pointer-events: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card--pad { padding: var(--space-6); }
.card--raised { box-shadow: var(--shadow-md); border-color: var(--border-subtle); }
.card--flat { box-shadow: none; }

.divider { height: 1px; background: var(--border); border: none; width: 100%; }
.divider--labeled {
  display: flex; align-items: center; gap: var(--space-4);
  color: var(--text-subtle); font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: var(--tracking-wide);
}
.divider--labeled::before,
.divider--labeled::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-2);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-subtle);
}
.badge--solid { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.badge--dot::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding-inline: 6px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.02em;
  user-select: none;
  flex: none;
}
.avatar--sm { width: 30px; height: 30px; font-size: var(--text-xs); }
.avatar--lg { width: 56px; height: 56px; font-size: var(--text-lg); }

.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-snug);
}
.banner__icon { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--text-muted); }
.banner strong { color: var(--text); font-weight: var(--weight-semibold); }
.banner--strong { border-color: var(--text); background: var(--surface-active); }
.banner--strong .banner__icon { color: var(--text); }
.banner--fixed {
  position: fixed; top: 0; left: 0; right: 0; z-index: var(--z-toast);
  border-radius: 0; justify-content: center; text-align: center;
  border-left: none; border-right: none; border-top: none;
  background: var(--text); color: var(--bg);
}
.banner--fixed .banner__icon, .banner--fixed strong { color: var(--bg); }

.codeblock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--surface-sunken);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  letter-spacing: 0.06em;
  color: var(--text);
  word-break: break-all;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-4);
  padding: clamp(var(--space-10), 8vw, var(--space-20)) var(--space-6);
  color: var(--text-muted);
}
.empty__art {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-subtle);
  background: var(--bg-subtle);
  margin-bottom: var(--space-1);
}
.empty__art svg { width: 26px; height: 26px; }
.empty__title { font-size: var(--text-md); font-weight: var(--weight-semibold); color: var(--text); }
.empty p { font-size: var(--text-sm); max-width: 34ch; }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
}
.skeleton::after {
  content: "";
  position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--surface-hover), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skeleton--text { height: 0.7em; margin-block: 0.28em; }
.skeleton--line { height: 12px; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--overlay);
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  display: grid;
  place-items: center;
  padding: var(--space-5);
  opacity: 0;
  animation: scrim-in var(--dur) var(--ease-out) forwards;
}
@keyframes scrim-in { to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  box-shadow: var(--shadow-xl), inset 0 1px 0 var(--edge-highlight);
  padding: var(--space-7);
  transform: translateY(8px) scale(0.98);
  opacity: 0;
  animation: modal-in var(--dur-slow) var(--ease-out) forwards;
  max-height: calc(100dvh - var(--space-10));
  overflow-y: auto;
}
@keyframes modal-in { to { transform: translateY(0) scale(1); opacity: 1; } }
.modal__title { font-size: var(--text-xl); letter-spacing: var(--tracking-tight); }
.modal__body { margin-top: var(--space-3); color: var(--text-secondary); font-size: var(--text-sm); line-height: var(--leading-relaxed); }
.modal__actions { margin-top: var(--space-6); display: flex; gap: var(--space-3); justify-content: flex-end; flex-wrap: wrap; }
.modal--wide { max-width: 560px; }

.toast-region {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: min(420px, calc(100vw - var(--space-8)));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  color: var(--text);
  transform: translateY(12px);
  opacity: 0;
  animation: toast-in var(--dur-slow) var(--ease-out) forwards;
}
.toast.is-leaving { animation: toast-out var(--dur) var(--ease-in-out) forwards; }
@keyframes toast-in  { to { transform: translateY(0); opacity: 1; } }
@keyframes toast-out { to { transform: translateY(8px); opacity: 0; } }
.toast__icon { flex: none; width: 18px; height: 18px; color: var(--text-muted); }
.toast__msg { flex: 1; line-height: var(--leading-snug); }

[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: var(--space-1) var(--space-3);
  background: var(--text);
  color: var(--bg);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  z-index: var(--z-toast);
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }

.theme-toggle svg { transition: transform var(--dur-slow) var(--ease-spring); }

.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-sun  { display: block; }
}
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: block; }
:root[data-theme="light"] .theme-toggle .icon-sun  { display: none; }
