/* OD-LAYOUT-PRIMITIVES v1 — structure only: display, flex/grid, overflow, wrapping, ratio, geometry.
   Put this @layer first; product CSS outside the layer wins ordinary layout rules.
   Native hidden and closed-dialog states take precedence over component display rules. */
@layer od-layout {
  [hidden]:not([hidden="until-found" i]) { display: none !important; }
  dialog:not([open]) { display: none !important; }

  :where(.od-stack,.od-row,.od-row-top,.od-cluster,.od-grid,.od-field,.od-stat,.od-cell,.od-tile) > :where(*) { min-width: 0; }

  /* containers */
  .od-stack   { display: flex; flex-direction: column; gap: var(--od-gap, 8px); }
  .od-row     { display: flex; align-items: center; gap: var(--od-gap, 8px); }
  .od-row-top { display: flex; align-items: flex-start; gap: var(--od-gap, 8px); }
  .od-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--od-gap, 8px); }
  .od-fill    { flex: 1 1 0; min-width: 0; }
  .od-fixed   { flex: none; }
  .od-grid    { display: grid; gap: var(--od-gap, 12px); grid-template-columns: repeat(var(--od-cols, 3), minmax(0, 1fr)); }

  /* stacked information: each piece is its own line — never sibling inline spans */
  .od-stat, .od-field, .od-cell { display: grid; gap: var(--od-gap, 2px); }
  :where(.od-stat,.od-field,.od-cell) > :where(*) { display: block; }
  .od-tile { display: grid; grid-template-rows: auto 1fr; }
  :where(.od-tile) > :where(*) { display: block; }

  /* media keeps its intrinsic ratio by default; never a distorted or cropped
     cover by accident. height:auto lets the ratio win over an <img height="…">
     attribute. Cropping to a uniform box is an explicit opt-in: set --od-ratio
     AND add .od-media-cover together (per the core rule, only where a crop is
     deliberate — tile thumbs, decorative fills — never on full-frame content). */
  .od-media { display: block; width: 100%; height: auto; aspect-ratio: var(--od-ratio, auto); }
  .od-media-cover { object-fit: cover; }

  /* functional inline SVG icons opt into bounded geometry; content SVGs keep their own */
  .od-icon { display: inline-block; inline-size: var(--od-icon-size, 1em); block-size: var(--od-icon-size, 1em); flex: none; }

  /* data text only — authored copy is rewritten to its budget instead */
  .od-truncate { display: block; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .od-clamp-2, .od-clamp-3 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
  .od-clamp-2 { -webkit-line-clamp: 2; }
  .od-clamp-3 { -webkit-line-clamp: 3; }
  .od-lines-2 { min-height: calc(2 * 1.4em); }   /* block-level reservation for a shared baseline */
  .od-nowrap  { white-space: nowrap; }           /* 数字+单位 · 价格+起 · 日期+星期 */
  .od-keep    { word-break: keep-all; overflow-wrap: anywhere; } /* CJK labels break at spaces / <wbr> first */

  /* screen skeleton (optional): bars take their own space, the middle scrolls — no padding guessed for chrome */
  .od-screen { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
  .od-scroll { overflow-y: auto; overscroll-behavior: contain; min-height: 0; }

  /* horizontal rail: the next item peeks at the edge; trailing room survives overflow */
  .od-rail { display: flex; gap: var(--od-gap, 8px); overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none;
             padding-inline: var(--od-rail-pad, 16px); scroll-padding-inline: var(--od-rail-pad, 16px); }
  .od-rail::-webkit-scrollbar { display: none; }
  :where(.od-rail) > :where(*) { flex: none; scroll-snap-align: start; }
  :where(.od-rail) > :where(:last-child) { margin-inline-end: var(--od-rail-pad, 16px); }

  .od-spacer { flex: none; visibility: hidden; pointer-events: none; }
  .od-touch  { min-width: 44px; min-height: 44px; }
}
:root [hidden]:where(:not([hidden="until-found" i])) { display: none; }
/* /OD-LAYOUT-PRIMITIVES v1 */

/* Visuals — dark editorial system. Work-specific visuals stay in works/. */
:root {
  color-scheme: dark;
  --bg: #0b0f16;
  --surface: #171d27;
  --surface-raised: #202835;
  --fg: #eff1f5;
  --muted: #a7afbd;
  --border: #2b3442;
  --accent: #e99b85;
  --accent-dark: #332b2b;
  --stage: #0b1019;
  --stage-2: #080c13;
  --stage-line: #253041;
  --ambient-dot: #c7d3ec;
  --ambient-meteor: #d8e2f5;
  --ambient-opacity: .78;
  --font-display: 'Iowan Old Style', 'Charter', 'Songti SC', 'STSong', Georgia, serif;
  --font-heading: 'Songti SC', 'STSong', 'Iowan Old Style', Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', ui-monospace, 'JetBrains Mono', Menlo, monospace;
  --type-xs: 12px;
  --type-sm: 14px;
  --type-body: 16px;
  --type-lead: 18px;
  --type-card: 28px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;
  --radius: 8px;
  --radius-small: 4px;
  --maxw: 1440px;
  --viewer-width: 1568px;
  --viewer-height: 920px;
  --viewer-inset: var(--space-8);
  --gutter: var(--space-12);
  --motion-fast: 180ms;
  --motion-base: 240ms;
  --motion-enter: 360ms;
  --ease-out: cubic-bezier(.2,.7,.2,1);
  --ease-in: cubic-bezier(.4,0,1,1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: var(--space-24); -webkit-font-smoothing: antialiased; }
body { margin: 0; background: var(--bg); color: var(--fg); font: var(--type-body)/1.6 var(--font-body); text-rendering: optimizeLegibility; isolation: isolate; }
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button, a { touch-action: manipulation; }
button:not(:disabled), a { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: var(--space-1); }
::selection { background: var(--accent); color: var(--bg); }
h1, h2, h3, p, dl, dd { margin: 0; }
.od-icon { --od-icon-size: 20px; vertical-align: middle; stroke-width: 1.5; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: 0; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.page-width { position: relative; z-index: 1; width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gutter); }

.ambient { position: fixed; inset: 0; z-index: 0; display: block; width: 100%; height: 100vh; height: 100dvh; pointer-events: none; opacity: var(--ambient-opacity); }
.masthead__inner { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-6); padding-block: var(--space-8) var(--space-5); border-bottom: 1px solid var(--border); }
.masthead__title { font: 600 clamp(36px,4vw,46px)/.95 var(--font-display); letter-spacing: -.015em; }
.masthead__title em { color: var(--accent); font-style: italic; }
.masthead__aside { display: flex; align-items: center; gap: var(--space-4); }
.masthead__tagline { color: var(--muted); font: var(--type-xs)/1.5 var(--font-mono); letter-spacing: .16em; white-space: nowrap; }
.ambient-toggle { display: grid; place-items: center; flex: none; width: 44px; height: 44px; padding: var(--space-3); border: 0; border-radius: var(--radius-small); background: transparent; color: var(--muted); }
.ambient-toggle__play, .ambient-toggle__pause { display: grid; place-items: center; }
.ambient-toggle .od-icon { --od-icon-size: 16px; }

/* Catalogue: filters and work, without introductory chrome. */
.collection { padding-block: var(--space-5) var(--space-12); scroll-margin-top: var(--space-6); }
.toolbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding-block: var(--space-3) var(--space-4); margin-bottom: var(--space-6); background: var(--bg); }
.filters { display: flex; flex-wrap: wrap; gap: var(--space-2); min-width: 0; }
.filter { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); flex: none; min-height: 44px; padding: var(--space-2) var(--space-4); border: 1px solid transparent; border-radius: var(--radius-small); background: transparent; color: var(--muted); font-size: var(--type-sm); white-space: nowrap; }
.filter[aria-pressed='true'] { border-color: var(--border); background: var(--surface-raised); color: var(--fg); }
.filter__label { display: block; }
.filter .count { display: block; color: var(--muted); font: var(--type-xs)/1 var(--font-mono); }
.filter[aria-pressed='true'] .count { color: var(--accent); }
.index-count { flex: none; color: var(--muted); font-size: var(--type-xs); letter-spacing: .02em; white-space: nowrap; }
.work-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); column-gap: var(--space-8); row-gap: var(--space-12); }
.work-card-item { min-width: 0; }
.work-card { position: relative; display: flex; flex-direction: column; width: 100%; min-width: 0; padding: 0; border: 0; border-radius: var(--radius); background: transparent; color: var(--fg); text-align: left; font: inherit; transition: transform var(--motion-base) var(--ease-out); }
.work-card:focus-visible { outline-offset: var(--space-2); }
.work-card__thumb { position: relative; display: block; width: 100%; aspect-ratio: 16/10; margin-bottom: var(--space-5); border-radius: var(--radius); background: var(--stage); overflow: clip; }
.work-card__art { position: absolute; inset: 0; display: block; }
.work-card__art > svg { display: block; }
.work-card__status { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--space-4); color: var(--muted); text-align: center; }
.work-card__retry { min-height: 44px; margin-top: var(--space-3); padding: var(--space-2) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-small); background: var(--surface); color: var(--fg); }
.work-card__retry[hidden] { display: none; }
.work-card__expand { position: absolute; top: var(--space-3); right: var(--space-3); display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid #586172; border-radius: 50%; background: var(--stage); color: var(--fg); opacity: 0; transform: translateY(var(--space-1)); transition: opacity var(--motion-fast) var(--ease-out), transform var(--motion-fast) var(--ease-out); }
.work-card__body { display: flex; flex: 1; flex-direction: column; width: 100%; min-width: 0; }
.work-card__meta { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); margin-bottom: var(--space-2); }
.work-card__cat { display: block; color: var(--accent); font-size: var(--type-xs); letter-spacing: .06em; }
.work-card__title { display: block; margin-bottom: var(--space-2); font: 500 var(--type-card)/1.25 var(--font-display); letter-spacing: -.02em; overflow-wrap: anywhere; text-wrap: pretty; }
.work-card__desc { color: var(--muted); font-size: var(--type-body); line-height: 1.65; }
.work-card:focus-visible .work-card__expand { opacity: 1; transform: none; }
.pagination { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); margin-top: var(--space-12); }
.pagination[hidden] { display: none; }
.pagination__button { min-width: 44px; min-height: 44px; padding: var(--space-2) var(--space-3); border: 1px solid transparent; border-radius: var(--radius-small); background: transparent; color: var(--muted); }
.pagination__button[aria-current='page'] { border-color: var(--border); background: var(--surface-raised); color: var(--fg); }
.pagination__button:disabled { opacity: .45; }
.pagination__ellipsis { display: inline-grid; place-items: center; min-width: 36px; min-height: 44px; color: var(--muted); }
.empty-state { padding: var(--space-20) var(--space-6); border: 1px solid var(--border); border-radius: var(--radius); text-align: center; }
.empty-state h2 { margin-bottom: var(--space-2); font-size: 20px; font-weight: 500; }
.empty-state p { color: var(--muted); }
.empty-state button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; margin-top: var(--space-6); padding: var(--space-2) var(--space-5); border: 1px solid var(--border); border-radius: var(--radius-small); background: var(--surface-raised); color: var(--fg); }

