@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap");

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; font-family: 'Courier New', monospace; background: #0a0a0a; color: #e8e8e8; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; }

/* ── PASSWORD GATE ── */
#gate {
  position: fixed; inset: 0; z-index: 2000;
  background: #0a0a0a;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Inter', 'Courier New', sans-serif;
}
#gate.hidden { display: none; }
.gate-inner { text-align: center; max-width: 360px; padding: 32px; }
.gate-mark {
  width: 56px; height: 56px; border-radius: 12px;
  background: #8c5b3c; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; letter-spacing: 0.06em;
  margin-bottom: 24px;
}
.gate-title { font-size: 28px; font-weight: 300; color: #c57b45; letter-spacing: 3px; margin-bottom: 6px; font-family: 'Courier New', monospace; }
.gate-sub { font-size: 12px; color: #555; letter-spacing: 2px; margin-bottom: 36px; }
.gate-form { display: flex; gap: 8px; margin-bottom: 12px; }
.gate-input {
  flex: 1; padding: 12px 16px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px; color: #e8e8e8;
  font-family: 'Courier New', monospace; font-size: 14px; letter-spacing: 1px;
  outline: none; transition: border-color 0.2s;
}
.gate-input:focus { border-color: rgba(197,123,69,0.5); }
.gate-btn {
  padding: 12px 24px;
  background: rgba(197,123,69,0.2); border: 1px solid #c57b45;
  color: #c57b45; cursor: pointer;
  font-family: 'Courier New', monospace; font-size: 12px; font-weight: 600;
  letter-spacing: 2px; border-radius: 5px;
  transition: background 0.2s;
}
.gate-btn:hover { background: rgba(197,123,69,0.4); }
.gate-error { font-size: 11px; color: #e74c3c; min-height: 16px; letter-spacing: 1px; }
.gate-footer { margin-top: 32px; }
.gate-link { font-size: 12px; color: #555; text-decoration: none; letter-spacing: 1px; transition: color 0.2s; }
.gate-link:hover { color: #c57b45; }

/* ── SCREENS ── */
.screen-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 800; display: none; }
.screen-overlay.active { display: flex; }

/* ── INTRO ── */
#introScreen { background: rgba(8,8,8,0.97); align-items: center; justify-content: center; flex-direction: column; z-index: 1000; cursor: pointer; }
.intro-title { font-size: 52px; font-weight: bold; color: #c57b45; margin-bottom: 6px; letter-spacing: 4px; }
.intro-subtitle { font-size: 18px; color: #777; margin-bottom: 40px; letter-spacing: 2px; }
.intro-cta { font-size: 15px; color: #aaa; margin-bottom: 50px; }

/* ── WORKSHOP ── */
#workshopScreen { background: rgba(6,6,8,0.98); flex-direction: column; align-items: center; justify-content: center; z-index: 900; }
.ws-header { text-align: center; margin-bottom: 40px; }
.ws-title { font-size: 28px; color: #c57b45; letter-spacing: 3px; font-weight: bold; margin-bottom: 6px; }
.ws-sub { font-size: 12px; color: #666; letter-spacing: 2px; }
.ws-tools { display: flex; gap: 20px; margin-bottom: 40px; flex-wrap: wrap; justify-content: center; max-width: 900px; }
.ws-tool-btn { width: 180px; height: 160px; background: rgba(20,20,24,0.95); border: 1px solid rgba(197,123,69,0.2); border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; transition: all 0.2s; }
.ws-tool-btn:hover { border-color: rgba(197,123,69,0.6); background: rgba(197,123,69,0.06); transform: translateY(-2px); }
.ws-tool-btn.active { border-color: #c57b45; background: rgba(197,123,69,0.12); }
.ws-tool-icon { font-size: 36px; color: #c57b45; }
.ws-tool-name { font-size: 13px; color: #aaa; letter-spacing: 2px; font-weight: bold; }
.ws-tool-desc { font-size: 10px; color: #555; text-align: center; padding: 0 12px; }
.ws-queue { display: flex; gap: 10px; margin-bottom: 30px; flex-wrap: wrap; justify-content: center; max-width: 800px; }
.ws-queue-piece { padding: 8px 14px; background: rgba(30,28,24,0.9); border: 1px solid rgba(197,123,69,0.25); border-radius: 3px; font-size: 11px; color: #b8a080; cursor: pointer; transition: all 0.15s; }
.ws-queue-piece:hover { border-color: #c57b45; }
.ws-queue-piece.selected { border-color: #c57b45; background: rgba(197,123,69,0.15); color: #c57b45; }
.ws-queue-label { font-size: 9px; color: #555; letter-spacing: 2px; margin-bottom: 8px; text-align: center; }
.ws-bottom-bar { display: flex; gap: 12px; }
.ws-bar-btn { padding: 12px 28px; background: rgba(197,123,69,0.15); border: 1px solid rgba(197,123,69,0.4); color: #c57b45; cursor: pointer; font-family: 'Courier New', monospace; font-size: 12px; letter-spacing: 2px; border-radius: 3px; transition: all 0.15s; }
.ws-bar-btn:hover { background: rgba(197,123,69,0.3); }
.ws-bar-btn.primary { background: rgba(197,123,69,0.25); border-color: #c57b45; }
.ws-bar-btn.muted { background: transparent; border-color: rgba(255,255,255,0.1); color: #666; }

/* ── TOOL PANELS ── */
.tool-panel { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(10,10,14,0.98); border: 1px solid rgba(197,123,69,0.4); border-radius: 6px; padding: 28px 32px; width: 420px; z-index: 950; display: none; backdrop-filter: blur(12px); }
.tool-panel.active { display: block; }
.tp-title { color: #c57b45; font-size: 16px; font-weight: bold; letter-spacing: 2px; margin-bottom: 16px; border-bottom: 1px solid rgba(197,123,69,0.2); padding-bottom: 10px; }
.tp-row { margin: 12px 0; }
.tp-label { color: #888; font-size: 10px; letter-spacing: 2px; margin-bottom: 4px; }
.tp-val { color: #c57b45; font-weight: bold; font-size: 15px; }
.tp-slider { width: 100%; margin: 4px 0; cursor: pointer; accent-color: #c57b45; }
.tp-toggles { display: flex; gap: 8px; margin: 10px 0; }
.tp-tog { flex: 1; padding: 8px 0; text-align: center; background: rgba(197,123,69,0.08); border: 1px solid rgba(197,123,69,0.25); color: #777; cursor: pointer; font-size: 11px; font-family: 'Courier New', monospace; border-radius: 3px; transition: all 0.15s; }
.tp-tog.active { background: rgba(197,123,69,0.4); color: #fff; border-color: #c57b45; }
.tp-piece-info { color: #888; font-size: 11px; margin: 10px 0; padding: 8px 10px; background: rgba(255,255,255,0.02); border-radius: 3px; border: 1px solid rgba(255,255,255,0.04); }
.tp-btn { width: 100%; padding: 12px; margin-top: 8px; background: rgba(197,123,69,0.2); border: 1px solid #c57b45; color: #c57b45; cursor: pointer; font-family: 'Courier New', monospace; font-size: 13px; border-radius: 3px; letter-spacing: 1px; transition: background 0.15s; }
.tp-btn:hover { background: rgba(197,123,69,0.45); }
.tp-btn.secondary { background: transparent; border-color: rgba(197,123,69,0.25); color: #777; font-size: 11px; }

/* ── CATALOG ── */
#catalogPanel { width: 640px; max-height: 80vh; overflow: hidden; padding: 0; }
#catalogPanel .tp-title { padding: 20px 24px 10px; margin: 0; }
.cat-tabs { display: flex; border-bottom: 1px solid rgba(255,255,255,0.06); padding: 0 24px; }
.cat-tab { flex: 1; text-align: center; padding: 10px; color: #555; cursor: pointer; font-size: 11px; letter-spacing: 1px; border-bottom: 2px solid transparent; transition: all 0.15s; }
.cat-tab.active { color: #c57b45; border-bottom-color: #c57b45; }
.cat-tab:hover { color: #aaa; }
.cat-body { max-height: 50vh; overflow-y: auto; padding: 12px 24px; scrollbar-width: thin; scrollbar-color: #333 #111; }
.cat-item { display: flex; align-items: center; padding: 10px 12px; margin-bottom: 6px; background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.04); border-radius: 3px; cursor: pointer; transition: all 0.15s; }
.cat-item:hover { background: rgba(197,123,69,0.08); border-color: rgba(197,123,69,0.3); }
.cat-swatch { width: 36px; height: 36px; border-radius: 3px; margin-right: 14px; flex-shrink: 0; border: 1px solid rgba(255,255,255,0.08); }
.cat-info { flex: 1; }
.cat-info strong { color: #ddd; font-size: 13px; }
.cat-info small { color: #666; font-size: 10px; }

/* ── 3D HUD ── */
#assemblyHUD { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; display: none; }
#assemblyHUD.active { display: block; }
.a-hud-top { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; pointer-events: auto; }
.a-hud-btn { padding: 10px 18px; background: rgba(6,6,6,0.85); border: 1px solid rgba(197,123,69,0.3); color: #888; cursor: pointer; font-family: 'Courier New', monospace; font-size: 11px; letter-spacing: 1px; border-radius: 3px; transition: all 0.15s; backdrop-filter: blur(4px); }
.a-hud-btn:hover { border-color: rgba(197,123,69,0.6); color: #aaa; }
.a-hud-btn.active { background: rgba(197,123,69,0.2); border-color: #c57b45; color: #c57b45; }
.a-hud-info { position: absolute; bottom: 16px; left: 16px; font-size: 11px; color: #b8b8b8; pointer-events: none; }
.a-hud-selection { position: absolute; bottom: 16px; right: 16px; font-size: 11px; color: #c57b45; pointer-events: none; text-align: right; }
#crosshairOverlay { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 20px; height: 20px; border: 1.5px solid rgba(197,123,69,0.4); border-radius: 50%; display: none; pointer-events: none; }
#crosshairOverlay.active { display: block; }

/* ── ASSEMBLY TOOLBAR ── */
#assemblyToolbar { position: absolute; bottom: 50px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; pointer-events: auto; z-index: 60; }
.at-btn { padding: 10px 16px; background: rgba(6,6,8,0.9); border: 1px solid rgba(255,255,255,0.1); color: #777; cursor: pointer; font-family: 'Courier New', monospace; font-size: 10px; letter-spacing: 1px; border-radius: 3px; transition: all 0.15s; backdrop-filter: blur(4px); display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 64px; }
.at-btn:hover { border-color: rgba(197,123,69,0.5); color: #aaa; }
.at-btn.active { border-color: #c57b45; color: #c57b45; background: rgba(197,123,69,0.15); }
.at-icon { font-size: 16px; }
.at-label { font-size: 9px; letter-spacing: 1px; }

/* ── ASSEMBLIES PANEL ── */
#assembliesPanel { position: absolute; top: 60px; right: 16px; width: 240px; max-height: 60vh; background: rgba(6,6,8,0.92); border: 1px solid rgba(255,255,255,0.08); border-radius: 4px; pointer-events: auto; z-index: 60; overflow-y: auto; display: none; backdrop-filter: blur(6px); scrollbar-width: thin; scrollbar-color: #333 transparent; }
#assembliesPanel.active { display: block; }
.lp-title { font-size: 10px; color: #888; letter-spacing: 2px; padding: 10px 12px 6px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.lp-group { border-bottom: 1px solid rgba(255,255,255,0.03); }
.lp-group-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; cursor: pointer; transition: background 0.1s; }
.lp-group-header:hover { background: rgba(197,123,69,0.06); }
.lp-group-name { font-size: 11px; color: #aaa; font-weight: 600; }
.lp-group-count { font-size: 9px; color: #555; }
.lp-group-actions { display: flex; gap: 6px; }
.lp-act { font-size: 11px; color: #666; cursor: pointer; padding: 2px 4px; }
.lp-act:hover { color: #c57b45; }
.lp-piece { display: flex; align-items: center; padding: 5px 12px 5px 24px; font-size: 10px; color: #777; cursor: pointer; transition: background 0.1s; }
.lp-piece:hover { background: rgba(197,123,69,0.06); }
.lp-piece.selected { color: #c57b45; background: rgba(197,123,69,0.08); }
.lp-piece.hidden-piece { opacity: 0.35; }

/* ── RIGHT-CLICK MENU ── */
#ctxMenu { position: absolute; display: none; background: rgba(8,8,12,0.96); border: 1px solid rgba(197,123,69,0.5); border-radius: 4px; z-index: 200; pointer-events: auto; min-width: 220px; backdrop-filter: blur(10px); }
#ctxMenu.show { display: block; }
.ctx-item { padding: 10px 18px; color: #aaa; cursor: pointer; font-family: 'Courier New', monospace; font-size: 11px; letter-spacing: 1px; transition: all 0.12s; }
.ctx-item:hover { background: rgba(197,123,69,0.15); color: #c57b45; }
.ctx-item.danger:hover { background: rgba(200,60,60,0.15); color: #f77; }
.ctx-sep { height: 1px; background: rgba(255,255,255,0.06); margin: 2px 0; }

/* ── SNAP + FASTEN BADGES ── */
.snap-badge { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -80px); font-size: 12px; color: #5ddb5d; letter-spacing: 1px; pointer-events: none; display: none; text-shadow: 0 0 8px rgba(93,219,93,0.5); }
.snap-badge.active { display: block; }
.fasten-badge { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50px); font-size: 13px; color: #c57b45; letter-spacing: 2px; pointer-events: none; display: none; text-shadow: 0 0 10px rgba(197,123,69,0.5); animation: fastenPulse 0.6s ease-out; }
.fasten-badge.active { display: block; }
@keyframes fastenPulse { 0% { transform: translate(-50%, -50px) scale(1.3); opacity: 1; } 100% { transform: translate(-50%, -50px) scale(1); opacity: 0.8; } }

/* ── MULTI-SELECT BOX ── */
#selectBox { position: absolute; border: 1px solid rgba(197,123,69,0.6); background: rgba(197,123,69,0.08); pointer-events: none; display: none; z-index: 55; }

/* ── BOM TABLE ── */
.bom-section { margin-bottom: 16px; }
.bom-section-title { font-size: 11px; color: #c57b45; letter-spacing: 2px; margin-bottom: 8px; border-bottom: 1px solid rgba(197,123,69,0.2); padding-bottom: 4px; }
.bom-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.bom-table th { text-align: left; color: #888; font-size: 9px; letter-spacing: 1px; padding: 4px 8px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.bom-table td { color: #bbb; padding: 4px 8px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.bom-table tr:hover td { color: #c57b45; }
.bom-total { font-size: 11px; color: #888; margin-top: 8px; text-align: right; }
