:root {
  color-scheme: dark;
  --bg: #0f1114; --strip: #15171c; --panel: #1a1d23; --inset: #111317; --line: #ffffff1a; --line-strong: #ffffff38;
  --text: #fff; --text-2: #ffffffc2; --text-3: #ffffff8f;
  --sans: Inter, "SF Pro Text", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --round: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", var(--sans);
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  --gutter: clamp(16px, 4vw, 56px);
  font-family: var(--sans); font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; scrollbar-color: #ffffff40 transparent;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; }
a { color: inherit; text-decoration: none; }
p, h1, h2, h3 { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; transition: background-color .15s, border-color .15s, color .15s; }
button:disabled { cursor: not-allowed; opacity: .45; }
:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
[hidden] { display: none !important; }
/* Canvas text must rasterize exactly like the exported standalone HTML. */
canvas { -webkit-font-smoothing: auto; }

/* Page chrome */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px var(--gutter); background: var(--strip); border-bottom: 1px solid var(--line); }
.wordmark { display: flex; align-items: center; gap: 10px; font: 700 18px var(--round); letter-spacing: -.01em; }
.brand-mark { width: 22px; height: 22px; fill: currentColor; }
.box-button { display: grid; place-items: center; height: 36px; padding: 0 16px; font-size: 13px; background: #ffffff0d; border: 1px solid var(--line); border-radius: 9px; }
.box-button:hover { background: #ffffff1c; }
.text-button { background: none; border: 0; color: var(--text-2); padding: 6px 0; font-size: 13px; }
.text-button:hover { color: var(--text); }
main { max-width: calc(1480px + 2 * var(--gutter)); padding: 0 var(--gutter); margin: auto; }
.tools { display: flex; gap: 8px; align-items: center; min-width: 0; }
.result-count { margin-right: 6px; font: 11px var(--mono); letter-spacing: .08em; color: var(--text-3); white-space: nowrap; }
.search { display: flex; align-items: center; gap: 8px; height: 36px; min-width: 0; padding: 0 10px 0 12px; background: var(--inset); border: 1px solid var(--line); border-radius: 9px; }
.search:focus-within { border-color: var(--line-strong); }
.search svg { width: 14px; height: 14px; fill: none; stroke: var(--text-3); stroke-width: 1.5; stroke-linecap: round; flex-shrink: 0; }
.search input { width: 170px; min-width: 0; background: none; border: 0; outline: 0; font-size: 13px; }
.search input::placeholder { color: var(--text-3); }
.search kbd { font: 11px var(--mono); color: var(--text-3); border: 1px solid var(--line-strong); border-radius: 5px; padding: 1px 6px; }
.icon-button { display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0; background: #ffffff0d; border: 1px solid var(--line); border-radius: 9px; color: var(--text-2); }
.icon-button:hover { background: #ffffff1c; color: var(--text); }
.icon-button::before { content: ""; width: 12px; height: 12px; background: currentColor; }
.icon-button[data-icon=play]::before { clip-path: polygon(18% 4%, 96% 50%, 18% 96%); }
.icon-button[data-icon=pause]::before { clip-path: polygon(12% 4%, 38% 4%, 38% 96%, 12% 96%, 12% 4%, 62% 4%, 62% 96%, 88% 96%, 88% 4%, 62% 4%); }
.icon-button[data-icon=close]::before { clip-path: polygon(14% 4%, 50% 40%, 86% 4%, 96% 14%, 60% 50%, 96% 86%, 86% 96%, 50% 60%, 14% 96%, 4% 86%, 40% 50%, 4% 14%); }
/* The legend under the table doubles as the series filter. */
.families { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 28px; }
.family { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 13px 0 11px; border: 1px solid var(--line); border-radius: 17px; background: none; color: var(--text-2); font-size: 13px; white-space: nowrap; }
.family i { width: 12px; height: 12px; border-radius: 4px; background: var(--fill); }
.family small { font: 11px var(--mono); color: var(--text-3); }
.family:hover { color: var(--text); background: #ffffff0d; }
.family[aria-pressed=true] { border-color: var(--line-strong); background: #ffffff1c; color: var(--text); }

/*
 * Periodic table. Columns are bottom-aligned and run through the hue wheel left to right; each series is named once
 * above its tallest column, and the title sits in the gap above the short middle columns.
 */
.periodic-table { display: grid; grid-template-columns: repeat(var(--columns, 18), minmax(0, 1fr)); gap: 3px; margin-top: 10px; }
.series-label { grid-column: var(--column); grid-row: var(--row); align-self: end; padding: 14px 0 6px 2px; font-size: 11px; line-height: 1.2; color: var(--text-2); white-space: nowrap; pointer-events: none; }
.element { grid-column: var(--column); grid-row: calc(var(--row) + 1); position: relative; aspect-ratio: 3 / 4; container-type: inline-size; min-width: 0; padding: 0; overflow: hidden; text-align: left; color: #fff; background: var(--fill); border: 0; border-radius: 7px; transition: scale .12s, box-shadow .12s; }
.element:hover, .element:focus-visible { z-index: 2; scale: 1.08; box-shadow: 0 0 0 2px #fff, 0 10px 24px #0009; outline: 0; }
/* The 8:5 scene is cropped to its middle and nudged down, leaving the top of the cell for the symbol. */
.zoom { position: absolute; inset: 0; overflow: hidden; }
.zoom canvas { position: absolute; left: 50%; top: 5%; height: 100%; aspect-ratio: 8 / 5; translate: -50% 0; }
.element-symbol, .element-number, .element-name { position: absolute; }
.element-symbol { left: 8cqw; top: 7cqw; font: 700 clamp(13px, 25cqw, 30px)/1 var(--round); letter-spacing: -.02em; }
.element-number { right: 8cqw; top: 8cqw; font: clamp(8px, 11.5cqw, 13px)/1 var(--mono); opacity: .75; }
.element-name { left: 8cqw; right: 4cqw; bottom: 7cqw; overflow: hidden; font-size: clamp(10px, 13.5cqw, 15px); font-weight: 500; line-height: 1.2; white-space: nowrap; }
.table-title { grid-row: 2 / 4; grid-column: var(--title-columns, 1 / -1); display: grid; place-items: center; text-align: center; }
h1 { font: 700 clamp(34px, 5vw, 72px)/1.1 var(--sans); letter-spacing: .08em; text-indent: .08em; }
h1 span { display: block; margin-top: 16px; font: 12px var(--mono); letter-spacing: .36em; text-indent: .36em; text-transform: uppercase; color: var(--text-3); }
.table-hint { grid-row: 4; grid-column: var(--hint-columns, 1 / -1); align-self: start; padding: 4px 12px 0; text-align: center; text-wrap: balance; font-size: 13px; line-height: 1.55; color: var(--text-2); }
.periodic-table.filtered { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.periodic-table.filtered .element { grid-column: auto; grid-row: auto; }
.periodic-table.filtered .table-title, .periodic-table.filtered .table-hint { grid-column: 1 / -1; grid-row: auto; }
.periodic-table.filtered .table-title { padding: 24px 0 4px; }
.periodic-table.filtered .table-hint { padding-bottom: 20px; }
.page-status { color: var(--text-3); font-size: 13px; margin-top: 16px; text-align: center; }
.page-status:empty { display: none; }
.empty { text-align: center; padding: 56px 20px; color: var(--text-2); font-size: 14px; }
footer { display: flex; justify-content: space-between; gap: 24px; margin-top: 36px; padding: 20px 0 32px; border-top: 1px solid var(--line); color: var(--text-3); font-size: 13px; }

/* Detail dialog */
dialog { width: min(1080px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); padding: 0; overflow: auto; color: var(--text); background: var(--panel); border: 1px solid var(--line-strong); border-radius: 16px; box-shadow: 0 32px 96px #000c; scrollbar-width: thin; }
dialog::backdrop { background: #07080ad9; }
.detail-header { display: flex; align-items: center; gap: 16px; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.detail-symbol { display: grid; place-items: center; flex-shrink: 0; width: 54px; height: 54px; font: 700 24px/1 var(--round); letter-spacing: -.02em; background: var(--fill); border-radius: 12px; }
.detail-identity { flex: 1; min-width: 0; }
.detail-identity h2 { font-size: 22px; font-weight: 700; letter-spacing: .02em; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 2px; font-size: 12px; color: var(--text-2); }
#recipe-id { font-family: var(--mono); color: var(--text-3); }
.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.preview-panel { padding: 24px; min-width: 0; }
#canvas { display: block; width: 100%; height: auto; aspect-ratio: 8 / 5; border-radius: 12px; }
.transport { display: flex; align-items: center; gap: 14px; padding-top: 16px; }
.transport .icon-button { border-radius: 50%; }
.transport input { flex: 1; min-width: 10px; }
.transport span { min-width: 70px; text-align: right; color: var(--text-2); font: 12px var(--mono); white-space: nowrap; }
.recipe-description { margin-top: 14px; color: var(--text-2); font-size: 14px; line-height: 1.7; }
.controls { display: flex; flex-direction: column; padding: 24px; border-left: 1px solid var(--line); }
.controls-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.controls-heading h3 { font-size: 15px; font-weight: 600; letter-spacing: .08em; }
.parameter { margin-bottom: 20px; }
.parameter label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 13px; }
.parameter output { font: 12px var(--mono); color: var(--text-2); }
input[type=range] { --fill-to: 0%; appearance: none; -webkit-appearance: none; display: block; width: 100%; height: 20px; margin: 0; background: none; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, #fff var(--fill-to), var(--line-strong) var(--fill-to)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px var(--fill, var(--panel)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-strong); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: #fff; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: #fff; }
.field { display: block; font-size: 12px; color: var(--text-2); }
.parameter select, .field textarea, .field input { display: block; width: 100%; padding: 8px 10px; font-size: 13px; color: var(--text); background: var(--inset); border: 1px solid var(--line-strong); border-radius: 8px; }
.parameter select { appearance: none; padding-right: 30px; background: var(--inset) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='m3 4.5 3 3 3-3' fill='none' stroke='%23ffffff' stroke-width='1.5'/%3E%3C/svg%3E") right 10px center / 12px no-repeat; }
.field textarea, .field input { margin-top: 6px; }
.field textarea { resize: vertical; line-height: 1.6; margin-bottom: 16px; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.backend-state { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 24px; font-size: 12px; }
.backend-state span { padding: 3px 10px; border: 1px solid var(--line-strong); border-radius: 12px; color: var(--text-2); }
.backend-state .backend-ready { color: #fff; border-color: #fff; }
.code-panel { padding: 16px 24px 20px; border-top: 1px solid var(--line); }
.code-heading { display: flex; align-items: center; gap: 16px; }
.code-tabs { display: flex; flex-shrink: 0; padding: 3px; background: var(--inset); border: 1px solid var(--line); border-radius: 10px; }
.code-tabs button { padding: 6px 12px; background: none; border: 0; border-radius: 7px; color: var(--text-2); font: 12px var(--mono); white-space: nowrap; }
.code-tabs button:hover { color: var(--text); }
.code-tabs button[aria-selected=true] { background: #fff; color: #15171c; }
#code-note { font-size: 12px; line-height: 1.5; color: var(--text-3); }
#scene-source { max-height: 180px; margin: 12px 0 14px; padding: 14px 16px; overflow: auto; white-space: pre; font: 12px/1.65 var(--mono); color: var(--text-2); background: var(--inset); border: 1px solid var(--line); border-radius: 10px; scrollbar-width: thin; }
.code-actions { display: flex; align-items: center; gap: 10px; }
.status { flex: 1; min-width: 0; font-size: 12px; line-height: 1.5; color: var(--text-2); }
.status.error, .page-status.error { color: #ffb4a6; }
.primary, .secondary { height: 38px; padding: 0 18px; flex-shrink: 0; font-size: 13px; font-weight: 600; white-space: nowrap; border-radius: 9px; }
.primary { background: #fff; border: 1px solid #fff; color: #15171c; }
.primary:hover:enabled { background: #ffffffd9; }
.secondary { background: #ffffff0d; border: 1px solid var(--line-strong); color: var(--text); }
.secondary:hover:enabled { background: #ffffff1c; }
#about { width: min(560px, calc(100vw - 32px)); }
.about-content { padding: 32px; }
.about-content > button { float: right; }
.eyebrow { font: 11px var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--text-3); margin-bottom: 12px; }
.about-content h2 { font-size: 22px; font-weight: 700; margin-bottom: 16px; }
.about-content > p:not(.eyebrow) { color: var(--text-2); line-height: 1.8; margin-top: 10px; }

@media (max-width: 1100px) {
  .series-label { display: none; }
  .periodic-table { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .element { grid-column: auto; grid-row: auto; }
  .table-title, .table-hint { grid-column: 1 / -1; grid-row: auto; }
  .table-title { padding: 24px 0 4px; }
  .table-hint { padding-bottom: 20px; }
  .detail-layout { grid-template-columns: minmax(0, 1fr) 280px; }
}
@media (max-width: 680px) {
  .search kbd, .result-count, #recipe-id { display: none; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .periodic-table { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  footer { flex-direction: column; gap: 6px; margin-top: 32px; }
  dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .detail-header { padding: 12px 16px; gap: 12px; }
  .detail-layout { grid-template-columns: minmax(0, 1fr); }
  .preview-panel, .controls { padding: 16px; }
  .controls { border-left: 0; border-top: 1px solid var(--line); }
  .code-panel { padding: 14px 16px 16px; }
  .code-heading { flex-direction: column; align-items: flex-start; gap: 10px; }
  .code-actions { flex-wrap: wrap; justify-content: flex-end; }
  .status { flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  button, .element { transition: none; }
  .element:hover, .element:focus-visible { scale: none; }
}
