/* blubber — the gate below the ideenformen site: the checkbox, the Bot Challenge tile and the cube.
   Light and dark follow the site's switch (html[data-theme]). The site's own styles are in idf/idf.css. */
:root, [data-theme="dark"] {
  --bg: #0a0b12;
  --panel: #0e0f18;
  --panel-2: #121320;
  --line: rgba(255, 255, 255, 0.075);
  --line-2: rgba(255, 255, 255, 0.12);
  --text: #e9e9f4;
  --text-2: #c3c4d6;
  --muted: #8a8ba3;
  --faint: #898ba3;
  --accent: #a78bfa;
  --accent-soft: rgba(167, 139, 250, 0.16);
  --primary-bg: #b3a3f5;
  --primary-bg-hover: #c2b5f8;
  --primary-text: #1c1745;
  --mint: #5eead4;
  --amber: #f5c86b;
  --red: #f06464;
  --blue: #4f9dff;
  --success-bg: rgba(94, 234, 212, 0.07);
  --success-line: rgba(94, 234, 212, 0.45);
  --canvas-bg: #0c0d16;
  /* the layer maps (read by cube.js) */
  --lm-cell: #1c2438;
  --lm-reach: #22375f;
  --lm-landing: #3a2d63;
  --lm-rock: #141a29;
  --lm-hatch: #2b3550;
  --lm-wall: #6f7fa6;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f1f0fa;
  --panel: #ffffff;
  --panel-2: #f7f6fd;
  --line: rgba(40, 30, 110, 0.10);
  --line-2: rgba(40, 30, 110, 0.18);
  --text: #191a2e;
  --text-2: #3b3c55;
  --muted: #6d6e88;
  --faint: #73758e;
  --accent: #5b4fd6;
  --accent-soft: rgba(91, 79, 214, 0.12);
  --primary-bg: #6a58e6;
  --primary-bg-hover: #5b48dc;
  --primary-text: #ffffff;
  --mint: #087d6a;
  --amber: #d99a1e;
  --red: #e14b4b;
  --blue: #3b82f6;
  --success-bg: rgba(18, 168, 143, 0.07);
  --success-line: rgba(18, 168, 143, 0.5);
  --canvas-bg: #efeef9;
  --lm-cell: #e3e8fb;
  --lm-reach: #bfd2fb;
  --lm-landing: #d9ccfb;
  --lm-rock: #eef0f9;
  --lm-hatch: #cfd3ea;
  --lm-wall: #5d5f96;
  color-scheme: light;
}

/* ---------- basics ---------- */
* { box-sizing: border-box; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: wait; opacity: .5; }
[hidden] { display: none !important; }
.caps { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }
.faint { color: var(--faint); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; background: var(--blue); }
.noscript { text-align: center; padding: 20px; color: var(--muted); }

/* ---------- the gate: one narrow column under the site ---------- */
.idf-gate { max-width: 480px; margin: var(--gate-drop, 0px) auto 0; padding: 14px 0 40px; font-size: 14px; color: var(--text); }
/* --gate-drop is set by cube.js (placeGate); it glides when the gate moves after a verdict */
.idf-gate.placed { transition: margin-top .35s ease; }
.gate-lead { color: var(--i-muted); font-size: 14px; line-height: 1.45; margin: 0 0 10px; text-align: center; }
.return-notice { border: 1px solid var(--amber); border-radius: 8px; padding: 12px; color: var(--text-2); font-size: 12px; line-height: 1.6; }

