/* JellyTest: a small lab for a squishy puzzle. Cool rose-grey neutrals lean towards the jelly red;
   gold marks the target and green a fit (semantic colours, separate from the accent).
   Layout: a picture-first stage beside a column of wheels; explanations alternate text and diagram. */
:root {
  --bg: #f4f1f3; --panel: #ffffff; --ink: #1e181c; --muted: #6c6169; --line: #e2dade; --sunken: #ebe5e8;
  --accent: #cf2a3c; --accent-ink: #ffffff; --accent-deep: #9b1b2b; --gold: #e3a12f; --good: #2c8a4d; --good-soft: #e3f3e8;
  --gloss: #ffffffb3; --depth: #00000014; --glow: #cf2a3c40;
  --display: 'Bricolage Grotesque', 'Avenir Next', system-ui, sans-serif;
  --body: 'Figtree', 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151113; --panel: #1f1a1d; --ink: #f2ecef; --muted: #a59aa2; --line: #352d32; --sunken: #292226;
    --accent: #ff5466; --accent-ink: #1e0a0d; --accent-deep: #ff8f9b; --gold: #f2b84b; --good: #4fbf72; --good-soft: #1b3324;
    --gloss: #ffffff26; --depth: #00000059; --glow: #ff546633; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151113; --panel: #1f1a1d; --ink: #f2ecef; --muted: #a59aa2; --line: #352d32; --sunken: #292226;
  --accent: #ff5466; --accent-ink: #1e0a0d; --accent-deep: #ff8f9b; --gold: #f2b84b; --good: #4fbf72; --good-soft: #1b3324;
  --gloss: #ffffff26; --depth: #00000059; --glow: #ff546633; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--body); }
main { max-width: 992px; margin: auto; padding-block: 28px 64px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
h1, h2, h3, h4 { font-family: var(--display); line-height: 1.15; text-wrap: balance; margin: 0; }
h2 { font-size: 34px; letter-spacing: -.02em; }
h3 { font-size: 22px; letter-spacing: -.01em; }
h4 { font-size: 17px; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
code { font: 13px var(--mono); background: var(--sunken); padding: 1px 5px; border-radius: 4px; }
small { color: var(--muted); }
.muted, .lead, .intro, #status, #stats { color: var(--muted); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
header h1 { display: flex; align-items: center; gap: 10px; font-size: 28px; letter-spacing: -.02em; }
header h1 a { color: inherit; text-decoration: none; display: contents; }
header > a { font-weight: 600; text-decoration: none; }
.lead { font-size: 18px; max-width: 62ch; margin-bottom: 24px; }
.demo > .lead { color: var(--accent-deep); font-weight: 600; }

/* Buttons: neutral by default, accent for the main action, green once solved. All of them are a
   little jelly-like: a glossy top edge, depth underneath, and a springy squish when pressed. */
button { font: 600 15px var(--body); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 9px 16px; cursor: pointer;
  box-shadow: inset 0 1px 0 var(--gloss), inset 0 -3px 6px var(--depth), 0 2px 6px var(--depth);
  transition: transform .35s cubic-bezier(.34, 1.8, .64, 1), box-shadow .2s; }
button:active:not(:disabled) { transform: scale(1.04, .92); transition-duration: .08s; }
@media (hover: hover) { button:hover { border-color: var(--muted); } }
button:disabled { opacity: .5; cursor: default; }
#new, .primary, #continue { --tint: var(--accent); color: var(--accent-ink); border-color: transparent;
  background: radial-gradient(120% 90% at 30% 10%, color-mix(in srgb, var(--tint), white 30%), var(--tint) 55%, color-mix(in srgb, var(--tint), black 22%));
  box-shadow: inset 0 2px 1px #ffffff66, inset 0 -4px 8px #0000002e, 0 6px 14px -4px color-mix(in srgb, var(--tint), transparent 45%); }
#continue { --tint: var(--good); }
#solve { color: var(--accent); border-color: color-mix(in srgb, var(--accent), transparent 50%); }
@media (hover: hover) { #solve:hover { background: var(--accent); color: var(--accent-ink); } }

/* Stage: picture with its overlap meter, and the wheels. */
/* The demo and the tutorial share one stage, so their pictures are the same size. */
.stage, .tutorial { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 320px); gap: 32px; align-items: center;
  max-width: 960px; padding: 24px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 1px 0 var(--gloss) inset, 0 18px 40px -24px var(--glow); }
.picture { display: grid; grid-template-columns: minmax(0, 1fr) 28px; gap: 12px; }
.view { position: relative; aspect-ratio: 1; max-width: 100%; border-radius: 14px; overflow: hidden; background: var(--sunken); }
.view img { position: absolute; inset: 0; width: 100%; height: 100%; }
/* Until the first frame arrives, a soft shimmer shows that a shape is on its way. */
.view:has(> img:first-child[hidden]) { background: linear-gradient(110deg, var(--sunken) 30%, var(--line) 50%, var(--sunken) 70%) 0 0 / 300% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -150% 0; } }
.view .target, #target { transition: filter .5s; }
.solved .target, .solved #target { filter: hue-rotate(75deg) saturate(1.4); } /* the gold outline turns green */
#solved, .solved-note { margin-top: 12px; padding: 8px 12px; border-radius: 10px; text-align: center; font-weight: 600; color: var(--good); background: var(--good-soft); }
#solved::before, .solved-note::before { content: '✓ '; }
#status { min-height: 1.55em; margin: 20px 0 16px; }
#status.error { color: var(--accent); }
.bar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.levels { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel);
  box-shadow: inset 0 1px 0 var(--gloss), inset 0 -3px 6px var(--depth), 0 2px 6px var(--depth); }
.levels button { border: 0; border-radius: 0; box-shadow: none; }
.levels button[aria-pressed=true] { background: var(--ink); color: var(--bg); box-shadow: inset 0 2px 1px #ffffff2e, inset 0 -3px 6px #0000004d; }
.after { display: grid; gap: 8px; margin-top: 24px; }

/* Overlap meter: filled to --value, with a line at --goal. */
.meter { position: relative; border-radius: 8px; background: var(--sunken); }
.meter { box-shadow: inset 0 2px 4px var(--depth); }
.meter .fill { position: absolute; inset: auto 0 0; height: calc(var(--value, 0)*100%); border-radius: 8px;
  background: linear-gradient(to top, var(--gold), color-mix(in srgb, var(--gold), white 35%)); transition: height .25s, background .25s;
  box-shadow: inset 2px 2px 2px #ffffff80, inset -2px -2px 4px #0000001f; } /* a jelly-glossy fill */
.meter.met .fill { background: linear-gradient(to top, var(--good), color-mix(in srgb, var(--good), white 30%)); }
.meter .goal { position: absolute; left: -5px; right: -5px; bottom: calc(var(--goal, .94)*100%); height: 2px; border-radius: 1px; background: var(--ink); }
.meter .label { position: absolute; inset: auto 0 6px; text-align: center; font: 600 11px var(--mono); font-variant-numeric: tabular-nums; color: #1e181c; } /* inside the fill, clear of the goal line */

/* Thumbwheels: a ridged drum (ridges shift with --x) above a thin range bar. */
#wheels, #t-wheels { display: grid; gap: 18px; }
.wheel { display: grid; gap: 7px; align-items: center; cursor: grab; touch-action: none; outline: none; }
/* Long presses on the wheels (iOS especially) must not select text or open a callout. */
.stage, .tutorial, .wheel { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.panel p, #t-text { -webkit-user-select: text; user-select: text; }
.wheel.active { cursor: grabbing; }
.wheel .drum { height: 38px; border-radius: 9px; box-shadow: inset 0 0 0 1px #0002, 0 2px 4px #0002; transition: box-shadow .15s;
  background:
    linear-gradient(90deg, #0008, #0000 22%, #fff3 50%, #0000 78%, #0008), /* cylinder shading */
    linear-gradient(#fff4, #0000 40%, #0002),
    repeating-linear-gradient(90deg, #0000 0 8px, #0004 8px 10px, #fff3 10px 11px, #0000 11px 14px) var(--x, 0) 0 / 14px 100%,
    var(--accent); }
.wheel.active .drum { box-shadow: inset 0 0 0 1px #0003, 0 0 0 4px color-mix(in srgb, var(--accent), transparent 75%); }
@media (hover: hover) { .wheel:hover .drum { box-shadow: inset 0 0 0 1px #0003, 0 0 0 4px color-mix(in srgb, var(--accent), transparent 75%); } }
.wheel:focus-visible .drum { box-shadow: inset 0 0 0 1px #0003, 0 0 0 3px var(--accent); }
.wheel .range { position: relative; height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, #0000 calc(50% - 1px), var(--muted) calc(50% - 1px) calc(50% + 1px), #0000 calc(50% + 1px)), var(--line); }
.wheel .range i { position: absolute; top: -3px; width: 12px; height: 10px; border-radius: 5px; transform: translateX(-50%); background: var(--accent); }
.wheel .range b { position: absolute; top: -5px; width: 14px; height: 14px; border-radius: 50%; transform: translateX(-50%);
  border: 2px solid var(--good); background: var(--panel); } /* tutorial target */
.wheel[aria-disabled=true] { opacity: .5; cursor: default; }
.wheel[aria-disabled=true] .drum { box-shadow: inset 0 0 0 1px #0002; }

/* Settings */
details { margin-top: 32px; border-top: 1px solid var(--line); padding-top: 14px; }
summary { cursor: pointer; font-weight: 600; }
details > p { font-size: 14px; color: var(--muted); margin-top: 8px; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 18px 0 0; padding: 14px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px 28px; min-width: 0; }
legend { font: 600 16px var(--display); padding-right: 8px; }
fieldset > small { grid-column: 1 / -1; }
.field { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 12px; font-size: 15px; }
.field small { grid-column: 1 / -1; font-size: 13px; line-height: 1.4; }
.field input[type=checkbox] { justify-self: end; }
input[type=number], input[type=color] { width: 92px; font: 14px var(--mono); padding: 4px 6px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
input[type=number]:invalid { border-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
fieldset table { grid-column: 1 / -1; border-collapse: collapse; font-size: 14px; display: block; overflow-x: auto; }
td, th { padding: 4px 10px 4px 0; text-align: left; vertical-align: top; }
td label { display: flex; gap: 8px; align-items: center; white-space: nowrap; font-weight: 600; }
td input[type=number] { width: 76px; }
td small { font-size: 13px; line-height: 1.35; }
tr.off td:not(:first-child) { opacity: .35; }
.tag { font: 500 11px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; vertical-align: 1px; }
#stats { font: 13px var(--mono); margin: 16px 0 8px; }

/* Explanation page */
.article { max-width: 992px; display: grid; gap: 22px; } /* same width as the demo, so the stages match */
.article > h2 { margin-top: 36px; }
.article > header + h2 { margin-top: 0; }
.intro { max-width: 70ch; }
.rules { display: grid; gap: 16px; margin-top: 18px; }
/* Rule cards: live thumbnails of the clashing transformations, a title, and why. */
.rule-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.rule { display: grid; gap: 12px; align-content: start; padding: 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.rule > div:nth-child(2) { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.rule p { font-size: 15px; color: var(--muted); }
.thumbs { display: flex; align-items: center; gap: 10px; }
.thumbs figure { margin: 0; display: grid; gap: 4px; justify-items: center; }
.thumbs img { width: 72px; height: 72px; border-radius: 8px; background: var(--sunken); display: block; }
.thumbs img:not([src]) { visibility: hidden; }
.thumbs figcaption { font: 12px var(--mono); color: var(--muted); }
.thumbs .op { font: 600 18px var(--mono); color: var(--muted); padding-bottom: 18px; }
.never { font: 600 12px var(--mono); color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent), transparent 55%); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.panel { display: grid; gap: 14px; align-content: start; min-width: 0; }
.progress { display: flex; gap: 8px; list-style: none; margin: 0; padding: 0; }
.progress button { width: 34px; height: 34px; padding: 0; border-radius: 50%; font-family: var(--mono); }
.progress .done button { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.progress .current button { background: var(--ink); border-color: var(--ink); color: var(--bg); }
#t-status { min-height: 1.55em; font-size: 14px; }
#t-status.error { color: var(--accent); }
.tips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; font-size: 15px; color: var(--muted); }
.tips b { color: var(--ink); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 40px; align-items: center; margin-top: 18px; }
.split > div { display: grid; gap: 12px; }
/* Transformation cards: two per row, a small live render beside its name, formula, and effect. */
.gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.gallery figure { margin: 0; padding: 12px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line);
  display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 16px; align-items: center; }
.gallery img { width: 100%; aspect-ratio: 1; border-radius: 9px; display: block; background: var(--sunken); }
.gallery figcaption { display: grid; gap: 8px; min-width: 0; }
.gallery .name { font: 600 17px var(--display); }
.gallery .formula { overflow-x: auto; font-size: 17px; padding-block: 2px; }
.gallery small { font-size: 13px; line-height: 1.4; }
.tables { display: grid; gap: 24px; overflow-x: auto; }
.reference { width: 100%; border-collapse: collapse; font-size: 14px; }
.reference th { font: 600 15px var(--display); border-bottom: 1px solid var(--line); padding-top: 14px; }
.reference td { border-bottom: 1px solid var(--line); padding: 8px 14px 8px 0; }
.reference td:nth-child(2) { font: 13px var(--mono); white-space: nowrap; }
.reference td:last-child { color: var(--muted); }
.diagram-wrap { min-width: 0; overflow-x: auto; }
.diagram { display: block; width: 100%; height: auto; font: 14px var(--body); }
.diagram text { fill: var(--ink); text-anchor: middle; }
.diagram .title { font-weight: 600; }
.diagram .muted { fill: var(--muted); }
.diagram .small { font-size: 13px; fill: var(--muted); }
.diagram .start { text-anchor: start; }
.diagram .end { text-anchor: end; }
.diagram .box { fill: var(--panel); stroke: var(--line); stroke-width: 1.5; }
.diagram .box.accent { stroke: var(--accent); }
.diagram .line { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.diagram .ink { fill: var(--muted); }
.diagram .dash { stroke: var(--muted); stroke-dasharray: 4 4; }
.diagram .band { fill: var(--good); fill-opacity: .15; }
.diagram .curve { fill: none; stroke-width: 3; }
.diagram .muted-stroke { stroke: var(--muted); }
.diagram .accent-stroke { stroke: var(--accent); }
.diagram .dot { fill: var(--good); }
.diagram .faded { opacity: .3; }
.diagram .jelly { fill: var(--accent); opacity: .85; }
.diagram .current { fill: var(--accent); opacity: .35; }
.diagram .target { fill: none; stroke: var(--gold); stroke-width: 3; }
.diagram .overlap { fill: var(--accent); opacity: .7; }

/* Phones: picture and wheels together on one screen; diagrams keep readable text and scroll. */
@media (max-width: 760px) {
  main { padding-block: 16px 48px; }
  header { margin-bottom: 12px; }
  header h1 { font-size: 24px; }
  .lead { font-size: 15px; margin-bottom: 12px; }
  .stage, .tutorial, .split, .tips { grid-template-columns: minmax(0, 1fr); }
  /* Phones: no card around the stage, so the picture can take the full width. */
  .stage, .tutorial { padding: 0; gap: 14px; border: 0; background: none; box-shadow: none; }
  /* As big as fits while leaving room for the header and every wheel (about 44px each). */
  .picture { width: min(100%, calc(100svh - 170px - var(--wheels, 3)*44px)); min-width: 240px; margin-inline: auto; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  /* The overlap meter becomes a thin bar under the picture. */
  .meter { height: 14px; }
  .meter .fill { inset: 0 auto 0 0; height: auto; width: calc(var(--value, 0)*100%); transition: width .25s, background .25s; }
  .meter .goal { inset: -4px auto -4px calc(var(--goal, .94)*100%); width: 2px; height: auto; }
  .meter .label { inset: 0 auto 0 6px; line-height: 14px; font-size: 10px; text-align: left; color: #1e181c; } /* on the fill, away from the goal line */
  #wheels, #t-wheels { gap: 10px; }
  .wheel { gap: 5px; }
  .wheel .drum { height: 32px; }
  /* Tutorial: level and title above the picture, the wheels right below it, instructions after. */
  .tutorial .panel { display: contents; }
  .tutorial .progress { order: -2; } #t-title { order: -1; } #t-wheels { order: 1; } #t-text { order: 2; } #t-status { order: 3; } #t-next { order: 4; }
  .tutorial > p:has(#t-next), .tutorial #t-next { order: 4; }
  /* Settings: drop the description column; the unit and bounds stay on one line. */
  .transforms td:last-child, .transforms th:last-child { display: none; }
  .transforms td:nth-child(4) { white-space: nowrap; }
  .after { margin-top: 16px; }
  fieldset { grid-template-columns: minmax(0, 1fr); }
  .split { gap: 16px; }
  .diagram { min-width: 560px; }
  h2 { font-size: 28px; }
}
/* Touch: comfortable targets. */
@media (pointer: coarse) {
  button { min-height: 44px; }
  .progress button { width: 44px; height: 44px; }
}
@media (max-width: 860px) { .gallery, .rule-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 480px) { .gallery figure { grid-template-columns: 96px minmax(0, 1fr); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
