@font-face { font-family: 'EB Garamond'; src: url(../fonts/EBGaramond.woff2) format('woff2'); font-weight: 400 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'EB Garamond'; src: url(../fonts/EBGaramond-Italic.woff2) format('woff2'); font-weight: 400 800; font-style: italic; font-display: swap; }

:root {
  --bg: #e7e9ee;
  --panel: #f8f9fb;
  --panel2: #ffffff;
  --line: #d6dae2;
  --text: #1d2129;
  --dim: #6b7280;
  --accent: #2f7cf6;
  --danger: #c2413b;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
.dim { color: var(--dim); }
.small { font-size: 12px; }

/* toolbar */
.top {
  display: flex; align-items: center; gap: 16px; padding: 8px 12px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.home { font-size: 12px; color: var(--dim); text-decoration: none; white-space: nowrap; }
.home:hover { color: var(--accent); }
.brand { font-family: 'EB Garamond', Georgia, serif; font-size: 20px; font-weight: 600; letter-spacing: .1px; margin-right: 4px; }
.grp { display: flex; align-items: center; gap: 6px; }
.grp.end { margin-left: auto; }
.zoom { min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; }
.btn, select, input, textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px;
}
.btn { cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #b8bfcc; background: #f1f3f7; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.icon { min-width: 30px; padding-left: 6px; padding-right: 6px; text-align: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #1f6ae0; border-color: #1f6ae0; }
.btn.danger { color: var(--danger); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px #2f7cf622; }

/* three-pane layout */
.main { flex: 1; min-height: 0; display: grid; grid-template-columns: 230px 1fr 280px; }
.panel { background: var(--panel); overflow-y: auto; }
#palette { border-right: 1px solid var(--line); padding: 6px 12px 16px; }
#inspector { border-left: 1px solid var(--line); padding: 4px 14px 20px; }

.pal-sec h4, #inspector h4 {
  margin: 14px 0 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--dim);
}
.pal-item {
  display: flex; justify-content: center; align-items: center; min-height: 40px; margin-bottom: 6px; padding: 4px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  cursor: grab; user-select: none; touch-action: none;
}
.pal-item:hover { border-color: var(--accent); box-shadow: 0 1px 4px #2f7cf622; }
.pal-item svg { display: block; max-width: 100%; height: auto; pointer-events: none; }
.pal-sub { margin: 10px 0 6px; font-size: 11px; font-weight: 500; color: var(--dim); }
.pal-item.annot { background: transparent; border-style: dashed; }
.pal-tip { color: var(--dim); font-size: 12px; margin: 14px 2px 0; }

/* stage */
.stage-col { position: relative; min-width: 0; min-height: 0; }
#stageWrap { overflow: auto; position: absolute; inset: 0; }
.byline {
  position: absolute; right: 18px; bottom: 12px; pointer-events: none;
  font-family: 'EB Garamond', Georgia, serif; font-size: 14px; color: var(--dim);
}
.byline a { color: inherit; text-decoration: none; pointer-events: auto; }
.byline a:hover { color: var(--accent); text-decoration: underline; }
#stage { padding: 32px; display: inline-block; min-width: 100%; user-select: none; -webkit-user-select: none; }
#stage svg { display: block; background: #fff; box-shadow: 0 1px 3px #0002, 0 6px 24px #0000000f; border-radius: 2px; }
#stage .shape, #stage [data-bracket], #stage [data-row] { cursor: pointer; }
#stage .ann { cursor: ew-resize; }
#stage [data-note] { cursor: move; }
#stage .shape:hover > path:first-child { fill: #f2f6ff; }
body.dragging, body.dragging * { cursor: grabbing !important; }

.ghost { position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, -50%); opacity: .85; filter: drop-shadow(0 4px 10px #0003); }
.ghost.off { opacity: .45; }

/* inspector */
#inspector h3 { margin: 14px 0 10px; font-size: 15px; }
.fld { display: flex; flex-direction: column; gap: 3px; margin-bottom: 9px; }
.fld > span { font-size: 12px; color: var(--dim); }
.fld input, .fld select, .fld textarea { width: 100%; min-width: 0; }
.fld.short input { width: 90px; }
.fld textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 8px; }
.chk { display: flex; align-items: center; gap: 7px; margin: 0 0 8px; cursor: pointer; }
.row-btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
table.keys { border-collapse: collapse; font-size: 12px; }
table.keys td { padding: 3px 8px 3px 0; vertical-align: top; }
kbd {
  display: inline-block; min-width: 18px; padding: 0 4px; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; background: var(--panel2); font: 11px/16px ui-monospace, Menlo, monospace; text-align: center;
}

/* toast + help */
#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0; transition: .2s;
  background: #1d2129; color: #fff; padding: 8px 14px; border-radius: 8px; pointer-events: none; z-index: 60; max-width: 80vw;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
dialog#help { border: none; border-radius: 12px; padding: 0; max-width: 900px; width: calc(100vw - 32px); box-shadow: 0 20px 60px #0004; }
dialog#help::backdrop { background: #1d212966; }
.help-body { padding: 22px 28px 20px; position: relative; max-height: 85vh; overflow-y: auto; }
.help-body h2 { font-family: 'EB Garamond', Georgia, serif; font-size: 26px; font-weight: 600; margin: 0 0 8px; }
.help-body h3 { margin: 18px 0 6px; font-size: 14px; }
.help-body ol { padding-left: 20px; margin: 0; }
.help-body li { margin-bottom: 5px; }
.help-body .close { position: absolute; top: 14px; right: 14px; }
.legend { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; margin: 0; }
.legend dt { font-weight: 600; }
.legend dd { margin: 0; }
.help-fig { margin: 14px 0 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.help-fig svg { display: block; width: 100%; height: auto; }
.help-fig figcaption { margin-top: 6px; font-size: 12px; color: var(--dim); }
.help-actions { display: flex; gap: 8px; margin: 10px 0 4px; }
.help-hide { margin-top: 16px; color: var(--dim); font-size: 12px; }
.credit { margin-top: 18px; color: var(--dim); font-size: 12px; border-top: 1px solid var(--line); padding-top: 12px; }

/* narrow screens: stack the panels */
@media (max-width: 900px) {
  body { overflow: auto; }
  .main { flex: none; grid-template-columns: 1fr; grid-template-rows: auto minmax(360px, 60vh) auto; }
  #examples { max-width: 150px; }
  #palette { border-right: none; border-bottom: 1px solid var(--line); display: flex; gap: 12px; overflow-x: auto; }
  .pal-sec { min-width: 180px; }
  .pal-tip { display: none; }
  #inspector { border-left: none; border-top: 1px solid var(--line); }
  .stage-col { min-height: 360px; }
  .legend { grid-template-columns: 1fr; }
}
