/* ==========================================================================
   HotHub — Paper Sketch(纸绘手稿)
   Torn-paper slips on textured stock, hand-drawn radii, pencil strokes,
   marker/handwriting display type over a readable sans body.
   Dual theme: 蓝图纸(light) / 夜间墨稿(dark), ink-spread view transition.
   Design source: design-system/hothub/MASTER.md
   ========================================================================== */

/* --------------------------- Light Theme — 蓝图纸 ----------------------- */
:root {
  --paper:        #d9eaf8;
  --paper-card:   #eaf3fb;
  --paper-deep:   #c4dbed;
  --paper-shadow: #b4c8d7;

  --ink:          #1a1814;
  --ink-soft:     #2c2823;
  --ink-pale:     #5a534a;
  --pencil:       #6b7f96;

  --accent:       #b8442e;
  --accent-blue:  #2d4a7a;
  --on-accent:    #fff;
  --danger:       #b8442e;
  --ring:         #b8442e;

  --drop:         rgba(40, 30, 10, 0.18);
  --drop-lift:    rgba(40, 30, 10, 0.28);

  /* Grid lines + fibre tint (theme-dependent) */
  --grid-line:    rgba(55, 116, 128, 0.18);
  --fibre:        rgba(0, 0, 0, 0.035);
  --vignette:     rgba(60, 50, 30, 0.18);

  /* Grain overlay blend (see body::before) */
  --grain-blend:   multiply;
  --grain-opacity: 0.55;

  /* Hand-drawn geometry */
  --radius-hand:    8px 12px 7px 11px / 11px 7px 12px 8px;
  --radius-hand-sm: 5px 8px 4px 7px / 7px 4px 8px 5px;
  --radius-blob:    50% 46% 52% 48% / 48% 52% 46% 52%;
  /* Hand-drawn pill: over-large radii clamp to half the box, and the uneven
     values survive the clamp as a lopsided capsule — never a perfect 999px. */
  --radius-pill:    14px 20px 15px 19px / 20px 15px 19px 14px;
  --torn:           polygon(1% 0.5%, 99% 1.2%, 99.6% 50%, 98.8% 99.4%, 0.8% 98.8%, 0.4% 49%);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --font-body:   "Inter", "PingFang SC", "HarmonyOS Sans SC", "MiSans",
                 "Microsoft YaHei", system-ui, sans-serif;
  --font-hand:   "Caveat", "Zhi Mang Xing", "Patrick Hand", cursive;
  --font-marker: "Permanent Marker", "Zhi Mang Xing", "Caveat", cursive;

  color-scheme: light;
}

/* --------------------------- Dark Theme — 夜间墨稿 ---------------------- */
[data-theme="dark"] {
  --paper:        #151a20;
  --paper-card:   #1f262e;
  --paper-deep:   #10141a;
  --paper-shadow: #2a323c;

  --ink:          #e8e2d4;
  --ink-soft:     #c3bcae;
  --ink-pale:     #8e887c;
  --pencil:       #6b7f96;

  --accent:       #e0705a;
  --accent-blue:  #8fb4e0;
  --on-accent:    #151a20;   /* dark ink on the lifted rust — #fff would be ~2.6:1 */
  --danger:       #e0705a;
  --ring:         #e0705a;

  --drop:         rgba(0, 0, 0, 0.45);
  --drop-lift:    rgba(0, 0, 0, 0.62);

  --grid-line:    rgba(143, 180, 224, 0.09);
  --fibre:        rgba(255, 255, 255, 0.045);
  --vignette:     rgba(0, 0, 0, 0.25);

  --grain-blend:   soft-light;
  --grain-opacity: 0.35;

  color-scheme: dark;
}

