/* monoline — reset, typography, UI primitives */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 96px;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--t-base);
  line-height: 1.6;
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 500; line-height: 1.12; letter-spacing: -0.03em; }
p  { margin: 0; }
img, video, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }

a { color: inherit; text-decoration: none; }
a:not([class]) {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--line-loud);
  transition: text-decoration-color var(--fast);
}
a:not([class]):hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--text); color: var(--ink); }

/* Screen-reader-only helper */
.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: var(--s-4); top: -100px; z-index: 200;
  padding: var(--s-3) var(--s-4); background: var(--surface-2);
  border: 1px solid var(--line-loud); border-radius: var(--r-md);
}
.skip-link:focus { top: var(--s-4); }

/* ── Layout ───────────────────────────────────────────────────────── */
.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--s-5); }
.stack   { display: flex; flex-direction: column; gap: var(--s-4); }
.row     { display: flex; align-items: center; gap: var(--s-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.grow    { flex: 1; min-width: 0; }
.hairline { height: 1px; background: var(--line); border: 0; margin: 0; }

/* ── Type helpers ─────────────────────────────────────────────────── */
.serif    { font-family: var(--serif); font-weight: 400; letter-spacing: -0.015em; }
.muted    { color: var(--muted); }
.faint    { color: var(--faint); }
.t-sm     { font-size: var(--t-sm); }
.t-xs     { font-size: var(--t-xs); }
.nums     { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  --btn-bg: transparent;
  --btn-fg: var(--text);
  --btn-bd: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: 10px var(--s-4);
  min-height: 40px;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-bd); border-radius: var(--r-md);
  font-size: var(--t-sm); font-weight: 500; letter-spacing: -0.01em;
  cursor: pointer;
  transition: background var(--fast), border-color var(--fast), opacity var(--fast), transform var(--fast);
  user-select: none;
}
.btn:hover:not(:disabled) { --btn-bd: var(--line-loud); background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary { --btn-bg: var(--solid); --btn-fg: var(--on-solid); --btn-bd: var(--solid); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--solid); opacity: .88; border-color: var(--solid); }

.btn-ghost  { --btn-bd: transparent; }
.btn-ghost:hover:not(:disabled) { --btn-bd: var(--line); }

.btn-danger { --btn-fg: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(255,107,107,.08); --btn-bd: rgba(255,107,107,.3); }

.btn-sm   { min-height: 32px; padding: 6px var(--s-3); font-size: var(--t-xs); }
.btn-icon { padding: 0; width: 36px; min-height: 36px; }
.btn-icon.btn-sm { width: 30px; min-height: 30px; }
.btn-block { width: 100%; }

/* Busy state: the label is replaced by a spinner so width does not jump. */
.btn[data-busy='true'] { color: transparent; position: relative; pointer-events: none; }
.btn[data-busy='true']::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  color: var(--btn-fg);
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Fields ───────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--t-sm); font-weight: 500; color: var(--text); }
.field .hint { font-size: var(--t-xs); color: var(--faint); }
.field .hint[data-state='bad']  { color: var(--danger); }
.field .hint[data-state='good'] { color: var(--good); }

.input, .textarea, .select {
  width: 100%;
  padding: 10px var(--s-3);
  min-height: 42px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--text);
  transition: border-color var(--fast), background var(--fast);
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--line-loud); }
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--text); background: var(--surface-2);
}
.input[aria-invalid='true'] { border-color: var(--danger); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.55; }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238c8c8e' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
  cursor: pointer;
}
.select option { background: var(--surface-2); color: var(--text); }

/* Prefix field, e.g. monoline.to/‹username› */
.input-group { display: flex; align-items: stretch; }
.input-group .prefix {
  display: flex; align-items: center; padding-inline: var(--s-3);
  background: var(--surface-2); border: 1px solid var(--line); border-right: 0;
  border-radius: var(--r-md) 0 0 var(--r-md);
  color: var(--muted); font-size: var(--t-sm); white-space: nowrap;
}
.input-group .input { border-radius: 0 var(--r-md) var(--r-md) 0; }

