/*
 * sketch-ui: the hand-drawn look for the toolbox.
 *
 * Strokes are SVG paths from the seeded generator (src/rough.rs). Paths with the
 * .ink class draw themselves in once; sketch.js staggers them and the text.
 */

/* ------------------------------------------------------------------------------
 * Fonts and tokens
 * ------------------------------------------------------------------------------ */

@font-face {
  font-family: "Work Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/work-sans-latin-400-normal.woff2) format("woff2");
}

@font-face {
  font-family: "Work Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/work-sans-latin-700-normal.woff2) format("woff2");
}

/* Kalam, the handwriting font of the original designs; set --font to use it again. */
@font-face {
  font-family: "Kalam";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/kalam-latin-400-normal.woff2) format("woff2");
}

@font-face {
  font-family: "Kalam";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/kalam-latin-700-normal.woff2) format("woff2");
}

:root {
  --paper: #fbf8f1;
  --ink: #1f1d1a;
  --ink-soft: #6b655c;
  --muted: #8a8377;
  --faint: #cfc8bb;
  --rule: #e4ded3;
  --link: #2b4c9b;
  --link-hover: #1f3570;
  --live: #c92a2a;
  --accent: #d9480f;
  --accent-tint: color-mix(in srgb, var(--accent) 20%, transparent);
  --focus: #2b4c9b;
  --font: "Work Sans", system-ui, sans-serif;

  color-scheme: light;
}

/* ------------------------------------------------------------------------------
 * Base and layout
 * ------------------------------------------------------------------------------ */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 19px;
  line-height: 1.4;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.h1 {
  font-size: 34px;
  line-height: 1.15;
  font-weight: 700;
}

.h2 {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
}

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

.page {
  display: flex;
  flex-direction: column;
  gap: 32px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 40px 64px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 20px;
}

/* Visually hidden, still read by screen readers. */
.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 699px) {
  .page {
    gap: 24px;
    padding: 20px 20px 40px;
  }

  .h1 {
    font-size: 28px;
  }
}

/* ------------------------------------------------------------------------------
 * Sketch overlays
 *
 * An .sk SVG stretches over its positioned parent (preserveAspectRatio="none"),
 * so the wobble scales with the box while non-scaling-stroke keeps the line width.
 * ------------------------------------------------------------------------------ */

