/* ============================================================
   WORKSPACE (outer container — holds LEDGER and WORKSHOP spaces)
   ============================================================ */
.workspace {
  background:
    linear-gradient(180deg, #2a3e4a 0%, #1a2830 100%);
  background-image:
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(180deg, var(--grid) 1px, transparent 1px),
    linear-gradient(180deg, #2a3e4a 0%, #1a2830 100%);
  background-size: 24px 24px, 24px 24px, 100% 100%;
  border: 4px solid var(--brass-dark);
  border-radius: 6px;
  padding: 14px;
  color: #e4d8b8;
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,0.05),
    inset 0 -4px 10px rgba(0,0,0,0.4),
    0 6px 14px rgba(0,0,0,0.4);
}

.cd-header {
  background: linear-gradient(180deg, var(--brass) 0%, var(--brass-dark) 100%);
  color: #fdf0d5;
  padding: 8px 12px;
  border-radius: 3px;
  margin-bottom: 12px;
  border: 1px solid var(--brass-dark);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.2),
    inset 0 -2px 4px rgba(0,0,0,0.3);
}
.cd-header h3 {
  font-size: 13px;
  letter-spacing: 3px;
  font-family: 'Didot', Georgia, serif;
}
.cd-header .chassis-info {
  font-family: 'Courier New', monospace;
  font-size: 11px;
}
.cd-header .chassis-info strong { color: var(--gold); letter-spacing: 1px; }
.cd-header .view-toggle { margin-left: auto; }

/* ============================================================
   CHAIN ROWS
   ============================================================ */
.rails-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 12px;
  min-height: 120px;
}

.chain-row {
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--brass);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.06);
}

.chain-header {
  background: linear-gradient(180deg, var(--brass) 0%, var(--brass-dark) 100%);
  padding: 4px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--brass-dark);
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  color: #fdf0d5;
}
.chain-label { letter-spacing: 3px; font-weight: bold; }
.chain-meter {
  background: var(--ink);
  color: var(--ok);
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 10px;
  border: 1px solid rgba(61, 139, 80, 0.6);
}
.chain-meter.warn { color: var(--warn); border-color: rgba(200, 136, 40, 0.6); }
.chain-meter.over {
  color: var(--bad);
  border-color: var(--bad);
  animation: pulseBad 1s infinite;
}
@keyframes pulseBad {
  50% { background: rgba(166, 48, 48, 0.2); }
}

.chain-body {
  padding: 12px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: stretch;
  background:
    repeating-linear-gradient(90deg,
      transparent 0 20px,
      rgba(184, 117, 67, 0.05) 20px 21px);
}

.chain-arrow {
  align-self: center;
  color: var(--copper);
  font-size: 22px;
  font-weight: bold;
  line-height: 1;
  padding: 0 2px;
  text-shadow: 0 0 6px rgba(184, 117, 67, 0.5);
  user-select: none;
}

/* ============================================================
   BATTERY CLUSTER (parallel batteries at chain head)
   ============================================================ */
.battery-cluster {
  background: linear-gradient(180deg, rgba(45, 90, 63, 0.4) 0%, rgba(26, 54, 38, 0.6) 100%);
  border: 1px solid var(--green-dark);
  border-radius: 3px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 120px;
  max-width: 180px;
}
.cluster-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding-bottom: 4px;
  border-bottom: 1px dashed rgba(253, 240, 213, 0.2);
}
.voltage-badge {
  background: var(--ink);
  color: var(--gold);
  font-family: 'Courier New', monospace;
  font-size: 13px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--gold);
  letter-spacing: 1px;
}
.cluster-cap {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  color: rgba(253, 240, 213, 0.8);
}

.cluster-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.battery-tile {
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-dark) 100%);
  border: 1px solid var(--paper-edge);
  border-radius: 3px;
  padding: 3px 5px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ink);
  position: relative;
  cursor: pointer;
  transition: transform 0.12s;
  font-size: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.battery-tile:hover { transform: translateY(-1px); }
.battery-tile.locked { cursor: default; opacity: 0.9; }
.battery-tile .bat-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.battery-tile .bat-name {
  font-weight: bold;
  font-size: 9px;
  letter-spacing: 0.3px;
}
.battery-tile .remove-x {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  background: var(--red);
  color: white;
  border-radius: 50%;
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  border: 1px solid var(--red-dark);
}
.battery-tile:hover .remove-x { opacity: 1; }
.battery-tile .lock-badge {
  font-size: 10px;
  opacity: 0.6;
}

