/* ── Strings — neumorphic design system ───────────────────────────
   Soft-UI done carefully: surfaces share the page colour and get their
   shape from paired light/dark shadows, but text, focus rings and status
   colours keep real contrast (>= 4.5:1) instead of the washed-out greys
   that give classic neumorphism its accessibility problem.
   ───────────────────────────────────────────────────────────────── */

:root {
  color-scheme: dark;

  --bg: #22252c;
  --bg-deep: #1b1e24;
  --shadow-dark: #171920;
  --shadow-light: #2d313a;
  --line: #33373f;

  --text: #eef1f7;
  --text-dim: #a3abbd;
  --text-faint: #737b8c;

  --accent: #7c5cff;
  --accent-2: #34e3ff;
  /* Primary buttons stay in the violet half of the ramp: white on violet
     clears 5:1, whereas white (or black) on the cyan end never does. */
  --accent-grad-a: #6a45ff;
  --accent-grad-b: #9a6bff;
  --accent-ink: #ffffff;
  --ok: #4ade80;
  --warn: #f5c451;
  --danger: #ff6b6b;

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 30px;

  --d-1: 4px;
  --d-2: 7px;
  --d-3: 12px;

  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  /* overshoots ~4% past the target before settling — the wobble in "jelly" */
  --ease-jelly: cubic-bezier(0.2, 1.72, 0.36, 1);
  --t-fast: 140ms;
  --t-mid: 260ms;
  --t-slow: 420ms;
  --t-jelly: 340ms;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: #e7eaf1;
  --bg-deep: #dde1ea;
  --shadow-dark: #c1c6d1;
  --shadow-light: #ffffff;
  --line: #d2d7e1;

  --text: #1c2029;
  --text-dim: #545c6c;
  --text-faint: #7b8394;

  --accent: #5f43e8;
  --accent-2: #0a9fbd;
  --accent-grad-a: #5734db;
  --accent-grad-b: #7d54ef;
  --accent-ink: #ffffff;
  --ok: #17914d;
  --warn: #a06f04;
  --danger: #cf3535;
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] is display:none, but any author `display` (e.g.
   .btn's inline-flex) outranks it — so hidden elements would still show. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background var(--t-mid) var(--ease-out), color var(--t-mid) var(--ease-out);
}

/* Theme swap shouldn't strobe every element on the page. */
.theming, .theming * {
  transition: background-color var(--t-mid) var(--ease-out),
              color var(--t-mid) var(--ease-out),
              box-shadow var(--t-mid) var(--ease-out),
              border-color var(--t-mid) var(--ease-out) !important;
}

