@font-face {
  font-family: "Mojangles";
  src: url("../datapack-builder/assets/mojangles.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #181818;
  --bar: #262626;
  --panel: #222222;
  --panel-2: #292929;
  --panel-3: #303030;
  --input: #242424;
  --line: #393939;
  --line-soft: #303030;
  --text: #e5e5e5;
  --muted: #a5a5a5;
  --faint: #787878;
  --accent: #4c8d2b;
  --accent-strong: #5fa735;
  --accent-soft: #21351a;
  --danger: #d16a5c;
  --danger-bg: #311d1a;
  --warn: #d2a84e;
  --warn-bg: #302716;
  --info: #77a9d8;
  --info-bg: #172332;
  --font-ui: "Mojangles", "Helvetica Neue", sans-serif;
  --font-code: "Cascadia Mono", "Consolas", monospace;
  --header-height: 62px;
  --left-width: 252px;
  --right-width: 326px;
}

* { box-sizing: border-box; }
* { scrollbar-width: thin; scrollbar-color: #555 #1f1f1f; }

html, body { width: 100%; height: 100%; overflow: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 var(--font-ui); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 17px; }
h3 { font-size: 16px; }
small { font-size: 13px; }

.app-shell { width: 100vw; height: 100vh; display: grid; grid-template-rows: var(--header-height) minmax(0, 1fr); }
.app-header {
  display: grid;
  grid-template-columns: minmax(190px, max-content) minmax(110px, 1fr) max-content max-content;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: var(--bar);
  border-bottom: 1px solid #151515;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.brand img { width: 34px; height: 34px; object-fit: contain; image-rendering: pixelated; }
.suite-links, .toolbar, .modal-actions, .section-actions, .inline-actions { display: flex; align-items: center; gap: 8px; }
.suite-links a { color: var(--muted); text-decoration: none; padding: 6px 4px; }
.suite-links a:hover { color: var(--text); text-decoration: underline; text-underline-offset: 4px; }
.save-state { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 14px; }
.save-state.is-saving { color: var(--warn); }
.save-state.is-error { color: var(--danger); }

.button, .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--panel-3);
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}
.button { padding: 7px 12px; }
.icon-button { width: 36px; padding: 0; flex: 0 0 auto; }
.button svg, .icon-button svg, .workflow-nav svg, .template-options svg, .check-item svg { width: 17px; height: 17px; stroke-width: 1.9; }
.button:hover, .icon-button:hover { background: #3a3a3a; border-color: #515151; }
.button:focus-visible, .icon-button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 1px; }
.button:disabled, .icon-button:disabled { opacity: .4; cursor: not-allowed; }
.button-primary { background: var(--accent); border-color: var(--accent-strong); color: #f4ffe8; }
.button-primary:hover { background: var(--accent-strong); }
.button-secondary { background: var(--panel-2); }
.button-danger { background: #9f4338; border-color: var(--danger); color: #fff4f2; }
.button-danger:hover { background: #b64d41; }
.button-plain { background: transparent; border-color: transparent; }

.workspace { min-height: 0; display: grid; grid-template-columns: var(--left-width) minmax(430px, 1fr) var(--right-width); }
.left-panel, .checks-panel { min-height: 0; background: var(--panel); overflow: auto; }
.left-panel { border-right: 1px solid var(--line); }
.checks-panel { border-left: 1px solid var(--line); }
.checks-panel.is-collapsed { width: 48px; overflow: hidden; }
.workspace:has(.checks-panel.is-collapsed) { grid-template-columns: var(--left-width) minmax(430px, 1fr) 48px; }

.project-header { padding: 16px; border-bottom: 1px solid var(--line-soft); }
.project-header label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.project-header input { width: 100%; font-weight: 700; }
.panel-heading { height: 45px; padding: 0 12px 0 16px; display: flex; align-items: center; justify-content: space-between; }
.panel-heading .icon-button { width: 30px; min-height: 30px; }
.quest-list { padding: 0 8px 12px; border-bottom: 1px solid var(--line-soft); }
.quest-list button {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 9px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  background: transparent;
}
.quest-list button:hover { background: var(--panel-2); }
.quest-list button.is-active { background: var(--accent-soft); border-color: #35552a; }
.quest-list strong, .quest-list small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quest-list small { margin-top: 2px; color: var(--muted); }
.quest-health { align-self: center; min-width: 20px; color: var(--muted); text-align: center; font-size: 12px; }
.quest-health.has-errors { color: var(--danger); }
.quest-health.is-valid { color: var(--accent-strong); }

.workflow-nav { padding: 12px 8px; border-bottom: 1px solid var(--line-soft); }
.workflow-nav button {
  width: 100%;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}
.workflow-nav button:hover { color: var(--text); background: var(--panel-2); }
.workflow-nav button.is-active { color: var(--text); background: #303030; box-shadow: inset 3px 0 var(--accent-strong); }
.workflow-nav strong, .workflow-nav small { display: block; }
.workflow-nav strong { font-size: 15px; }
.workflow-nav small { margin-top: 1px; color: var(--faint); }
.workflow-nav button.is-active small { color: var(--muted); }
.stage-shortcuts { padding: 12px 8px 22px; }
.stage-shortcuts:empty { display: none; }
.stage-shortcuts h3 { padding: 4px 8px 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.stage-shortcuts button { width: 100%; padding: 7px 9px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-shortcuts button:hover, .stage-shortcuts button.is-active { background: var(--panel-2); color: var(--text); }
.stage-shortcuts button.is-entry::before { content: "→"; color: var(--accent-strong); margin-right: 7px; }

.editor { min-width: 0; min-height: 0; overflow: auto; background: var(--bg); }
.editor-content { width: min(980px, 100%); margin: 0 auto; padding: 24px 28px 80px; }
.editor-header { min-height: 48px; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.editor-header h1 { font-size: 22px; margin: 0 0 4px; }
.editor-header p { color: var(--muted); }
.section-card { margin-bottom: 16px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.section-card > h2, .section-card-header { margin-bottom: 16px; }
.section-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.section-card-header p { margin-top: 3px; color: var(--muted); font-size: 14px; }
.section-card.is-danger { border-color: #744039; }
.subsection { padding-top: 16px; margin-top: 18px; border-top: 1px solid var(--line-soft); }
.subsection h3 { margin-bottom: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; }
.field { grid-column: span 6; min-width: 0; }
.field.span-3 { grid-column: span 3; }
.field.span-4 { grid-column: span 4; }
.field.span-8 { grid-column: span 8; }
.field.full { grid-column: 1 / -1; }
.field label, .field-label { display: block; margin-bottom: 6px; color: #d5d5d5; font-size: 14px; font-weight: 700; }
.field-help { display: block; margin-top: 5px; color: var(--muted); font-size: 13px; font-weight: 400; }
input, select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--input);
  border: 1px solid #454545;
  border-radius: 6px;
}
textarea { min-height: 92px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #727272; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); background: #2c211f; }
.field-error { margin-top: 5px; color: var(--danger); font-size: 13px; }
.checkbox-field { display: flex; gap: 9px; align-items: flex-start; min-height: 38px; padding-top: 8px; }
.checkbox-field input { width: 16px; min-height: 16px; margin: 2px 0 0; accent-color: var(--accent-strong); }
.checkbox-field span { color: var(--muted); font-size: 14px; }
.checkbox-field strong { display: block; color: var(--text); margin-bottom: 2px; }

.graph-card { padding: 0; overflow: hidden; }
.graph-toolbar { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px 8px 18px; border-bottom: 1px solid var(--line); }
.graph-toolbar span { color: var(--muted); font-size: 14px; }
.graph-scroll { overflow: auto; }
.quest-graph { position: relative; min-width: 620px; min-height: 230px; padding: 28px; display: grid; grid-template-columns: repeat(4, minmax(142px, 1fr)); grid-auto-rows: minmax(92px, auto); gap: 48px 56px; align-items: center; }
.graph-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.graph-lines path { fill: none; stroke: #626262; stroke-width: 2; }
.graph-lines path.is-branch { stroke: var(--warn); stroke-dasharray: 5 4; }
.graph-node { position: relative; z-index: 2; min-height: 82px; padding: 11px; border: 1px solid #4a4a4a; border-radius: 7px; color: var(--text); background: #2a2a2a; text-align: left; }
.graph-node:hover { border-color: #696969; background: #303030; }
.graph-node.is-active { border-color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--accent-strong); }
.graph-node.is-entry::after { content: "Entry"; position: absolute; top: -10px; right: 8px; padding: 1px 5px; border: 1px solid #426c31; border-radius: 4px; background: #21351a; color: #b9dc9f; font-size: 11px; }
.graph-node strong, .graph-node span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.graph-node span { margin-top: 4px; color: var(--muted); font-size: 13px; }
.graph-node .node-status { margin-top: 7px; color: var(--faint); font-size: 12px; }

.objective-list, .response-list { display: grid; gap: 12px; }
.objective-card, .response-row { padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: #242424; }
.objective-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.objective-number { color: var(--muted); font-size: 13px; }
.remove-button { color: var(--muted); }
.remove-button:hover { color: #ffe7e3; border-color: #734038; background: var(--danger-bg); }
.empty-state { padding: 26px; border: 1px dashed #494949; border-radius: 7px; text-align: center; color: var(--muted); }
.empty-state p { margin-bottom: 12px; }

.dialogue-layout { display: grid; grid-template-columns: 185px minmax(0, 1fr); gap: 16px; }
.slot-list { display: flex; flex-direction: column; gap: 6px; }
.slot-list button { padding: 9px 10px; border: 1px solid transparent; border-radius: 6px; color: var(--muted); background: transparent; text-align: left; }
.slot-list button:hover { background: var(--panel-2); color: var(--text); }
.slot-list button.is-active { border-color: var(--line); background: var(--panel-3); color: var(--text); }
.slot-list button.is-configured::after { content: "Configured"; display: block; margin-top: 2px; color: var(--accent-strong); font-size: 11px; }
.dialogue-editor { min-width: 0; }
.slot-enable { padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: #242424; }
.response-row { display: grid; grid-template-columns: minmax(120px, .7fr) minmax(160px, 1.4fr) minmax(135px, .8fr) minmax(150px, 1fr) auto; align-items: end; gap: 10px; }
.response-row label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }

.checks-header { min-height: 66px; padding: 14px 10px 12px 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); }
.checks-header span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.checks-list { padding: 10px; }
.check-item { width: 100%; display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 9px; padding: 11px 9px; border: 1px solid transparent; border-radius: 6px; color: var(--text); background: transparent; text-align: left; }
.check-item:hover { background: var(--panel-2); border-color: var(--line); }
.check-item svg { margin-top: 1px; }
.check-item.error svg { color: var(--danger); }
.check-item.warning svg { color: var(--warn); }
.check-item.info svg { color: var(--info); }
.check-item strong, .check-item span, .check-item code { display: block; }
.check-item strong { font-size: 14px; }
.check-item span { margin-top: 3px; color: var(--muted); font-size: 13px; }
.check-item code { margin-top: 4px; color: var(--faint); font: 11px/1.3 var(--font-code); word-break: break-all; }
.all-clear { padding: 20px 10px; color: var(--muted); text-align: center; }
.all-clear svg { width: 26px; height: 26px; color: var(--accent-strong); margin-bottom: 8px; }
.checks-panel.is-collapsed .checks-header { padding: 12px 6px; justify-content: center; }
.checks-panel.is-collapsed .checks-header > div, .checks-panel.is-collapsed .checks-list { display: none; }

.status-strip { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.status-strip.error { border-color: #714038; background: var(--danger-bg); }
.status-strip.warning { border-color: #69582d; background: var(--warn-bg); }
.status-strip.valid { border-color: #3a5d2c; background: var(--accent-soft); }
.status-strip svg { width: 19px; flex: 0 0 auto; }
.status-strip span { color: var(--muted); }
.status-strip strong { color: var(--text); }

.code-panel { position: relative; }
.code-panel textarea { min-height: 480px; padding: 14px; font: 13px/1.55 var(--font-code); tab-size: 2; white-space: pre; }
.path-display { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.path-display code { color: var(--muted); font: 13px var(--font-code); word-break: break-all; }
.raw-error { padding: 10px 12px; margin-bottom: 12px; border: 1px solid #744039; border-radius: 6px; background: var(--danger-bg); color: #f3c0b8; }

.modal-overlay { position: fixed; inset: 0; z-index: 100; display: none; place-items: center; padding: 24px; background: rgba(0, 0, 0, .68); }
.modal-overlay.is-open { display: grid; }
.modal { width: min(620px, 100%); max-height: min(760px, calc(100vh - 48px)); overflow: auto; padding: 18px; border: 1px solid #484848; border-radius: 9px; background: #252525; box-shadow: 0 4px 12px rgba(0,0,0,.4); }
.modal-small { width: min(440px, 100%); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.modal > p { color: var(--muted); }
.modal-actions { justify-content: flex-end; margin-top: 20px; }
.template-options { display: grid; gap: 10px; }
.template-options button { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 2px 10px; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--text); text-align: left; }
.template-options button:hover { border-color: #626262; background: var(--panel-2); }
.template-options svg { grid-row: 1 / span 2; margin-top: 2px; color: var(--accent-strong); }
.template-options span { color: var(--muted); }
.export-option { padding: 14px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.export-option:last-child { border-bottom: 0; }
.export-option p { color: var(--muted); font-size: 14px; margin-top: 3px; }

.toast { position: fixed; z-index: 200; right: 18px; bottom: 18px; max-width: 390px; padding: 10px 13px; border: 1px solid #515151; border-radius: 7px; background: #303030; color: var(--text); opacity: 0; pointer-events: none; transition: opacity 150ms ease; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.toast.is-visible { opacity: 1; }
.toast.is-error { border-color: var(--danger); background: var(--danger-bg); }

.construction-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(12, 12, 12, .88);
}

.construction-dialog {
  width: min(440px, 100%);
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 16px;
  padding: 22px;
  border: 1px solid #4a4a4a;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}

.construction-dialog:focus-visible { outline: 2px solid var(--warn); outline-offset: 2px; }
.construction-dialog img { width: 42px; height: 42px; object-fit: contain; image-rendering: pixelated; }
.construction-dialog h1 { margin: 0 0 8px; font-size: 22px; }
.construction-dialog p { margin: 0; color: var(--muted); }

@media (max-width: 1120px) {
  :root { --left-width: 220px; --right-width: 280px; }
  .suite-links { display: none; }
  .app-header { grid-template-columns: max-content minmax(80px, 1fr) max-content; }
  .response-row { grid-template-columns: 1fr 1.5fr; }
  .response-row > *:last-child { align-self: end; }
}

@media (max-width: 850px) {
  html, body { overflow: auto; }
  .app-shell { min-height: 100vh; height: auto; display: block; }
  .app-header { position: sticky; top: 0; min-height: var(--header-height); grid-template-columns: 1fr auto; }
  .save-state { display: none; }
  .toolbar .button { width: 36px; padding: 0; font-size: 0; }
  .toolbar .button svg { width: 17px; }
  .workspace, .workspace:has(.checks-panel.is-collapsed) { display: block; }
  .left-panel, .checks-panel { border: 0; width: 100%; overflow: visible; }
  .project-header, .quest-list, .stage-shortcuts { display: none; }
  .panel-heading { display: none; }
  .workflow-nav { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 8px; border-bottom: 1px solid var(--line); }
  .workflow-nav button { display: flex; justify-content: center; padding: 9px 4px; }
  .workflow-nav button span small { display: none; }
  .workflow-nav button span strong { font-size: 12px; }
  .workflow-nav button.is-active { box-shadow: inset 0 -3px var(--accent-strong); }
  .editor { overflow: visible; }
  .editor-content { padding: 20px 16px 60px; }
  .checks-panel { max-height: none; }
  .checks-panel.is-collapsed { height: 48px; width: 100%; }
  .checks-panel.is-collapsed .checks-header { justify-content: flex-end; }
  .dialogue-layout { grid-template-columns: 1fr; }
  .slot-list { flex-direction: row; overflow: auto; }
}

@media (max-width: 590px) {
  .brand span { display: none; }
  .field, .field.span-3, .field.span-4, .field.span-8 { grid-column: 1 / -1; }
  .editor-header, .section-card-header, .graph-toolbar, .export-option { align-items: stretch; flex-direction: column; }
  .section-actions { flex-wrap: wrap; }
  .workflow-nav button svg { display: none; }
  .quest-graph { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .response-row { grid-template-columns: 1fr; }
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
