:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --border: #e3e0d8;
  --text: #1f2328;
  --muted: #6b6f76;
  --accent: #7a2e2e;
  --accent-text: #ffffff;
  --select: #2563eb;
  --danger: #b42318;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
#app { height: 100%; }
#print-sheet { display: none; }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 17px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; }
.muted, .hint { color: var(--muted); font-size: 13px; }
.lead { color: var(--muted); margin: 0 0 24px; }
.error { color: var(--danger); min-height: 1em; }
.spacer { flex: 1; }

button, .btn {
  font: inherit; font-size: 14px; color: inherit; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; cursor: pointer;
}
.btn:hover { border-color: #bdb8ad; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 6px 9px; }

input, textarea {
  font: inherit; font-size: 14px; color: inherit;
  padding: 7px 9px; border: 1px solid #cfcabf; border-radius: 6px; background: #fff; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--select); outline-offset: -1px; border-color: transparent; }

/* ---- list + intro pages ---- */
.page { max-width: 880px; margin: 0 auto; padding: 32px 16px 64px; }
.brand { font-size: 32px; color: var(--accent); }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; }
.new-chart { display: flex; gap: 8px; }
.chart-list { list-style: none; margin: 0; padding: 0; }
.chart-list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.chart-list li:first-child { border-top: 0; }
.chart-list .empty { color: var(--muted); }
.chart-link { font-weight: 600; color: var(--text); font-size: 16px; }

.grid3 { display: grid; grid-template-columns: 2fr 2fr 1fr; gap: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.rows { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.row { display: flex; gap: 8px; align-items: center; width: 100%; }
.ability-row { width: auto; }
.ability-row .ability-name { width: 110px; }
.ability-row .score { width: 80px; }
.ability-row .mod { width: 40px; font-weight: 600; text-align: center; }
.item-row input:first-child { flex: 2; }
.item-row input:nth-child(2) { flex: 3; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 640px) {
  .grid3 { grid-template-columns: 1fr; }
  .item-row { flex-wrap: wrap; }
}

/* ---- editor ---- */
.editor { display: grid; grid-template-rows: auto auto 1fr; height: 100vh; }
.topbar, .toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.chart-name { font-size: 18px; margin: 0 8px; cursor: text; }
.chart-name:hover { text-decoration: underline dotted; }
.status { color: var(--muted); font-size: 13px; margin-right: 8px; }
.status.error { color: var(--danger); }
.toolbar { min-height: 48px; padding: 6px 16px; flex-wrap: wrap; row-gap: 6px; }
.toolbar .label { font-size: 13px; color: var(--muted); }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 4px; }
.toolbar .hint { margin-left: 8px; }
.swatch { width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 1px solid #9a958a; }
.swatch.active { outline: 2px solid var(--select); outline-offset: 2px; }
.shape-btn { padding: 3px 4px; }
.badge-icon { display: block; stroke-width: 1.5; }
.add-badge { padding: 4px 8px; font-size: 13px; }
.badge-chip { display: inline-flex; }
.badge-chip .chip-text { border-radius: 6px 0 0 6px; padding: 4px 8px; font-size: 13px; }
.badge-chip .chip-remove { border-radius: 0 6px 6px 0; border-left: 0; padding: 4px 7px; color: var(--muted); }
.badge-chip .chip-remove:hover { color: var(--danger); }
.btn.active { border-color: var(--select); background: #eef4ff; }
.shape-btn.active { border-color: var(--select); background: #eef4ff; }
.shape-icon { display: block; fill: #f1efe9; stroke: #3f3f46; stroke-width: 1.2; }

.workspace { display: grid; grid-template-columns: 240px 1fr; min-height: 0; }
.palette { overflow: auto; background: var(--panel); border-right: 1px solid var(--border); padding: 14px; }
.palette .hint { margin: 12px 0 0; }
.card {
  padding: 8px 10px; margin-bottom: 6px; font-size: 14px; border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, .18); cursor: grab; user-select: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card:hover { box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.card:active { cursor: grabbing; }

.summary-name { font-weight: 700; font-size: 16px; }
.summary-sub { color: var(--muted); font-size: 13px; }
.abilities { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.ability { font-size: 12px; background: #f1efe9; border-radius: 4px; padding: 2px 6px; }
.ability small { color: var(--muted); }

.canvas-wrap {
  position: relative; overflow: hidden; background-color: #fff;
  background-image: radial-gradient(circle, #d5d1c7 1px, transparent 1.3px);
}

/* ---- chart SVG (shared by editor and print) ---- */
.chart-svg { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.box-rect { stroke: #3f3f46; stroke-width: 1.5; stroke-linejoin: round; }
.box-text {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 6px 8px; overflow: hidden; text-align: center;
  font: 14px/1.25 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #111;
}
.box-inner { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 100%; }
.badge-shape { stroke-width: 1.5; stroke-linejoin: round; }
.badge-cost .badge-shape { stroke-width: 2.5; }
.interactive .badge { cursor: pointer; }
.badge.selected .badge-shape { stroke: var(--select); stroke-width: 3; }
.swatch.default-color { position: relative; }
.swatch.default-color::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; border: 2px solid #3f3f46; }
.badge-text { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-weight: 600; fill: #111; }
/* groups */
.group-line { fill: none; stroke: #3f3f46; stroke-width: 2; stroke-linejoin: round; }
.group-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.group.selected .group-line { stroke: var(--select); stroke-width: 3; }
.group-label {
  font: 600 13px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; fill: #111;
  paint-order: stroke; stroke: #fff; stroke-width: 6px; stroke-linejoin: round;
}
.group.selected .group-label { fill: var(--select); }
.group-line, .group-label { pointer-events: none; }

/* tracker side column */
.side-band { fill: #faf9f6; }
.side-band.selected { fill: #eef4ff; }
.side-divider { stroke: #4b5563; stroke-width: 1.5; pointer-events: none; }
.section-hit { fill: transparent; }
.section-name { font: 700 13px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; letter-spacing: .04em; text-transform: uppercase; fill: #374151; }
.section-rule { stroke: #9a958a; stroke-width: 1; }
.tracker-section.selected .section-name { fill: var(--select); }
.tracker-section.selected .section-rule { stroke: var(--select); stroke-width: 2; }
.tracker-item .box-text { font-size: 13px; line-height: 1.2; padding: 4px 6px; }
.item-rect { stroke: #3f3f46; stroke-width: 1.5; }
.tracker-item.selected .item-rect { stroke: var(--select); stroke-width: 3; }
.tick { fill: #fff; stroke: #3f3f46; stroke-width: 1.3; }
.interactive .tracker-item, .interactive .tracker-section { cursor: pointer; }
.toolbar .count { min-width: 1.5em; text-align: center; font-variant-numeric: tabular-nums; }
.edge-line { fill: none; stroke: #374151; stroke-width: 2; }
.edge-label {
  font: 600 13px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; fill: #111;
  paint-order: stroke; stroke: #fff; stroke-width: 5px; stroke-linejoin: round;
  pointer-events: none;
}

.lane-band { fill: #fff; }
.lane.drop-target .lane-band { fill: #eef4ff; }
.page-edge, .page-bottom { pointer-events: none; }
.page-edge { stroke: #9a958a; stroke-width: 1.5; stroke-dasharray: 6 4; }
.page-bottom { stroke: #9a958a; stroke-width: 1.5; stroke-dasharray: 6 4; }
.page-bottom.over { stroke: #dc2626; }
.page-bottom-label { font: 12px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; fill: #6b6b6b; pointer-events: none; }
.page-bottom-label.over { fill: #dc2626; }
.lane-divider { stroke: #4b5563; stroke-width: 1.5; }
.lane-header-rect { stroke: #3f3f46; stroke-width: 1.5; stroke-linejoin: round; }
.lane.selected .lane-header-rect { stroke: var(--select); stroke-width: 3; }
.lane-name {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 6px; text-align: center; overflow: hidden; overflow-wrap: anywhere;
  font: 600 15px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #111;
}
.interactive .lane-header { cursor: pointer; }
.add-lane rect { fill: #fff; stroke: #9a958a; stroke-dasharray: 4 3; }
.add-lane text { font: 13px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; fill: var(--muted); }
.add-lane { cursor: pointer; }
.add-lane:hover rect { stroke: var(--select); }
.add-lane:hover text { fill: var(--select); }
.card.lane-colored { background: repeating-linear-gradient(45deg, #fff, #fff 6px, #f1efe9 6px, #f1efe9 12px); }
.lane-name-input { width: 180px; }
.btn:disabled { opacity: .4; cursor: default; }

.interactive .box { cursor: move; }
.interactive.panning { cursor: grabbing; }
.box.selected .box-rect { stroke: var(--select); stroke-width: 3; }
.box.drop-target .box-rect { stroke: #16a34a; stroke-width: 3; }
.anchor { fill: #fff; stroke: var(--select); stroke-width: 2; opacity: 0; cursor: crosshair; }
.interactive .box:hover .anchor, .box.selected .anchor, .connecting .anchor { opacity: 1; }
.anchor:hover { fill: var(--select); }
.resize-handle { fill: var(--select); cursor: nwse-resize; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.edge.selected .edge-line { stroke: var(--select); stroke-width: 3; }
.ghost-line { fill: none; stroke: #9ca3af; stroke-width: 2; stroke-dasharray: 6 5; pointer-events: none; }
.ghost-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: copy; }
.ghost:hover .ghost-line { stroke: var(--select); stroke-dasharray: none; }
.temp-line { fill: none; stroke: var(--select); stroke-width: 2; stroke-dasharray: 4 4; pointer-events: none; }

.box-editor {
  position: absolute; z-index: 5; resize: none; text-align: center;
  padding: 6px 8px; line-height: 1.25; border: 2px solid var(--select); border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
}

/* ---- links dialog ---- */
.links-dialog { border: 1px solid var(--border); border-radius: 10px; padding: 20px 24px; max-width: 560px; width: calc(100% - 32px); box-sizing: border-box; }
.links-dialog::backdrop { background: rgb(0 0 0 / .35); }
.links-dialog h2 { margin-top: 0; }
.links-dialog .warning { background: #fff7e6; border: 1px solid #f5d491; border-radius: 6px; padding: 8px 12px; }
.link-row { margin: 14px 0; }
.link-row p { margin: 4px 0 0; }
.link-field { display: flex; gap: 8px; margin-top: 4px; }
.link-input { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.links-dialog form { text-align: right; }

/* ---- view page: the chart as it prints, sized to the window ---- */
.viewer { min-height: 100%; }
.viewer .error { padding: 0 16px; }
.view-sheet { background: #fff; max-width: 10.2in; margin: 16px auto 48px; padding: 16px; box-shadow: 0 1px 4px rgb(0 0 0 / .12); box-sizing: border-box; }
.view-sheet .chart-svg { display: block; width: 100%; height: auto; aspect-ratio: 10.2 / 6.8; }
.view-sheet.with-notes .chart-svg { aspect-ratio: 10.2 / 6; }
.view-sheet.portrait { max-width: 7.7in; }
.view-sheet.portrait .chart-svg { aspect-ratio: 7.7 / 9.3; }
.view-sheet.portrait.with-notes .chart-svg { aspect-ratio: 7.7 / 8.5; }
.view-sheet .print-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; border-bottom: 1px solid #999; margin-bottom: 8px; padding-bottom: 8px; }
.view-sheet .print-title { font-size: 12px; color: #555; }
.view-sheet .print-notes { border-top: 1px solid #999; padding-top: 8px; white-space: pre-wrap; font-size: 13px; }

/* ---- home page ---- */
.home .hero { margin-bottom: 8px; }
.home .brand { font-size: 40px; margin-bottom: 4px; }
.tagline { font-size: 20px; margin: 0 0 12px; }
.home .lead { max-width: 640px; }
.home .start .error:empty { display: none; }
.home .start .example { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.home h2 { margin-top: 0; }
.how { margin: 32px 0; }
.steps { padding-left: 1.4em; display: grid; gap: 10px; }
.steps li { line-height: 1.5; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.cards .panel { margin-bottom: 0; }
.cards p { line-height: 1.5; }
.media { display: grid; gap: 16px; margin: 32px 0; }
.media figure { margin: 0; }
.media img, .media video { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.media figcaption { color: var(--muted); font-size: 13px; margin-top: 6px; }
.site-footer { margin-top: 40px; text-align: center; }
.site-footer a { color: inherit; }
/* ---- static pages (app/templates/pages/) ---- */
.site-header { margin-bottom: 24px; }
.site-header .brand { font-weight: 700; text-decoration: none; }
.prose p, .prose li { line-height: 1.5; }
.prose .panel h2 { margin-top: 0; }
@media (max-width: 560px) {
  .new-chart { flex-direction: column; }
  .home .brand { font-size: 32px; }
}

/* ---- stats page ---- */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat-tile { display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-size: 32px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.bars { list-style: none; margin: 0 0 8px; padding: 0; }
.bars li { display: grid; grid-template-columns: 9em 1fr 3.5em; align-items: center; gap: 10px; padding: 3px 0; font-size: 14px; }
.bar-track { height: 12px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.bar { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }
.columns { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; }
.column { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; min-width: 0; }
.column-value { font-variant-numeric: tabular-nums; }
.column-track { display: flex; align-items: flex-end; width: 100%; height: 120px; background: var(--bg); border-radius: 3px; }
.column-bar { display: block; width: 100%; background: var(--accent); border-radius: 3px; }
.column-label { white-space: nowrap; font-size: 11px; }
@media (max-width: 640px) {
  .columns { gap: 2px; }
  .column-label { writing-mode: vertical-rl; transform: rotate(180deg); height: 3.5em; }
  .bars li { grid-template-columns: 7em 1fr 3em; }
}