/* Detail viewer: work content and essential controls. */
body.detail-open { overflow: hidden; }
.detail-modal { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; width: 100%; height: 100vh; height: 100dvh; padding: var(--viewer-inset); }
.detail-modal.is-open { display: flex; }
.detail-modal__backdrop { position: absolute; inset: 0; background: #05080de8; animation: fade-in var(--motion-fast) var(--ease-out) both; }
.detail-modal__panel { position: relative; display: grid; grid-template-columns: minmax(0,1fr) 344px; grid-template-rows: minmax(0,1fr); width: min(var(--viewer-width),100%); height: min(var(--viewer-height),100%); min-width: 0; max-height: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: clip; animation: panel-in var(--motion-enter) var(--ease-out) both; }
.detail-modal__actions { display: flex; justify-content: flex-end; align-items: center; gap: var(--space-2); margin-top: auto; padding-top: var(--space-6); }
.detail-modal__actions[hidden] { display: none; }
.detail-modal__button { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); flex: none; min-width: 44px; min-height: 44px; padding: var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-small); background: var(--surface); color: var(--fg); }
.detail-modal__button:disabled { border-color: transparent; color: #788397; }
.detail-modal__close { position: absolute; top: max(calc(var(--viewer-inset) + var(--space-3)),calc((100% - var(--viewer-height))/2 + var(--space-3))); right: max(calc(var(--viewer-inset) + var(--space-3)),calc((100% - var(--viewer-width))/2 + var(--space-3))); z-index: 5; padding: var(--space-2); background: var(--surface-raised); }
.detail-modal__stage { position: relative; display: flex; min-width: 0; min-height: 0; background: var(--stage); }
.detail-modal__mount { position: relative; flex: 1; min-width: 0; min-height: 0; }
.detail-modal__mount.is-mounted { animation: fade-in var(--motion-base) var(--ease-out) both; }
.detail-modal__mount canvas { display: block; }
/* Reserve a consistent arrow gutter while keeping each work's native select. */
.detail-modal__mount select:not([multiple]):not([size]) {
  appearance: none;
  -webkit-appearance: none;
  padding-inline-end: 40px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 17px center, right 12px center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
@media (forced-colors: active) {
  .detail-modal__mount select:not([multiple]):not([size]) { appearance: auto; -webkit-appearance: auto; background-image: none; padding-inline-end: 12px; }
}
.detail-modal__info { display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: var(--space-8); padding: var(--space-16) var(--space-8) var(--space-8); border-left: 1px solid var(--border); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.detail-modal__copy { animation: copy-in var(--motion-base) var(--ease-out) both; }
.detail-modal__cat { display: block; margin-bottom: var(--space-3); color: var(--accent); font-size: var(--type-sm); letter-spacing: .08em; }
.detail-modal__title { font: 500 clamp(28px,3vw,40px)/1.2 var(--font-display); letter-spacing: -.02em; overflow-wrap: anywhere; }
.detail-modal__title:focus { outline: none; }
.detail-modal__desc { margin-top: var(--space-6); color: var(--muted); font-size: var(--type-body); line-height: 1.8; text-wrap: pretty; overflow-wrap: anywhere; }
.detail-modal__desc strong { color: var(--fg); font-weight: 500; }
.detail-modal__error { display: grid; align-content: center; justify-items: center; gap: var(--space-4); height: 100%; padding: var(--space-8); color: var(--muted); text-align: center; }
.detail-modal__error strong { color: var(--fg); font-size: var(--type-lead); font-weight: 500; }

/* Small interactions: animate geometry and opacity, keep all text readable. */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes panel-in { from { transform: translateY(12px) scale(.99); } to { transform: none; } }
@keyframes copy-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.work-card.will-reveal { opacity: 0; }
.work-card.will-reveal.is-visible { opacity: 1; animation: rise var(--motion-enter) var(--ease-out) backwards; animation-delay: var(--reveal-delay,0ms); }
.work-card.will-reveal:focus { opacity: 1; transform: none; }
@media (hover:hover) and (pointer:fine) {
  .ambient-toggle:hover { color: var(--accent); background: var(--surface); }
  .filter:hover { border-color: var(--border); background: var(--surface); color: var(--accent); }
  .filter[aria-pressed='true']:hover { background: var(--surface-raised); color: var(--fg); }
  .pagination__button:not(:disabled):hover, .work-card__retry:hover { border-color: var(--border); color: var(--accent); }
  .work-card:hover { transform: translateY(-4px); }
  .work-card:hover .work-card__expand { opacity: 1; transform: none; }
  .work-card:hover .work-card__action { color: var(--accent); }
  .work-card:hover .work-card__action .od-icon { transform: translate(3px,-3px); }
  .detail-modal__button:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
  .empty-state button:hover { border-color: var(--accent); color: var(--accent); }
}
@media (hover:none) { .work-card__expand { opacity: 1; transform: none; } }

@media (max-width:1200px) { .toolbar { flex-wrap: wrap; } .index-count { padding-inline: var(--space-1); } }
@media (max-width:1024px) {
  :root { --gutter: var(--space-8); }
  .work-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  :root { --viewer-inset: var(--space-4); }
  .detail-modal__panel { display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; }
  .detail-modal__stage { flex: none; min-height: 420px; height: 58vh; height: 58dvh; }
  .detail-modal__info { flex: none; overflow-y: visible; border-top: 1px solid var(--border); border-left: 0; padding: var(--space-8); }
  .detail-modal__desc { max-width: 70ch; }
}
@media (max-width:768px) {
  :root { --gutter: var(--space-6); }
  .collection { padding-bottom: var(--space-16); }
  .toolbar { display: grid; grid-template-columns: minmax(0,1fr); gap: var(--space-2); padding-block: var(--space-2) var(--space-4); margin-bottom: var(--space-6); }
  .filters { flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: none; padding: var(--space-1); scroll-padding-inline: var(--space-1); }
  .filters::-webkit-scrollbar { display: none; }
  .index-count { justify-self: end; }
  .work-grid { column-gap: var(--space-6); row-gap: var(--space-10); }
  .work-card__title { font-size: 24px; }
  .work-card__desc { font-size: var(--type-body); }
  .detail-modal__stage { min-height: 360px; }
}
@media (max-width:560px) {
  :root { --gutter: var(--space-5); }
  .masthead__inner { padding-block: var(--space-6) var(--space-4); }
  .masthead__tagline { display: none; }
  .work-grid { grid-template-columns: minmax(0,1fr); }
  .work-card__title { font-size: var(--type-card); }
  .work-card__thumb { margin-bottom: var(--space-4); }
  :root { --viewer-inset: var(--space-2); }
  .detail-modal__actions { gap: var(--space-2); }
  .detail-modal__stage { min-height: 360px; height: 56vh; height: 56dvh; }
  .detail-modal__info { gap: var(--space-6); padding: var(--space-8) var(--space-6); }
}
@media (max-width:375px) {
  :root { --gutter: var(--space-4); }
}
@media (prefers-reduced-motion:reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .work-card.will-reveal { opacity: 1; transform: none; }
}
