/* Track editor — themed with stunts_championship (:root vars from
 * /css/style.css), laid out with /track-viewer/trackviewer.css classes.
 * Only editor-specific bits live here; site vars win over viewer grays. */
.ed-compact-header { text-align: left; margin-bottom: 10px; }
.ed-compact-header h1 { font-size: 1.4rem; }
.ed-compact-header p { font-size: 0.9em; margin-bottom: 0; }
.ed-toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--surface-light);
  border-radius: var(--border-radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 14px; font-size: 1.05rem;
}
.ed-toolbar .btn.selected {
  background: var(--primary-color); border-color: var(--primary-dark); color: #fff;
}
.ed-toolbar .btn:disabled, .track-selector .btn:disabled {
  opacity: 1;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(1);
  background: transparent;
  border: 2px dashed var(--text-secondary);
  color: var(--text-secondary);
}
.ed-toolbar .btn:disabled:hover, .track-selector .btn:disabled:hover { background: transparent; transform: none; }
.ed-toolbar label { color: var(--text-secondary); font-size: 0.9em; display: flex; gap: 6px; align-items: center; }
.ed-toolbar input[type="text"], .ed-toolbar select {
  padding: 8px 10px; background: var(--surface-light); color: var(--text-primary);
  border: 1px solid var(--text-secondary); border-radius: var(--border-radius);
  font-size: 1rem;
}
.ed-toolbar input[type="text"] { width: 130px; text-transform: uppercase; font-family: monospace; }
.ed-toolbar input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary-color); }
#ed-brush-wrap {
  /* Fixed slot for the biggest piece (2x2 at 3x = 96px): swapping brushes
   * never moves the toolbar. */
  width: 96px; height: 96px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: #000; border: 2px solid var(--primary-color);
  border-radius: var(--border-radius);
}
#ed-brush-preview { image-rendering: pixelated; display: block; }
#ed-brush-label { color: var(--primary-color); font-size: 0.95em; font-family: monospace; font-weight: bold; }
#ed-brush-heading { display: inline-block; width: 1.2em; text-align: center; color: var(--primary-color); font-size: 1.6em; line-height: 1; }
#ed-brush-cornering { display: inline-block; width: 1.2em; text-align: center; color: var(--warning); font-size: 1.6em; line-height: 1; }
.ed-zoom-group { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.ed-keys-panel {
  background: var(--surface); border: 1px solid var(--surface-light);
  border-radius: var(--border-radius); box-shadow: var(--shadow);
  padding: 10px 14px; margin-bottom: 12px;
}
.ed-key-row { display: flex; gap: 12px; align-items: center; padding: 2px 0; min-height: 68px; }
.ed-key-keys { min-width: 130px; flex: 0 0 auto; }
.ed-key-keys kbd, #ed-help kbd {
  display: inline-block; min-width: 26px; text-align: center;
  background: var(--surface-light); color: var(--text-primary);
  border: 1px solid var(--text-secondary); border-bottom-width: 3px;
  border-radius: 6px; padding: 2px 8px; margin: 1px;
  font-family: monospace; font-size: 0.85em;
}
.ed-key-desc { color: var(--text-secondary); font-size: 0.9em; display: inline-flex; align-items: center; min-height: 64px; }
.ed-key-row.smart kbd { border-color: var(--primary-color); color: var(--primary-color); font-weight: bold; }
.ed-key-heading .ed-key-desc { min-height: 0; font-weight: 600; color: var(--text-primary); }
.ed-key-thumb { image-rendering: pixelated; vertical-align: middle; background: #000; border-radius: 3px; }
#ed-status { color: var(--warning); font-size: 0.95em; min-height: 1.3em; }
#ed-coords { color: var(--text-secondary); font-size: 0.9em; font-family: monospace; }

.ed-canvas-wrap { text-align: center; position: relative; }
/* Direction overlay: HTML arrows above the canvas, click-through. */
.ed-overlay { position: absolute; display: none; pointer-events: none; z-index: 3; }
/* Orange straight heading arrow (SVG, rotated to the heading). */
.ed-ov-arrow {
  position: absolute; transform: translate(-50%, -50%);
  color: var(--primary-color); z-index: 1; display: none; line-height: 0;
  filter: drop-shadow(0 0 2px #000) drop-shadow(0 0 2px #000);
}
.ed-ov-arrow svg { width: 1.7em; height: 1.7em; display: block; overflow: visible; }
/* Yellow curved turn arrow, drawn behind the straight heading arrow. */
.ed-ov-curve {
  position: absolute; transform: translate(-50%, -50%);
  color: #ffd400; z-index: 0; display: none; line-height: 0;
  filter: drop-shadow(0 0 2px #000) drop-shadow(0 0 2px #000);
}
.ed-ov-curve svg { width: 1.7em; height: 1.7em; display: block; overflow: visible; }
.ed-ov-arrow path, .ed-ov-curve path {
  fill: none; stroke: currentColor; stroke-width: 2.5;
  stroke-linecap: round; stroke-linejoin: round;
}
/* Radial flick widget (hold Shift). Click-through, drawn above everything. */
.ed-radial {
  position: fixed; width: 208px; height: 208px; margin: 0;
  transform: translate(-50%, -50%); pointer-events: none; z-index: 60; display: none;
}
.ed-rad-svg { width: 100%; height: 100%; overflow: visible; }
.ed-rad-quad { fill: rgba(20, 20, 35, 0.55); stroke: var(--text-secondary); stroke-width: 1.5; }
.ed-rad-quad.active { fill: rgba(255, 107, 0, 0.4); stroke: var(--primary-color); }
.ed-rad-lbl { fill: var(--text-primary); font-size: 18px; font-weight: bold; text-anchor: middle; dominant-baseline: middle; }
.ed-rad-facet { fill: rgba(20, 20, 35, 0.35); stroke: var(--text-secondary); stroke-width: 1; }
.ed-rad-facet.active { fill: rgba(255, 107, 0, 0.45); stroke: var(--primary-color); }
.ed-rad-facet.selected { stroke: var(--primary-color); opacity: 0.5; }
.ed-rad-flbl { fill: var(--text-primary); font-size: 13px; font-weight: bold; text-anchor: middle; dominant-baseline: middle; }
.ed-rad-center { fill: var(--primary-color); }
/* Smart zones: real pieces beyond the outer ring, faded in as you approach. */
.ed-rad-smart { transition: opacity 0.08s linear; }
.ed-rad-szbg { fill: var(--background); }
.ed-rad-sbg { fill: var(--background); stroke: var(--text-secondary); stroke-width: 1.5; }
.ed-rad-sbg.active { fill: rgba(255, 107, 0, 0.5); stroke: var(--primary-color); stroke-width: 2.5; }
.ed-rad-simg { image-rendering: pixelated; }
/* Control radial: surface colours (N=paved, E=dirt, S=bridge, W=ice). */
#ed-cradial .ed-rad-quad { fill-opacity: 0.55; }
#ed-cradial .ed-rad-quad[data-dir="0"] { fill: #6b7280; } /* paved */
#ed-cradial .ed-rad-quad[data-dir="1"] { fill: #a9744f; } /* dirt */
#ed-cradial .ed-rad-quad[data-dir="2"] { fill: #8a9bb0; } /* bridge */
#ed-cradial .ed-rad-quad[data-dir="3"] { fill: #8fd6ff; } /* ice */
#ed-cradial .ed-rad-quad.active { fill-opacity: 0.95; stroke: var(--primary-color); stroke-width: 3; }
#ed-cradial .ed-rad-lbl { fill: #fff; stroke: #000; stroke-width: 0.7; paint-order: stroke; }
/* Hint banner shown while a radial widget is open. */
.ed-rad-hint {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 70; display: none; pointer-events: none;
  background: rgba(0, 0, 0, 0.85); color: #fff;
  border: 1px solid var(--primary-color); border-radius: 8px;
  padding: 8px 14px; font-size: 0.9em; max-width: 92vw; text-align: center;
}
.ed-rad-hint kbd {
  display: inline-block; min-width: 20px; text-align: center;
  background: var(--surface-light); color: var(--text-primary);
  border: 1px solid var(--text-secondary); border-bottom-width: 3px;
  border-radius: 5px; padding: 1px 6px; margin: 0 1px; font-family: monospace; font-size: 0.9em;
}
#track-canvas.ed-active {
  cursor: crosshair;
  /* Exact 3x: 480 internal px -> 1440 display px. Falls back to full width
   * on smaller screens (still pixelated, just not integer-scale there). */
  width: min(1440px, 100%); height: auto;
  border-color: var(--primary-color);
}

/* Editor pages only (this sheet loads nowhere else): never allow
 * page-level horizontal scroll — the 100vw breakout below overshoots
 * by the scrollbar width otherwise. */
body { overflow-x: clip; }
/* Break out of the site's 1400px column so map + picker fit side by side.
 * Plain class (no :has), works everywhere. */
.ed-app { width: 100%; max-width: 1840px; margin: 0 auto; }
@media (min-width: 1000px) {
  .ed-app { width: 100vw; margin-left: 50%; transform: translateX(-50%); }
}
.track-viewer-container { max-width: 1840px; }

/* Wider preview column for the bigger canvas (overrides viewer default). */
@media (min-width: 1000px) {
  .ed-app .track-viewer-layout { grid-template-columns: minmax(480px, 1440px) minmax(280px, 340px); align-items: start; }
  /* Third column only exists while the keys panel is open in it —
   * otherwise the empty track reserves phantom width (huge scrollbar). */
  .ed-app .track-viewer-layout.with-keys { grid-template-columns: max-content minmax(480px, 1440px) minmax(280px, 340px); }
  /* Keys live in their own column left of the map; like the palette it sticks
   * to the top and scrolls on its own. */
  #ed-keys-panel {
    align-self: start; max-width: 320px; margin-bottom: 0;
    position: sticky; top: 16px;
    max-height: calc(100vh - 32px); overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin; scrollbar-color: var(--primary-color) var(--surface-light);
    /* Put the scrollbar on the left edge; keep the content LTR. */
    direction: rtl;
  }
  #ed-keys-panel #ed-keys-list { direction: ltr; }
  .ed-app .track-viewer-view { position: static; }
  /* The picker sticks beside the map and scrolls on its own. */
  .ed-app .track-viewer-lists {
    position: sticky; top: 16px;
    max-height: calc(100vh - 32px); overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--surface); border: 1px solid var(--surface-light);
    border-radius: var(--border-radius); box-shadow: var(--shadow);
    padding: 12px 14px 12px 12px;
    scrollbar-width: thin; scrollbar-color: var(--primary-color) var(--surface-light);
  }
  .track-viewer-view::-webkit-scrollbar, .track-viewer-lists::-webkit-scrollbar, #ed-keys-panel::-webkit-scrollbar { width: 8px; }
  .track-viewer-view::-webkit-scrollbar-thumb, .track-viewer-lists::-webkit-scrollbar-thumb, #ed-keys-panel::-webkit-scrollbar-thumb { background: var(--primary-color); border-radius: 4px; }
  .track-viewer-view::-webkit-scrollbar-track, .track-viewer-lists::-webkit-scrollbar-track, #ed-keys-panel::-webkit-scrollbar-track { background: var(--surface-light); }
}
/* Single column: cap the picker too so the canvas isn't miles away. */
@media (max-width: 999px) {
  .track-viewer-lists { max-height: 70vh; overflow-y: auto; }
}

