/* ============================================================
   BUILD-MODE LAYOUT (Besiege / Kerbal VAB / Aviassembly)
   ============================================================
   Design intent:
   - The canvas IS the window. Topbar above, footer below, and
     every other piece of UI (drawer, specs, bench, meters) floats
     on top of the canvas as overlays.
   - No stacked rows above/below the canvas. No dead brown space.
   - Overlays collapse or stay out of the way when not in use.
*/

/* ============================================================
   BODY PHASE TOGGLES
   ============================================================ */
body.phase-working {
  padding: 0;
  margin: 0;
  overflow: hidden;
  height: 100vh;
}
body.phase-working .workshop {
  max-width: none;
  width: 100%;
  height: 100vh;
  padding: 0;
  gap: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;   /* topbar | buildmode | footer */
}

body.phase-scrapyard .topbar        { display: none; }
body.phase-scrapyard .buildmode     { display: none; }
body.phase-scrapyard .action-bar    { display: none; }
body.phase-working .scrapyard       { display: none; }

/* ============================================================
   TOPBAR — thin build-mode header
   ============================================================ */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-dark) 100%);
  border-bottom: 3px solid var(--brass-dark);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2),
    0 2px 6px rgba(0, 0, 0, 0.25);
  z-index: 50;
}
.topbar-back {
  background: var(--paper);
  border: 2px solid var(--brass-dark);
  color: var(--ink);
  padding: 6px 12px;
  font-family: 'Didot', Georgia, serif;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 2px;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: background 0.1s ease, transform 0.05s ease;
}
.topbar-back:hover {
  background: var(--santa);
  color: var(--snow-cream);
  border-color: var(--santa-dark);
}
.topbar-back:active { transform: translateY(1px); }

