/*
 * The editor's layout. The shared look (tokens, controls, menus, tool tab)
 * is in base.css.
 */
body {
	display: grid;
	grid-template-columns: 276px minmax(0, 1fr) 288px;
	grid-template-rows: 44px 40px minmax(0, 1fr) 150px;
	grid-template-areas:
		"top top top"
		"font opts glyph"
		"font canvas glyph"
		"font preview glyph";
}

/* left: font panel */
#font-panel { grid-area: font; display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.font-picker { display: flex; flex-direction: column; gap: 6px; padding: 12px 12px 10px; border-bottom: 1px solid var(--line); }
#font-select { width: 100%; font-weight: 600; font-size: 14px; padding: 6px 8px; }
.inline-row { display: flex; align-items: center; gap: 6px; }
.inline-row select { padding: 2px 4px; font-size: 12px; font-family: 'IBM Plex Mono', monospace; }
.inline-row .switch-label { margin-left: auto; font-size: 12px; }
#font-panel > .panel-heading { padding: 12px 12px 8px; }
#glyph-grid {
	flex: 1; overflow-y: auto; padding: 0 12px 8px;
	display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; align-content: start;
}
.glyph-cell {
	position: relative; height: 60px; padding: 0; color: var(--ink); background: var(--canvas);
	border: 1px solid var(--line); border-radius: 4px; overflow: hidden;
}
.glyph-cell:hover { border-color: var(--muted); }
.glyph-cell.current { border: 2px solid var(--accent); color: var(--select); }
.glyph-cell.missing { background: var(--missing); }
.glyph-cell svg { position: absolute; inset: 4px 4px 14px 4px; width: calc(100% - 8px); height: calc(100% - 18px); }
.glyph-cell .label {
	position: absolute; left: 0; right: 0; bottom: 2px; font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: #7b7d83;
	text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px;
}
.glyph-cell.current .label { color: var(--accent); }
/* the scratch pad: a full row at the top of the grid */
.glyph-cell.scratch-cell { grid-column: 1 / -1; height: 52px; border-style: dashed; }
.glyph-cell.scratch-cell.current { border-style: solid; }
.glyph-cell.scratch-cell.empty .label { top: 50%; bottom: auto; transform: translateY(-50%); font-size: 11px; color: var(--muted); font-family: 'IBM Plex Sans', sans-serif; }
.glyph-cell.scratch-cell.empty { background: var(--canvas); opacity: 0.75; }
.glyph-cell.missing .label { color: var(--muted); bottom: auto; top: 50%; transform: translateY(-50%); font-size: 13px; }
#add-glyph { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); }
#add-glyph input { flex: 1; min-width: 0; }
#add-glyph button { width: 30px; padding: 0; }

/* options bar */
#optionsbar {
	grid-area: opts; display: flex; align-items: center; gap: 16px; padding: 0 14px; min-width: 0;
	background: var(--panel-2); color: var(--muted); overflow: hidden;
}
#shape-options { display: flex; align-items: center; }
.snap-group { display: flex; align-items: center; gap: 12px; }
#shape-options[hidden] { display: none; }
#cursor-pos { margin-left: auto; font-family: 'IBM Plex Mono', monospace; font-size: 12px; white-space: nowrap; }

/* canvas */
#canvas-wrap { grid-area: canvas; outline: none; position: relative; min-width: 0; min-height: 0; background: var(--canvas); overflow: hidden; }
#editor-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#canvas-wrap.tool-pen, #canvas-wrap.tool-shape, #canvas-wrap.tool-scissors { cursor: crosshair; }
#canvas-wrap.panning { cursor: grab; }


