/*
 * Shared look for the gregfont pages ("Graphite"): colour tokens for both
 * themes, and the common pieces (buttons, fields, switches, menus, the top
 * bar, the tool tab, foldable sections). The canvas colours are read by
 * the pages' scripts for drawing, so every canvas colour lives here too.
 * Two themes: dark panels around a light canvas, or light panels around a
 * dark canvas. (The typesetter overrides this: its canvas and page follow
 * the panels, see typesetter.css.)
 */
:root,
:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #16171a;
	--panel: #1d1e22;
	--panel-2: #222327;
	--surface: #2a2b30;
	--line: #2c2d32;
	--line-2: #393a41;
	--text: #ececee;
	--muted: #a2a4aa;
	--accent: #5b95ff;
	--on-accent: #0b1220;
	--accent-soft: rgba(91, 149, 255, 0.16);
	--danger: #ef7a7a;
	--shadow: rgba(0, 0, 0, 0.45);

	/* the canvas side: light */
	--canvas: #f3f3f1;
	--canvas-grid: #e3e3e0;
	--canvas-grid-major: #d1d1cd;
	--canvas-cell: rgba(0, 0, 0, 0.1);
	--ink: #141414;
	--guide-cap: #2f6fd0;
	--guide-xh: #127a58;
	--guide-base: #b05f00;
	--guide-desc: #7a3a95;
	--guide-a: #0e8fa3;
	--guide-b: #a68a00;
	--guide-c: #c0392b;
	--guide-d: #6b7d1a;
	--guide-e: #8a5a2b;
	--guide-f: #5a6b8c;
	--bearing: #c2286a;
	--snap: #e8590c;   /* the path a point is snapping onto */
	--select: #2f6fe0;
	--order-start: #15803d;
	--order-end: #be123c;
	--order-travel: #8a8c93;
	--missing: #2a2b30;
}

:root[data-theme="light"] {
	color-scheme: light;
	--bg: #ffffff;
	--panel: #f6f6f7;
	--panel-2: #efeff1;
	--surface: #ffffff;
	--line: #e3e3e6;
	--line-2: #d4d4d9;
	--text: #18181b;
	--muted: #5b5d64;
	--accent: #2f6fe0;
	--on-accent: #ffffff;
	--accent-soft: rgba(47, 111, 224, 0.12);
	--danger: #c43c3c;
	--shadow: rgba(24, 24, 27, 0.16);

	/* the canvas side: dark */
	--canvas: #1a1b1f;
	--canvas-grid: #25262b;
	--canvas-grid-major: #31323a;
	--canvas-cell: rgba(255, 255, 255, 0.08);
	--ink: #f2f2ef;
	--guide-cap: #6aa5ff;
	--guide-xh: #3ec99a;
	--guide-base: #ffad42;
	--guide-desc: #c39af0;
	--guide-a: #4fd1e0;
	--guide-b: #e6c84a;
	--guide-c: #ff7a6b;
	--guide-d: #b5cc4a;
	--guide-e: #d9a066;
	--guide-f: #9fb0d6;
	--bearing: #ff5fa2;
	--snap: #ff8a3d;
	--select: #5b95ff;
	--order-start: #22c55e;
	--order-end: #fb7185;
	--order-travel: #8a8c93;
	--missing: #e7e7ea;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }
/* The apps are all controls: a drag that starts a few pixels off a field
   shouldn't highlight labels. Typing places still select normally. */
body { -webkit-user-select: none; user-select: none; }
input, textarea, select { -webkit-user-select: text; user-select: text; }

body {
	background: var(--panel);
	color: var(--text);
	font-family: 'IBM Plex Sans', system-ui, sans-serif;
	font-size: 13px;
	overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }
button {
	background: var(--surface); color: var(--text); border: 1px solid var(--line-2); border-radius: 4px;
	padding: 4px 10px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.danger { background: none; color: var(--danger); }
input, select {
	background: var(--surface); color: var(--text); border: 1px solid var(--line-2); border-radius: 4px; padding: 4px 8px;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=number] { font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.spacer { flex: 1; }

/* zoom controls: - 100% + Fit */
.zoom-group { display: flex; align-items: center; gap: 2px; }
.zoom-group .icon-button { width: 26px; height: 24px; font-size: 15px; line-height: 1; }
.zoom-group .zoom-label { min-width: 54px; padding: 2px 6px; font-family: 'IBM Plex Mono', monospace; font-size: 12px; }
.zoom-group .fit-button { height: 24px; padding: 0 9px; margin-left: 4px; font-size: 12px; }

/* scrollbars: thin, in the panel colours */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--muted); }
::-webkit-scrollbar-corner { background: transparent; }
.meta { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--muted); }
.hint { color: var(--muted); font-size: 11px; font-weight: 400; text-transform: none; letter-spacing: 0; }
.panel-heading { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

/* switches (checkboxes) */
.switch {
	-webkit-appearance: none; appearance: none; position: relative; flex: 0 0 auto;
	width: 26px; height: 15px; margin: 0; padding: 0; border: 0; border-radius: 8px; background: var(--line-2); cursor: pointer;
}
.switch::before {
	content: ''; position: absolute; left: 2px; top: 2px; width: 11px; height: 11px; border-radius: 50%;
	background: var(--muted); transition: transform .12s;
}
.switch:checked { background: var(--accent); }
.switch:checked::before { background: #fff; transform: translateX(11px); }
.switch-label { display: flex; align-items: center; gap: 7px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.switch-label:has(.switch:checked) { color: var(--text); }

/* fields: a label with an input inside; data-scrub ones can be dragged */
.field {
	display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px; min-width: 0;
	background: var(--surface); border: 1px solid var(--line-2); border-radius: 4px;
}
.field input { flex: 1; width: 100%; min-width: 0; height: 100%; padding: 0; background: none; border: 0; outline: none; }
.field input[type=number] { text-align: right; font-size: 12px; }
.field:focus-within { border-color: var(--accent); }
.field-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.field[data-scrub="x"] { cursor: ew-resize; }
.field[data-scrub="y"] { cursor: ns-resize; }
/* a few spare pixels around draggable fields, so a near miss still drags */
.field[data-scrub] { position: relative; isolation: isolate; }
.field[data-scrub]::before { content: ''; position: absolute; inset: -3px; z-index: -1; }   /* under the input */
.field[data-scrub] input:not(:focus) { cursor: inherit; }
.field.scrubbing { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.scrubbing .field-label { color: var(--text); }
.field.compact { height: 26px; width: 92px; }
.field-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.swatch { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 2px; }

/* segmented buttons */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2px; padding: 2px; background: var(--surface); border-radius: 4px; }
.segmented button { border: 0; border-radius: 3px; background: none; padding: 3px 10px; font-size: 12px; color: var(--muted); }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--line-2); color: var(--text); }
.segmented.icons button { height: 26px; padding: 0; display: grid; place-items: center; font-size: 11px; }
.segmented.icons svg { width: 22px; height: 14px; display: block; }
.segmented .mark { stroke: var(--accent); stroke-width: 1; }
.segmented button:disabled { opacity: .4; cursor: default; }

/* top bar */
#topbar {
	grid-area: top; display: flex; align-items: center; gap: 6px; padding: 0 12px;
	background: var(--bg); border-bottom: 1px solid var(--line);
}
#topbar .brand { font-weight: 600; margin-right: 8px; cursor: default; }
#topbar .link { color: var(--accent); text-decoration: none; margin: 0 8px; white-space: nowrap; }
#topbar .link:hover { text-decoration: underline; }
#tip {
	flex: 1; min-width: 0; margin: 0 12px; padding: 4px 8px; background: none; border: 0; border-radius: 4px;
	color: var(--muted); font-size: 12px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
	transition: opacity .25s;
}
#tip:hover { color: var(--text); border: 0; }
#tip.fading { opacity: 0; }
#tip.off { visibility: hidden; }
#status { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; margin-right: 6px; }
#status.error { color: var(--danger); }
.icon-button { width: 32px; height: 30px; padding: 0; display: grid; place-items: center; }
.icon-button svg { width: 16px; height: 16px; }
:root[data-theme="dark"] .icon-moon, :root[data-theme="light"] .icon-sun { display: none; }

