:root { --gutter: 24px; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body { margin: 0; background: var(--background); color: var(--foreground); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.sr-only:focus { position: fixed; top: 8px; left: 8px; z-index: 50; width: auto; height: auto; padding: 8px 12px; clip-path: none; border-radius: var(--radius-md); background: var(--card); }
svg.lu { display: block; width: 16px; height: 16px; }
a.oc-btn { text-decoration: none; }

.topbar { position: sticky; top: 0; z-index: 30; height: 56px; box-sizing: border-box; border-bottom: 1px solid var(--border); background: var(--frost); -webkit-backdrop-filter: blur(var(--blur-md)) saturate(var(--frost-saturate)); backdrop-filter: blur(var(--blur-md)) saturate(var(--frost-saturate)); }
.topbar-in { display: flex; align-items: center; gap: 6px; height: 100%; padding: 0 var(--gutter); }
.brand { margin-right: auto; color: var(--foreground); font: 500 var(--text-body)/1 var(--font-sans); letter-spacing: -0.01em; text-decoration: none; }
.tb-li svg, .theme-btn svg { width: 16px; height: 16px; }
.theme-btn .moon { display: none; }
[data-theme="dark"] .theme-btn .moon { display: block; }
[data-theme="dark"] .theme-btn .sun { display: none; }

.home { padding: 0 var(--gutter) var(--space-8); }
.hero { display: flex; flex-direction: column; align-items: center; padding: 64px 0 40px; text-align: center; }
.hero-pill { display: inline-flex; align-items: center; gap: var(--space-2); height: 28px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-full); background: var(--card); color: var(--foreground); font: 500 var(--text-small)/1 var(--font-sans); text-decoration: none; box-shadow: var(--shadow-xs); transition: border-color var(--duration-fast) var(--ease-out); }
.hero-pill:hover { border-color: var(--border-strong); }
.hero-pill .dot { width: 6px; height: 6px; border-radius: var(--radius-full); background: var(--tint, #f62134); }
.hero-pill svg { width: 14px; height: 14px; }
.hero h1 { max-width: 920px; margin: 20px 0 0; color: var(--foreground); font: 400 var(--text-display)/var(--leading-display) var(--font-sans); letter-spacing: var(--tracking-display); text-wrap: balance; }
.hero p { max-width: 640px; margin: 16px 0 0; color: var(--muted-foreground); font: 400 var(--text-body-lg)/var(--leading-body-lg) var(--font-sans); text-wrap: pretty; }
.hero-hl { padding: 1px 4px; margin: 0 -2px; border-radius: var(--radius-xs); color: var(--foreground); background: color-mix(in srgb, var(--tint, #f62134) 22%, transparent); }
.hero-cta { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); margin-top: 28px; }
.hero-browse svg { width: 16px; height: 16px; }

.tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--space-2) var(--space-6); max-width: 1440px; margin: 0 auto var(--space-4); }
.tool { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--space-2); }
.tool-label { color: var(--muted-foreground); font: 500 12px/1 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; }
.oc-tabs { background: var(--fill-on-subtle); }
.oc-tabs button { height: 28px; padding: 0 10px; font: 500 var(--text-small)/1 var(--font-sans); white-space: nowrap; }

.hex { display: inline-flex; align-items: center; gap: 6px; height: 34px; box-sizing: border-box; padding: 0 8px 0 6px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--card); transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out); }
.hex:focus-within { border-color: var(--ring); box-shadow: var(--focus-ring); }
.hex[data-bad] { border-color: var(--destructive, #d33); }
.hex input[type="color"] { flex: none; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 5px; background: none; cursor: pointer; }
.hex input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.hex input[type="color"]::-webkit-color-swatch { border: 1px solid color-mix(in srgb, currentColor 16%, transparent); border-radius: 5px; }
.hex input[type="color"]::-moz-color-swatch { border: 1px solid color-mix(in srgb, currentColor 16%, transparent); border-radius: 5px; }
.hex input[type="text"] { width: 68px; border: 0; outline: 0; background: none; color: var(--foreground); font: 500 13px/1 var(--font-mono); letter-spacing: 0.02em; text-transform: uppercase; }

.finder { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--space-2) var(--space-3); max-width: 1440px; margin: 0 auto var(--space-4); }
.find { flex: 0 1 220px; }
.find input { width: 100%; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.chip { height: 30px; padding: 0 11px; border: 1px solid transparent; border-radius: var(--radius-full); background: none; color: var(--muted-foreground); font: 500 var(--text-small)/1 var(--font-sans); cursor: pointer; transition: background var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out); }
.chip:hover { color: var(--foreground); background: var(--fill-on-subtle); }
.chip[aria-pressed="true"] { background: var(--foreground); color: var(--background); }
.chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.found { color: var(--muted-foreground); font: 400 12px/1 var(--font-mono); font-variant-numeric: tabular-nums; }
.none { margin: var(--space-8) 0; color: var(--muted-foreground); text-align: center; }
.hcard[hidden] { display: none; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-4); max-width: 1440px; margin: 0 auto; }
.hcard { display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); overflow: hidden; }
.hcard-head { display: flex; align-items: center; gap: var(--space-2); height: 48px; padding: 0 var(--space-2) 0 var(--space-4); border-bottom: 1px solid var(--border); }
.hcard-head .two-d { flex: none; color: var(--muted-foreground); }
.hcard-head b { min-width: 0; overflow: hidden; color: var(--foreground); font: 500 var(--text-ui)/var(--leading-ui) var(--font-sans); text-overflow: ellipsis; white-space: nowrap; }
.hcard-head .oc-btn { margin-left: auto; flex: none; }
.hcard-head .oc-btn svg { width: 14px; height: 14px; }
.hcard-stage { position: relative; display: grid; place-items: center; height: 304px; padding: 8px 8px 28px; box-sizing: border-box; overflow: hidden; background: radial-gradient(circle, var(--border) 1px, transparent 1.2px) center / 16px 16px, var(--subtle); }
[data-theme="dark"] :is(.sheet-stage, .hcard-stage) { background-color: var(--background); }
.hcard-stage .icon-host { width: min(100%, 268px); }
.hcard-hint { position: absolute; right: 8px; bottom: 9px; left: 8px; margin: 0; overflow: hidden; color: var(--muted-foreground); font: 400 12px/1.2 var(--font-sans); text-align: center; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.hcard-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: 8px; border-top: 1px solid var(--border); }
.hcard-foot .oc-btn svg { width: 14px; height: 14px; }
.hcard-actions { display: flex; flex: none; gap: 6px; }
.apartbtn[aria-pressed="true"] { --oc-btn-bg: var(--foreground); --oc-btn-hover: var(--foreground); border-color: var(--foreground); background: var(--foreground); color: var(--background); }
.hcard-hint { transition: opacity var(--duration-fast) var(--ease-out); }
.hcard[data-used] .hcard-hint { opacity: 0; }
.i3d:focus-visible { outline: 2px solid var(--ring); border-radius: var(--radius-lg); }