/* preview */
#preview-bar { grid-area: preview; display: flex; flex-direction: column; min-width: 0; background: var(--panel-2); }
.preview-controls { display: flex; gap: 12px; align-items: center; padding: 8px 14px; }
.panel-heading.inline { white-space: nowrap; }
.preview-controls input:not([type]) { flex: 1; min-width: 0; }
#preview { flex: 1; min-height: 0; margin: 0 14px 12px; padding: 6px 14px; background: var(--canvas); color: var(--ink); border-radius: 3px; overflow: hidden; }
#preview svg { display: block; max-width: none; overflow: visible; }
#optionsbar .zoom-group { flex: none; }
#cursor-pos { min-width: 90px; text-align: right; }
#preview g[data-ch] { cursor: pointer; }
#preview g[data-ch]:hover path { stroke: var(--select); }
#preview g.current path { stroke: var(--select); }
#preview g.kern-pick path { stroke: var(--bearing); }
#preview-sample { max-width: 190px; font-size: 12px; padding: 3px 6px; }
.specimen-only { display: none !important; }
#preview-expand { display: flex; align-items: center; gap: 6px; padding: 4px 10px; font-size: 12px; white-space: nowrap; }
#preview-expand svg { width: 14px; height: 14px; flex: none; }
#preview-expand .icon-collapse, #preview-expand .label-collapse { display: none; }

/* specimen view: the preview grows up over the canvas */
body.specimen #preview-bar { grid-row: 2 / 5; grid-column: 2; z-index: 5; }
body.specimen .specimen-only { display: flex !important; }
body.specimen #preview { overflow: hidden; padding: 0; cursor: grab; touch-action: none; }
body.specimen #preview svg { width: 100%; height: 100%; }
body.specimen #preview.panning, body.specimen #preview.panning g[data-ch] { cursor: grabbing; }
body.specimen #preview-expand .icon-expand, body.specimen #preview-expand .label-expand { display: none; }
body.specimen #preview-expand .icon-collapse { display: block; }
body.specimen #preview-expand .label-collapse { display: inline; }
body.specimen #preview-expand { border-color: var(--accent); color: var(--accent); }
body.sliding { overflow: hidden; }
body.sliding #preview-bar { box-shadow: 0 -8px 24px var(--shadow); }

.status-row { display: flex; align-items: center; gap: 8px; }
.status-row select { flex: 1; min-width: 0; font-size: 12px; padding: 3px 6px; }
#font-revision { white-space: nowrap; }