/* Pre-JS flash guard: system dark preference — MUST mirror [data-theme="dark"] */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper:        #151a20;
    --paper-card:   #1f262e;
    --paper-deep:   #10141a;
    --paper-shadow: #2a323c;

    --ink:          #e8e2d4;
    --ink-soft:     #c3bcae;
    --ink-pale:     #8e887c;
    --pencil:       #6b7f96;

    --accent:       #e0705a;
    --accent-blue:  #8fb4e0;
    --on-accent:    #151a20;
    --danger:       #e0705a;
    --ring:         #e0705a;

    --drop:         rgba(0, 0, 0, 0.45);
    --drop-lift:    rgba(0, 0, 0, 0.62);

    --grid-line:    rgba(143, 180, 224, 0.09);
    --fibre:        rgba(255, 255, 255, 0.045);
    --vignette:     rgba(0, 0, 0, 0.25);

    --grain-blend:   soft-light;
    --grain-opacity: 0.35;

    color-scheme: dark;
  }
  :root:not([data-theme]) .btn-theme .ic-sun  { display: block; }
  :root:not([data-theme]) .btn-theme .ic-moon { display: none; }
}

/* --------------------------- View Transition (ink spread) --------------- */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

/* ------------------------------- Reset ---------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--paper);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;

  /* 纸张纤维 + 四角暗角 */
  background-image:
    radial-gradient(ellipse at center, transparent 0%, var(--vignette) 100%),
    repeating-linear-gradient(37deg, var(--fibre) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(127deg, var(--fibre) 0 1px, transparent 1px 5px);
  background-attachment: fixed;
}

/* 纸张噪点颗粒:feTurbulence 分形噪声 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='320'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.35  0 0 0 0 0.32  0 0 0 0 0.25  0 0 0 0.18 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* 格线(方格纸) */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.75;
  background-image:
    linear-gradient(var(--grid-line) 2px, transparent 2px),
    linear-gradient(90deg, var(--grid-line) 2px, transparent 2px);
  background-size: 20px 20px;
  mask-image: radial-gradient(ellipse at center, black 20%, transparent 82%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 20%, transparent 82%);
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
[hidden] { display: none !important; }
/* Follows the theme — a hardcoded light-rust stain is invisible on 夜间墨稿 */
::selection { background: color-mix(in srgb, var(--accent) 26%, transparent); }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 3px; border-radius: var(--radius-hand-sm); }

/* Scrollbars — pencil grey */
* { scrollbar-width: thin; scrollbar-color: var(--paper-shadow) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--paper-shadow); border-radius: 9px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------ Ink strokes ----------------------------- */
/* Off-screen holder for the <filter> defs. Must NOT be display:none —
   a display:none SVG root drops its filter references in some engines. */
.sketch-defs {
  position: absolute;
  width: 0; height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* Roughened pencil line. `inset: 0` + `border-radius: inherit` traces the host
   box; the filter then wavers it. Anything using these must sit on a host that
   is already a containing block — `filter` makes one, so the paper surfaces
   qualify without an extra `position: relative`. */
.pencil-edge::before,
.site-header::before,
.site-foot::before,
.g-card::before,
.g-empty::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  filter: url(#rough-lo);
}

.ink-stroke {
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.ink-stroke--soft {
  stroke: var(--pencil);
  stroke-width: 1.1;
}
@keyframes draw-on {
  from { stroke-dashoffset: var(--len, 1000); }
  to   { stroke-dashoffset: 0; }
}
.draw-on {
  stroke-dasharray: var(--len, 1000);
  stroke-dashoffset: var(--len, 1000);
  animation: draw-on 1.6s var(--ease) forwards;
}

/* ----------------------------- App shell -------------------------------- */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 24px 48px;
  position: relative;
  z-index: 2;   /* above the fixed texture layers */
}

/* --------------------------- Paper surface mixin ------------------------ */
/* Applied to header / footer / cards: opaque stock + its own grain so the
   slips read as paper too, not as flat fills over the grainy page. */
.site-header,
.site-foot,
.g-card {
  background-color: var(--paper-card);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='c'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.4  0 0 0 0 0.37  0 0 0 0 0.3  0 0 0 0.055 0'/></filter><rect width='100%25' height='100%25' filter='url(%23c)'/></svg>");
}

/* ------------------------------- Header --------------------------------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap;
  padding: 19px 23px;
  border-radius: var(--radius-hand);
  transform: rotate(-0.4deg);
  filter: drop-shadow(-3px 5px 12px var(--drop));
}
.site-header::before { border: 1.6px solid var(--pencil); }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-emblem {
  width: 46px; height: 46px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--radius-blob);
  border: 2.2px solid var(--accent);
  color: var(--accent);
  background: transparent;
  transform: rotate(6deg);
  transition: transform 0.25s var(--ease);
}
.site-header:hover .brand-emblem { transform: rotate(-4deg) scale(1.06); }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name {
  font-family: var(--font-marker);
  font-size: 27px; font-weight: 400;
  color: var(--ink);
  letter-spacing: 0.5px;
}
.brand-underline {
  display: block;
  width: 190px; height: 11px;
  margin: 1px 0 3px;
}
.brand-sub {
  font-family: var(--font-hand);
  font-size: 17px; color: var(--ink-pale); font-weight: 400;
  letter-spacing: normal; text-transform: none;
}

.header-actions { display: flex; align-items: center; gap: 10px; }

/* Base button — pencil-outlined tag, tilts on hover */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-hand);
  border: 1.6px solid var(--pencil);
  font-family: var(--font-hand);
  font-size: 17px; font-weight: 400; color: var(--ink-soft);
  background: transparent;
  transform: rotate(-0.6deg);
  transition: transform 0.22s var(--ease), border-color 0.22s var(--ease),
              color 0.22s var(--ease);
}
.btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: rotate(1deg) translateY(-1px);
}
.btn:active { transform: rotate(0deg) translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; transform: rotate(-0.6deg); }
.btn.spinning .ic-refresh { animation: spin 0.8s linear infinite; }

