/* Build Planner tab -- styled against this site's own :root variables
   (index.html) so it matches natively rather than needing a separate
   reskin pass. No framework, plain CSS, matches the rest of the site. */

#view-planner .wrap { max-width: 1180px; }

/* ---------- shared buttons / inputs ---------- */

/* .btn is inline-flex with no justify-content (index.html), so it left-aligns
   by default -- fine for buttons whose text fills the box, but .pl-btn's
   min-width leaves short labels like "BACK" looking off-center. */
.pl-btn { height: 44px; min-width: 110px; justify-content: center; }

.pl-input, input[type="number"].pl-rule-override-input {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
}
.pl-input { width: 100%; box-sizing: border-box; margin-bottom: 16px; }

.pl-rules-small-btn {
  cursor: pointer;
  background: rgba(120, 150, 255, 0.1);
  border: 1px solid var(--stroke);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  transition: 0.15s;
}
.pl-rules-small-btn:hover:not(:disabled) { border-color: var(--stroke-bright); background: rgba(120, 150, 255, 0.18); }
.pl-rules-small-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.pl-rules-small-btn--outline { background: none; }
.pl-rules-small-btn--danger { border-color: var(--red); color: var(--red); }

/* ---------- Home ---------- */

.pl-home { text-align: center; padding: 20px 0 40px; }
.pl-home-main { display: flex; align-items: center; justify-content: center; gap: 32px; flex-wrap: wrap; }
.pl-home-captain { max-width: 220px; height: auto; }
.pl-home-buttons { display: flex; flex-direction: column; gap: 12px; min-width: 220px; }

/* ---------- New Build ---------- */

.pl-new-build, .pl-load-build { padding: 20px 0 40px; }
.pl-new-build h2, .pl-load-build h2 { margin: 0 0 20px; }
.pl-new-build-form { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 24px; }
.pl-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.pl-new-build-buttons { display: flex; gap: 12px; }

/* ---------- Load Build ---------- */

.pl-load-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.pl-load-row {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  background: var(--panel); border: 1px solid var(--stroke); border-radius: 14px;
  padding: 14px 18px; backdrop-filter: blur(10px);
}
.pl-load-row-info { display: flex; flex-direction: column; gap: 2px; }
.pl-load-row-name { font-weight: 700; }
.pl-load-row-meta { font-size: 12px; color: var(--muted); }
.pl-load-row-actions { display: flex; gap: 8px; flex: none; }

/* ---------- Plan page: header ---------- */

.pl-plan { padding: 16px 0 40px; }

.pl-header {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 12px 0 20px;
  border-bottom: 1px solid var(--stroke);
  margin-bottom: 16px;
}
.pl-build-name { font-weight: 700; white-space: nowrap; }
.pl-stats { display: flex; gap: 20px; flex-wrap: wrap; flex: 1 1 auto; }
.pl-stat { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 700; }
/* These are dark/black silhouette icons made for the desktop app's light
   theme -- invert them to white so they're visible against this site's
   dark background instead of re-drawing them. */
.pl-stat-icon { width: 20px; height: 20px; image-rendering: pixelated; filter: brightness(0) invert(1); }
.pl-stat-value--negative { color: var(--red); }
.pl-stat-value--positive { color: var(--green); }
.pl-actions { display: flex; align-items: center; gap: 10px; flex: none; flex-wrap: wrap; }
.pl-save-error { color: var(--red); font-size: 12px; font-weight: 700; }

@media (max-width: 720px) {
  .pl-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .pl-actions { overflow-x: auto; }
}

/* ---------- Plan page: hull grid ---------- */

.pl-grid-controls { margin-bottom: 12px; }
.pl-grid-controls-row { display: flex; gap: 8px; flex-wrap: wrap; }

.pl-hull-wrap {
  position: relative;
  margin-bottom: 20px;
  /* The grid's cells and placed rooms are positioned with raw pixel
     left/top values (not percentages) computed from planner.js's
     ROOM_UNIT_PX, which is recomputed on every plan-page render to fit the
     available width (down to a minimum cell size) -- see
     recomputeCellSize() in planner.js. overflow-x is just the fallback for
     viewports narrower than hull.columns * that minimum. */
  overflow-x: auto;
}
.pl-hull-placeholder { color: var(--muted); padding: 60px 0; }

.pl-grid {
  position: relative;
  /* Not `none` -- .pl-hull-wrap scrolls this horizontally on wide hulls
     (Pirate/Federation), and touch-action:none would block that pan
     entirely, same issue as the room tray. A drag already in progress is
     unaffected either way: it started on a .pl-placed tile or .pl-tray-img
     (each with their own touch-action) and pointer capture keeps routing
     events to that original element regardless of what's now underneath
     the finger, so blank grid background is free to pan. */
  touch-action: pan-x;
}
.pl-hull-art { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; image-rendering: pixelated; }

.pl-cell { position: absolute; box-sizing: border-box; border: 2px solid transparent; }
.pl-cell--enabled { border-color: var(--gold); }
.pl-cell--preview-valid { border-color: var(--green); background: rgba(82, 246, 160, 0.25); }
.pl-cell--preview-invalid { border-color: var(--red); background: rgba(255, 107, 122, 0.25); }