.topbar-toy {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}
.topbar-toy-name {
  font-family: 'Didot', Georgia, serif;
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 2px;
  color: var(--snow-cream);
  text-shadow: 1px 1px 0 var(--wood-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-toy-budget {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: var(--gold);
  letter-spacing: 1px;
}

.topbar-pills {
  display: flex;
  gap: 8px;
  align-items: center;
}
.topbar-pill {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 10px;
  background: var(--snow-cream);
  border: 2px solid var(--brass-dark);
  border-radius: 3px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}
.pill-label {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 1px;
  color: var(--brass-dark);
}
.pill-value {
  font-family: 'Didot', Georgia, serif;
  font-size: 16px;
  font-weight: bold;
  color: var(--ink);
  line-height: 1;
}
.pill-sub {
  font-family: Georgia, serif;
  font-size: 9px;
  font-style: italic;
  color: var(--ink-light);
}
.pill-wc { background: linear-gradient(180deg, #fff8e8 0%, #ffe0a8 100%); }
.pill-rp .pill-value { color: var(--sky-dark); }
.pill-clock {
  background: var(--paper-dark);
  font-family: 'Courier New', monospace;
}

/* ============================================================
   BUILDMODE CONTAINER — fills all space between topbar + footer
   ============================================================ */
.buildmode {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, rgba(253, 240, 213, 0.04) 0%, transparent 70%),
    linear-gradient(180deg, rgba(107, 68, 35, 0.28) 0%, rgba(58, 36, 22, 0.38) 100%);
}

/* ============================================================
   BUILD CANVAS — absolutely-positioned backdrop, fills buildmode
   ============================================================ */
.build-canvas {
  position: absolute;
  inset: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: none;
}
.build-canvas::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(201, 169, 97, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(201, 169, 97, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
}

.rails-container {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
}

.bb-wrap {
  width: 100%;
  height: 100%;
  display: block;
}
.bb-viewport {
  width: 100%;
  height: 100%;
}

/* ============================================================
   DRAWER (overlay, top-left)
   ============================================================ */
.part-drawer {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 320px;              /* leave room for specs floater on the right */
  z-index: 15;
  margin: 0;
}

/* ============================================================
   NEXT-ACTION HINT (overlay, under drawer)
   ============================================================ */
.next-action-bar {
  position: absolute;
  left: 10px;
  right: 320px;
  top: 66px;
  z-index: 14;
  pointer-events: none;
  margin: 0;          /* override legacy margin from main.css */
}
.next-action-bar:empty { display: none; }
.next-action-bar > * { pointer-events: auto; }

/* Close × button on the hint banner. Small, tucked to the right,
   matches the banner's own paper palette. */
.na-close {
  flex-shrink: 0;
  margin-left: auto;
  background: transparent;
  border: 1.5px solid var(--brass-dark);
  color: var(--ink);
  width: 20px;
  height: 20px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: background 0.1s ease;
}
.na-close:hover {
  background: var(--santa);
  color: var(--snow-cream);
  border-color: var(--santa-dark);
}

/* ============================================================
   PASSIVES SECTION (overlay, bottom-left, compact)
   ============================================================ */
.passives-section {
  position: absolute;
  left: 10px;
  bottom: 88px;
  z-index: 12;
  background: rgba(42, 20, 8, 0.6);
  border: 2px solid var(--brass-dark);
  border-radius: 4px;
  padding: 5px 8px 6px;
  min-width: 180px;
  backdrop-filter: blur(2px);
}
/* Hide when there are no passives — prevents tiny empty plate */
.passives-section:has(.empty-hint) { display: none; }
.passives-header {
  font-family: 'Didot', Georgia, serif;
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--gold);
  margin-bottom: 4px;
}
.passives-body {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  min-height: 0;
}

/* ============================================================
   BUILD METERS (overlay, bottom-right)
   ============================================================ */
.build-meters {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 10px;
  background: rgba(42, 20, 8, 0.6);
  border: 2px solid var(--brass-dark);
  border-radius: 4px;
  min-width: 260px;
  backdrop-filter: blur(2px);
}
.build-meters .meter-row {
  display: grid;
  grid-template-columns: 54px 1fr 60px;
  gap: 6px;
  align-items: center;
}
.build-meters .meter-label {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--gold);
  text-transform: uppercase;
}
.build-meters .meter-bar {
  height: 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--brass-dark);
  border-radius: 2px;
  overflow: hidden;
}
.build-meters .meter-bar-fill {
  height: 100%;
  background: linear-gradient(180deg, var(--gold), var(--brass));
  transition: width 0.2s ease;
}
.build-meters .meter-val {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  color: var(--snow-cream);
  text-align: right;
}

/* ============================================================
   FLOATING SPECS WINDOW — Kerbal objectives panel
   ============================================================ */
.specs-floater {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 290px;
  background: var(--snow-cream);
  border: 3px solid var(--brass-dark);
  border-radius: 6px;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
  z-index: 20;
  font-family: Georgia, serif;
  max-height: calc(100vh - 180px);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s ease, transform 0.12s ease;
}

/* Dragging state: lift the window, slight tilt, stronger shadow — a
   clear "I'm being carried" affordance. No transition on position or
   left/top so the drag tracking is 1:1 with the pointer. */
.specs-floater.dragging {
  box-shadow:
    0 10px 26px rgba(0, 0, 0, 0.55),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
  transform: rotate(-0.4deg) scale(1.01);
  cursor: grabbing;
}
.specs-floater-head {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px 8px;
  background: linear-gradient(180deg, var(--candy) 0%, var(--santa) 100%);
  border-bottom: 2px solid var(--santa-dark);
  border-radius: 3px 3px 0 0;
  color: var(--snow-cream);
  flex-shrink: 0;
}
.specs-floater-toy {
  width: 44px;
  height: 44px;
  background: var(--snow-cream);
  border: 2px solid var(--santa-dark);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.specs-floater-toy svg { width: 100%; height: 100%; }
.specs-floater-title { min-width: 0; }
.specs-floater-name {
  font-family: 'Didot', Georgia, serif;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 1px 1px 0 var(--santa-dark);
}
.specs-floater-tagline {
  font-size: 10px;
  font-style: italic;
  opacity: 0.9;
  line-height: 1.2;
  max-height: 2.4em;
  overflow: hidden;
}
.specs-floater-collapse {
  background: var(--snow-cream);
  border: 1.5px solid var(--santa-dark);
  color: var(--santa-dark);
  width: 22px;
  height: 22px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  align-self: start;
  margin-top: 2px;
  text-indent: -9999px;
  overflow: hidden;
}
.specs-floater-collapse:hover { background: var(--paper); }
.specs-floater:not(.collapsed) .specs-floater-collapse::before {
  content: '−'; text-indent: 0; float: left; margin-left: 6px; font-size: 14px;
}
.specs-floater.collapsed .specs-floater-collapse::before {
  content: '+'; text-indent: 0; float: left; margin-left: 6px; font-size: 14px;
}

.specs-floater-body {
  padding: 10px 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.specs-floater.collapsed .specs-floater-body,
.specs-floater.collapsed .specs-floater-foot { display: none; }

.spec-row {
  display: flex;
  align-items: start;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed rgba(201, 169, 97, 0.4);
  font-size: 12px;
}
.spec-row:last-child { border-bottom: none; }
.spec-check {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 2px solid var(--brass-dark);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  font-family: 'Courier New', monospace;
  font-weight: bold;
  font-size: 11px;
}
.spec-row.pass .spec-check {
  background: var(--ok);
  color: var(--snow-cream);
  border-color: var(--green-dark);
}
.spec-row.pass .spec-check::before { content: '✓'; }
.spec-row.fail .spec-check::before { content: '•'; color: var(--ink-light); }
.spec-text { flex: 1; color: var(--ink); line-height: 1.35; }
.spec-row.pass .spec-text { color: var(--ink-light); }
.spec-row.pass .spec-text-label {
  text-decoration: line-through;
  text-decoration-color: rgba(74, 133, 87, 0.5);
}
.spec-text-label { display: block; font-weight: normal; }
.spec-text-detail {
  display: block;
  font-size: 10px;
  color: var(--bad);
  font-style: italic;
  margin-top: 2px;
}

.specs-floater-foot {
  padding: 6px 12px 8px;
  border-top: 1px solid var(--paper-edge);
  background: var(--paper-dark);
  border-radius: 0 0 3px 3px;
  text-align: center;
  flex-shrink: 0;
}
.spec-serial {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--ink-light);
}

/* ============================================================
   BENCH STRIP — floating overlay at bottom
   ============================================================ */
.bench-strip {
  position: absolute;
  left: 10px;
  right: 290px;                  /* leave room for meters at right */
  bottom: 10px;
  z-index: 13;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 6px 10px;
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-dark) 100%);
  border: 3px solid var(--brass-dark);
  border-radius: 6px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -2px 0 rgba(0, 0, 0, 0.1),
    0 3px 6px rgba(0, 0, 0, 0.3);
  min-height: 64px;
}
.bench-strip-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 10px;
  border-right: 1px dashed var(--paper-edge);
}
.bench-strip-title {
  font-family: 'Didot', Georgia, serif;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 2px;
  color: var(--santa-dark);
}
.bench-strip-count {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  color: var(--ink-light);
  letter-spacing: 0.5px;
}
.bench-strip-body {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-height: 40px;
  padding: 2px;
}
.bench-strip-body:empty::before {
  content: 'Empty — procure parts from the drawer above.';
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 11px;
  color: var(--ink-light);
  padding: 6px 10px;
}
.bench-strip.drop-hover {
  border-color: var(--santa);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -2px 0 rgba(0, 0, 0, 0.1),
    0 0 0 2px rgba(200, 48, 48, 0.35),
    0 3px 10px rgba(200, 48, 48, 0.35);
}

