:root {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  color: #25372b;
  background: #f5f8f4;
  --editor-width: 45%;
  --code-line: 23px;
  --code-size: 13px;
  --header-height: 48px;
  --toolbar-height: 46px;
  --accent: #37634a;
  --accent-hover: #2c533d;
  --pastel: #e4efe6;
  --panel: #f4f8f3;
  --line: #d1ddd1;
  --muted: #647367;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer;
  background: #fff;
  border: 1px solid #bfcebf;
  border-radius: 4px;
  padding: 5px 11px;
  line-height: 18px;
}
button:hover { background: #edf4ed; border-color: #a4bba8; }
button:disabled { color: #87958a; cursor: default; background: #f8faf7; border-color: #dce4d9; }
button:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
label { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
input[type=checkbox] { accent-color: var(--accent); margin: 0; }
select { background: white; border: 1px solid #c3d1c2; border-radius: 3px; padding: 4px 7px; max-width: 240px; }
a { color: var(--accent); text-underline-offset: 3px; }

.project-header {
  height: var(--header-height);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  background: var(--pastel);
  border-bottom: 1px solid #c5d7c7;
  gap: 16px;
}
.project-name { font-size: 16px; font-weight: 600; color: #284732; white-space: nowrap; }
.about-button { background: transparent; border-color: transparent; font-size: 12px; padding: 5px 8px; color: #45664f; }
.about-button:hover { background: #d8e8db; border-color: transparent; }
.toolbar {
  height: var(--toolbar-height);
  padding: 7px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: #f5f9f3;
  gap: 16px;
}
.file-actions, .run-actions { display: flex; align-items: center; gap: 7px; }
.file-actions button { background: none; border-color: transparent; }
.file-actions button:hover { background: #e7f0e5; border-color: #d1dfcf; }
.run-actions { gap: 16px; }
.run-actions label { font-size: 12px; color: #516654; }
.compile-button { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; min-width: 87px; }
.compile-button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.compile-button:disabled { background: #e3ede1; border-color: #cbdac8; color: #6a7f6c; }
#engine-status { font-size: 11px; color: var(--muted); min-width: 115px; text-align: right; }
#engine-status.error { color: #a32121; }

#workbench { display: flex; height: calc(100dvh - var(--header-height) - var(--toolbar-height)); min-height: 540px; }
.editor-panel { width: var(--editor-width); min-width: 250px; display: flex; flex-direction: column; overflow: hidden; background: #fff; }
.panel-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 37px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  font-size: 12px;
  flex-shrink: 0;
}
.file-bar { height: 39px; gap: 6px; background: #edf4ed; }
#file-name {
  font-family: Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  border: 0;
  border-bottom: 2px solid #7ca186;
  border-radius: 0;
  background: none;
  padding: 3px 1px;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
#file-name-input { border: 1px solid #75927a; border-radius: 2px; padding: 2px 5px; font-family: Menlo, Consolas, monospace; min-width: 180px; max-width: 65%; }
#modified-indicator { color: #66866b; }
#rename-error { font-size: 11px; color: #a32121; }
.editor-area { position: relative; flex: 1; min-height: 190px; overflow: hidden; }
#syntax, #code {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 17px 16px 60px 54px;
  font-family: Menlo, Consolas, "Liberation Mono", monospace;
  font-size: var(--code-size);
  line-height: var(--code-line);
  letter-spacing: 0;
  tab-size: 2;
  white-space: pre;
  resize: none;
  background: transparent;
}
#syntax { overflow: hidden; pointer-events: none; color: #222; }
#code { color: transparent; caret-color: #20392a; outline: none; overflow: auto; z-index: 1; }
#code::selection { background: #b5d4bf70; color: transparent; }
.code-line { display: block; min-height: var(--code-line); position: relative; min-width: 100%; width: max-content; padding-right: 20px; }
.line-number { position: absolute; left: -42px; top: 0; width: 25px; text-align: right; font-size: 11px; color: #879788; user-select: none; }
.active-line { background: #eaf2e8; box-shadow: -5px 0 #eaf2e8; }
.problem-line { background: #ffeded; }
.token-keyword { color: #75309b; }
.token-tactic { color: #215991; }
.token-comment { color: #73806b; }
.token-hole { color: #b51f1f; background: #ffebeb; }
.token-type { color: #805c20; }
.token-string { color: #26742a; }
.editor-status { height: 27px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; border-top: 1px solid #e0e8dc; font-size: 11px; color: var(--muted); flex-shrink: 0; background: #fafcf8; }
.output-panel { height: 215px; min-height: 130px; border-top: 1px solid #bccfbe; display: flex; flex-direction: column; resize: vertical; overflow: auto; background: #fff; }
.output-panel .panel-bar { min-height: 34px; }
.output-panel .panel-bar span:first-child { font-weight: 600; }
.output-panel .panel-bar span:last-child { margin-left: auto; color: var(--muted); font-size: 11px; }
#output-summary.error { color: #b91c1c; font-weight: 600; }
#output { overflow: auto; flex: 1; padding: 12px 14px; font-family: Menlo, Consolas, "Liberation Mono", monospace; font-size: 12px; line-height: 19px; }
#output p { margin: 0 0 8px; }
#output pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.output-entry { border: 0; border-left: 2px solid #999; padding: 4px 8px; margin: 0 0 9px; display: block; width: 100%; text-align: left; background: transparent; border-radius: 0; font: inherit; }
.output-entry:hover { background: #f6f9f4; }
.output-entry.error { border-color: #b32424; color: #9a1e1e; }
.output-entry.warning { border-color: #ad761c; color: #80560f; }
.output-entry.info { border-color: #67829e; color: #253e58; }
.output-location { display: block; color: #68786d; font-family: Arial, Helvetica, sans-serif; font-size: 11px; margin-bottom: 3px; }
.muted { color: var(--muted); font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px; }
#resize-handle { width: 5px; background: #eaf1e7; border-left: 1px solid #bacdbd; border-right: 1px solid #d4e0d0; cursor: col-resize; flex-shrink: 0; }
#resize-handle:hover { background: #a2bea8; }

.graph-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; background: #fff; }
.graph-bar { min-height: 39px; height: auto; flex-wrap: wrap; gap: 6px 8px; }
.graph-bar > span:first-child { font-weight: 600; }
.graph-bar select { min-width: 80px; flex: 0 1 200px; font-family: Menlo, Consolas, monospace; font-size: 11px; border-color: #ccd8c8; }

.graph-files { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; margin-left: auto; }
.graph-files button { font-size: 11px; padding: 2px 6px; }
.graph-legend { display: flex; align-items: baseline; gap: 13px; flex-shrink: 0; padding: 9px 14px; border-bottom: 1px solid #e2eade; background: #fcfdfb; }
.legend-heading { font-size: 11px; color: #647367; line-height: 21px; }
#legend-items { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 12px; list-style: none; padding: 0; margin: 0; }
#legend-items li { display: inline-flex; align-items: center; gap: 4px; color: #536256; font-size: 11px; line-height: 21px; white-space: nowrap; }
#legend-items svg { flex-shrink: 0; }
.graph-container { position: relative; flex: 1; min-height: 180px; background: white; overflow: hidden; }
#graph-viewport { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; cursor: grab; }
#graph-viewport.panning { cursor: grabbing; user-select: none; }
#graph-space { position: relative; min-width: 100%; min-height: 100%; }
#graph-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; padding: 0; }
#graph-stage svg { display: block; overflow: visible; }
#graph-stage g.node { cursor: grab; touch-action: none; }
#graph-stage svg.node-dragging { user-select: none; }
#graph-stage g.node.dragging { cursor: grabbing; }
#graph-stage g.node.selected > polygon, #graph-stage g.node.selected > ellipse, #graph-stage g.node.selected > path, #graph-stage g.node.selected > rect,
#graph-stage g.node:focus-visible > polygon, #graph-stage g.node:focus-visible > ellipse, #graph-stage g.node:focus-visible > path, #graph-stage g.node:focus-visible > rect { stroke: #285c42; stroke-width: 2.5; }
#graph-stage g.node:focus { outline: none; }
#graph-stage g.node:hover > polygon, #graph-stage g.node:hover > ellipse, #graph-stage g.node:hover > path, #graph-stage g.node:hover > rect { stroke-width: 2; }
#graph-stage g.node text { user-select: none; }
.empty-state { position: absolute; inset: 0; margin: 0; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; font-size: 12px; color: #7a897c; line-height: 20px; pointer-events: none; }
.graph-statusbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; min-height: 46px; border-top: 1px solid #e1e9dc; padding: 3px 10px 3px 14px; font-size: 11px; color: var(--muted); gap: 8px; flex-shrink: 0; background: #fafcf8; }
.zoom-controls { display: flex; gap: 3px; align-items: center; margin-left: auto; }
.zoom-controls button { font-size: 11px; border-color: transparent; padding: 1px 7px; min-width: 23px; background: transparent; }
.zoom-controls button:hover { border-color: #ccdbc8; background: #edf3e9; }
#zoom-level { min-width: 43px; }
.inspector { height: 215px; min-height: 150px; border-top: 1px solid #bccfbe; display: flex; flex-direction: column; flex-shrink: 0; }
.inspector-bar { padding: 0 14px; min-height: 36px; justify-content: space-between; }
.inspector-bar [role=tablist] { display: flex; align-self: stretch; gap: 18px; }
.inspector-bar [role=tab] { border: 0; border-bottom: 2px solid transparent; padding: 8px 0 6px; border-radius: 0; background: none; font-size: 12px; color: #647367; }
.inspector-bar [aria-selected=true] { border-bottom-color: #60876a; color: #2f513b; font-weight: 600; }
#selected-location { font-size: 11px; color: var(--muted); white-space: nowrap; }
#inspector-content { padding: 14px; overflow: auto; font-size: 12px; line-height: 19px; }
#inspector-content p { margin: 0 0 8px; }
#inspector-content h2 { font-size: 13px; margin: 0 0 7px; font-weight: 600; }
#inspector-content pre { font-family: Menlo, Consolas, "Liberation Mono", monospace; font-size: 12px; line-height: 20px; white-space: pre-wrap; margin: 0; overflow-wrap: anywhere; }
.state-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.state-heading { font-size: 12px; margin-bottom: 7px; color: var(--muted); }
.state-code { border-left: 2px solid #d5e1d0; padding-left: 9px; }
.source-button { font-size: 11px; margin-top: 5px; padding: 2px 7px; }
.error-detail { color: #9a1e1e; margin-top: 10px !important; }

#about-dialog { border: 1px solid #a7c0ac; border-radius: 6px; padding: 0; width: min(650px, calc(100vw - 32px)); max-height: 86dvh; overflow: auto; overscroll-behavior: contain; background: #fff; color: #2c3b30; }
#about-dialog::backdrop { background: rgb(29 47 34 / 25%); }
.about-header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 22px; border-bottom: 1px solid #cfdfcf; background: var(--pastel); }
.about-header h1 { font-size: 18px; font-weight: 600; margin: 0; line-height: 25px; }
.about-header button { font-size: 12px; padding: 3px 10px; }
.about-content { padding: 5px 24px 22px; font-size: 13px; line-height: 21px; }
.about-content h2 { font-size: 14px; font-weight: 600; margin: 22px 0 8px; color: #355b40; }
.about-content p { margin: 14px 0; }
.about-content ol { padding-left: 20px; margin: 10px 0; }
.about-content li { padding-left: 3px; margin: 9px 0; }
.about-content code { font-family: Menlo, Consolas, monospace; font-size: 12px; background: #f0f5ed; border-radius: 2px; padding: 1px 3px; }
.about-content kbd { font-family: inherit; font-size: 11px; border: 1px solid #c9d7c6; border-radius: 3px; background: #f8faf6; padding: 1px 4px; }
.about-content .about-note { font-size: 12px; color: #657567; border-top: 1px solid #e0e9da; padding-top: 14px; margin-bottom: 0; }
.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; }
#notice { position: fixed; bottom: 15px; left: 50%; transform: translateX(-50%); border: 1px solid #b6cbb9; border-radius: 4px; background: #f5faf2; padding: 9px 15px; font-size: 12px; max-width: 90vw; z-index: 20; }
[hidden] { display: none !important; }

.graph-edit-hint { margin: 0; padding: 5px 14px 8px; font-size: 11px; color: var(--muted); border-bottom: 1px solid #e0e9da; }
#graph-stage g.edge[role=button] { cursor: pointer; }
#graph-stage g.edge:focus { outline: none; }
#graph-stage g.edge:hover path:not(.edge-hit), #graph-stage g.edge:focus path:not(.edge-hit) { stroke: #437643; stroke-width: 2.5; }
#graph-stage .edge-hit { stroke: transparent; stroke-width: 18; fill: none; pointer-events: stroke; }
/* Actions stay inside the graph rather than opening a modal. */
.graph-container { position: relative; }
.graph-tools { position: absolute; z-index: 12; width: min(330px, calc(100% - 16px)); max-height: calc(100% - 16px); overflow: auto; overscroll-behavior: contain; border: 1px solid #a9c2ad; border-radius: 9px; background: #fff; box-shadow: 0 6px 24px rgb(31 60 40 / 16%); color: #28452f; font-size: 12px; }
.graph-tools-header { display: flex; align-items: center; gap: 7px; padding: 9px 10px; background: #edf5e9; position: sticky; top: 0; z-index: 1; border-bottom: 1px solid #dbe8d7; }
.graph-tools-header h2 { flex: 1; margin: 0; font-size: 13px; font-weight: 600; }
.graph-tools-header button { border: 0; padding: 1px 7px; font-size: 20px; background: transparent; }
#graph-tools-goal { margin: 0; padding: 9px 11px; max-height: 100px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 11px/17px Menlo, Consolas, monospace; background: #fbfdf9; border-bottom: 1px solid #e6eee2; }
#graph-action-search { box-sizing: border-box; width: calc(100% - 18px); margin: 9px; padding: 7px 9px; border: 1px solid #c3d5be; border-radius: 5px; font: inherit; background: #fff; }
#hole-choice-label { display: block; padding: 0 10px 7px; font-size: 11px; }
#hole-choice { max-width: 100%; margin-left: 6px; font-size: 11px; }
#graph-action-list, #graph-context-list { max-height: 270px; overflow-y: auto; overscroll-behavior: contain; padding: 3px 5px 6px; }
.graph-action { display: flex; flex-direction: column; gap: 3px; width: 100%; padding: 8px; margin: 1px 0; border: 0; border-radius: 4px; background: transparent; text-align: left; color: #2e4b35; font: inherit; }
.graph-action:hover, .graph-action:focus-visible { background: #eaf4e5; }
.graph-action strong { font-size: 12px; font-weight: 600; }
.graph-action span { color: #6a7d67; font-size: 11px; line-height: 15px; }
.graph-action-heading { padding: 7px 8px 3px; font-size: 10px; color: #70816d; text-transform: uppercase; letter-spacing: .05em; }
#graph-tool-form { padding: 10px; }
#graph-tool-fields label { display: block; margin: 7px 0 4px; font-size: 11px; font-weight: 600; }
#graph-tool-fields input, #graph-tool-fields textarea { box-sizing: border-box; width: 100%; padding: 7px; border: 1px solid #bfd2b9; border-radius: 4px; background: #fcfefb; color: #263e2b; font: 12px/19px Menlo, Consolas, monospace; }
#graph-tool-fields textarea { min-height: 65px; resize: vertical; }
#graph-tool-apply { margin-top: 10px; width: 100%; }
#graph-tool-preview { margin-top: 9px; color: #60735a; font-size: 11px; }
#graph-tool-code { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 11px/17px Menlo, Consolas, monospace; background: #f2f8ee; padding: 7px; max-height: 180px; overflow: auto; }
#graph-tools-error { color: #a22d2d; margin: 8px 11px 11px; font-size: 11px; line-height: 17px; }
#graph-mode-bar { position: absolute; z-index: 9; top: 8px; left: 8px; right: 8px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid #abc6a5; border-radius: 6px; background: #f0f8ea; padding: 7px 10px; font-size: 12px; box-shadow: 0 2px 8px rgb(31 60 40 / 8%); }
#graph-mode-bar button { font-size: 11px; padding: 2px 7px; }
.graph-draft-card { position: absolute; z-index: 10; width: 240px; max-width: calc(100% - 24px); padding: 10px; border: 2px dashed #a6bc9c; border-radius: 6px; background: #fcfff8; box-shadow: 0 4px 12px rgb(31 60 40 / 10%); font-size: 11px; pointer-events: auto; }
.graph-draft-card header { display: flex; align-items: center; justify-content: space-between; color: #607954; }
.graph-draft-card header button { padding: 0 5px; border: 0; background: none; font-size: 18px; }
.graph-draft-card pre { white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/19px Menlo, Consolas, monospace; margin: 7px 0; max-height: 100px; overflow: auto; }
.graph-draft-card p { color: #74866a; margin: 5px 0 0; font-size: 11px; }
.graph-history { display: flex; gap: 5px; align-items: center; min-width: 0; }
.graph-history button { font-size: 14px; font-weight: 600; min-height: 33px; padding: 6px 10px; color: #fff; background: var(--accent); border-color: var(--accent); }
.graph-history button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.graph-history button:disabled { color: #526a55; background: #dce9d9; border-color: #c2d4bd; }
.graph-history #renderer-status { padding-left: 4px; font-size: 10px; }
#graph-stage g.node.connect-target > path, #graph-stage g.node.connect-target > polygon, #graph-stage g.node.connect-target > ellipse, #graph-stage g.node.connect-target > rect { stroke: #3c7f47; stroke-width: 2.5; stroke-dasharray: 5 3; }
#graph-stage.choosing-target g.node { cursor: crosshair; }
@media (max-width: 1050px) { .graph-history #renderer-status { display: none; } }

@media (max-width: 1050px) {

  .graph-files { gap: 3px; }
  .graph-files button { padding: 2px 5px; }
  .graph-bar select { max-width: 180px; }
  .inspector-bar [role=tablist] { gap: 12px; }
  .inspector-bar [role=tab] { font-size: 11px; }
  #engine-status { min-width: 95px; }
  .graph-legend { padding-left: 10px; padding-right: 10px; gap: 10px; }
  #legend-items { gap: 4px 10px; }
}
@media (max-width: 720px) {
  .project-header { min-height: var(--header-height); height: auto; padding: 10px 12px; flex-wrap: wrap; gap: 4px 10px; }
  .project-name { font-size: 15px; }
  .about-button { font-size: 11px; padding: 3px 0; }
  .toolbar { padding: 7px 9px; height: auto; min-height: var(--toolbar-height); gap: 7px; flex-wrap: wrap; }
  .run-actions { gap: 10px; }
  .run-actions label { font-size: 11px; }
  #engine-status { min-width: 0; }
  .file-actions { gap: 0; }
  .file-actions button { padding: 4px 7px; }
  #workbench { height: auto; min-height: calc(100dvh - var(--header-height) - var(--toolbar-height)); flex-direction: column; }
  .editor-panel { width: 100% !important; height: 650px; min-width: 0; }
  .output-panel { height: 190px; }
  #resize-handle { display: none; }
  .graph-panel { height: 840px; }
  .graph-container { min-height: 300px; }

  .graph-files { margin-left: auto; }
  .inspector { height: 230px; }
  .inspector-bar [role=tab] { font-size: 12px; }
  .graph-bar select { max-width: 50vw; }
  .state-grid { grid-template-columns: 1fr; }
  #rename-error { max-width: 35%; font-size: 10px; }
  #code, #syntax { font-size: 14px; }
  #notice { width: max-content; }
  .about-header { padding: 13px 16px; }
  .about-header h1 { font-size: 17px; }
  .about-content { padding: 4px 18px 18px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
