/*
  The single source of design truth for the whole app.

  The old /gen and /studio pages each carried their own copy of these values,
  which is why they drifted into looking like two different products. Nothing
  below this file is allowed to invent a colour, a radius, or a shadow: views
  compose these tokens and the primitives at the bottom, so a change here
  moves the entire app at once.
*/

:root {
  /* Surfaces, from the page backdrop up to the highest floating panel. The
     steps are deliberately close together — on a dark UI, large jumps in
     lightness read as dirt rather than as depth. */
  --bg: #08090d;
  --s1: #0e1016;
  --s2: #14171f;
  --s3: #1b1f2a;
  --s4: #232836;

  --line: #23283400;
  --border: #262c3a;
  --border-2: #333a4d;

  /* Text. Only three weights of emphasis; more than that and nothing reads
     as emphasised. */
  --fg: #eef1f7;
  --fg-2: #a8b0c2;
  --fg-3: #6f7789;

  /* One accent, used for the current thing and the primary action, and
     nothing else. The violet echoes the tools this app sits beside. */
  --accent: #7c5cff;
  --accent-2: #9d84ff;
  --accent-soft: rgba(124, 92, 255, .14);
  --accent-line: rgba(124, 92, 255, .38);

  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .13);
  --nsfw: #f472b6;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 6px 20px rgba(0, 0, 0, .45);
  --shadow-3: 0 18px 50px rgba(0, 0, 0, .6);

  --rail-w: 84px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  /* Everything that moves uses one of these two, so the app has a single
     sense of pace rather than a different speed per component. */
  --t-fast: 120ms ease;
  --t-med: 220ms cubic-bezier(.22, .61, .36, 1);
}

/* --------------------------------------------------------------- reset */

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -.015em;
  line-height: 1.25;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 19px;
}

h3 {
  font-size: 15px;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

img,
video,
svg {
  display: block;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

::selection {
  background: var(--accent-soft);
}

/* One focus treatment everywhere, and only for keyboard users so pointer
   clicks don't leave rings behind. */
:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

/* Scrollbars, so panels don't get a bright OS-coloured stripe. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--s4) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-thumb {
  background: var(--s4);
  border: 3px solid transparent;
  border-radius: var(--r-pill);
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--border-2);
  background-clip: content-box;
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ---------------------------------------------------------- primitives */

.muted {
  color: var(--fg-2);
}

.dim {
  color: var(--fg-3);
}

.small {
  font-size: 12.5px;
}

.tiny {
  font-size: 11.5px;
}

.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.row.wrap {
  flex-wrap: wrap;
}

.row.between {
  justify-content: space-between;
}

.row.end {
  justify-content: flex-end;
}

/* Takes the leftover space and, unlike .spacer, may hold content: a flex item
   without min-width:0 refuses to shrink below its text. */
.grow {
  flex: 1;
  min-width: 0;
}

.col {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.spacer {
  flex: 1;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
}

.icon.lg {
  width: 22px;
  height: 22px;
}

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

.btn {
  --btn-bg: var(--s3);
  --btn-fg: var(--fg);
  --btn-line: var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0 14px;
  height: 36px;
  border: 1px solid var(--btn-line);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast),
    transform var(--t-fast), opacity var(--t-fast);
}

.btn:hover:not(:disabled) {
  background: var(--s4);
  border-color: var(--border-2);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.btn.primary {
  --btn-bg: var(--accent);
  --btn-line: transparent;
  color: #fff;
  box-shadow: 0 4px 14px rgba(124, 92, 255, .3);
}

.btn.primary:hover:not(:disabled) {
  --btn-bg: var(--accent-2);
  border-color: transparent;
}

.btn.ghost {
  --btn-bg: transparent;
  --btn-line: transparent;
  color: var(--fg-2);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--s3);
  color: var(--fg);
  border-color: transparent;
}

.btn.outline {
  --btn-bg: transparent;
}

.btn.danger {
  --btn-bg: var(--danger-soft);
  --btn-line: rgba(248, 113, 113, .3);
  color: var(--danger);
}

.btn.danger:hover:not(:disabled) {
  --btn-bg: rgba(248, 113, 113, .2);
  border-color: rgba(248, 113, 113, .5);
}

.btn.sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  border-radius: var(--r-sm);
}

.btn.lg {
  height: 44px;
  padding: 0 22px;
  font-size: 15px;
}

.btn.block {
  width: 100%;
}

.btn.icon-only {
  width: 36px;
  padding: 0;
}

.btn.sm.icon-only {
  width: 30px;
}

/* Fields --------------------------------------------------------------- */

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

.field > span {
  font-size: 12.5px;
  font-weight: 550;
  color: var(--fg-2);
}

input[type=text],
input[type=password],
input[type=number],
input[type=search],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: var(--border-2);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.5;
}

::placeholder {
  color: var(--fg-3);
}

.form-error {
  color: var(--danger);
  font-size: 12.5px;
}

.check {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  user-select: none;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Cards, pills, badges ------------------------------------------------- */

.card {
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: 12px;
  color: var(--fg-2);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: .03em;
  text-transform: uppercase;
  background: var(--s4);
  color: var(--fg-2);
}

.badge.nsfw {
  background: rgba(244, 114, 182, .16);
  color: var(--nsfw);
}

.badge.video {
  background: rgba(124, 92, 255, .16);
  color: var(--accent-2);
}

.badge.ok {
  background: rgba(52, 211, 153, .14);
  color: var(--ok);
}

.badge.warn {
  background: rgba(251, 191, 36, .14);
  color: var(--warn);
}

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

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

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.seg-btn {
  padding: 6px 14px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg-2);
  font-weight: 550;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}

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

.seg-btn.active {
  background: var(--s3);
  color: var(--fg);
  box-shadow: var(--shadow-1);
}

/* Empty + loading states ---------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-7) var(--sp-4);
  text-align: center;
  color: var(--fg-2);
}

.empty svg {
  width: 34px;
  height: 34px;
  color: var(--fg-3);
}

.empty h3 {
  color: var(--fg);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.skeleton {
  background: linear-gradient(90deg, var(--s2), var(--s3), var(--s2));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-md);
}

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

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

.toasts {
  position: fixed;
  right: var(--sp-5);
  bottom: var(--sp-5);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  padding: 11px 15px;
  max-width: 380px;
  background: var(--s3);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  animation: toast-in var(--t-med);
}

.toast.good {
  border-left-color: var(--ok);
}

.toast.bad {
  border-left-color: var(--danger);
}

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

/*
  "A new version is ready." Top centre, and not in the toast stack: a toast
  takes itself away after a few seconds, and this has to still be there when
  the reader looks up. Width from its contents, so it is a strip rather than a
  banner across the screen. It only ever goes up with nothing else open — see
  core/version.js — so this sits above the views and below the toasts.
*/
.update-bar {
  position: fixed;
  top: calc(var(--sp-4) + env(safe-area-inset-top));
  right: 0;
  left: 0;
  z-index: 89;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: fit-content;
  max-width: calc(100% - 2 * var(--sp-4));
  margin: 0 auto;
  padding: 8px 8px 8px 14px;
  background: var(--s3);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-3);
  animation: update-in var(--t-med);
}

@keyframes update-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
}
