:root {
  --bg: #14161c;
  --surface: #1c1f27;
  --raised: #252a35;
  --line: #2f3542;
  --text: #e9e4d8;
  --mute: #a2a7b3;
  --amber: #f2b54a;
  --amber-hi: #f7c86e;
  --ink: #221704;
  --fog: #8fa3c7;
  --r: 8px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
[id] { scroll-margin-top: 72px; }
button, input, label.btn { font: inherit; color: inherit; }
a { color: var(--amber); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  height: 56px; padding: 0 12px 0 14px;
  border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; min-height: 40px; color: var(--text); text-decoration: none; min-width: 0; }
.brand .word { font: italic 600 22px/1 var(--serif); letter-spacing: .01em; }
.brand .tag { color: var(--mute); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.conn { color: var(--mute); font-size: 13px; padding-right: 4px; white-space: nowrap; }
.conn.on { color: #9fd8a8; }
.conn.on::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #6cc37b; margin-right: 6px; vertical-align: 1px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--raised); color: var(--text);
  font-weight: 600; font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #4a5263; }
.btn.amber { background: var(--amber); border-color: var(--amber); color: var(--ink); }
.btn.amber:hover { background: var(--amber-hi); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 48px; padding: 0 20px; font-size: 15px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
body.pro .buy, body.pro .is-free { display: none !important; }
body:not(.pro) .is-pro { display: none; }

/* layout: app-height on wide screens */
.layout { display: grid; grid-template-columns: 76px minmax(0, 1fr) 312px; }
@media (min-width: 900px) {
  body { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
  main { flex: 1; min-height: 0; }
  /* one row capped at the screen, so the settings column scrolls on its own */
  .layout { height: 100%; grid-template-rows: minmax(0, 1fr); }
  /* relative so screen-reader-only labels inside stay in the scroller instead of stretching the page */
  .panel { position: relative; overflow-y: auto; border-left: 1px solid var(--line); }
  .only-narrow { display: none !important; }
}

/* tool rail */
.rail {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 12px 8px; background: var(--surface); border-right: 1px solid var(--line);
}
.seg { display: flex; flex-direction: column; gap: 4px; padding: 4px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.tool {
  width: 52px; height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--mute); cursor: pointer;
  font-size: 11px; font-weight: 600;
}
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { color: var(--text); }
.tool[aria-pressed="true"] { background: var(--raised); color: var(--amber); border-color: #4b4130; }
.tool[data-mode="hide"][aria-pressed="true"] { color: var(--fog); border-color: #3a4459; }
.tool:disabled { opacity: .35; cursor: default; }

/* stage */
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #0d0f13; }
#gm { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.stage.panning #gm { cursor: grab; }
.empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 4px;
  background: radial-gradient(ellipse at 50% 42%, rgba(242,181,74,.10), transparent 60%), #0d0f13;
}
.empty h1 { font: italic 600 clamp(28px, 4vw, 44px)/1.12 var(--serif); margin: 0 0 8px; max-width: 16em; text-wrap: balance; }
.empty p { color: var(--mute); max-width: 32em; margin: 0 0 18px; }
.empty .fine { font-size: 13px; margin: 14px 0 0; }
.empty-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.stage.drag::after { content: ""; position: absolute; inset: 10px; border: 2px dashed var(--amber); border-radius: 12px; pointer-events: none; }
.drop-hint { position: absolute; left: 50%; top: 18px; transform: translateX(-50%); background: var(--amber); color: var(--ink); font-weight: 700; padding: 8px 14px; border-radius: 99px; }
.popnote {
  position: absolute; left: 12px; right: 12px; top: 12px; display: flex; gap: 10px; align-items: flex-start;
  background: #2b2416; border: 1px solid #6b5426; border-radius: var(--r); padding: 10px 12px; max-width: 560px;
}
.popnote p { margin: 0; font-size: 14px; }
.x { background: none; border: 0; color: var(--text); font-size: 22px; line-height: 1; cursor: pointer; min-width: 32px; min-height: 32px; }

/* panel */
.panel { background: var(--surface); }
.blk { padding: 16px 16px 18px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.blk h2 { margin: 0; font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.blk h3 { margin: 4px 0 0; font-size: 14px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.pro-tag { font-size: 11px; font-weight: 700; color: var(--amber); border: 1px solid #5a4a2a; border-radius: 99px; padding: 1px 7px; }
body.pro .pro-tag { display: none; }
.note { margin: 0; color: var(--mute); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.row.slider { flex-wrap: wrap; justify-content: space-between; }
.row.slider input { width: 100%; }
.row output { color: var(--mute); font-variant-numeric: tabular-nums; font-size: 13px; }
.row.check { cursor: pointer; min-height: 32px; }
.row.text input, .save-row input {
  flex: 1; min-width: 0; height: 40px; border-radius: var(--r); border: 1px solid var(--line); background: var(--bg); padding: 0 10px;
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--amber); }
input[type="range"] { accent-color: var(--amber); height: 28px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.sw { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(0,0,0,.5); cursor: pointer; }
.sw[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 2px; }
.save-row { display: flex; gap: 8px; }
.pro-only-box { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }
.lib { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lib li { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); }
.lib .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.lib .btn { min-height: 34px; padding: 0 10px; font-size: 13px; }
.lib .empty-lib { color: var(--mute); font-size: 13px; background: none; border: 0; padding: 0; }
.panel .blk { scroll-margin-top: 64px; }
.unlock { background: linear-gradient(180deg, rgba(242,181,74,.07), transparent); }
.unlock p { margin: 0; }
.price { color: var(--amber); font-weight: 700; }
.gets { margin: 0; padding-left: 18px; color: var(--mute); font-size: 14px; }
.gets li { margin-bottom: 3px; }
body:not(.pro) [data-pro] { opacity: .75; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px; padding: 10px 16px; border-radius: 99px;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center; z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body:has(#tp-bar) .toast { bottom: 74px; }

/* narrow: map on top, tool dock under it, settings below (page scrolls) */
@media (max-width: 899px) {
  .brand .tag { display: none; }
  .conn { display: none; }
  .top { padding: 0 10px; }
  .top-actions { gap: 6px; }
  .top .btn { min-height: 38px; padding: 0 11px; font-size: 13px; }
  .layout { display: flex; flex-direction: column; }
  .stage { order: 1; height: calc(100dvh - 56px - 72px); min-height: 300px; }
  body:has(#tp-bar) .stage { height: calc(100dvh - 56px - 72px - 56px); }
  .rail { order: 2; flex-direction: row; justify-content: center; gap: 8px; padding: 6px 6px; border-right: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); height: 72px; }
  .seg { flex-direction: row; padding: 3px; gap: 2px; }
  .tool { width: 50px; height: 54px; font-size: 10.5px; }
  .panel { order: 3; }
  .panel .blk { padding: 16px 14px; }
}
@media (max-width: 480px) {
  /* the trial bar and the Pro card in Settings carry the unlock; keep the brand readable */
  .top .buy { display: none; }
}
@media (max-width: 400px) {
  .tool { width: 47px; }
  .rail { gap: 5px; }
  .brand .word { font-size: 20px; }
}
@media (min-width: 600px) and (max-width: 899px) {
  .panel { display: grid; grid-template-columns: 1fr 1fr; }
  .panel .unlock { grid-column: 1 / -1; }
}
/* FAQ + legal footer */
.faq h3 { margin: 6px 0 0; }
.legal { flex-shrink: 0; padding: 8px 16px; border-top: 1px solid var(--line); color: var(--mute); font-size: 12px; line-height: 1.4; text-align: center; }
.legal a { color: inherit; display: inline-block; min-height: 24px; line-height: 24px; }
