/* Kästchen · night 055 of Nachtschicht · style.css */
:root {
  --bg: #070a16; --text: #dfe6f5; --muted: #8d97ab; --amber: #e8a84a; --violet: #a98bff;
  --panel: rgba(13, 18, 33, 0.78); --border: rgba(255, 255, 255, 0.1); --field: rgba(10, 14, 27, 0.92);
  --paper: #f3eedd; --ink: #141a2c;
  --mono: ui-monospace, Menlo, "SF Mono", Consolas, "Liberation Mono", monospace;
  --top: 56px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); font-size: 14px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent; min-height: 100vh; min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top strip: back link, title overlay, help ---------- */
.top { position: relative; height: var(--top); display: flex; align-items: center; justify-content: space-between;
  padding: 0 calc(14px + env(safe-area-inset-right, 0px)) 0 calc(14px + env(safe-area-inset-left, 0px)); }
a.home { font-size: 12px; color: #8d9ab0; text-decoration: none; padding: 4px 7px; border-radius: 5px;
  background: rgba(6, 10, 22, 0.84); border: 1px solid var(--border); white-space: nowrap; }
a.home:hover, a.home:focus-visible { color: var(--amber); }
.title-overlay { position: absolute; top: 4px; left: 50%; transform: translateX(-50%); z-index: 9; pointer-events: none;
  text-align: center; width: max-content; max-width: calc(100% - 260px); padding: 4px 16px; border-radius: 10px;
  background: rgba(8, 10, 18, 0.82); border: 1px solid var(--border); opacity: 1; transition: opacity 0.8s ease; }
.title-overlay.faded { opacity: 0; }
.title-overlay h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 0.06em; color: #f0e2c4; line-height: 1.2; }
.title-overlay p { margin: 1px 0 0; font-size: 11.5px; color: #b3bccb; line-height: 1.3; }
.title-overlay .short { display: none; }

.btn { min-height: 36px; min-width: 36px; padding: 0 11px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: rgba(18, 24, 38, 0.8); border-radius: 8px; font-size: 13px; color: var(--text);
  cursor: pointer; white-space: nowrap; touch-action: manipulation; }
.btn:hover { border-color: rgba(255, 255, 255, 0.26); }
.btn.on { color: var(--amber); border-color: rgba(232, 168, 74, 0.7); }
.help-btn { font-weight: 600; }

/* ---------- layout ---------- */
.layout { display: grid; gap: 14px; padding: 0 16px 24px; grid-template-columns: minmax(0, 1fr);
  padding-left: calc(16px + env(safe-area-inset-left, 0px)); padding-right: calc(16px + env(safe-area-inset-right, 0px)); }
.stage { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.card { width: 100%; max-width: 560px; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden; background: var(--paper);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45); border: 1px solid rgba(255, 255, 255, 0.08); position: relative; }
.card.night { background: #0b1022; border-color: rgba(255, 255, 255, 0.18); }
#cv:focus-visible { outline: 3px solid var(--amber); outline-offset: -3px; }
#cv { display: block; width: 100%; height: 100%; touch-action: manipulation; cursor: crosshair; transition: opacity 0.3s; }
.card.stale #cv { opacity: 0.3; filter: grayscale(1); }
.summary { margin: 10px 0 0; font-family: var(--mono); font-size: 12.5px; color: var(--text); text-align: center; font-variant-numeric: tabular-nums; }
.readout { margin: 4px 0 0; min-height: 2.9em; font-size: 12px; color: var(--muted); text-align: center; max-width: 560px; }
.readout b { color: #f0e2c4; font-weight: 600; }

.input-panel, .bauplan { min-width: 0; }
.lbl { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 4px; }
textarea { display: block; width: 100%; min-height: 4.6em; resize: vertical; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--field); color: var(--text); font-family: var(--mono); font-size: 13px; line-height: 1.45; }
textarea:focus { border-color: rgba(232, 168, 74, 0.55); outline: none; }
textarea:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; }
.counts { margin: 6px 0 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counts b { color: var(--text); font-weight: 500; }
.error { margin: 6px 0 0; padding: 6px 9px; border-radius: 7px; font-size: 12.5px; color: #ffcfb8; background: rgba(120, 40, 20, 0.35);
  border: 1px solid rgba(255, 140, 100, 0.4); }

.panel { margin-top: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.panel > summary { cursor: pointer; padding: 9px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--amber);
  font-weight: 600; list-style-position: inside; touch-action: manipulation; }
.panel[open] > summary { border-bottom: 1px solid var(--border); }
.opts { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 12px; }
.opt.row2 { display: grid; grid-template-columns: 1fr 1fr; column-gap: 10px; }
.opt.row2 .lbl:nth-of-type(1) { grid-column: 1; grid-row: 1; } .opt.row2 select:nth-of-type(1) { grid-column: 1; grid-row: 2; }
.opt.row2 .lbl:nth-of-type(2) { grid-column: 2; grid-row: 1; } .opt.row2 select:nth-of-type(2) { grid-column: 2; grid-row: 2; }
select { width: 100%; min-height: 36px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--field); color: var(--text); }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1 1 0; min-height: 36px; border: 0; border-left: 1px solid var(--border); background: rgba(18, 24, 38, 0.8);
  cursor: pointer; font-size: 13px; touch-action: manipulation; padding: 0 6px; min-width: 0; }