/* ---------- the knock: the checkbox ---------- */
.knock-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 0 0 32px; }
.knock {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 0; width: 100%; min-height: 74px;
  padding: 10px 14px 10px 16px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .12);
}
.knock-box {
  position: relative; margin-right: 14px; width: 30px; height: 30px; padding: 0; border-radius: 4px; border: 2px solid var(--muted); background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; cursor: pointer; transition: border-color .15s;
}
.knock-box:hover:not(:disabled) { border-color: var(--accent); }
.knock-box:disabled { cursor: default; }
.knock-box > span { display: none; }
.knock-spin { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: knock-spin .8s linear infinite; }
@keyframes knock-spin { to { transform: rotate(360deg); } }
@keyframes knock-pop { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
.knock[data-state="working"] .knock-box { border-color: transparent; background: transparent; }
.knock[data-state="working"] .knock-spin { display: block; }
.knock[data-state="pass"] .knock-box { border-color: transparent; background: transparent; color: var(--mint); }
.knock[data-state="pass"] .knock-tick { display: flex; animation: knock-pop .35s ease-out both; }
.knock[data-state="cube"] .knock-box { border-color: var(--amber); color: var(--amber); }
.knock[data-state="cube"] .knock-cube { display: flex; }
.knock[data-state="error"] .knock-box { border-color: var(--red); }
.knock-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.knock-label { font-size: 14.5px; color: var(--text); }
.knock-sub { font-size: 12.5px; color: var(--muted); min-height: 1em; }
.knock-sub:empty { display: none; }
.knock[data-state="pass"] .knock-sub { color: var(--mint); }
.knock[data-state="cube"] .knock-sub { color: var(--amber); }
/* the session: how long the pass still runs without activity, and a reset that makes this a first visit */
.knock-session {
  align-self: stretch; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 96px; margin: -10px 0; padding: 6px 14px; border-left: 1px solid var(--line-2); border-right: 1px solid var(--line-2);
}
.knock-session b { font-size: 14px; font-weight: 400; color: var(--text); }
.knock-session span { font: 11px/1.2 "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); font-variant-numeric: tabular-nums; }
.knock-session button {
  margin-top: 2px; padding: 3px 14px; border: 1px solid transparent; border-radius: 6px; background: var(--accent-soft);
  color: var(--accent); font-weight: 500; font-size: 11.5px; cursor: pointer;
}
.knock-session button:hover:not(:disabled) { background: var(--accent); color: var(--bg); }
.knock-brand { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 130px; padding-left: 14px; color: var(--accent); }
.knock-brand b { font-size: 10.5px; color: var(--text-2); font-weight: 600; letter-spacing: -0.01em; }
.knock-brand small { font-size: 7.5px; line-height: 1.5; color: var(--faint); text-align: center; white-space: nowrap; }
.knock-msg { margin: 0; font-size: 12.5px; color: var(--muted); max-width: 520px; text-align: center; }
.knock[data-state="error"] + .knock-msg { color: var(--red); }
.idf a.knock-continue { width: auto; min-width: 240px; height: 42px; margin-top: 4px; color: var(--primary-text); text-decoration: none; }
/* the honeypot: off screen, out of the keyboard order, hidden from screen readers */
.knock-hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }

/* ---------- the Bot Challenge: one tile; opened, the cube and its panels hang below it, divided by lines ---------- */
.challenge-card {
  margin: -22px 0 16px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .08); overflow: hidden;
}
.challenge-tile {
  width: 100%; min-height: 78px; display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 14px;
  margin: 0; padding: 10px 14px 10px 16px; border: 0; background: transparent; color: var(--text); text-align: left; cursor: pointer;
}
.challenge-tile:hover { background: var(--accent-soft); }
.ct-icon { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.ct-icon > * { display: none; }
.ct-x { font-size: 26px; font-weight: 500; line-height: 1; }
.ct-chev { width: 20px; height: 20px; color: var(--muted); transition: transform .2s; }
.challenge-tile[data-mode="optional"] .ct-chev,
.challenge-tile[data-mode="solved"] .ct-chev { display: block; }
.challenge-tile[data-mode="solved"] .ct-chev { color: var(--mint); }
.challenge-tile[data-mode="required"] .ct-x { display: block; color: var(--amber); }
.challenge-tile[aria-expanded="true"] .ct-chev { transform: rotate(180deg); }
.ct-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ct-text b { font-size: 14.5px; font-weight: 500; }
.ct-text small { font-size: 12px; color: var(--muted); }
.challenge-tile[data-mode="required"] .ct-text small { color: var(--amber); }
.challenge-tile[data-mode="solved"] .ct-text small { color: var(--mint); }
.ct-thumb { width: 58px; height: 58px; padding: 4px; border-radius: 8px; background: var(--canvas-bg); }
.ct-plate { fill: rgba(140, 120, 255, .18); }
.ct-edge { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; }
.ct-grid { fill: none; stroke: var(--accent); stroke-width: .8; opacity: .35; }
.ct-exit { fill: none; stroke: var(--mint); stroke-width: 2; }
.ct-ball { fill: var(--blue); }

.game-grid { display: grid; grid-template-columns: 1fr; align-items: start; border-top: 1px solid var(--line); }
.game-main { display: flex; flex-direction: column; min-width: 0; }

/* ---------- the playfield ---------- */
.cube-tile { overflow: hidden; }
.canvas-area { position: relative; height: clamp(380px, 62vh, 520px); background: var(--canvas-bg); touch-action: none; }
.canvas-area canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.canvas-area canvas:active { cursor: grabbing; }
.ov { position: absolute; pointer-events: none; font-size: 9px; letter-spacing: .2em; color: var(--muted); }
.ov-level { top: 18px; left: 22px; font-size: 12px; letter-spacing: .02em; }
.ov-level span { margin-left: 4px; color: var(--text-2); font-weight: 600; }
.ov-hint { left: 24px; bottom: 20px; display: flex; align-items: center; gap: 10px; font-size: 11.5px; letter-spacing: 0; }
.help-btn {
  pointer-events: auto; right: 20px; bottom: 16px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: transparent;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.help-btn:hover { color: var(--text); }
/* the instructions cover the whole playfield; "Close" sits at the bottom under a line */
.help-pop { position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; padding: 22px 24px 0; background: var(--panel); overflow: auto; }
.help-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.help-pop ul { flex: 1; overflow: auto; margin: 0; padding-left: 20px; color: var(--text-2); font-size: 13.5px; line-height: 1.6; }
.help-pop li + li { margin-top: 6px; }
.help-foot { display: flex; justify-content: center; margin: 16px -24px 0; padding: 14px 0 16px; border-top: 1px solid var(--line-2); }
.help-close {
  min-width: 140px; height: 38px; padding: 0 20px; border: 0; border-radius: 9px; cursor: pointer;
  background: var(--primary-bg); color: var(--primary-text); font-weight: 600; font-size: 14px;
}
.help-close:hover { background: var(--primary-bg-hover); }

/* ---------- the controls under the playfield ---------- */
.bar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.bar-label { font-size: 8.5px; letter-spacing: .2em; color: var(--muted); white-space: nowrap; }
.btn-row { display: flex; gap: 6px; }
.sq-btn, .level-btn {
  height: 32px; min-width: 32px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel); color: var(--text-2); cursor: pointer;
}
.level-btn { padding: 0 12px; font-size: 12.5px; }
.sq-btn:hover:not(:disabled), .level-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.sq-btn:disabled, .level-btn:disabled { opacity: .45; cursor: not-allowed; }
.bar-tilt { padding: 14px 20px; gap: 14px; }
.bar-tilt .sq-btn { width: 38px; height: 38px; border-radius: 9px; background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.bar-tilt .sq-btn:hover { background: var(--accent); color: var(--bg); }
.bar-tilt .level-btn { height: 36px; margin-left: 2px; }
/* turn the view, the six faces, zoom: one row */
.view-bar { flex-wrap: nowrap; gap: 8px; padding: 10px 12px; }
.view-bar .btn-row { gap: 4px; flex: none; }
.view-bar .sq-btn { min-width: 30px; height: 30px; }
.sq-btn.face.on { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 1px var(--accent), 0 0 12px var(--accent-soft); background: var(--accent-soft); }
/* the zoom slider carries its value on the handle (cube.js moves the label and sets --p) */
.zoom { position: relative; flex: 1; min-width: 90px; display: flex; align-items: center; margin: 0 0 0 4px; }
.zoom input {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; margin: 0; border-radius: 2px; cursor: pointer;
  background: linear-gradient(to right, var(--accent) var(--p, 33%), var(--line-2) var(--p, 33%));
}
.zoom input::-webkit-slider-thumb { -webkit-appearance: none; width: 38px; height: 22px; border-radius: 11px; background: var(--accent); border: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, .2); }
.zoom input::-moz-range-thumb { width: 38px; height: 22px; border-radius: 11px; background: var(--accent); border: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, .2); }
.zoom input:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; }
.zoom-thumb {
  position: absolute; top: 50%; left: 19px; transform: translate(-50%, -50%); pointer-events: none;
  font: 600 10px/1 "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--primary-text); letter-spacing: .02em;
}

