/* =========================================================
   CSS Animation Demo — gallery layout (card grid)
   Design: dark technical playground + bento-style cells
   ========================================================= */

/* System fonts only — works offline / file:// without network */
:root {
  --bg: #09090b;
  --bg-elevated: #0c0c0f;
  --surface: #141418;
  --surface-hover: #1a1a20;
  --surface-2: #1c1c22;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #fafafa;
  --muted: #a1a1aa;
  --muted-2: #797982;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --accent-2: #a78bfa;
  --pill-bg: rgba(56, 189, 248, 0.12);
  --preview-bg: #050507;
  --demo: #38bdf8;
  --demo-alt: #f0a060;
  --radius: 16px;
  --radius-sm: 12px;
  --grid-gap: 12px;
  --card-min: 168px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC",
    "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --header-h: auto;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html {
  color-scheme: dark;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(900px 480px at 12% -8%, rgba(56, 189, 248, 0.09), transparent 55%),
    radial-gradient(700px 420px at 92% 0%, rgba(167, 139, 250, 0.08), transparent 50%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

/* ----- sticky shell ----- */
.page-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
}

@media (min-width: 768px) {
  .page-shell {
    padding: 0 1.5rem 4rem;
  }
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  margin: 0 -1rem;
  padding: 0.85rem 1rem 0.75rem;
  background: rgba(9, 9, 11, 0.82);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid var(--border);
}

@media (min-width: 768px) {
  .top-bar {
    margin: 0 -1.5rem;
    padding: 1rem 1.5rem 0.85rem;
  }
}

.top-bar-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.brand-row {
  display: flex;
  align-items: center;
}

.brand-row h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2.2vw, 1.45rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.search-wrap {
  flex: 1 1 220px;
  position: relative;
  min-width: 0;
}

.search-wrap .search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted-2);
  pointer-events: none;
}

#search-input {
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.9rem 0.65rem 2.45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
  outline: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease),
    background 0.2s var(--ease);
}

#search-input::placeholder {
  color: var(--muted-2);
}

#search-input:hover {
  border-color: var(--border-strong);
}

#search-input:focus {
  border-color: rgba(56, 189, 248, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface-2);
}

#category-filter {
  min-height: 44px;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  min-width: 9.5rem;
  transition: border-color 0.2s var(--ease);
}

#category-filter:hover,
#category-filter:focus {
  border-color: var(--border-strong);
  outline: none;
}

#category-filter:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-bottom: 0.15rem;
}

.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  min-height: 38px;
  transition: background 0.18s var(--ease), color 0.18s var(--ease),
    border-color 0.18s var(--ease);
}

.chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface);
}

.chip.is-active {
  color: #0c4a6e;
  background: var(--accent);
  border-color: transparent;
  font-weight: 600;
}

.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ----- main gallery ----- */
main {
  padding-top: 1.25rem;
}

.demo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr));
  gap: var(--grid-gap);
  list-style: none;
  margin: 0;
  padding: 0;
}

/* full-width category band when browsing 全部 */
.grid-section {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  margin: 0.35rem 0 0.1rem;
  padding: 0.85rem 0.15rem 0.2rem;
  border-bottom: 1px solid var(--border);
}

.grid-section:first-child {
  padding-top: 0.15rem;
  margin-top: 0;
}

.grid-section-title {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
}

.grid-section-count {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted-2);
}

@media (min-width: 640px) {
  :root {
    --card-min: 176px;
    --grid-gap: 14px;
  }
}

@media (min-width: 1024px) {
  :root {
    --card-min: 188px;
    --grid-gap: 16px;
  }
}

/* one cell = one animation */
.demo-card {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.22s var(--ease), border-color 0.22s var(--ease),
    background 0.22s var(--ease), box-shadow 0.22s var(--ease);
}

.demo-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  background: var(--surface-hover);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 14px 32px rgba(0, 0, 0, 0.4);
}

.demo-card:focus-within {
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* preview fills the cell — motion-readable stage */
.preview-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(56, 189, 248, 0.1), transparent 55%),
    var(--preview-bg);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  /* motion guide: cross + grid so travel distance is obvious */
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(56, 189, 248, 0.12), transparent 55%),
    linear-gradient(to right, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(
      to right,
      transparent calc(50% - 0.5px),
      rgba(56, 189, 248, 0.22) calc(50% - 0.5px),
      rgba(56, 189, 248, 0.22) calc(50% + 0.5px),
      transparent calc(50% + 0.5px)
    ),
    linear-gradient(
      to bottom,
      transparent calc(50% - 0.5px),
      rgba(56, 189, 248, 0.22) calc(50% - 0.5px),
      rgba(56, 189, 248, 0.22) calc(50% + 0.5px),
      transparent calc(50% + 0.5px)
    ),
    var(--preview-bg);
  background-size:
    auto,
    auto,
    24px 24px,
    24px 24px,
    auto,
    auto,
    auto;
}

.preview-stage::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  pointer-events: none;
  z-index: 0;
}

.preview-stage > * {
  position: relative;
  z-index: 1;
}

.preview-stage--wide {
  /* keep same cell; typewriter still fits */
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.7rem 0.75rem 0.8rem;
  flex: 1;
  min-width: 0;
}

.demo-name {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.demo-name-zh {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-top: 0.25rem;
  min-width: 0;
}

.cat-pill {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.chip-toggle.is-active {
  color: #0c4a6e;
  background: var(--accent);
  border-color: transparent;
  font-weight: 600;
}

.demo-card.is-variant {
  border-style: dashed;
  opacity: 0.96;
}

/* Plain-language family expand — not a +N badge */
.family-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  width: 100%;
  margin-top: 0.45rem;
  min-height: 44px;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--accent);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease),
    color 0.15s var(--ease);
}

.family-link:hover {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--text);
}

.family-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.family-link[aria-expanded='true'] {
  border-color: rgba(56, 189, 248, 0.4);
  background: var(--accent-soft);
}

.family-link-text {
  min-width: 0;
}

.family-link-chevron {
  flex-shrink: 0;
  opacity: 0.75;
  font-size: 0.65rem;
}

.family-hint {
  margin: 0.4rem 0 0;
  padding: 0;
  font-size: 0.68rem;
  color: var(--muted-2);
  line-height: 1.35;
}

.card-class {
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--muted-2);
  background: transparent;
  padding: 0;
  border: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

.demo-box {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: linear-gradient(145deg, #7dd3fc 0%, #38bdf8 40%, #a78bfa 100%);
  color: #0c0c0f;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform, opacity, filter;
  transform-origin: center center;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.18),
    0 10px 28px rgba(56, 189, 248, 0.45),
    0 0 36px rgba(167, 139, 250, 0.35);
}

/* empty */
#empty-state {
  text-align: center;
  padding: 3.5rem 1.25rem;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

#empty-state[hidden] {
  display: none;
}

#empty-state p {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
  font-weight: 500;
}

/* reduce motion for chrome only; demos still teach motion but slower when PRM */
@media (prefers-reduced-motion: reduce) {
  .demo-card {
    transition: none;
  }
  .demo-card:hover {
    transform: none;
  }
  html {
    scroll-behavior: auto;
  }
}