.seg button:first-child { border-left: 0; }
.seg button[aria-checked="true"] { background: var(--amber); color: #15110a; font-weight: 600; }
.seg button:focus-visible { outline-offset: -3px; }
.check { display: flex; align-items: baseline; gap: 7px; font-size: 13px; cursor: pointer; flex-wrap: wrap; }
.check input { accent-color: var(--amber); width: 16px; height: 16px; margin: 0; align-self: center; }
.hint { font-size: 11.5px; color: var(--muted); }
.note { margin: 6px 0 0; font-size: 11.5px; color: #c9b38c; }
.exports { display: flex; gap: 6px; flex-wrap: wrap; }
.exports .btn { flex: 1 1 auto; }

/* ---------- Bauplan ---------- */
.bp-controls { display: flex; align-items: center; gap: 6px; padding: 10px 12px 0; }
.bp-controls .btn { padding: 0; width: 36px; font-size: 15px; flex: 0 0 auto; }
.bp-controls .play { color: var(--amber); }
#scrub { flex: 1 1 auto; min-width: 0; accent-color: var(--amber); height: 36px; touch-action: manipulation; }
.step-label { margin: 6px 12px 0; font-family: var(--mono); font-size: 12px; color: #f0e2c4; font-variant-numeric: tabular-nums; }
.step-text { margin: 3px 12px 0; font-size: 12.5px; color: #b9c2d3; min-height: 3.8em; }
.step-text code { font-family: var(--mono); font-size: 12px; color: var(--text); }
.phases { list-style: none; margin: 8px 12px 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.phases button { font-size: 11.5px; padding: 3px 7px; border-radius: 6px; border: 1px solid var(--border); background: rgba(18, 24, 38, 0.8);
  cursor: pointer; touch-action: manipulation; min-height: 28px; }
.phases button.cur { border-color: var(--amber); color: var(--amber); }
.phases button.done { color: #c8cfdc; }
.phases button.todo { color: #6f7a8f; }

.sub { border-top: 1px solid var(--border); }
.sub > summary { cursor: pointer; padding: 8px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  font-weight: 600; touch-action: manipulation; }
.sub-hint { margin: 0 12px 6px; font-size: 11.5px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 8px; margin: 0 12px 6px; font-size: 11px; }
.legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; background: currentColor; vertical-align: -1px; }
.bits { margin: 0 12px 12px; font-family: var(--mono); font-size: 11.5px; line-height: 1.7; word-break: normal; overflow-wrap: anywhere;
  -webkit-user-select: text; user-select: text; }
.bits .cw { display: inline-block; margin-right: 6px; white-space: nowrap; }
.bits .more { color: var(--muted); font-family: system-ui, sans-serif; }
.b-mode { color: #f0b85c; } .b-count { color: #c5a6ff; } .b-data { color: #8fc3ff; } .b-terminator { color: #ff8f7a; }
.b-padbits { color: #8d97ab; } .b-padbytes { color: #8fe0b6; }
.masks { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 0 12px 12px; }
.mask { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px 5px; border-radius: 8px; border: 1px solid var(--border);
  background: rgba(18, 24, 38, 0.8); cursor: pointer; touch-action: manipulation; min-width: 0; }
.mask canvas { width: 35px; height: 35px; image-rendering: pixelated; border-radius: 2px; }
.mask .mk { font-size: 11px; color: var(--muted); }
.mask .pt { font-family: var(--mono); font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; }
.mask .pn { font-family: var(--mono); font-size: 10.5px; color: var(--muted); line-height: 1.25; text-align: center; font-variant-numeric: tabular-nums; }
.mask.best .mk::after { content: " · best"; color: #c9b38c; }
.mask.cur { border-color: var(--amber); box-shadow: inset 0 0 0 1px var(--amber); }
.mask.cur .pt { color: var(--amber); }
.blocks { margin: 0 12px 12px; font-size: 12.5px; color: #b9c2d3; }
.blocks code { font-family: var(--mono); font-size: 12px; color: var(--text); }

/* ---------- help ---------- */
.help { position: fixed; z-index: 20; top: calc(10px + env(safe-area-inset-top, 0px)); right: calc(14px + env(safe-area-inset-right, 0px));
  max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); width: min(420px, calc(100vw - 28px)); display: flex; flex-direction: column;
  border-radius: 12px; background: rgba(8, 12, 22, 0.97); border: 1px solid rgba(255, 255, 255, 0.14); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6); }
.help-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--border); }
.help-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: 0.04em; color: #f0e2c4; }
.help-body { overflow: auto; padding: 6px 14px 14px; font-size: 12.5px; line-height: 1.45; }
.help-body h3 { margin: 12px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--amber); font-weight: 600; }
.help-body p { margin: 6px 0; color: #b3bccb; }
.help-body dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; }
.help-body dt { font-family: var(--mono); font-size: 12px; color: var(--text); }
.help-body dd { margin: 0; color: var(--muted); }

/* ---------- medium widths: the symbol on the left, input and Bauplan stacked on the right ---------- */
@media (min-width: 50rem) and (max-width: 67.99rem) {
  .layout { grid-template-columns: minmax(0, 1.15fr) minmax(18rem, 1fr); grid-template-areas: "stage input" "stage bauplan";
    grid-template-rows: auto 1fr; align-items: start; }
  .stage { grid-area: stage; position: sticky; top: 8px; }
  .card { width: min(100%, calc(100vh - var(--top) - 104px)); width: min(100%, calc(100dvh - var(--top) - 104px)); max-width: none; min-width: min(100%, 340px); }
  .input-panel { grid-area: input; }
  .bauplan { grid-area: bauplan; }
  .readout { max-width: 100%; }
}

/* ---------- wide: three regions ---------- */
@media (min-width: 68rem) {
  html, body { height: 100%; overflow: hidden; }
  .layout { height: calc(100vh - var(--top)); height: calc(100dvh - var(--top)); padding-bottom: 14px;
    grid-template-columns: minmax(15rem, 20rem) minmax(0, 1fr) minmax(16rem, 23rem); grid-template-areas: "input stage bauplan"; }
  .stage { grid-area: stage; justify-content: flex-start; overflow: hidden; }
  .card { width: min(100%, calc(100vh - var(--top) - 104px)); width: min(100%, calc(100dvh - var(--top) - 104px)); max-width: none; flex: 0 0 auto; }
  .input-panel { grid-area: input; overflow: auto; padding-right: 2px; }
  .bauplan { grid-area: bauplan; overflow: auto; padding-right: 2px; }
  .bauplan .panel { margin-top: 0; }
  .readout { max-width: 100%; }
}

/* ---------- phone ---------- */
@media (max-width: 34rem) {
  :root { --top: 54px; }
  .top { padding-left: calc(10px + env(safe-area-inset-left, 0px)); padding-right: calc(10px + env(safe-area-inset-right, 0px)); }
  .title-overlay { top: 3px; left: 104px; right: 54px; transform: none; width: auto; max-width: none; padding: 4px 8px; border-radius: 8px;
    background: rgba(8, 10, 18, 0.9); transition: opacity 0.5s ease; }
  .title-overlay h1 { font-size: 14px; }
  .title-overlay p { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .title-overlay .long { display: none; }
  .title-overlay .short { display: inline; }
  .stage { padding-top: 2px; }
  .masks { gap: 4px; }
}
@media (prefers-reduced-motion: reduce) { .title-overlay, #cv { transition: none; } }