/* Theme toggle — hand-drawn circle in rust ink */
.btn-theme {
  width: 46px; height: 46px; padding: 0;
  display: grid; place-items: center;
  border-radius: var(--radius-blob);
  border: 2.2px solid var(--accent);
  color: var(--accent);
  background: transparent;
  transform: rotate(6deg);
  transition: transform 0.25s var(--ease), background-color 0.25s var(--ease);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn-theme:hover { transform: rotate(-5deg) scale(1.08); background-color: color-mix(in srgb, var(--accent) 9%, transparent); }
.btn-theme:active { transform: rotate(0deg) scale(0.95); transition-duration: 0.08s; }
.btn-theme svg { width: 19px; height: 19px; }
.btn-theme .ic-sun  { display: none; }
.btn-theme .ic-moon { display: block; }
[data-theme="dark"] .btn-theme .ic-sun  { display: block; }
[data-theme="dark"] .btn-theme .ic-moon { display: none; }

/* ------------------------------- Filters -------------------------------- */
.filters { display: flex; flex-direction: column; gap: 14px; margin-top: 26px; }
/* Pencil rule closing the filter block. NO roughen filter here: the box is a
   bare border-top, so its filter region is ~1.4px tall and the ±2.25px
   displacement would be clipped into holes. `dashed` carries it alone. */
.filters::after {
  content: "";
  display: block;
  margin: 4px 2px 0;
  border-top: 1.4px dashed var(--pencil);
  opacity: 0.55;
}
.filter-row { display: flex; align-items: flex-start; gap: 14px; }
.filter-label {
  flex-shrink: 0; width: 40px; padding-top: 10px;
  position: relative;
  font-family: var(--font-hand);
  font-weight: 400; font-size: 19px;
  color: var(--accent-blue);
  text-transform: none; letter-spacing: normal;
}
/* Marker swipe under the label — anchored to `bottom` so it keeps hugging the
   glyphs as the font-size steps down across breakpoints. */
.filter-label::before {
  content: "";
  position: absolute;
  left: -4px; right: -3px; bottom: 7px;
  height: 11px;
  z-index: -1;
  background: color-mix(in srgb, var(--accent-blue) 22%, transparent);
  border-radius: 6px 10px 5px 9px / 9px 5px 10px 6px;
  rotate: -1.2deg;
  filter: url(#rough-hi);
}
.chips { display: flex; flex-wrap: wrap; gap: 9px; }

/* Chip — dashed pencil tag, rust fill when active */
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 42px;
  padding: 8px 15px;
  border-radius: var(--radius-hand);
  border: 1.6px dashed var(--pencil);
  font-family: var(--font-hand);
  font-size: 18px; font-weight: 400; color: var(--ink-soft);
  background: transparent;
  transform: rotate(var(--chip-rot, 0deg));
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease),
              color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.chip:nth-child(3n+1) { --chip-rot: -0.7deg; }
.chip:nth-child(3n+2) { --chip-rot: 0.8deg; }
.chip:nth-child(3n)   { --chip-rot: -0.4deg; }
.chip:hover { color: var(--accent); border-color: var(--accent); }
.chip.active {
  --chip-rot: 0deg;
  color: var(--on-accent);
  background-color: var(--accent);
  border: 1.6px solid var(--accent);
  filter: drop-shadow(-2px 3px 6px var(--drop));
}
.chip .pdot { width: 9px; height: 9px; border-radius: var(--radius-blob); flex-shrink: 0; background: var(--ink-pale); }
.chip.active .pdot { background: color-mix(in srgb, var(--on-accent) 70%, transparent); }
.chip-n {
  font-family: var(--font-body);
  font-size: 11px; font-weight: 600; color: var(--ink-pale);
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
}
/* 88%, not 78% — at 11px/600 the count still has to clear 4.5:1 on the rust fill */
.chip.active .chip-n { color: color-mix(in srgb, var(--on-accent) 88%, transparent); }

/* ------------------------------- Gallery (slip stack) ------------------- */
.gallery {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 4px;   /* absorb the rotation overhang */
}

/* ------------------------------- Card — a torn paper slip --------------- */
.g-card {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 14px;
  padding: 15px 18px;
  clip-path: var(--torn);
  /* Tilt rides the independent `rotate` property, the drop-in rides
     `translate`, and the hover lift rides `transform`. Three separate
     properties = the filling animation can never freeze out the hover. */
  rotate: var(--rot, 0deg);
  /* filter applies AFTER clip-path, so the shadow hugs the torn silhouette */
  filter: drop-shadow(-3px 5px 10px var(--drop));
  animation: card-in 0.34s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 20ms);
  transition: rotate 0.22s var(--ease), transform 0.22s var(--ease),
              filter 0.22s var(--ease);
}
.g-card:nth-child(3n+1) { --rot: 0.35deg; }
.g-card:nth-child(3n+2) { --rot: -0.45deg; }
.g-card:nth-child(3n)   { --rot: 0.25deg; }