.sk {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.sk .outline {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.sk .fill {
  fill: var(--accent-tint);
}

.sk .outline.dashed {
  stroke-dasharray: 7 9;
}

.sketch-box {
  position: relative;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 240px;
  padding: 18px 22px;
}

.underlined {
  position: relative;
  align-self: flex-start;
  padding-bottom: 6px;
}

.underline {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 6px;
  overflow: visible;
  pointer-events: none;
}

.underline path {
  --d: 600ms;
  fill: none;
  stroke: var(--faint);
  stroke-width: 2;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.arrow {
  width: 1em;
  height: 1em;
  overflow: visible;
  vertical-align: -0.15em;
}

.arrow path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spinner {
  width: 1em;
  height: 1em;
  overflow: visible;
  vertical-align: -0.15em;
  animation: sk-spin 900ms linear infinite;
}

.spinner path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

@keyframes sk-spin {
  to {
    transform: rotate(1turn);
  }
}

.check {
  width: 1.1em;
  height: 1.1em;
  overflow: visible;
  vertical-align: -0.15em;
}

.check .stroke {
  --d: 300ms;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------------------------
 * Draw-in animations
 *
 * sketch.js walks the page in document order and gives every visible stroke, fill,
 * text and form field an entrance with a delay: --t for strokes and fills, --wt
 * (delay) and --wd (duration) for text. Until it has run (html.sk-js without .sk-go)
 * the page stays hidden, so nothing flashes before its entrance. The inline script in
 * base.html sets .sk-go after 2.5s regardless, in case sketch.js fails to load.
 * ------------------------------------------------------------------------------ */

/* The dash only exists while drawing, so a finished stroke is always solid, even after
   its box is resized. --k is the stroke's on-screen length in pathLength units: 1 for
   normal strokes, more for non-scaling strokes in a stretched box (sketch.js measures
   it), so the dash always covers the whole stroke. */
.ink {
  animation: sk-draw var(--d, 550ms) cubic-bezier(0.55, 0.1, 0.35, 1) var(--t, 0ms) backwards;
}

/* Headings, button labels and links are "written": a left-to-right wipe, like a pen
   moving along the line. Negative insets keep overhanging glyphs unclipped. */
.sk-write {
  animation: sk-write var(--wd, 350ms) cubic-bezier(0.35, 0.15, 0.4, 1) var(--wt, 0ms) backwards;
}

/* Longer text fades in. */
.sk-fade {
  animation: sk-fade 380ms ease-out var(--wt, 0ms) backwards;
}

/* Fills fade in just after the stroke drawn before them. */
.sk-fill-in {
  animation: sk-fill 450ms ease-out calc(var(--t, 0ms) + 120ms) backwards;
}

.sk-js:not(.sk-go) body > * {
  opacity: 0;
}

.sk-js:not(.sk-go) .ink {
  animation-play-state: paused;
}

@keyframes sk-draw {
  from {
    stroke-dasharray: var(--k, 1) var(--k, 1);
    stroke-dashoffset: var(--k, 1);
  }
  to {
    stroke-dasharray: var(--k, 1) var(--k, 1);
    stroke-dashoffset: 0;
  }
}

@keyframes sk-fill {
  from {
    opacity: 0;
  }
}

@keyframes sk-write {
  from {
    clip-path: inset(-30% 100% -30% -6px);
  }
  to {
    clip-path: inset(-30% -10px -30% -6px);
  }
}

@keyframes sk-fade {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
}

/* ------------------------------------------------------------------------------
 * Controls
 * ------------------------------------------------------------------------------ */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 22px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 20px;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

.btn > span {
  position: relative;
}

.btn:hover .outline {
  stroke-width: 2.8;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  font-weight: 700;
}

.link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--link);
  font: inherit;
  font-size: 18px;
  text-decoration: none;
  cursor: pointer;
}

.link:hover {
  color: var(--link-hover);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.icon-btn {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #a9a196;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--ink);
}

.saved {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 16px;
}

:where(a, button, input, textarea, select, [tabindex]):focus-visible {
  outline: 3px dashed var(--focus);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------------------
 * Sortable lists (sketch.js): drag handle, dragged row, drop line
 * ------------------------------------------------------------------------------ */

.grip {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 44px;
  color: var(--faint);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.grip:active {
  cursor: grabbing;
}

[data-sort-id]:hover .grip {
  color: var(--muted);
}

[data-sort-id] {
  position: relative;
}

.sort-dragging {
  opacity: 0.4;
}

.sort-drop-before::before,
.sort-drop-after::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 3px 1px 2px 1px;
  background: var(--accent);
  pointer-events: none;
}

.sort-drop-before::before {
  top: -3px;
}

.sort-drop-after::after {
  bottom: -3px;
}

/* ------------------------------------------------------------------------------
 * Live indicator
 * ------------------------------------------------------------------------------ */

.live-dot {
  display: inline-block;
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--live);
  animation: sk-livepulse 2s ease-out infinite;
}

@keyframes sk-livepulse {
  0% {
    box-shadow: 0 0 0 0 rgb(201 42 42 / 0.5);
  }
  70% {
    box-shadow: 0 0 0 8px rgb(201 42 42 / 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgb(201 42 42 / 0);
  }
}

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

.toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 480px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  border-radius: 10px 14px 9px 13px;
  background: var(--ink);
  color: var(--paper);
  font-size: 17px;
  box-shadow: 0 6px 20px rgb(31 29 26 / 0.18);
  pointer-events: auto;
  animation: sk-toast-in 160ms ease-out;
}

.toast.error {
  background: #8f1d1d;
}

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

/* ------------------------------------------------------------------------------
 * Reduced motion
 * ------------------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .ink,
  .sk-fill-in,
  .sk-write,
  .sk-fade,
  .live-dot,
  .toast,
  .spinner {
    animation: none;
  }
}