.pl-placed {
  position: absolute;
  box-sizing: border-box;
  /* outline (not border) so this doesn't eat into the box -- the box is
     sized to exactly match the grid cells underneath, and .pl-placed-img
     fills 100% of it, so a border here would inset the art and reveal the
     .pl-cell grid line in a ring around every placed room. */
  outline: 3px solid transparent;
  cursor: grab;
  touch-action: none; /* nothing to scroll inside a placed grid tile */
}
.pl-placed--armor-unmet { outline-color: var(--red); }
/* Screenshot-scan review marks (planner-scan.js): matched-nothing cells and
   low-confidence rooms. Same colours as the scan page's canvas overlay;
   violet, not orange, since enabled empty cells already have a gold border. */
.pl-cell--scan-flag { border-color: var(--red); background: rgba(255, 107, 122, 0.35); }
.pl-placed--scan-uncertain { outline-color: var(--violet); }
/* fill (not contain) to match .pl-hull-art -- stretches exactly to the
   footprint box with no letterboxing, so it fully covers the grid lines
   underneath regardless of the source art's native aspect ratio. */
.pl-placed-img { display: block; width: 100%; height: 100%; object-fit: fill; image-rendering: pixelated; }
.pl-armor-overlay {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 20px; height: 20px; pointer-events: none; image-rendering: pixelated;
}

.pl-ghost {
  position: fixed;
  z-index: 99999;
  pointer-events: none;
  opacity: 0.85;
  object-fit: contain;
  image-rendering: pixelated;
}

/* ---------- Plan page: room tray ---------- */

.pl-tray {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 8px;
  border-top: 1px solid var(--stroke);
}
.pl-tray-item { flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pl-tray-img {
  flex-shrink: 0;
  box-sizing: border-box;
  border: 3px solid transparent;
  border-radius: 4px;
  background: var(--panel-2);
  object-fit: contain;
  image-rendering: pixelated;
  /* Not `none` -- these sit inside a horizontally-scrolling tray and cover
     nearly all of it, so a horizontal swipe still needs to reach native
     scroll; only non-horizontal movement is left free for drag capture. */
  touch-action: pan-x;
}
.pl-tray-img--wanted { border-color: var(--green); }
.pl-tray-count { font-size: 11px; font-weight: 700; color: var(--muted); }
.pl-tray-count--depleted { color: var(--red); }

/* ---------- Rules list ---------- */

.pl-rules-header-actions { display: flex; gap: 8px; margin-bottom: 14px; }
.pl-rules-error { color: var(--red); font-size: 13px; font-weight: 700; }
.pl-rules-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.pl-rules-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--stroke); border-radius: 10px;
  padding: 10px 14px;
}
.pl-rules-list-name { font-weight: 700; flex: 1 1 auto; }
.pl-rules-builtin-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
  color: var(--gold); border: 1px solid var(--gold); border-radius: 20px; padding: 2px 8px;
}
.pl-rules-list-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Rule set form ---------- */

.pl-rules-form-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.pl-rules-name-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.pl-rules-energy-inputs { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.pl-rules-energy-title { font-weight: 700; color: var(--violet); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.pl-rules-energy-inputs label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.pl-rules-energy-inputs input { width: 70px; }

.pl-rule-table-header, .pl-rule-row {
  display: grid;
  align-items: center;
  gap: 10px;
}
.pl-rule-table-header { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 0 4px 8px; }
.pl-rule-table { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow-y: auto; }
.pl-rule-row { background: var(--panel); border: 1px solid var(--stroke); border-radius: 10px; padding: 8px; }
.pl-rule-thumb { object-fit: contain; image-rendering: pixelated; border-radius: 4px; background: var(--panel-2); }
.pl-rule-override-input { width: 100%; box-sizing: border-box; }

.pl-pref-toggle-group { display: flex; gap: 6px; }
.pl-pref-toggle {
  cursor: pointer; flex: 1;
  background: none; border: 1px solid var(--stroke); color: var(--muted);
  border-radius: 8px; padding: 8px; font-size: 11px; font-weight: 700;
}
.pl-pref-toggle--wanted { color: #06060f; background: var(--green); border-color: transparent; }
.pl-pref-toggle--unwanted { color: #06060f; background: var(--red); border-color: transparent; }

@media (max-width: 640px) {
  .pl-rule-table-header, .pl-rule-row { grid-template-columns: 1fr !important; }
  .pl-rule-table-header span:not(:first-child) { display: none; }
}

/* ---------- Scan screenshot ---------- */

.pl-scan { padding: 20px 0 40px; }
.pl-scan-form { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.pl-scan-file { cursor: pointer; }
.pl-scan-file--disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.pl-scan-stage {
  border: 1px solid var(--stroke);
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel-2);
  margin-bottom: 12px;
}
.pl-scan-stage--empty { padding: 48px 16px; text-align: center; color: var(--muted); }
/* Canvas keeps the screenshot's native resolution (the scan reads it 1:1);
   CSS scales it to the column, and pointer math converts back. */
.pl-scan-canvas { display: block; width: 100%; height: auto; cursor: move; touch-action: none; }
.pl-scan-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.pl-scan-controls input[type="range"] { flex: 1 1 160px; min-width: 120px; }
.pl-scan-label { font-size: 12px; color: var(--muted); margin-left: 6px; }
.pl-scan-buttons { flex-wrap: wrap; }
.pl-scan-status { font-size: 13px; color: var(--muted); min-height: 1.4em; margin: 0 0 14px; }
.pl-scan-review {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border: 1px solid var(--violet);
  border-radius: 10px;
  background: rgba(155, 107, 255, 0.1);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
}