/* Pencil rule drawn INSIDE the tear. The torn polygon bites up to 1% off each
   side, so the line is inset past the deepest bite (~11px at desktop width) —
   otherwise clip-path shaves it off. Reads as a box ruled inside the slip. */
.g-card::before {
  inset: 5px 11px;
  border: 1.4px solid var(--pencil);
  border-radius: var(--radius-hand);
  opacity: 0.5;
  transition: opacity 0.22s var(--ease);
}

/* Hover: the slip is picked up and flattened */
.g-card:hover {
  --rot: 0deg;
  transform: translateY(-2px);
  filter: drop-shadow(-5px 8px 16px var(--drop-lift));
}
.g-card:hover::before { opacity: 0.8; }

/* ------------------------------- Rank ----------------------------------- */
.g-rank {
  flex-shrink: 0;
  position: relative;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-family: var(--font-hand);
  font-size: 20px; font-weight: 700;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
  border-radius: var(--radius-blob);
  border: 1.4px solid var(--pencil);
  background: transparent;
}
/* Second loop — the overshoot you get when a number is circled twice by hand.
   Different blob values + a counter-rotation so the two rings never trace. */
.g-rank::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50% 47% 53% 46% / 46% 53% 47% 54%;
  border: 1.1px solid var(--pencil);
  opacity: 0.45;
  rotate: -14deg;
  pointer-events: none;
  filter: url(#rough-hi);
  transition: rotate 0.22s var(--ease), opacity 0.22s var(--ease);
}
.g-card:hover .g-rank::after { rotate: 8deg; opacity: 0.75; }
/* top-3: rust fill. Stays in --font-hand — Permanent Marker's digits are
   near-illegible at this size (its "1" reads as a stray curl). */
.g-rank.top {
  color: var(--on-accent);
  background-color: var(--accent);
  border-color: var(--accent);
  font-size: 21px;
}
.g-rank.top::after { border-color: var(--accent); opacity: 0.7; }

