/* ArchBoard — app shell: reset, top bar, buttons, dialogs, toast. */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font: 15.5px/1.45 var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- top bar ---------- */
.topbar {
  flex: none;
  height: var(--bar-h);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 0 14px 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 5;
}
.topbar__left, .topbar__right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar__right { justify-content: flex-end; }
.topbar__rule { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--accent); flex: none; }
.brand__name { font-size: 19px; font-weight: 500; letter-spacing: -.01em; color: var(--ink); white-space: nowrap; }
.brand__name b { font-weight: 750; color: var(--accent); }
.brand__sep { width: 1px; height: 26px; background: var(--line-2); margin: 0 6px 0 8px; flex: none; }
.brand svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.project-name {
  min-width: 0; width: min(300px, 100%);
  padding: 7px 10px;
  font-weight: 600; font-size: 17px; letter-spacing: -.005em;
  background: transparent; border: 1px solid transparent; border-radius: var(--r-2);
  text-overflow: ellipsis;
}
.project-name:hover { background: var(--hover); }
.project-name:focus { background: var(--raised); border-color: var(--line-2); outline: none; }

.save-status { color: var(--ink-3); font-size: 14px; margin-right: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.save-status[data-state="dirty"] { color: var(--ink-2); }
.save-status[data-state="error"] { color: var(--danger); }

/* ---------- buttons ---------- */
.btn {
  height: 38px; padding: 0 15px;
  background: transparent; border: 1px solid var(--line-2); border-radius: var(--r-2);
  font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--press); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn--quiet { border-color: transparent; color: var(--ink-2); }
.btn--danger { border-color: transparent; color: var(--danger); padding: 0 6px; }

.iconbtn {
  width: 40px; height: 40px; flex: none;
  display: inline-grid; place-items: center;
  background: transparent; border: 0; border-radius: var(--r-2);
  color: var(--ink-2);
}
.iconbtn i { display: contents; }
.iconbtn:hover { background: var(--hover); color: var(--ink); }
.iconbtn:active { background: var(--press); }
.iconbtn:disabled { opacity: .35; cursor: default; background: none; }
.iconbtn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.iconbtn--text { font-weight: 600; font-size: 15px; }
.iconbtn--sm { width: 28px; height: 28px; }
.spacer { flex: 1; }

/* ---------- main area ---------- */
.stagearea { flex: 1; position: relative; min-height: 0; overflow: hidden; overflow: clip; }
.view { position: absolute; inset: 0; }

/* ---------- swatches (selection bar + colour popover) ---------- */
.swatch {
  --sw: var(--shape-fill); --sw-edge: var(--line-2);
  width: 24px; height: 24px; padding: 0; flex: none;
  background: var(--sw); border: 1.5px solid var(--sw-edge); border-radius: 50%;
  position: relative;
}
.swatch--default-fill { --sw: var(--canvas); }
.swatch--default-line { --sw: var(--ink); --sw-edge: var(--ink); }
.swatch--none { background: transparent; border-color: var(--line-2); overflow: hidden; }
.swatch--none::after { content: ""; position: absolute; left: -2px; right: -2px; top: 50%; height: 1.5px; background: var(--danger); transform: rotate(-45deg); }
.swatch.is-active { box-shadow: 0 0 0 2px var(--raised), 0 0 0 3.5px var(--accent); }

/* ---------- theme colour popover (top bar) ---------- */
.colorpop.colorpop--top { position: fixed; left: auto; right: 14px; bottom: auto; top: calc(var(--bar-h) + 6px); z-index: 10; max-height: calc(100vh - var(--bar-h) - 20px); overflow-y: auto; }
.colorpop__section { display: flex; flex-direction: column; gap: 10px; }
.colorpop.colorpop--top { display: grid; grid-template-columns: repeat(2, auto); gap: 18px 26px; }
.colorpop--top .colorpop__section:nth-child(n + 3) { padding-top: 14px; border-top: 1px solid var(--line); }
@media (max-width: 560px) {
  .colorpop.colorpop--top { grid-template-columns: auto; left: 14px; }
  .colorpop--top .colorpop__section:nth-child(n + 2) { padding-top: 14px; border-top: 1px solid var(--line); }
}

/* ---------- dialogs ---------- */
.dialog {
  width: min(500px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line-2); border-radius: var(--r-3);
  background: var(--raised); color: var(--ink);
  box-shadow: var(--pop-shadow);
}
.dialog--narrow { width: min(430px, calc(100vw - 32px)); }
.dialog--wide { width: min(860px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(8, 16, 13, .42); }
.dialog[open] { animation: dialog-in .18s var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px) scale(.985); } }
.dialog__form { display: flex; flex-direction: column; gap: 16px; padding: 22px; margin: 0; }
.dialog__head { display: flex; align-items: center; justify-content: space-between; }
.dialog__title { font-size: 18px; font-weight: 650; letter-spacing: -.005em; }
.dialog__text { color: var(--ink-2); line-height: 1.5; }
.dialog__actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 14px; color: var(--ink-2); font-weight: 500; }
.field__input {
  width: 100%; padding: 9px 11px;
  background: var(--canvas); border: 1px solid var(--line-2); border-radius: var(--r-2);
  resize: vertical;
}
.field__input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- shortcuts help ---------- */
.help { columns: 2; column-gap: 28px; overflow: auto; }
.help__group { break-inside: avoid; margin-bottom: 16px; }
.help__group h3 { font-size: 14px; font-weight: 600; color: var(--ink-3); margin-bottom: 4px; }
.help dl { margin: 0; }
.help dl > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 4px 0; border-top: 1px solid var(--line); }
.help dt { white-space: nowrap; display: flex; gap: 3px; align-items: center; }
.help dd { margin: 0; color: var(--ink-2); text-align: right; }
.help__sep { color: var(--ink-3); padding: 0 1px; }
kbd {
  font: 600 13px/1 var(--font-ui);
  min-width: 24px; padding: 5px 6px; text-align: center;
  background: var(--surface); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px;
}
@media (max-width: 640px) { .help { columns: 1; } }

/* ---------- accessibility / no-JS ---------- */
.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; }
.noscript { position: fixed; inset: auto 16px 16px; z-index: 40; max-width: 640px; margin: 0 auto; padding: 14px 18px; border-radius: var(--r-3); background: var(--raised); border: 1px solid var(--line-2); line-height: 1.5; }

/* ---------- hover hints (js/tooltip.js) ---------- */
.tip {
  position: fixed; left: 0; top: 0; z-index: 30;
  max-width: 320px; padding: 7px 11px; border-radius: var(--r-2);
  background: var(--ink); color: var(--bg);
  font-size: 15px; font-weight: 500; line-height: 1.3;
  box-shadow: var(--pop-shadow);
  pointer-events: none; opacity: 0; transform: translateY(2px);
  transition: opacity .12s, transform .12s var(--ease);
}
.tip.is-on { opacity: 1; transform: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 64px; z-index: 20;
  padding: 10px 16px; border-radius: var(--r-2);
  background: var(--ink); color: var(--bg); font-weight: 500;
  opacity: 0; transform: translate(-50%, 8px); pointer-events: none;
  transition: opacity .2s, transform .2s var(--ease);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .save-status, .topbar__rule { display: none; }
  .project-name { width: 140px; }
  .brand__sep { margin: 0 2px; }
  .btn { padding: 0 8px; }
}
@media (max-width: 620px) {
  .topbar { gap: 6px; }
  .project-name, #btnSave, .brand__sep { display: none; }
}