.cluster-add {
  background: transparent;
  color: rgba(253, 240, 213, 0.6);
  border: 1px dashed rgba(253, 240, 213, 0.3);
  border-radius: 2px;
  padding: 2px 8px;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  cursor: pointer;
  letter-spacing: 1px;
}
.cluster-add:hover {
  background: rgba(253, 240, 213, 0.1);
  color: #fdf0d5;
  border-color: rgba(253, 240, 213, 0.6);
}

/* ============================================================
   SLOTS
   Each slot is a vertical mini-card showing zone + part (or +).
   Zone tint comes from .zone-*v modifier classes.
   ============================================================ */
.slot {
  min-width: 130px;
  max-width: 170px;
  border-radius: 3px;
  padding: 4px 6px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: linear-gradient(180deg, rgba(253, 240, 213, 0.05) 0%, rgba(0, 0, 0, 0.25) 100%);
  border: 1px solid rgba(253, 240, 213, 0.15);
  position: relative;
  transition: transform 0.12s;
}
.slot .slot-zone {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: rgba(253, 240, 213, 0.5);
  text-align: center;
  text-transform: uppercase;
  padding: 2px 0 3px;
  border-bottom: 1px dashed rgba(253, 240, 213, 0.15);
}

/* Zone tints — applied by .zone-9v / .zone-5v / .zone-3v etc. */
.slot.zone-9v  { border-left: 3px solid #c77a3a; }   /* 9V: copper */
.slot.zone-9v  .slot-zone { color: #e8a66e; }
.slot.zone-5v  { border-left: 3px solid #5aa0c4; }   /* 5V: blue */
.slot.zone-5v  .slot-zone { color: #7fc3e8; }
.slot.zone-3v  { border-left: 3px solid #68c47e; }   /* 3V: green */
.slot.zone-3v  .slot-zone { color: #98e8b0; }
.slot.zone-1\.5v { border-left: 3px solid #c4c4c4; }
.slot.zone-1\.5v .slot-zone { color: #d8d8d8; }

/* Empty slot */
.slot.slot-empty {
  cursor: pointer;
  background: repeating-linear-gradient(
    -45deg,
    rgba(253, 240, 213, 0.03) 0 6px,
    rgba(253, 240, 213, 0.07) 6px 12px);
  border-style: dashed;
}
.slot.slot-empty:hover {
  background: repeating-linear-gradient(
    -45deg,
    rgba(201, 169, 97, 0.08) 0 6px,
    rgba(201, 169, 97, 0.16) 6px 12px);
  transform: translateY(-1px);
}
.slot.slot-empty .slot-plus {
  font-size: 34px;
  font-weight: 300;
  text-align: center;
  color: rgba(253, 240, 213, 0.4);
  line-height: 1;
  padding: 10px 0 4px;
}
.slot.slot-empty:hover .slot-plus { color: var(--gold); }
.slot.slot-empty .slot-hint {
  font-size: 9px;
  font-style: italic;
  text-align: center;
  color: rgba(253, 240, 213, 0.35);
  letter-spacing: 0.5px;
}

/* Filled slot: part mini-tile */
.slot-part {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 2px 4px;
}
.slot-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(253, 240, 213, 0.08);
  border-radius: 2px;
  padding: 2px;
}
.slot-name {
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 0.3px;
  text-align: center;
  line-height: 1.15;
  color: #fdf0d5;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot-specs {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  color: rgba(253, 240, 213, 0.65);
  text-align: center;
}
.slot-warn {
  background: var(--bad);
  color: #fff;
  font-family: 'Courier New', monospace;
  font-size: 8px;
  font-weight: bold;
  letter-spacing: 1px;
  padding: 1px 4px;
  border-radius: 2px;
  margin-top: 2px;
  animation: pulseBad 1.5s infinite;
}
.slot-lock {
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--gold);
  margin-top: 2px;
  font-family: 'Courier New', monospace;
}

/* Broken part slot */
.slot.slot-voltage_mismatch,
.slot.slot-no_power,
.slot.slot-invalid_part {
  border-color: var(--bad);
  background: linear-gradient(180deg, rgba(166, 48, 48, 0.15) 0%, rgba(0, 0, 0, 0.3) 100%);
}

/* Remove-X on filled slots (non-locked) */
.slot-part .remove-x {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 16px;
  height: 16px;
  background: var(--red);
  color: white;
  border-radius: 50%;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  border: 1px solid var(--red-dark);
  cursor: pointer;
}
.slot:hover .slot-part .remove-x { opacity: 1; }

/* ============================================================
   PASSIVES SECTION
   ============================================================ */
.passives-section {
  background: rgba(0, 0, 0, 0.35);
  border: 1px dashed var(--green);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}
.passives-header {
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  padding: 4px 10px;
  color: #fdf0d5;
  font-size: 10px;
  letter-spacing: 2px;
  text-align: center;
}
.passives-body {
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 44px;
  align-items: center;
}

/* Passive tile (re-uses .part-tile from old styles — keep compact form) */
.part-tile {
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-dark) 100%);
  border: 1px solid var(--paper-edge);
  border-radius: 3px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  position: relative;
  cursor: pointer;
  min-width: 140px;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
}
.part-tile .tile-icon {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.part-tile .tile-info { flex: 1; min-width: 0; }
.part-tile .tile-name {
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.part-tile .tile-specs {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  color: var(--ink-light);
}
.part-tile .remove-x {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  background: var(--red);
  color: white;
  border-radius: 50%;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  border: 1px solid var(--red-dark);
}
.part-tile:hover .remove-x { opacity: 1; }

/* ============================================================
   CIRCUIT ACTIONS ROW
   ============================================================ */
.cd-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.cd-actions button {
  background: linear-gradient(180deg, var(--brass) 0%, var(--brass-dark) 100%);
  color: #fdf0d5;
  border: 1px solid var(--brass-dark);
  padding: 8px 14px;
  font-family: Georgia, serif;
  font-size: 11px;
  letter-spacing: 1.5px;
  border-radius: 3px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.3);
}
.cd-actions button:hover { transform: translateY(-1px); }
.cd-actions button:active { transform: translateY(1px); }
.cd-actions button.catalog-btn {
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  margin-left: auto;
}

/* ============================================================
   POWER SUMMARY (bulk / draw / chain count)
   ============================================================ */
.power-summary {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--brass-dark);
  border-radius: 3px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
}
.meter-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.meter-label {
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--gold);
  text-transform: uppercase;
}
.meter-bar {
  height: 12px;
  background: var(--ink);
  border: 1px solid var(--brass-dark);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.meter-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ok) 0%, #5eb27a 100%);
  transition: width 0.4s;
}
.meter-bar-fill.warn { background: linear-gradient(90deg, var(--warn), #e6b85c); }
.meter-bar-fill.over { background: linear-gradient(90deg, var(--bad), #d65050); }
.meter-bar-target {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 2px dashed var(--gold);
  opacity: 0.6;
}
.meter-val {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  color: #fdf0d5;
}

@media (max-width: 600px) {
  .power-summary { grid-template-columns: 1fr; }
}

/* ============================================================
   TUNING BADGE on filled slots (tuneable parts)
   ============================================================ */
.slot-tuning {
  background: var(--ink);
  color: var(--gold);
  font-family: 'Courier New', monospace;
  font-size: 9px;
  font-weight: bold;
  letter-spacing: 1px;
  padding: 1px 6px;
  border-radius: 2px;
  border: 1px solid var(--brass-dark);
  margin-top: 2px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
}
.slot-tuning.locked {
  opacity: 0.7;
}

/* Tuneable slots get a subtle hover affordance on the whole body */
.slot.slot-tuneable {
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.slot.slot-tuneable:hover {
  transform: translateY(-1px);
  box-shadow:
    0 3px 6px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(253, 240, 213, 0.1);
}
.slot.slot-tuneable:hover .slot-tuning {
  color: #fdf0d5;
  border-color: var(--gold);
}

/* Base-draw badge on workbench chain header */
.chain-header .chain-base {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  background: rgba(43, 24, 16, 0.3);
  color: rgba(253, 240, 213, 0.75);
  padding: 1px 6px;
  border-radius: 2px;
  border: 1px dashed rgba(253, 240, 213, 0.2);
  letter-spacing: 0.5px;
  margin-left: 6px;
}

/* ============================================================
   SPACE TOGGLE — top-level LEDGER vs WORKSHOP
   ============================================================ */
.space-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  background: linear-gradient(180deg, #1a2830 0%, #0e1a20 100%);
  border: 2px solid var(--brass-dark);
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.05),
    inset 0 -2px 4px rgba(0,0,0,0.4);
}

.space-toggle .space-btn {
  background: transparent;
  color: rgba(201, 169, 97, 0.55);
  border: 1px solid transparent;
  padding: 8px 22px;
  font-family: Georgia, serif;
  font-size: 13px;
  letter-spacing: 4px;
  font-weight: bold;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
}
.space-toggle .space-btn:hover {
  color: var(--gold);
  background: rgba(201, 169, 97, 0.08);
}
.space-toggle .space-btn.active {
  background: linear-gradient(180deg, var(--brass) 0%, var(--brass-dark) 100%);
  color: #fdf0d5;
  border-color: var(--gold);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.25),
    0 2px 4px rgba(0,0,0,0.35);
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

.space-toggle-chassis {
  margin-left: auto;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  color: rgba(201, 169, 97, 0.7);
  padding: 0 10px;
}
.space-toggle-chassis strong {
  color: var(--gold);
  letter-spacing: 2px;
}

.space-toggle .back-to-board-btn {
  margin-left: 0;
  padding: 6px 12px;
  font-size: 10px;
  letter-spacing: 1px;
  background: rgba(43, 24, 16, 0.6);
  color: var(--gold);
  border: 1px solid var(--brass-dark);
  border-radius: 3px;
  cursor: pointer;
  font-family: Georgia, serif;
}
.space-toggle .back-to-board-btn:hover {
  background: rgba(166, 48, 48, 0.6);
  color: #fdf0d5;
}

/* ============================================================
   SPACE VISIBILITY — only one space visible at a time
   ============================================================ */
.space {
  display: none;
}
.space.active {
  display: block;
}

/* ============================================================
   LEDGER PAGE — dedicated space for inventory + crafting
   ============================================================ */
.ledger-page {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 14px;
  align-items: start;
}

.ledger-panel {
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-dark) 100%);
  border: 3px solid var(--brass-dark);
  border-radius: 4px;
  padding: 12px 14px;
  color: var(--ink);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 2px 4px rgba(0, 0, 0, 0.2);
}

.ledger-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 2px dashed var(--paper-edge);
}
.ledger-panel-head h3 {
  font-family: 'Didot', Georgia, serif;
  font-size: 13px;
  letter-spacing: 3px;
  color: var(--ink);
  margin: 0;
}
.ledger-panel-count {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--ink-light);
  background: rgba(43, 24, 16, 0.08);
  padding: 2px 8px;
  border-radius: 2px;
  border: 1px solid var(--paper-edge);
}
.ledger-panel-count.live {
  background: var(--green);
  color: #fdf0d5;
  border-color: var(--green-dark);
  font-weight: bold;
}

.ledger-panel-body {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 64px;
  align-items: flex-start;
}

/* Crafting panel body is column, not flex-wrap */
.ledger-panel-craft .ledger-panel-body {
  flex-direction: column;
  align-items: stretch;
}

/* ============================================================
   LEDGER CRAFT PREVIEW — compact recipe list
   ============================================================ */
.ledger-craft-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.ledger-craft-row {
  display: grid;
  grid-template-columns: 20px 1fr 20px 1fr;
  gap: 6px;
  align-items: center;
  padding: 5px 8px;
  background: rgba(253, 240, 213, 0.5);
  border: 1px solid var(--paper-edge);
  border-left: 3px solid var(--paper-edge);
  border-radius: 2px;
  font-family: Georgia, serif;
  font-size: 10px;
  color: var(--ink-light);
  transition: all 0.15s;
}
.ledger-craft-row.live {
  border-left-color: var(--green-dark);
  background: rgba(253, 240, 213, 0.9);
  color: var(--ink);
}

.craft-row-state {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  font-weight: bold;
  text-align: center;
  color: var(--ink-light);
}
.ledger-craft-row.live .craft-row-state { color: var(--green-dark); }

.craft-row-inputs {
  font-size: 10px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.craft-row-arrow {
  text-align: center;
  color: var(--brass-dark);
  font-weight: bold;
}
.craft-row-output {
  font-weight: bold;
  color: var(--ink);
  font-size: 10px;
  line-height: 1.2;
}
.ledger-craft-row:not(.live) .craft-row-output { color: var(--ink-light); }

@media (max-width: 900px) {
  .ledger-page { grid-template-columns: 1fr; }
}