/* ------------------------------- Body (text area) ----------------------- */
.g-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-top: 1px;
}
.g-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.g-title {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-weight: 600; font-size: 16px; line-height: 1.6;
  color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-word;
  transition: color 0.18s var(--ease);
}
.g-title:hover {
  color: var(--accent);
  text-decoration: underline wavy var(--accent) 1.2px;
  text-underline-offset: 5px;
}

/* Platform tag — thin pencil pill in ink blue */
.g-plat {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px; border-radius: var(--radius-pill);
  border: 1.2px solid var(--pencil);
  font-family: var(--font-hand);
  font-size: 15px; font-weight: 400; color: var(--accent-blue);
  background: transparent;
  white-space: nowrap;
}
.g-plat .pdot {
  width: 7px; height: 7px; border-radius: var(--radius-blob); flex-shrink: 0;
  background: var(--ink-pale);
}

/* Sub row */
.g-sub {
  display: flex;
  align-items: center;
  gap: 12px;
}
.g-sum {
  font-size: 12px; color: var(--ink-pale); line-height: 1.5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.g-heat {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-hand);
  font-size: 17px; font-weight: 600; color: var(--ink-soft);
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
}
.g-heat svg { color: var(--accent); }
.g-heat.cold { color: var(--ink-pale); }
.g-heat.cold svg { color: var(--ink-pale); }

/* ------------------------------- Thumbnail (pencil frame) --------------- */
.g-thumb {
  flex-shrink: 0;
  display: block;
  width: 92px; height: 70px;
  border-radius: var(--radius-hand);
  border: 1.4px solid var(--pencil);
  overflow: hidden;
  background: var(--paper-deep);
  position: relative;
  transform: rotate(-1.2deg);
  transition: transform 0.22s var(--ease), border-color 0.22s var(--ease);
}
.g-card:hover .g-thumb { transform: rotate(1deg); border-color: var(--accent); }

/* Washi tape across the top edge — the one detail that says "stuck onto paper"
   rather than "image in a frame". Overflow-clipped to a half strip on purpose.
   Tinted from --ink so it flips to translucent chalk on 夜间墨稿. */
.g-thumb::after {
  content: "";
  position: absolute;
  z-index: 2;
  top: -7px; left: 50%;
  width: 36px; height: 15px;
  translate: -50% 0;
  rotate: -6deg;
  background: color-mix(in srgb, var(--ink) 9%, transparent);
  border-left: 1px solid color-mix(in srgb, var(--ink) 15%, transparent);
  border-right: 1px solid color-mix(in srgb, var(--ink) 15%, transparent);
  pointer-events: none;
}

/* Shimmer while image loads */
.g-thumb:not(.loaded)::before {
  content: "";
  position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--paper-shadow) 45%, var(--paper-card)) 25%,
    var(--paper-card) 50%,
    color-mix(in srgb, var(--paper-shadow) 45%, var(--paper-card)) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s infinite;
}
.g-thumb.loaded::before { display: none; }

.g-thumb img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
  opacity: 0;
  transition: opacity 0.25s var(--ease);
}
.g-thumb.loaded img { opacity: 1; }

/* ------------------------------- Skeleton ------------------------------- */
.g-card.skeleton { pointer-events: none; animation: none; }
.sk-line {
  height: 14px;
  border-radius: 6px 9px 5px 8px / 8px 5px 9px 6px;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--paper-shadow) 45%, var(--paper-card)) 25%,
    var(--paper-card) 50%,
    color-mix(in srgb, var(--paper-shadow) 45%, var(--paper-card)) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s infinite;
}
.sk-title { width: 70%; height: 17px; }
.sk-sum  { width: 45%; height: 13px; }

