:root {
  color-scheme: light;
  --paper: #f3eee5;
  --ink: #1c1b19;
  --muted: #77736b;
  --rule: #d9d2c4;
  --accent: #c2410c;
  --tile: var(--paper);
  --checker: repeating-conic-gradient(#e3ddd2 0 25%, #f7f3ec 0 50%) 0 0 / 16px 16px;
}
body[data-bg="white"] { --tile: #ffffff; }
body[data-bg="black"] { --tile: #0d0d0e; }
body[data-bg="none"] { --tile: var(--checker); }

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Yu Gothic UI', system-ui, sans-serif;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: fixed; top: -100px; left: 1rem; background: var(--paper); padding: 1rem; z-index: 20; }
.skip-link:focus { top: 1rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.masthead, main, footer { width: min(1280px, calc(100% - 96px)); margin: auto; }
.masthead { padding: 28px 0 0; }
.home-link { font-size: 15px; letter-spacing: .03em; text-decoration: none; }

/* --- intro ------------------------------------------------------------- */
.intro { padding: 44px 0 28px; max-width: 760px; }
h1 { font-size: clamp(36px, 5vw, 60px); line-height: 1; letter-spacing: -.04em; font-weight: 600; margin: 0 0 20px; }
h1 span { display: block; font-size: .36em; letter-spacing: .02em; font-weight: 500; color: var(--muted); margin-top: 12px; }
.lede { font-size: 16px; line-height: 1.7; margin: 0 0 26px; color: #3b3935; }
.loader { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 14px; }
.hint { font-size: 13px; color: var(--muted); }
.status { min-height: 1.4em; font-size: 13px; color: var(--muted); margin: 12px 0 0; }
.status.error { color: #b91c1c; }

.pill {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 44px; padding: 0 20px; border-radius: 999px;
  border: 1px solid var(--ink); background: transparent; cursor: pointer;
  font-size: 14px; font-weight: 500; white-space: nowrap;
}
.pill:hover { background: rgba(0, 0, 0, .05); }
.pill.primary { background: var(--ink); color: var(--paper); }
.pill.primary:hover { background: #000; }
.pill:disabled { opacity: .5; cursor: default; }
label.pill:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }

.backgrounds { border: 0; padding: 0; margin: 18px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: 13px; }
.backgrounds legend { float: left; margin-right: 6px; color: var(--muted); padding: 0; }
.backgrounds label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; min-height: 32px; }
.backgrounds input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatch { width: 18px; height: 18px; border-radius: 50%; border: 1px solid #b9b2a4; }
.swatch-paper { background: #f3eee5; }
.swatch-white { background: #fff; }
.swatch-black { background: #0d0d0e; }
.swatch-none { background: var(--checker); background-size: 8px 8px; }
.backgrounds input:checked + .swatch { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3.5px var(--ink); }
.backgrounds input:focus-visible + .swatch { outline: 2px solid var(--accent); outline-offset: 4px; }

/* --- gallery ----------------------------------------------------------- */
.group-nav { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; overflow-x: auto; padding: 12px 0; background: var(--paper); border-bottom: 1px solid var(--rule); scrollbar-width: none; }
.group-nav a { flex: none; text-decoration: none; font-size: 13px; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--rule); }
.group-nav a:hover { border-color: var(--ink); }
.group-nav a span { color: var(--muted); margin-left: 6px; font-size: 12px; }

.group { padding: 36px 0 8px; scroll-margin-top: 64px; }
.group h2 { font-size: 13px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; margin: 0 0 22px; display: flex; gap: 12px; align-items: baseline; }
.group h2 span { font-size: 13px; letter-spacing: .04em; font-weight: 500; color: var(--muted); text-transform: none; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 34px 26px; }

.card { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; text-align: center; }
.thumb { position: relative; display: block; aspect-ratio: 4 / 3; background: var(--tile); border-radius: 6px; overflow: hidden; transition: transform .2s ease, box-shadow .2s ease; }
body[data-bg="paper"] .thumb { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .04); }
.card:hover .thumb { transform: translateY(-3px); box-shadow: 0 10px 24px -14px rgba(40, 30, 10, .45); }
.thumb canvas { position: absolute; inset: 6%; width: 88%; height: 88%; object-fit: contain; opacity: 0; transition: opacity .25s ease; }
.card[data-state="done"] .thumb canvas { opacity: 1; }
.card[data-state="pending"] .thumb::after, .card[data-state="running"] .thumb::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px;
  border-radius: 50%; border: 2px solid var(--rule); border-top-color: var(--muted);
}
.card[data-state="running"] .thumb::after { animation: spin .8s linear infinite; }
.card[data-state="error"] .thumb::after { content: 'Could not render'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: #b91c1c; }
.badge { position: absolute; top: 8px; right: 8px; font-size: 10px; font-weight: 600; letter-spacing: .08em; padding: 3px 7px; border-radius: 999px; background: var(--ink); color: var(--paper); }
.card .en { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }

footer { border-top: 1px solid var(--rule); display: flex; justify-content: space-between; gap: 16px; padding: 26px 0 40px; margin-top: 48px; color: var(--muted); font-size: 12px; }
footer a { text-decoration: none; }
footer a span { color: var(--ink); }

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

/* --- detail dialog ------------------------------------------------------ */
dialog { padding: 0; border: 0; margin: 0; width: 100%; height: 100%; max-width: none; max-height: none; background: var(--paper); color: var(--ink); }
dialog::backdrop { background: rgba(28, 27, 25, .4); }
body:has(dialog[open]) { overflow: hidden; }
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 360px; height: 100%; }
.stage { position: relative; background: var(--tile); margin: 16px 0 16px 16px; border-radius: 8px; overflow: hidden; }
.stage[data-drag="orbit"], .stage[data-drag="point"] { touch-action: none; }
.stage canvas { position: absolute; inset: 24px; width: calc(100% - 48px); height: calc(100% - 48px); object-fit: contain; }
.stage[data-drag="orbit"] { cursor: grab; }
.stage[data-drag="orbit"].dragging { cursor: grabbing; }
.stage[data-drag="point"] { cursor: crosshair; }
.stage-note { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); margin: 0; font-size: 13px; color: #b91c1c; background: var(--paper); padding: 10px 14px; border-radius: 6px; max-width: 80%; }
.busy { position: absolute; right: 16px; bottom: 16px; width: 22px; height: 22px; opacity: 0; transition: opacity .15s; pointer-events: none; }
.busy span { display: block; width: 100%; height: 100%; border-radius: 50%; border: 2px solid rgba(120, 110, 95, .35); border-top-color: var(--ink); animation: spin .8s linear infinite; }
.stage.busy-on .busy { opacity: 1; }

.panel { padding: 18px 24px 24px; overflow-y: auto; display: flex; flex-direction: column; }
.panel-top { display: flex; gap: 6px; justify-content: flex-end; }
.icon { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--rule); background: none; cursor: pointer; font-size: 17px; line-height: 1; }
.icon:hover { border-color: var(--ink); }
.icon.close { font-size: 22px; margin-left: 6px; }
.panel-group { margin: 14px 0 6px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.panel h2 { margin: 0 0 18px; }
.panel h2 .en { display: block; font-size: 14px; font-weight: 400; color: var(--muted); margin-top: 4px; }
.drag-hint { font-size: 12px; color: var(--muted); margin: -8px 0 16px; }

.controls { display: grid; gap: 16px; padding: 18px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.ctl { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px 10px; font-size: 13px; }
.ctl label { font-weight: 500; }
.ctl output { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.ctl input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--ink); margin: 0; height: 22px; }
.ctl select { grid-column: 2; min-height: 34px; border: 1px solid var(--rule); border-radius: 6px; background: #fbf9f5; padding: 0 8px; }
.ctl input[type="color"] { width: 44px; height: 30px; border: 1px solid var(--rule); border-radius: 6px; padding: 2px; background: #fbf9f5; }
.ctl input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--ink); }
.ctl .seed { display: flex; gap: 6px; align-items: center; }
.ctl .seed input { width: 72px; min-height: 32px; border: 1px solid var(--rule); border-radius: 6px; padding: 0 8px; background: #fbf9f5; }
.ctl .seed button { min-height: 32px; border: 1px solid var(--rule); border-radius: 6px; background: none; cursor: pointer; padding: 0 10px; }

.actions { display: flex; gap: 10px; margin: 18px 0 14px; }
.actions .pill { flex: 1; min-height: 40px; padding: 0 12px; font-size: 13px; }
.export { display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; font-size: 13px; margin-top: auto; padding-top: 6px; }
.export select { min-height: 36px; border: 1px solid var(--rule); border-radius: 6px; background: #fbf9f5; padding: 0 8px; }
.export .pill { grid-column: 1 / -1; }

.drop-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(243, 238, 229, .86); border: 3px dashed var(--ink); font-size: 22px; font-weight: 600; pointer-events: none; }

@media (min-width: 1500px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (max-width: 1000px) {
  .masthead, main, footer { width: calc(100% - 56px); }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .detail { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (max-width: 720px) {
  .masthead, main, footer { width: calc(100% - 32px); }
  .intro { padding: 28px 0 18px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 12px; }
  footer { flex-direction: column; }
  .detail { display: flex; flex-direction: column; height: auto; min-height: 100%; }
  .stage { flex: none; height: 58dvh; margin: 10px 10px 0; }
  .stage canvas { inset: 10px; width: calc(100% - 20px); height: calc(100% - 20px); }
  .panel { overflow: visible; padding: 10px 16px 28px; }
  dialog { overflow-y: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: 2s !important; }
}