.align-grid { margin-top: 2px; }
#align-buttons { grid-template-columns: repeat(6, minmax(0, 1fr)); }
#align-buttons svg { width: 16px; height: 16px; }
#align-to { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* New font from shapes */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 28px; background: rgba(8, 9, 11, 0.6); }
.modal[hidden] { display: none; }
.modal-box {
	width: min(1240px, 100%); height: min(820px, 100%); display: flex; flex-direction: column; overflow: hidden;
	background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px; box-shadow: 0 24px 60px var(--shadow);
}
.modal-head, .modal-foot { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel-2); }
.modal-head { border-bottom: 1px solid var(--line); }
.modal-foot { border-top: 1px solid var(--line); }
#si-title, .modal-title { font-size: 15px; font-weight: 600; }
.modal-box.modal-small { width: min(480px, 100%); height: auto; }
.modal-text { margin: 0; padding: 16px; line-height: 1.5; }
.si-bar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
#si-hint.note { color: var(--text); }
.si-warnings { margin: 0; padding: 6px 16px; font-size: 12px; color: var(--danger); border-bottom: 1px solid var(--line); }
.si-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
#si-tiles { overflow-y: auto; padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, 92px); gap: 8px; align-content: start; justify-content: start; }
.si-group { grid-column: 1 / -1; margin-top: 6px; }
.si-group:first-child { margin-top: 0; }
.si-tile { width: 92px; padding: 5px; border: 1px solid var(--line-2); border-radius: 5px; background: var(--panel-2); cursor: pointer; user-select: none; }
.si-tile svg { display: block; margin: 0 auto; background: var(--canvas); color: var(--ink); border-radius: 3px; }
.si-tile.selected { border: 2px solid var(--accent); padding: 4px; }
.si-tile.picked { box-shadow: 0 0 0 2px var(--accent-soft); border-color: var(--accent); }
.si-tile.skipped { opacity: 0.5; }
.si-caption { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 2px 0; }
.si-num { font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: var(--muted); }
.si-char { font-family: 'IBM Plex Mono', monospace; font-size: 13px; color: var(--muted); max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.si-tile.named .si-char { color: var(--text); font-weight: 500; }
.si-baseline { stroke: var(--bearing); stroke-width: 1; stroke-dasharray: 3 3; }
.si-baseline-grab { stroke: transparent; stroke-width: 9; cursor: ns-resize; }
.si-side { border-left: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.si-side section { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.si-side .field input:not([type]) { text-align: left; font-size: 13px; }
.si-name-form { display: flex; gap: 6px; }
.si-name-form input { flex: 1; min-width: 0; }
#si-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(26px, 1fr)); gap: 3px; }
.si-map-cell { height: 26px; padding: 0; font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
.si-map-cell.filled { color: var(--text); border-color: var(--ok, #3ec99a); background: var(--panel-2); }
.si-map-cell.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* right: glyph panel */
#glyph-panel { grid-area: glyph; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; background: var(--panel); }
#glyph-panel section { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
#glyph-panel details.fold { padding: 12px 16px 14px; }
.sub-heading { font-size: 11px; font-weight: 500; color: var(--muted); margin-top: 14px !important; }
.glyph-head { flex-direction: row !important; align-items: center; gap: 14px !important; }
#glyph-big { flex: 0 0 auto; width: 64px; height: 76px; border-radius: 4px; background: var(--canvas); color: var(--ink); position: relative; }
#glyph-big svg { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); }
.glyph-ident { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
#glyph-title { margin: 0; font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }
.style-grid { display: grid; grid-template-columns: 54px minmax(0, 1fr); align-items: center; gap: 8px; }
#path-style-row.disabled .style-grid { opacity: .5; }
#pos-size[hidden] { display: none; }
#position-row .field:has(input:disabled) { opacity: .5; }
#position-row .panel-heading .hint { margin-left: 4px; }
#path-style-row.disabled > summary::after { content: ' · none selected'; text-transform: none; letter-spacing: 0; font-weight: 400; }
.kern-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) 28px; align-items: center; gap: 6px; }
.kern-row .pair { font-family: 'IBM Plex Mono', monospace; font-weight: 500; font-size: 14px; }
.kern-row button { padding: 0; height: 28px; color: var(--muted); }
/* custom guides: full-width rows under the built-in guides */
#custom-guides { display: flex; flex-direction: column; gap: 4px; }
#custom-guides:empty { display: none; }
.guide-row { display: grid; grid-template-columns: 30px auto minmax(0, 1fr) 28px; align-items: center; gap: 6px; padding: 3px 0 3px 6px; border-left: 3px solid var(--guide-color); border-radius: 2px; background: var(--surface); }
.guide-row .guide-name { font-family: 'IBM Plex Mono', monospace; font-weight: 500; font-size: 13px; color: var(--guide-color); }
.guide-row .segmented { background: var(--panel-2); }
.guide-row .segmented button { padding: 2px 8px; }
.guide-row > button { padding: 0; height: 26px; color: var(--muted); border: 0; background: none; }
.guide-row > button:hover { color: var(--danger); }
#add-guide { width: 100%; height: 28px; padding: 0; font-size: 12px; color: var(--muted); border-style: dashed; background: none; }
#add-guide:hover { color: var(--text); }
#kerning-list { display: flex; flex-direction: column; gap: 4px; }
#kerning-list:empty { display: none; }
#add-kern { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 6px; }
#add-kern input { min-width: 0; }
#glyph-panel .hint { margin: 0; line-height: 1.5; }
#stroke-order .switch-label { font-size: 12px; }
.glyph-actions { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.glyph-actions button { flex: 1; font-size: 12px; padding: 6px 0; }