/* Range */
input[type='range'] {
  appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer;
}
input[type='range']::-webkit-slider-runnable-track { height: 2px; background: var(--line-loud); border-radius: 2px; }
input[type='range']::-moz-range-track { height: 2px; background: var(--line-loud); border-radius: 2px; }
input[type='range']::-webkit-slider-thumb {
  appearance: none; width: 14px; height: 14px; margin-top: -6px;
  background: var(--text); border-radius: 50%; transition: transform var(--fast);
}
input[type='range']::-moz-range-thumb { width: 14px; height: 14px; border: 0; background: var(--text); border-radius: 50%; }
input[type='range']:active::-webkit-slider-thumb { transform: scale(1.15); }

/* Colour input, restyled to a neat swatch */
input[type='color'] {
  appearance: none; width: 42px; height: 42px; padding: 3px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); cursor: pointer;
}
input[type='color']::-webkit-color-swatch { border: 0; border-radius: 7px; }
input[type='color']::-webkit-color-swatch-wrapper { padding: 0; }
input[type='color']::-moz-color-swatch { border: 0; border-radius: 7px; }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 38px; height: 22px; flex: none; padding: 2px;
  background: var(--surface-3); border: 1px solid var(--line);
  border-radius: var(--r-full);
  transition: background var(--base), border-color var(--base);
}
.switch .thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--muted);
  transition: transform var(--base), background var(--base);
}
.switch input:checked + .track { background: var(--solid); border-color: var(--solid); }
.switch input:checked + .track .thumb { transform: translateX(16px); background: var(--on-solid); }
.switch input:focus-visible + .track { outline: 2px solid var(--text); outline-offset: 2px; }

/* Segmented control — used for appearance choices */
.segmented {
  display: flex; gap: 2px; padding: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.segmented button {
  flex: 1; padding: 7px var(--s-3);
  background: transparent; border: 0; border-radius: 9px;
  color: var(--muted); font-size: var(--t-xs); font-weight: 500; cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed='true'] { background: var(--surface-3); color: var(--text); }

/* ── Cards & panels ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.card-head h3 { font-size: var(--t-md); }

/* ── Toasts ───────────────────────────────────────────────────────── */
#toasts {
  position: fixed; z-index: 120; left: 50%; bottom: var(--s-5);
  transform: translateX(-50%);
  display: flex; flex-direction: column-reverse; gap: var(--s-2);
  width: min(420px, calc(100vw - var(--s-5) * 2));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2); border: 1px solid var(--line-loud);
  border-radius: var(--r-md); box-shadow: var(--shadow);
  font-size: var(--t-sm);
  animation: toast-in 240ms var(--ease);
  pointer-events: auto;
}
.toast[data-tone='bad']  { border-color: rgba(255,107,107,.45); }
.toast[data-tone='good'] { border-color: rgba(107,219,160,.4); }
.toast.leaving { animation: toast-out 180ms var(--ease) forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(6px) scale(.98); } }

/* ── Dialog ───────────────────────────────────────────────────────── */
dialog {
  width: min(460px, calc(100vw - var(--s-5) * 2));
  padding: var(--s-5);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-loud); border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.66); backdrop-filter: blur(4px); }
dialog[open] { animation: dialog-in 200ms var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }

/* ── Loading skeleton ─────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--r-md);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ── Empty state ──────────────────────────────────────────────────── */
.empty {
  padding: var(--s-8) var(--s-5);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--r-lg);
  color: var(--muted);
}
.empty h4 { font-size: var(--t-base); color: var(--text); margin-bottom: 4px; }

/* ── Avatar ───────────────────────────────────────────────────────── */
.avatar {
  border-radius: 50%; object-fit: cover; background: var(--surface-3);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  color: var(--faint); font-weight: 500;
  overflow: hidden; flex: none;
}