/* ---------- a closer look: the layer above, the ball's own, the layer below ---------- */
.layers-tile { padding: 20px 22px 22px; border-top: 1px solid var(--line); }
.tile-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; font-size: 8.5px; letter-spacing: .22em; color: var(--muted); }
.save-state { margin-left: auto; font-size: 8px; letter-spacing: .06em; text-transform: none; }
.save-state[data-state="error"] { color: var(--amber); }
.layer-row { display: grid; grid-template-columns: repeat(3, minmax(0, 170px)); gap: 8px; justify-content: center; }
.layer-slot {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 8px 10px;
  border: 1px solid var(--line-2); border-radius: 10px; background: var(--panel);
}
.layer-slot.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft); }
.layer-slot.empty { border-style: dashed; }
.layer-title { display: flex; align-items: center; gap: 6px; font-size: 8px; letter-spacing: .08em; color: var(--muted); }
.layer-slot.current .layer-title { color: var(--text); font-weight: 600; }
.layer-map { display: block; width: 100%; max-width: 140px; aspect-ratio: 1; }
.layer-empty {
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  width: 100%; max-width: 140px; aspect-ratio: 1; font-size: 10.5px; color: var(--faint); text-align: center;
}
.layer-slot.empty .layer-map { display: none; }
.layer-slot.empty .layer-empty { display: flex; }