/* ------------------------------- Empty / States ------------------------- */
.g-empty {
  position: relative;
  margin: 6px 2px;
  padding: 56px 20px; text-align: center;
  border-radius: var(--radius-hand);
  font-family: var(--font-hand);
  font-size: 21px; color: var(--ink-pale);
}
/* An empty box sketched on the page, rather than bare floating text */
.g-empty::before {
  border: 1.6px dashed var(--pencil);
  opacity: 0.55;
}
.state-block {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 60px 20px;
  font-family: var(--font-hand);
  font-size: 20px; color: var(--ink-soft);
}
#error-state > svg { color: var(--danger); }
.spinner {
  width: 32px; height: 32px;
  border-radius: var(--radius-blob);
  border: 2.4px solid var(--paper-shadow);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

/* ------------------------------- Pager ---------------------------------- */
.pager { margin-top: 26px; }
.pager-inner {
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.pg-btn, .pg-num {
  display: grid; place-items: center;
  min-width: 40px; height: 40px;
  border-radius: var(--radius-blob);
  border: 1.4px solid var(--pencil);
  font-family: var(--font-hand);
  font-size: 18px; font-weight: 400;
  color: var(--ink-soft);
  background: transparent;
  transform: rotate(var(--pg-rot, 0deg));
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
}
.pg-num:nth-child(odd)  { --pg-rot: -1deg; }
.pg-num:nth-child(even) { --pg-rot: 1.2deg; }
.pg-btn:hover, .pg-num:hover {
  color: var(--accent); border-color: var(--accent);
  transform: rotate(0deg) scale(1.08);
}
.pg-num.active {
  --pg-rot: 0deg;
  color: var(--on-accent);
  background-color: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
  font-size: 19px;
}
.pg-btn[disabled] { opacity: 0.3; pointer-events: none; }
.pg-nums { display: flex; gap: 5px; }
.pg-dots {
  display: grid; place-items: center;
  width: 30px; height: 40px;
  font-family: var(--font-hand);
  font-size: 18px; color: var(--ink-pale);
  letter-spacing: 0.1em;
}
.pg-total {
  font-family: var(--font-hand);
  font-size: 17px; font-weight: 400; color: var(--ink-pale);
  margin: 0 6px;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
}

/* ------------------------------- Footer --------------------------------- */
.site-foot {
  margin-top: 34px; padding: 17px 23px;
  border-radius: var(--radius-hand);
  transform: rotate(0.35deg);
  filter: drop-shadow(-3px 5px 12px var(--drop));
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-family: var(--font-hand);
  font-size: 17px; color: var(--ink-pale);
  font-weight: 400; letter-spacing: normal;
}
.site-foot::before { border: 1.6px solid var(--pencil); }
.site-foot a { color: var(--accent-blue); border-bottom: 1.4px dashed var(--pencil); }
.site-foot a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ----------------------------- Animations ------------------------------- */
/* Slips are dealt onto the desk. Uses `translate`, NOT `transform` — the `both`
   fill-mode would otherwise pin transform forever and kill the hover lift. */
@keyframes card-in {
  from { opacity: 0; translate: 0 -7px; }
  to   { opacity: 1; translate: 0 0; }
}
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------- Responsive ------------------------------- */
@media (max-width: 1024px) {
  .app { padding: 20px 20px 40px; }
}

@media (max-width: 768px) {
  .app { padding: 16px 16px 32px; }
  .site-header { padding: 14px 18px; gap: 12px; }
  .brand-name { font-size: 23px; }
  .brand-underline { width: 150px; }
  .brand-sub { font-size: 15px; }
  .header-actions { gap: 8px; }

  /* Filters stack vertically */
  .filter-row { flex-direction: column; gap: 6px; }
  .filter-label { width: auto; padding-top: 0; font-size: 17px; }
  .chip { padding: 6px 12px; font-size: 16px; min-height: 38px; }
  .chip-n { font-size: 10px; }

  /* Slips */
  .gallery { gap: 10px; }
  .g-card { gap: 12px; padding: 13px 15px; }
  .g-title { font-size: 15px; }
  .g-thumb { width: 76px; height: 58px; }
  .g-rank { width: 33px; height: 33px; font-size: 17px; }
  .g-rank.top { font-size: 15px; }
  .g-plat { font-size: 14px; padding: 1px 8px; }

  /* Pager */
  .pg-num, .pg-btn { min-width: 36px; height: 36px; font-size: 16px; }
  .pg-num.active { font-size: 14px; }
  .pg-dots { width: 26px; height: 36px; }

  /* Footer */
  .site-foot { flex-direction: column; text-align: center; gap: 6px; font-size: 15px; }
}

@media (max-width: 480px) {
  .app { padding: 10px 10px 24px; }

  /* Narrow screens: no rotation, no torn edges — they eat usable width */
  .site-header, .site-foot { transform: none; }
  .gallery { gap: 8px; padding: 0; }
  .g-card,
  .g-card:hover { --rot: 0deg; rotate: 0deg; transform: none; clip-path: none; }
  .g-card { border-radius: var(--radius-hand-sm); }
  /* No tear to clear any more — the rule can hug the slip edge */
  .g-card::before { inset: 4px 5px; border-radius: var(--radius-hand-sm); }
  .g-card:hover { filter: drop-shadow(-3px 5px 10px var(--drop-lift)); }
  .chip { --chip-rot: 0deg; }
  .pg-num, .pg-btn { --pg-rot: 0deg; }

  /* Header — compact */
  .site-header { padding: 12px 15px; gap: 8px; border-radius: var(--radius-hand-sm); }
  .brand-emblem { width: 38px; height: 38px; }
  .brand-name { font-size: 21px; }
  .brand-underline { display: none; }
  .brand-sub { display: none; }

  /* Buttons — icon-only */
  .btn { padding: 8px 11px; font-size: 15px; min-height: 38px; border-radius: var(--radius-hand-sm); }
  .btn span { display: none; }
  .btn-theme { width: 38px; height: 38px; }

  /* Filters */
  .filters { gap: 10px; margin-top: 16px; }
  .chips { gap: 7px; }
  .chip { padding: 5px 11px; font-size: 15px; min-height: 36px; border-radius: var(--radius-hand-sm); }

  /* Gallery */
  .gallery { margin-top: 16px; }

  /* Card — tight */
  .g-card { gap: 9px; padding: 11px 13px; }
  .g-head { flex-direction: column; gap: 4px; }
  .g-title { font-size: 14px; -webkit-line-clamp: 2; }
  .g-sub { gap: 8px; }
  .g-sum { display: none; }
  .g-heat { font-size: 15px; }
  .g-plat { font-size: 13px; padding: 1px 7px; }
  .g-thumb { width: 58px; height: 44px; border-radius: var(--radius-hand-sm); transform: none; }
  .g-thumb::after { width: 24px; height: 12px; top: -6px; }
  .g-card:hover .g-thumb { transform: none; }
  .g-rank { width: 30px; height: 30px; font-size: 15px; }
  .g-rank.top { font-size: 13px; }

  /* Pager */
  .pager { margin-top: 16px; }
  .pg-nums { gap: 4px; }
  .pg-num, .pg-btn { min-width: 32px; height: 32px; font-size: 15px; }
  .pg-num.active { font-size: 13px; }
  .pg-dots { width: 22px; height: 32px; font-size: 16px; }
  .pg-total { display: none; }

  /* Footer */
  .site-foot { border-radius: var(--radius-hand-sm); }
}

@media (max-width: 360px) {
  .app { padding: 8px 8px 20px; }
  .site-header { padding: 10px 13px; }
  .brand-name { font-size: 19px; }
  .brand-emblem { width: 34px; height: 34px; }

  .g-card { gap: 8px; padding: 9px 11px; }
  .g-title { font-size: 13px; }
  .g-thumb { width: 50px; height: 38px; }
  .g-rank { width: 28px; height: 28px; font-size: 14px; }
  .g-rank.top { font-size: 12px; }
  .g-plat { font-size: 12px; padding: 1px 6px; }
  .g-heat { font-size: 14px; }
  .g-heat svg { width: 12px; height: 12px; }

  .pg-num, .pg-btn { min-width: 28px; height: 28px; font-size: 14px; }
  .pg-num.active { font-size: 12px; }
  .pg-dots { width: 20px; height: 28px; font-size: 15px; }

  .chip { padding: 4px 9px; font-size: 14px; min-height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    /* Without this the stagger holds cards at opacity 0 for up to 400ms */
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
  /* Static tilt is also unwelcome for motion-sensitive users */
  .g-card, .g-card:hover { --rot: 0deg; rotate: 0deg; transform: none; }
  .site-header, .site-foot, .brand-emblem, .btn, .btn-theme, .g-thumb { transform: none; }
  .g-rank::after, .g-card:hover .g-rank::after { rotate: 0deg; }
  .chip { --chip-rot: 0deg; }
  .pg-num, .pg-btn { --pg-rot: 0deg; }
}