h1, h2, h3, h4 {
  margin: 0 0 .5em;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.2;
}
h1 { font-size: clamp(1.9rem, 4.5vw, 3rem); }
h2 { font-size: clamp(1.35rem, 2.6vw, 1.9rem); }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: color-mix(in srgb, var(--accent) 45%, transparent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ── neumorphic primitives ──────────────────────────────────────── */
.neu {
  background: linear-gradient(145deg,
    color-mix(in srgb, var(--bg) 88%, var(--shadow-light)),
    color-mix(in srgb, var(--bg) 88%, var(--shadow-dark)));
  box-shadow: var(--d-2) var(--d-2) calc(var(--d-2) * 2) var(--shadow-dark),
              calc(var(--d-2) * -1) calc(var(--d-2) * -1) calc(var(--d-2) * 2) var(--shadow-light);
  border-radius: var(--r-lg);
}

.neu-sm {
  box-shadow: var(--d-1) var(--d-1) calc(var(--d-1) * 2) var(--shadow-dark),
              calc(var(--d-1) * -1) calc(var(--d-1) * -1) calc(var(--d-1) * 2) var(--shadow-light);
}

.neu-in {
  background: var(--bg);
  box-shadow: inset var(--d-1) var(--d-1) calc(var(--d-1) * 2) var(--shadow-dark),
              inset calc(var(--d-1) * -1) calc(var(--d-1) * -1) calc(var(--d-1) * 2) var(--shadow-light);
  border-radius: var(--r-md);
}

.neu-flat {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

/* ── buttons ────────────────────────────────────────────────────── */
/**
 * Hover is a small jelly: the button lifts, widens a little more than it
 * grows tall, and settles a beat after it has stopped moving.
 *
 * `translate` and `scale` are used instead of one `transform` so the lift and
 * the squash can run on their own springs — that mismatch is what reads as
 * soft material rather than a scale-up. Both are real animatable properties,
 * so the effect reverses just as smoothly on the way out, which a keyframe
 * animation on :hover would not.
 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .55em;
  padding: .72em 1.5em;
  border: 0;
  border-radius: var(--r-md);
  background: linear-gradient(145deg,
    color-mix(in srgb, var(--bg) 88%, var(--shadow-light)),
    color-mix(in srgb, var(--bg) 88%, var(--shadow-dark)));
  box-shadow: var(--d-2) var(--d-2) calc(var(--d-2) * 2) var(--shadow-dark),
              calc(var(--d-2) * -1) calc(var(--d-2) * -1) calc(var(--d-2) * 2) var(--shadow-light);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: .95em;
  cursor: pointer;
  user-select: none;
  /* an <a class="btn"> would otherwise inherit the global a:hover underline */
  text-decoration: none;
  translate: 0 0;
  scale: 1;
  transition: translate var(--t-mid) var(--ease-spring),
              scale var(--t-jelly) var(--ease-jelly),
              box-shadow var(--t-fast) var(--ease-out),
              filter var(--t-fast) var(--ease-out),
              color var(--t-fast) var(--ease-out);
}
.btn:hover, .btn:focus-visible { text-decoration: none; }
.btn:hover {
  color: var(--text);
  translate: 0 -2px;
  scale: 1.035 1.014;   /* wider than it is taller — the squash */
}
.btn:active, .btn.is-active {
  translate: 0 0;
  scale: .988 1.008;    /* and the other way round when pressed */
  transition-duration: 110ms;
  box-shadow: inset var(--d-1) var(--d-1) calc(var(--d-1) * 2) var(--shadow-dark),
              inset calc(var(--d-1) * -1) calc(var(--d-1) * -1) calc(var(--d-1) * 2) var(--shadow-light);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover, .btn:disabled:active { translate: 0 0; scale: 1; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-grad-a), var(--accent-grad-b));
  color: var(--accent-ink);
  box-shadow: var(--d-2) var(--d-2) calc(var(--d-2) * 2) var(--shadow-dark),
              calc(var(--d-2) * -1) calc(var(--d-2) * -1) calc(var(--d-2) * 2) var(--shadow-light),
              0 0 22px color-mix(in srgb, var(--accent) 30%, transparent),
              inset 0 1px 0 color-mix(in srgb, #fff 28%, transparent);
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-danger { color: var(--danger); }
.btn-ghost { box-shadow: none; background: transparent; }
.btn-ghost:hover { box-shadow: var(--d-1) var(--d-1) calc(var(--d-1) * 2) var(--shadow-dark),
                               calc(var(--d-1) * -1) calc(var(--d-1) * -1) calc(var(--d-1) * 2) var(--shadow-light); }
.btn-sm { padding: .5em 1em; font-size: .86em; border-radius: var(--r-sm); }
.btn-icon { padding: .6em; width: 2.7em; height: 2.7em; border-radius: 50%; }

/* ── form controls ──────────────────────────────────────────────── */
.field { margin-bottom: 1.1rem; }
.field label,
.label {
  display: block;
  margin-bottom: .45em;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: .02em;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="search"], input[type="number"], textarea, select {
  width: 100%;
  padding: .8em 1em;
  border: 0;
  border-radius: var(--r-md);
  background: var(--bg);
  box-shadow: inset var(--d-1) var(--d-1) calc(var(--d-1) * 2) var(--shadow-dark),
              inset calc(var(--d-1) * -1) calc(var(--d-1) * -1) calc(var(--d-1) * 2) var(--shadow-light);
  color: var(--text);
  font: inherit;
  font-size: .97em;
  transition: box-shadow var(--t-mid) var(--ease-out);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  box-shadow: inset var(--d-1) var(--d-1) calc(var(--d-1) * 2) var(--shadow-dark),
              inset calc(var(--d-1) * -1) calc(var(--d-1) * -1) calc(var(--d-1) * 2) var(--shadow-light),
              0 0 0 2px color-mix(in srgb, var(--accent) 70%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
textarea { resize: vertical; min-height: 5em; line-height: 1.55; }
select { cursor: pointer; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.6em;
}

.hint { font-size: .82rem; color: var(--text-faint); margin-top: .4em; }
.hint.error { color: var(--danger); }
.hint.ok { color: var(--ok); }

/* toggle switch */
.switch { display: inline-flex; align-items: center; gap: .8em; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 52px; height: 30px; border-radius: 999px; background: var(--bg); position: relative;
  box-shadow: inset 3px 3px 6px var(--shadow-dark), inset -3px -3px 6px var(--shadow-light);
  transition: box-shadow var(--t-mid) var(--ease-out);
  flex: none;
}
.switch .thumb {
  position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(145deg, var(--shadow-light), var(--bg));
  box-shadow: 2px 2px 5px var(--shadow-dark), -1px -1px 3px var(--shadow-light);
  transition: transform var(--t-mid) var(--ease-spring), background var(--t-mid) var(--ease-out);
}
.switch input:checked + .track .thumb {
  transform: translateX(22px);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ── surfaces ───────────────────────────────────────────────────── */
.card {
  padding: 1.6rem;
  border-radius: var(--r-lg);
  background: linear-gradient(145deg,
    color-mix(in srgb, var(--bg) 88%, var(--shadow-light)),
    color-mix(in srgb, var(--bg) 88%, var(--shadow-dark)));
  box-shadow: var(--d-2) var(--d-2) calc(var(--d-2) * 2) var(--shadow-dark),
              calc(var(--d-2) * -1) calc(var(--d-2) * -1) calc(var(--d-2) * 2) var(--shadow-light);
}

.pill {
  display: inline-flex; align-items: center; gap: .4em;
  padding: .32em .85em; border-radius: 999px;
  font-size: .78rem; font-weight: 650; letter-spacing: .02em;
  background: var(--bg);
  box-shadow: inset 2px 2px 4px var(--shadow-dark), inset -2px -2px 4px var(--shadow-light);
  color: var(--text-dim);
  text-decoration: none;
  scale: 1;
  transition: scale var(--t-jelly) var(--ease-jelly), color var(--t-fast) var(--ease-out);
}
/* profile-card links are <a class="pill">, so they need the underline killed
   at :hover specificity, not just on the base rule */
a.pill:hover { text-decoration: none; scale: 1.045 1.02; }
.pill.accent { color: var(--accent); }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill.danger { color: var(--danger); }

.divider { height: 1px; background: var(--line); border: 0; margin: 1.6rem 0; opacity: .6; }

/* ── toasts ─────────────────────────────────────────────────────── */
#toasts {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 10px; z-index: 900;
  pointer-events: none; width: min(440px, calc(100vw - 32px));
}
.toast {
  pointer-events: auto;
  padding: .85em 1.15em;
  border-radius: var(--r-md);
  background: linear-gradient(145deg,
    color-mix(in srgb, var(--bg) 84%, var(--shadow-light)),
    color-mix(in srgb, var(--bg) 84%, var(--shadow-dark)));
  box-shadow: 6px 6px 16px var(--shadow-dark), -5px -5px 14px var(--shadow-light);
  font-size: .92rem;
  display: flex; gap: .7em; align-items: flex-start;
  animation: toast-in var(--t-slow) var(--ease-spring) both;
  border-left: 3px solid var(--accent);
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
.toast.leaving { animation: toast-out var(--t-mid) var(--ease-out) both; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(18px) scale(.96); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(10px) scale(.97); }
}

/* ── modal ──────────────────────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; z-index: 950;
  background: color-mix(in srgb, var(--bg-deep) 72%, transparent);
  backdrop-filter: blur(7px);
  display: grid; place-items: center; padding: 20px;
  animation: fade-in var(--t-mid) var(--ease-out) both;
}
.modal {
  width: min(520px, 100%);
  max-height: 88vh; overflow: auto;
  padding: 1.8rem;
  border-radius: var(--r-xl);
  background: linear-gradient(145deg,
    color-mix(in srgb, var(--bg) 88%, var(--shadow-light)),
    color-mix(in srgb, var(--bg) 88%, var(--shadow-dark)));
  box-shadow: 14px 14px 34px var(--shadow-dark), -10px -10px 30px var(--shadow-light);
  animation: modal-in var(--t-slow) var(--ease-spring) both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(24px) scale(.95); }
  to { opacity: 1; transform: none; }
}

/* ── shared bits ────────────────────────────────────────────────── */
.wordmark {
  font-weight: 750; letter-spacing: .16em; font-size: 1.05rem;
  display: inline-flex; align-items: center; gap: .1em;
}
.wordmark i { color: var(--accent); font-style: normal; }

.spinner {
  width: 1.05em; height: 1.05em; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--text) 25%, transparent);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }
.row.tight { gap: .45rem; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: .86rem; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