/* ---------- levels, reset, stats ---------- */
.control { display: flex; flex-direction: column; overflow: hidden; padding: 14px 22px 0; border-top: 1px solid var(--line); }
.verdict { margin: 0 0 22px; padding: 15px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel-2); }
.verdict.error { border-color: var(--red); }
.verdict:focus { outline: none; }
.verdict .v-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.verdict p { margin: 6px 0 0; color: var(--text-2); font-size: 12.5px; line-height: 1.5; }
.verdict button { margin-top: 10px; }
.primary-btn {
  width: 100%; height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 18px;
  border: 0; border-radius: 10px; background: var(--primary-bg); color: var(--primary-text); font-size: 12px; font-weight: 600;
  cursor: pointer; box-shadow: 0 6px 24px var(--accent-soft);
}
.primary-btn span { flex: 1; text-align: center; }
.primary-btn:hover { background: var(--primary-bg-hover); }
.primary-btn:disabled { opacity: .6; cursor: progress; }

.field-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 6px; font-weight: 600; }
.field-head .caps { font-size: 7.5px; letter-spacing: .2em; font-weight: 400; }
.ladder { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; margin-bottom: 14px; }
.rung {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 5px 6px;
  border: 1px solid var(--line-2); border-radius: 7px; background: var(--panel-2); text-align: center; line-height: 1.2; cursor: pointer;
}
.rung b { font-size: 11px; font-weight: 600; white-space: nowrap; }
.rung small { font-size: 9px; color: var(--muted); white-space: nowrap; }
.rung:hover { border-color: var(--accent); }
.rung.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
/* a solved level: the whole box turns green */
.rung.done { border-color: var(--success-line); background: var(--success-bg); box-shadow: 0 0 0 1px var(--success-line); }
.rung.done b { color: var(--mint); }
.rung.done.on { border-color: var(--mint); box-shadow: 0 0 0 1px var(--mint), 0 0 12px var(--success-bg); }
.rung .tick { position: absolute; top: 3px; right: 3px; display: none; color: var(--mint); }
.rung.done .tick { display: flex; }
.rung .tick svg { width: 10px; height: 10px; }
/* Reset: red, in the tenth slot of the level grid */
.reset-btn {
  display: flex; align-items: center; justify-content: center; gap: 5px; padding: 5px 6px;
  border: 0; border-radius: 7px; background: var(--red); color: #fff; cursor: pointer;
}
.reset-btn:hover:not(:disabled) { filter: brightness(1.08); }
.reset-btn:disabled { opacity: .5; cursor: not-allowed; }
.reset-btn:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 -22px; border-top: 1px solid var(--line); }
.stats > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 4px; padding: 7px 11px 8px; border-right: 1px solid var(--line); }
.stats > div:last-child { border-right: 0; }
.stats > div:first-child, .stats > div:last-child { display: grid; grid-template-columns: auto auto; justify-content: center; }
.stats > div:first-child .caps, .stats > div:last-child .caps { grid-column: 1 / -1; }
.stats .caps { display: flex; align-items: center; gap: 5px; width: 100%; margin-bottom: 1px; font-size: 7px; letter-spacing: .1em; color: var(--muted); }
.stats b { font-size: 15px; font-weight: 500; letter-spacing: -0.02em; }
.stats small { font-size: 9.5px; color: var(--muted); }
.progress { display: block; width: 100%; height: 2px; margin-top: 3px; background: var(--line-2); }
.progress i { display: block; width: 0; height: 100%; background: var(--accent); }

