/* Chaoregon Trail Editor — visual grid maker */
#chaoregon-trail-editor-panel.hidden { display: none !important; }
#chaoregon-trail-editor-panel:not(.hidden) {
  display: flex !important;
  flex-direction: column !important;
  width: min(1420px, calc(100vw - 340px));
  height: min(820px, calc(100vh - 90px));
  min-width: 980px;
  min-height: 620px;
}
#chaoregon-trail-editor-panel > .panel-header {
  flex: 0 0 auto;
}
#chaoregon-trail-editor-panel > .cteditor-body,
#chaoregon-trail-editor-panel > .panel-body.cteditor-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
}
.cteditor-topbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1.3fr 1fr 1.35fr 110px auto;
  gap: 8px;
  align-items: end;
  padding: 8px;
  border: 2px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.22);
  border-radius: 10px;
}
.cteditor-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.55);
}
.cteditor-field input,
.cteditor-field select {
  width: 100%;
  min-height: 30px;
  border: 2px solid rgba(255,255,255,0.45);
  border-radius: 7px;
  background: rgba(10, 28, 48, 0.88);
  color: #fff;
  padding: 4px 6px;
  font: inherit;
}
.cteditor-small-field input { text-align: right; }
.cteditor-main {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 10px;
}
.cteditor-tools,
.cteditor-workspace {
  min-height: 0;
  overflow: auto;
  border: 2px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.22);
  border-radius: 10px;
  padding: 10px;
}
.cteditor-tools {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cteditor-section-title {
  margin-top: 4px;
  padding: 4px 6px;
  border-radius: 6px;
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 11px;
}
.cteditor-toggle-row,
.cteditor-palette {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.cteditor-palette.placeables { grid-template-columns: 1fr; }
.cteditor-btn,
.cteditor-tool {
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.22), rgba(0,0,0,0.28));
  color: #fff;
  min-height: 30px;
  padding: 5px 8px;
  font-weight: 800;
  cursor: pointer;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.55);
}
.cteditor-btn:hover,
.cteditor-tool:hover,
.cteditor-btn.active,
.cteditor-tool.active {
  filter: brightness(1.12);
  border-color: rgba(255,255,255,0.82);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25), 0 2px 8px rgba(0,0,0,0.3);
}
.cteditor-btn.primary {
  min-height: 38px;
  background: linear-gradient(180deg, rgba(92,218,255,0.8), rgba(23,88,155,0.86));
}
.cteditor-help {
  color: rgba(255,255,255,0.86);
  font-size: 12px;
  line-height: 1.35;
  padding: 8px;
  border-radius: 8px;
  background: rgba(0,0,0,0.24);
}
.cteditor-workspace {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cteditor-map-meta,
.cteditor-status {
  flex: 0 0 auto;
  min-height: 24px;
  border-radius: 8px;
  padding: 5px 8px;
  background: rgba(0,0,0,0.28);
  color: #fff;
  font-weight: 800;
}
.cteditor-status.ok { color: #bfffd8; }
.cteditor-status.warn { color: #ffe9a8; }
.cteditor-status.error { color: #ffb8b8; }
.cteditor-grid-wrap {
  flex: 1 1 auto;
  min-height: 280px;
  overflow: auto;
  border: 2px solid rgba(255,255,255,0.28);
  border-radius: 10px;
  background: rgba(0,0,0,0.32);
  padding: 10px;
}
.cteditor-grid {
  display: grid;
  grid-auto-rows: 22px;
  gap: 1px;
  width: max-content;
  min-width: 100%;
}
.cteditor-cell {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(0,0,0,0.38);
  border-radius: 2px;
  cursor: crosshair;
  image-rendering: pixelated;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  line-height: 18px;
  text-align: center;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.9);
}
.cteditor-cell span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(0,0,0,0.44);
}
.cteditor-cell.terrain-grass { background: linear-gradient(135deg, #63c35b, #3f983a); }
.cteditor-cell.terrain-mountain { background: linear-gradient(135deg, #9a8a71, #5f5548); }
.cteditor-cell.terrain-snow { background: linear-gradient(135deg, #f7fbff, #a8cde8); color: #15324a; text-shadow: 1px 1px 0 rgba(255,255,255,0.8); }
.cteditor-cell.terrain-water { background: linear-gradient(135deg, #4ec9ff, #2369c8); }
.cteditor-cell.placeable-road span { background: rgba(95, 57, 25, 0.86); border-radius: 2px; }
.cteditor-cell.placeable-start span { background: #127d3f; }
.cteditor-cell.placeable-end span { background: #8f1c1c; }
.cteditor-cell.placeable-fork span { background: #b47c1d; }
.cteditor-cell.placeable-outpost span { background: #6243a3; }
.cteditor-cell.placeable-monument span { background: #8c8c8c; }
.cteditor-cell.placeable-event span { background: #b31b7a; }
.cteditor-cell.placeable-river span { background: #124e9d; }
.cteditor-json {
  flex: 0 0 128px;
  width: 100%;
  resize: vertical;
  min-height: 80px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.28);
  background: rgba(0,0,0,0.72);
  color: #d9f3ff;
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 8px;
}
@media (max-width: 1250px) {
  #chaoregon-trail-editor-panel:not(.hidden) {
    width: calc(100vw - 24px);
    left: 12px !important;
  }
  .cteditor-topbar { grid-template-columns: 1fr 1fr; }
  .cteditor-main { grid-template-columns: 220px minmax(0, 1fr); }
}

/* Chaoregon Trail Editor pass 2 — graph preview / inspector / validation */
#chaoregon-trail-editor-panel:not(.hidden) {
  width: min(1520px, calc(100vw - 300px));
  min-width: 1120px;
}
.cteditor-main {
  grid-template-columns: 260px minmax(0, 1fr) 280px;
}
.cteditor-inspector {
  min-height: 0;
  overflow: auto;
  border: 2px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.22);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cteditor-grid-stage {
  position: relative;
  width: max-content;
  min-width: 100%;
}
.cteditor-edge-svg {
  position: absolute;
  inset: 0 auto auto 0;
  z-index: 8;
  overflow: visible;
  pointer-events: none;
}
.cteditor-edge-line {
  stroke: rgba(255, 244, 157, 0.88);
  stroke-width: 4;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.85));
}
.cteditor-edge-line.unreachable {
  stroke: rgba(255, 88, 88, 0.85);
  stroke-dasharray: 5 4;
}
.cteditor-grid {
  position: relative;
  z-index: 4;
}
.cteditor-cell {
  position: relative;
  z-index: 4;
}
.cteditor-cell.selected {
  outline: 3px solid #fff2a0;
  outline-offset: -1px;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.7), 0 0 10px rgba(255,242,160,0.9);
}
.cteditor-cell.targeted {
  outline: 3px solid rgba(255,255,255,0.95);
  outline-offset: -2px;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.72), 0 0 12px rgba(255,255,255,0.88);
  transform: translateY(-1px);
}
.cteditor-cell.selected.targeted {
  outline-color: #fff2a0;
}
.cteditor-cell.unreachable {
  box-shadow: inset 0 0 0 2px rgba(255, 54, 54, 0.95);
}
.cteditor-cell.has-meta::after {
  content: '';
  position: absolute;
  right: 2px;
  top: 2px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff2a0;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.75);
}
.cteditor-cell span em {
  position: absolute;
  right: -3px;
  bottom: -4px;
  min-width: 12px;
  height: 12px;
  border-radius: 6px;
  background: rgba(0,0,0,0.78);
  border: 1px solid rgba(255,255,255,0.75);
  color: #fff2a0;
  font-style: normal;
  font-size: 8px;
  line-height: 10px;
}
.cteditor-field textarea {
  width: 100%;
  min-height: 58px;
  resize: vertical;
  border: 2px solid rgba(255,255,255,0.45);
  border-radius: 7px;
  background: rgba(10, 28, 48, 0.88);
  color: #fff;
  padding: 5px 6px;
  font: inherit;
}
.cteditor-field input:disabled,
.cteditor-field textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.cteditor-cell-summary,
.cteditor-validation-list {
  border-radius: 8px;
  background: rgba(0,0,0,0.28);
  color: rgba(255,255,255,0.92);
  padding: 8px;
  font-size: 12px;
  line-height: 1.35;
}
.cteditor-validation-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cteditor-validation-ok {
  color: #bfffd8;
  font-weight: 900;
}
.cteditor-validation-item {
  border-radius: 7px;
  padding: 6px 7px;
  font-weight: 800;
}
.cteditor-validation-item.warn {
  color: #ffe9a8;
  background: rgba(128, 88, 0, 0.32);
}
.cteditor-validation-item.error {
  color: #ffb8b8;
  background: rgba(128, 0, 0, 0.32);
}
@media (max-width: 1250px) {
  .cteditor-main {
    grid-template-columns: 220px minmax(0, 1fr);
  }
  .cteditor-inspector {
    grid-column: 1 / -1;
    max-height: 240px;
  }
}

/* Chaoregon Trail Editor pass 3 — route graph arrows, branch labels, zoom */
.cteditor-map-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cteditor-zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.cteditor-zoom-btn {
  min-width: 28px;
  min-height: 24px;
  padding: 1px 7px;
}
#cteditor-zoom-label {
  min-width: 44px;
  text-align: center;
  font-size: 12px;
  color: #dff7ff;
}
.cteditor-grid {
  grid-auto-rows: var(--cteditor-cell-size, 22px);
  gap: var(--cteditor-cell-gap, 1px);
}
.cteditor-cell {
  width: var(--cteditor-cell-size, 22px);
  height: var(--cteditor-cell-size, 22px);
  line-height: calc(var(--cteditor-cell-size, 22px) - 4px);
  font-size: clamp(10px, calc(var(--cteditor-cell-size, 22px) * 0.52), 18px);
}
.cteditor-route-edge-line {
  stroke: rgba(99, 232, 255, 0.95);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 7 5;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.95));
}
.cteditor-route-edge.branch-route .cteditor-route-edge-line {
  stroke: rgba(255, 245, 130, 0.98);
  stroke-width: 4;
  stroke-dasharray: none;
}
.cteditor-route-arrow-head {
  fill: rgba(255, 245, 130, 0.98);
  stroke: rgba(0,0,0,0.65);
  stroke-width: 0.8;
}
.cteditor-route-edge-label {
  fill: #fff2a0;
  stroke: rgba(0,0,0,0.9);
  stroke-width: 3px;
  paint-order: stroke;
  font-size: 13px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}
.cteditor-branch-choices {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.cteditor-branch-choice-help {
  border-radius: 8px;
  background: rgba(0,0,0,0.24);
  color: rgba(255,255,255,0.86);
  font-size: 12px;
  line-height: 1.35;
  padding: 7px;
}
.cteditor-branch-choice-row span {
  color: #fff2a0;
  font-weight: 900;
}

/* Chaoregon Trail Editor pass 4 — road gameplay nodes / per-road event toggle */
.cteditor-road-event-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: 8px;
  background: rgba(0,0,0,0.24);
  border: 1px solid rgba(255,255,255,0.28);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.3;
  padding: 7px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.55);
}
.cteditor-road-event-toggle input {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}
.cteditor-road-event-toggle:has(input:disabled) {
  opacity: 0.52;
}
.cteditor-cell.placeable-road.events-off span {
  background: rgba(80, 80, 80, 0.88);
  box-shadow: inset 0 0 0 2px rgba(255, 210, 90, 0.85);
}
.cteditor-cell.placeable-road.events-off span::after {
  content: '×';
  display: block;
  color: #ffe07a;
  font-weight: 900;
  line-height: inherit;
}