/* menus */
#menubar { display: flex; align-self: stretch; align-items: center; }
.menu { position: relative; }
.menu-title { background: none; border: none; border-radius: 4px; padding: 5px 10px; }
.menu-title:hover, .menu.open .menu-title { background: var(--surface); }
.menu-items {
	display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; min-width: 220px; width: max-content;
	background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 0;
	box-shadow: 0 8px 24px var(--shadow);
}
.menu.open .menu-items { display: block; }
.menu-item {
	position: relative; display: flex; justify-content: space-between; gap: 24px; width: 100%; white-space: nowrap;
	background: none; border: none; border-radius: 0; padding: 5px 14px 5px 28px; text-align: left;
}
.menu-item:hover:not(:disabled) { background: var(--accent); color: var(--on-accent); }
.menu-item:hover:not(:disabled) .shortcut { color: inherit; opacity: .8; }
.menu-item:disabled { color: var(--muted); opacity: .55; cursor: default; }
.menu-item .shortcut { color: var(--muted); font-family: 'IBM Plex Mono', monospace; font-size: 12px; }
.menu-item.checked::before { content: '\2713'; position: absolute; left: 10px; }
.menu-sep { height: 1px; background: var(--line); margin: 4px 0; }


/* foldable sections */
details.fold { padding: 10px 12px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; }
details.fold[hidden] { display: none; }
details.fold > :not(summary) + :not(summary) { margin-top: 8px; }
details.fold > summary + * { margin-top: 8px; }
details.fold summary {
	display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; list-style: none;
	font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
details.fold summary::-webkit-details-marker { display: none; }
details.fold summary::before { content: '\25B8'; font-size: 10px; transition: transform .12s; }
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold summary:hover { color: var(--text); }
details.fold summary .hint { margin-left: auto; }
details.fold.sub { padding: 0; border: 0; }
details.fold.sub > summary { font-size: 11px; font-weight: 500; letter-spacing: 0.02em; text-transform: none; }

/* the tool tab: grows out of the left panel over the canvas, with curved fillets top and bottom */
#toolbox {
	position: absolute; left: 0; top: 30px; z-index: 2; display: flex; flex-direction: column; gap: 2px;
	padding: 6px 6px 6px 5px; background: var(--panel); border-radius: 0 12px 12px 0;
}
#toolbox::before, #toolbox::after { content: ''; position: absolute; left: 0; width: 12px; height: 12px; pointer-events: none; }
#toolbox::before { top: -12px; background: radial-gradient(circle at 100% 0, transparent 11.5px, var(--panel) 12px); }
#toolbox::after { bottom: -12px; background: radial-gradient(circle at 100% 100%, transparent 11.5px, var(--panel) 12px); }
.tool { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; background: none; border: 0; border-radius: 6px; color: var(--text); }
.tool svg { width: 18px; height: 18px; display: block; }
.tool:hover { background: var(--surface); }
.tool.active { background: var(--accent); color: var(--on-accent); }

.button-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.button-row button { font-size: 12px; padding: 5px 0; white-space: nowrap; }