.bench-craft-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 12px;
  background: linear-gradient(180deg, var(--holly) 0%, #1f5a2d 100%);
  border: 2px solid #133d1c;
  color: var(--snow-cream);
  font-family: 'Didot', Georgia, serif;
  font-weight: bold;
  letter-spacing: 2px;
  border-radius: 4px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.05s ease, background 0.15s ease;
  min-width: 74px;
}
.bench-craft-btn:hover {
  background: linear-gradient(180deg, #3f9553 0%, var(--holly) 100%);
  transform: translateY(-1px);
}
.bench-craft-btn:active { transform: translateY(0); }
.bench-craft-icon { font-size: 16px; }
.bench-craft-label { font-size: 9px; }
.bench-craft-sub {
  font-family: 'Courier New', monospace;
  font-size: 8px;
  font-weight: normal;
  letter-spacing: 0.5px;
  opacity: 0.85;
}
.bench-craft-btn.has-ready {
  animation: craftReadyPulse 2s ease-in-out infinite;
}
@keyframes craftReadyPulse {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 2px 4px rgba(0, 0, 0, 0.2); }
  50%      { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 2px 12px rgba(74, 133, 87, 0.7); }
}

/* ============================================================
   FOOTER ACTION BAR
   ============================================================ */
body.phase-working .action-bar {
  padding: 8px 14px;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-dark) 100%);
  border-top: 3px solid var(--brass-dark);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 2px 0 rgba(0, 0, 0, 0.15);
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 14px;
  align-items: center;
  z-index: 50;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .part-drawer, .next-action-bar { right: 250px; }
  .specs-floater { width: 230px; }
  .bench-strip { right: 240px; }
  .build-meters { min-width: 220px; }
}
@media (max-width: 780px) {
  .part-drawer, .next-action-bar, .bench-strip { right: 10px; }
  .specs-floater {
    top: auto; bottom: 10px; right: 10px;
    width: auto; left: 10px; max-height: 40vh;
  }
  .build-meters { display: none; }
  .passives-section { display: none; }
}
