:root {
  --bg: #0d0d0d;
  --panel: rgba(18, 18, 18, 0.94);
  --border: #2e2e2e;
  --text: #ededed;
  --muted: #8a8a8a;
  --accent: #f8471e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  min-height: 100%;
}

/* ---------- stage / canvas ---------- */

#stage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 32px 32px 380px;
}

#canvas-holder canvas {
  display: block;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
  max-width: 100%;
  height: auto !important;
  width: auto !important;
  max-height: calc(100vh - 64px);
}

/* ---------- overlay UI ---------- */

.ui {
  position: fixed;
  top: 20px;
  left: 20px;
  width: 320px;
  max-height: calc(100vh - 40px);
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.ui-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.ui-head h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: -0.3px;
  text-transform: uppercase;
}
.ui-head h1 span { color: var(--accent); }

#collapseBtn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 26px;
  height: 26px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
#collapseBtn:hover { color: var(--text); border-color: #555; }

.ui-body {
  padding: 14px 16px 18px;
  overflow-y: auto;
}
.ui.collapsed .ui-body { display: none; }

.ui section { margin-bottom: 14px; }

label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.val { color: var(--accent); }

input[type="text"], select, textarea {
  width: 100%;
  background: #060606;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 9px;
  font-size: 13px;
  border-radius: 4px;
  font-family: inherit;
  resize: vertical;
}
textarea { line-height: 1.35; font-size: 12px; }
input[type="text"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 2px;
  background: #060606;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

input[type="range"] { width: 100%; accent-color: var(--accent); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.grid3 input { padding: 6px; font-size: 11px; }

.btns { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

button.primary, #exportBtn {
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #060606;
  color: var(--text);
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #111;
}
button.primary:hover { filter: brightness(1.1); }
#exportBtn:hover { border-color: #555; }

.fontrow { display: flex; gap: 8px; }
.fontrow .filebtn:first-child { flex: 1; }

.filebtn {
  display: block;
  text-align: center;
  padding: 9px 12px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #060606;
  color: var(--text);
  margin: 0;
  font-family: inherit;
  line-height: 1.2;
}
.filebtn:hover { border-color: var(--accent); color: var(--accent); }
.filebtn.ghost { flex: 0 0 auto; width: 38px; color: var(--muted); font-size: 14px; }

.hint.bad { color: #ff8b6b; }
/* Was opacity .6 over --muted, which computed to 2.71:1 against the panel and
   failed WCAG AA. Full opacity on --muted is 5.4:1. */
.hint.subtle { margin-top: 3px; }

/* `.fontrow { display:flex }` outranks the UA `[hidden] { display:none }`,
   so the row needs its own hidden rule or it stays on screen. */
.fontrow[hidden] { display: none; }

#inkPressRow { margin-top: 10px; }

button.toggle {
  width: 100%;
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #060606;
  color: var(--muted);
}
button.toggle:hover { border-color: #555; color: var(--text); }
button.toggle.on {
  background: #ffe94a;
  border-color: #ffe94a;
  color: #111;
}

.hint {
  margin: 7px 0 0;
  font-size: 10px;
  line-height: 1.45;
  color: var(--muted);
  display: none;
}
.hint.show { display: block; }

/* ---------- pinned area + accordion groups ----------
   The panel used to be ~20 flat <section>s of mixed control types, which
   read as one long undifferentiated list. Now only the text input and the
   primary actions are pinned; everything else lives in named <details>
   groups. name="panel" makes browsers that support it (Chrome/Safari/
   Firefox 2024+) treat them as a native accordion — opening one closes
   the others — with zero JS and a harmless fallback (independent
   collapsibles) anywhere that doesn't. */

.pinned { margin-bottom: 18px; }

details {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-bottom: 4px;
}
details[open] { padding-bottom: 4px; }
details summary {
  cursor: pointer;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
details summary:hover { color: var(--accent); }
details summary .val {
  margin-left: auto;
  font-size: 10px;
  text-transform: none;
  letter-spacing: normal;
}
details label { margin-top: 10px; }
details label:first-of-type { margin-top: 0; }
/* A second logical sub-group inside one panel (e.g. "Frame" typeface
   after "Display" typeface) needs a bigger break than the normal 10px
   label rhythm, without the weight of a whole new <details>. */
details label.spaced { margin-top: 18px; }

/* A toggle + its own hint, repeated a few times in one panel (Lock boxes,
   Edit boxes, Ink press) — .stack gives each pair the same breathing room
   a new field would get, so they don't read as one run-on block. */
details .stack { margin-top: 14px; }
details .stack:first-child { margin-top: 0; }

.status {
  margin: 14px 0 0;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* Below 900px the panel stops floating and joins the flow. The old rule kept
   it `fixed` and pushed the stage down by a hardcoded 380px — a guess at the
   panel's height that stopped being true as controls were added, leaving the
   panel sitting on top of 54% of the poster at 768px and 78% at 375px.
   Going static removes the guess entirely: the panel can be any height.
   #stage precedes .ui in the DOM, so the poster stays on top. */
@media (max-width: 900px) {
  #stage {
    padding: 16px;
    min-height: 0;
    display: block;
  }
  #canvas-holder { display: flex; justify-content: center; }
  .ui {
    position: static;
    width: auto;
    max-height: none;
    margin: 0 16px 24px;
    backdrop-filter: none;
  }
  .ui-body { overflow-y: visible; }
}