/* ---------- tablets and laptops: the card, once opened, takes the site's width; the cube on the left, its controls
   stacked on the right (the playfield's sections give up their own boxes and join the card's grid) ---------- */
@media (min-width: 900px) {
  .challenge-card:has(> .game-grid:not([hidden])) { margin-left: calc((100% - min(832px, 100vw - 48px)) / 2); margin-right: calc((100% - min(832px, 100vw - 48px)) / 2); }
  .game-grid { grid-template-columns: minmax(0, 1fr) 420px; grid-template-rows: auto auto auto 1fr; }
  .game-main, .cube-tile { display: contents; }
  .canvas-area { grid-column: 1; grid-row: 1 / span 4; align-self: stretch; height: auto; min-height: 400px; }
  .bar, .layers-tile, .control { grid-column: 2; border-left: 1px solid var(--line); }
  .bar-tilt { border-top: 0; }
  .control { align-self: stretch; }
  .stats { margin-top: auto; }
  /* compact, so the opened card fits a tablet held sideways without scrolling */
  .challenge-tile { min-height: 62px; padding-top: 6px; padding-bottom: 6px; }
  .ct-thumb { width: 48px; height: 48px; }
  .bar-tilt { gap: 10px; padding: 10px 16px; }
  .bar-tilt .sq-btn { width: 36px; height: 36px; }
  .bar-tilt .level-btn { height: 34px; margin-left: auto; }
  .view-bar { padding: 8px 12px; }
  .layers-tile { padding: 12px 16px 12px; }
  .tile-head { margin-bottom: 10px; }
  .layer-slot { gap: 6px; padding: 6px 6px 8px; }
  .layer-map, .layer-empty { max-width: 100px; }
  .control { padding-top: 10px; }
  .ladder { margin-bottom: 10px; }
}

/* ---------- phones ---------- */
@media (max-width: 680px) {
  .knock-session { min-width: 0; padding: 8px 10px; }
  .knock-brand { min-width: 0; padding-left: 10px; }
  .ov-hint { left: 16px; }
  .hint-desktop { display: none; }
  .bar-tilt { gap: 9px; padding: 12px; }
  .bar-tilt .bar-label { font-size: 8px; }
  .bar-tilt .sq-btn { width: 36px; height: 38px; }
  .bar-tilt .level-btn { margin-left: auto; }
  .view-bar { flex-wrap: wrap; }
  .view-bar .btn-row { gap: 3px; }
  .view-bar .sq-btn { width: 28px; min-width: 28px; height: 28px; padding: 0; }
  .view-bar { row-gap: 12px; }
  .zoom { min-width: 64px; }
  .layers-tile { padding: 16px 12px; }
  .layer-title { font-size: 7px; }
  .layer-empty { font-size: 9px; }
  .control { padding: 14px 20px 0; }
  .rung, .reset-btn { padding: 5px 2px; }
  .rung b { font-size: 10.5px; }
  .rung small { font-size: 8.5px; }
  .stats { margin: 0 -20px; }
}
@media (max-width: 420px) { .bar-tilt .bar-label { display: none; } }
/* touch screens without a keyboard: no arrow-key hint */
@media (hover: none) { .hint-desktop { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .idf-gate.placed { transition: none; }
  .knock-spin { animation-duration: 2.4s; }
  .knock[data-state="pass"] .knock-tick { animation: none; }
}