/* Compact pickers: tighter grid, smaller swatches. */
.ed-pal-grid { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 8px; }
.ed-swatch {
  /* Fixed slot for the biggest piece (2x2 at 2x = 64px + padding/border):
   * every slot identical, so picking brushes never reflows the grid. */
  width: 68px; height: 68px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  padding: 1px; background: var(--surface-light);
  border: 1px solid var(--surface-light);
  border-radius: 4px; cursor: pointer; line-height: 0;
}
.ed-swatch:hover { border-color: var(--primary-color); }
.ed-swatch img { image-rendering: pixelated; display: block; background: #000; }
#ed-palette h3 { color: var(--primary-color); font-size: 1rem; margin: 8px 0 4px; }
.ed-pal-keys { margin-left: 8px; }
.ed-pal-key {
  display: inline-block; min-width: 24px; text-align: center;
  background: var(--surface-light); color: var(--text-primary);
  border: 1px solid var(--text-secondary); border-bottom-width: 3px;
  border-radius: 6px; padding: 1px 7px; margin-left: 4px;
  font-family: monospace; font-size: 0.8em; font-weight: bold; cursor: pointer;
}
.ed-pal-key:hover { border-color: var(--primary-color); color: var(--primary-color); }
.ed-note { color: var(--text-secondary); font-size: 0.9em; margin-top: 8px; }
/* Developer-facing detail (remap table etc.) only shows while debug is on. */
.ed-debug-only { display: none; }
body.ed-debug .ed-debug-only { display: inline; }
.ed-overwrite {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: rgba(255, 193, 7, 0.1); border: 1px solid var(--warning);
  border-radius: var(--border-radius); padding: 10px 14px; margin-bottom: 12px;
  color: var(--warning); font-size: 0.95em;
}

.ed-debug {
  margin-top: 16px; background: var(--surface); border: 1px solid var(--surface-light);
  border-radius: var(--border-radius); padding: 12px 16px; box-shadow: var(--shadow);
}
.ed-debug summary { color: var(--primary-color); cursor: pointer; font-size: 1.05rem; font-weight: 600; }
.ed-play summary { font-size: 1.15rem; }
.ed-play .dos-container-wrapper { max-width: 960px; margin: 0 auto; }
#pv-status { flex: 1; min-width: 200px; }
.ed-debug-pre {
  background: #000; color: #7ee787; border: 1px solid var(--surface-light); border-radius: 4px;
  padding: 8px 10px; font-size: 0.85em; white-space: pre-wrap; word-break: break-word;
  max-height: 220px; overflow-y: auto; margin: 8px 0;
}
#ed-debug-near { max-height: 150px; text-align: left; margin: 4px auto 8px; max-width: 100%; }
.ed-terrain-list { display: flex; flex-wrap: wrap; gap: 10px; }
.ed-terrain-item {
  position: relative;
  background: var(--surface-light); border: 2px solid transparent;
  border-radius: var(--border-radius); padding: 8px; cursor: pointer;
  text-align: center; max-width: 150px;
}
.ed-terrain-item:hover { border-color: var(--text-secondary); }
.ed-terrain-item.selected { border-color: var(--primary-color); }
.ed-terrain-item canvas { image-rendering: pixelated; width: 120px; height: 120px; display: block; background: #000; }
.ed-terrain-item .btn {
  display: none;
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  margin: 0; z-index: 2; white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}
.ed-terrain-item:hover .btn, .ed-terrain-item.selected .btn { display: inline-block; }
.ed-backup-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.ed-backup-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-light); border: 1px solid transparent;
  border-radius: var(--border-radius); padding: 6px 10px;
}
.ed-backup-when { font-family: monospace; color: var(--text-primary); min-width: 78px; }
.ed-backup-meta { color: var(--text-secondary); font-size: 0.9em; flex: 1 1 auto; }
.ed-backup-item .btn { margin: 0; }