.home-foot { max-width: 1440px; margin: var(--space-12) auto 0; padding-top: var(--space-6); border-top: 1px solid var(--border); text-align: center; }
.home-foot p { margin: 0; color: var(--muted-foreground); font: var(--text-small)/var(--leading-small) var(--font-sans); text-wrap: balance; }
.home-foot a { color: var(--foreground); font-weight: 500; text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 4px; transition: text-decoration-color var(--duration-fast) var(--ease-out); }
.home-foot a:hover { text-decoration-color: currentColor; }

.sheet { width: min(1120px, calc(100vw - 32px)); max-width: none; height: min(760px, calc(100dvh - 32px)); max-height: none; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); color: var(--foreground); overflow: hidden; }
.sheet::backdrop { background: color-mix(in srgb, #000 42%, transparent); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.sheet-in { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); height: 100%; }
.sheet-stage { position: relative; display: grid; place-items: center; min-height: 0; padding: 16px; overflow: hidden; background: radial-gradient(circle, var(--border) 1px, transparent 1.2px) center / 16px 16px, var(--subtle); }
#sheet-host { width: min(100%, 460px); }
.sheet-hint { position: absolute; right: 16px; bottom: 14px; left: 16px; margin: 0; color: var(--muted-foreground); font: 400 var(--text-small)/1.2 var(--font-sans); text-align: center; }
.sheet-side { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; min-height: 0; padding: var(--space-5, 20px); overflow-y: auto; border-left: 1px solid var(--border); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.sheet-head h2 { margin: 0; font: 400 24px/1.15 var(--font-sans); letter-spacing: -0.02em; }
.sheet-head p { margin: 6px 0 0; color: var(--muted-foreground); font: 400 var(--text-small)/var(--leading-small) var(--font-sans); text-wrap: pretty; }
.sheet-head .oc-btn svg, #sheet-play svg, .code-actions svg { width: 14px; height: 14px; }
.sheet-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
#sheet-play { margin-left: auto; }

.opt { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.opts { min-width: 0; margin: 0; padding: 0; border: 0; }
.opts legend { padding: 0 0 8px; color: var(--muted-foreground); font: 500 12px/1 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; }
#sheet-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px var(--space-4); }
#sheet-opts .opt { font: 500 var(--text-small)/1.2 var(--font-sans); }
.sliders { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3) var(--space-4); }
.slider { display: grid; grid-template-columns: 1fr auto; gap: 4px; font: 500 var(--text-small)/1.2 var(--font-sans); }
.slider code { color: var(--muted-foreground); font: 400 12px/1.2 var(--font-mono); font-variant-numeric: tabular-nums; }
.slider input { grid-column: 1 / -1; width: 100%; margin: 0; accent-color: var(--tint, #f62134); }

.stats { display: flex; flex-wrap: wrap; gap: 4px var(--space-5, 20px); margin: 0; }
.stats div { display: flex; align-items: baseline; gap: 6px; }
.stats dt { color: var(--muted-foreground); font: 400 var(--text-small)/1.2 var(--font-sans); }
.stats dd { margin: 0; font: 500 13px/1.2 var(--font-mono); font-variant-numeric: tabular-nums; }

.code { display: flex; flex: 1; flex-direction: column; gap: var(--space-2); min-height: 220px; }
.code-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.code-actions { display: flex; gap: 6px; }
#sheet-text { flex: 1; min-height: 140px; box-sizing: border-box; width: 100%; padding: var(--space-3); resize: none; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--subtle); color: var(--foreground); font: 400 12px/1.55 var(--font-mono); white-space: pre; overflow: auto; tab-size: 2; }
#sheet-text:focus-visible { outline: none; border-color: var(--ring); box-shadow: var(--focus-ring); }
.code-note { margin: 0; color: var(--muted-foreground); font: 400 12px/1.4 var(--font-sans); }

@media (max-width: 1180px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 880px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet { width: 100vw; height: 100dvh; border: 0; border-radius: 0; }
  .sheet-in { display: flex; flex-direction: column; height: 100%; overflow-y: auto; }
  .sheet-stage { flex: none; height: min(52vw, 340px); padding: 8px 8px 28px; }
  #sheet-host { width: auto; height: 100%; aspect-ratio: 1; }
  .sheet-side { flex: none; overflow: visible; border-top: 1px solid var(--border); border-left: 0; }
  #sheet-text { min-height: 260px; }
}
@media (max-width: 620px) {
  :root { --gutter: 16px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .hero { padding: 40px 0 28px; }
  .tb-handle { display: none; }
  .hcard-stage { height: 288px; }
  .sliders { grid-template-columns: minmax(0, 1fr); }
  .sheet-stage { height: 76vw; }
}
/* A hand-drawn hint at the color picker: a ring draws round it, an arrow curls in, a note writes itself,
   then it all fades and starts again. The house scribble: Caveat 600 in rust. It goes once the color is changed */
.hex-wrap { position: relative; display: inline-flex; }
.scribble-hint { --ink: #B5481A; position: absolute; left: -12px; top: -74px; width: 340px; height: 130px; pointer-events: none; z-index: 2; }
[data-theme="dark"] .scribble-hint { --ink: #F0A27A; }
.scribble-hint svg { position: absolute; inset: 0; overflow: visible; }
.scribble-hint path { fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 1.1; stroke-dashoffset: 1.05; }
/* One 8s cycle, drawn in and erased out, never faded, so every piece starts and ends hidden and the loop point cannot flash:
   ring, arrow, note draw in (0-34%), hold (to 70%), then note, arrow, ring erase in reverse (70-100%) and the ring draws again at once.
   Hidden is a dash offset of 1.05 with a 1.1 gap, so a round cap never leaves a dot at the end of a hidden line */
.scribble-hint .s-ring { animation: s-ring 8s linear infinite; }
.scribble-hint .s-arrow { animation: s-arrow 8s linear infinite; }
.scribble-hint .s-head { animation: s-head 8s linear infinite; }
.scribble-hint .s-text { position: absolute; left: 162px; top: 16px; color: var(--ink); font: 600 23px/1 'Caveat', cursive; white-space: nowrap; transform: rotate(-3deg); transform-origin: left center; clip-path: inset(-30% 104% -30% -4%); animation: s-text 8s linear infinite; }
@keyframes s-ring { 0% { stroke-dashoffset: 1.05; animation-timing-function: cubic-bezier(.45,0,.3,1); } 13%, 86% { stroke-dashoffset: 0; animation-timing-function: cubic-bezier(.5,0,.6,1); } 100% { stroke-dashoffset: 1.05; } }
@keyframes s-arrow { 0%, 13% { stroke-dashoffset: 1.05; animation-timing-function: ease-out; } 19%, 81% { stroke-dashoffset: 0; animation-timing-function: ease-in; } 86%, 100% { stroke-dashoffset: 1.05; } }
@keyframes s-head { 0%, 19% { stroke-dashoffset: 1.05; } 21.5%, 79% { stroke-dashoffset: 0; } 81%, 100% { stroke-dashoffset: 1.05; } }
@keyframes s-text { 0%, 21.5% { clip-path: inset(-30% 104% -30% -4%); } 34%, 70% { clip-path: inset(-30% -4% -30% -4%); } 79%, 100% { clip-path: inset(-30% 104% -30% -4%); } }
.hex-wrap:has(#all-hex[style*="none"]) .scribble-hint, .scribble-hint[data-done] { display: none; }
@media (max-width: 880px) { .scribble-hint { display: none; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .scribble-hint, .scribble-hint path, .scribble-hint .s-text { animation: none; }
  .scribble-hint path { stroke-dasharray: none; stroke-dashoffset: 0; }
  .scribble-hint .s-text { clip-path: none; }
}
