:root {
  --primary-color: #f13c20;
  --bg-dark: #121212;
  --glass-bg: rgba(25, 25, 25, 0.7);
  --glass-border: rgba(255, 255, 255, 0.1);
  --text-color: #ededed;
}

* {
  box-sizing: border-box;
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body { margin: 0; overflow: hidden; background-color: var(--bg-dark); color: var(--text-color); user-select: none; }

#canvas-container {
  position: absolute; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#canvas-container canvas {
  touch-action: none;
  display: block;
}

#ui-container {
  position: absolute; top: 0; left: 0; width: 100vw; height: 100vh;
  pointer-events: none; z-index: 10; display: flex; flex-direction: column;
}

.glass-header {
  pointer-events: auto; background: var(--glass-bg); backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--glass-border);
  padding: 8px 15px; display: flex; justify-content: space-between; align-items: center;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.15);
  position: relative; z-index: 100;
  flex-wrap: nowrap; gap: 12px;
  min-height: 56px;
}
.glass-header::-webkit-scrollbar { height: 4px; }
.glass-header::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }


.header-left { display: flex; align-items: center; gap: 16px; }

.header-link-btn {
  background: transparent; border: none; color: rgba(255,255,255,0.7);
  font-size: 0.8rem; font-weight: 500; cursor: pointer; padding: 6px 10px;
  transition: color 0.2s;
}
.header-link-btn:hover { color: white; }

.controls-menu { position: relative; z-index: 300; }
.controls-content {
  display: none; position: absolute; top: 100%; left: 0;
  background: rgba(25, 25, 25, 0.95); backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border); border-radius: 8px;
  padding: 16px; width: 420px; max-height: 80vh; overflow-y: auto;
  z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,0.7);
}
.controls-content.show { display: block; }
.controls-content p { margin: 8px 0; font-size: 0.9rem; line-height: 1.4; color: #ddd; }
.controls-content b { color: var(--primary-color); }

.glass-header h1 {
  font-size: 1.2rem; font-weight: 700; white-space: nowrap;
  background: -webkit-linear-gradient(45deg, #f13c20, #ff7b54);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.stage-dims {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.8rem; background: rgba(0,0,0,0.3); padding: 6px 12px; border-radius: 6px; color: #aaa;
}
.dims-label { color: var(--primary-color); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
.stage-dims label { white-space: nowrap; }
.stage-dims input { width: 42px; background: rgba(255,255,255,0.1); color: white; border: 1px solid var(--glass-border); border-radius: 3px; text-align: center; padding: 3px; font-size: 0.8rem; }

#stage-info { display: flex; gap: 8px; align-items: center; font-size: 0.8rem; flex-shrink: 1; min-width: 0; }
#user-display {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    color: white;
    font-size: 13px;
    font-weight: bold;
    padding: 0 4px;
}


/* Auth group: pinned to right, never collapses */
.auth-group {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 12px;
    padding-left: 12px;
    border-left: 1px solid rgba(255,255,255,0.2);
    flex-shrink: 0;
}

/* Hide info chip text on narrower screens to save space */
@media (max-width: 1400px) {
    .info-chip { padding: 6px 10px; font-size: 0.75rem; }
    .stage-name-display { display: none; }
}
@media (max-width: 1200px) {
    .stage-dims { font-size: 0.7rem; padding: 4px 8px; }
    .stage-dims input { width: 36px; }
    .dims-label { display: none; }
}

.info-chip { background: rgba(0,0,0,0.3); padding: 6px 12px; border-radius: 6px; white-space: nowrap; }
.info-chip strong { color: var(--primary-color); font-size: 0.9rem; }
.stage-name-display strong { color: #10b981 !important; }

.btn-group { display: flex; gap: 0; }
.btn-group .action-btn { border-radius: 0; border-right: none; }
.btn-group .action-btn:first-child { border-radius: 6px 0 0 6px; }
.btn-group .action-btn:last-child { border-radius: 0 6px 6px 0; border-right: 1px solid rgba(255,255,255,0.15); }

.action-btn {
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255,255,255,0.85); padding: 6px 14px; border-radius: 6px; cursor: pointer;
  transition: all 0.15s; font-weight: 500; font-size: 0.78rem; white-space: nowrap;
}
.action-btn:hover { background: rgba(255, 255, 255, 0.18); color: white; }
.action-btn.accent { background: rgba(16, 185, 129, 0.25); border-color: rgba(16, 185, 129, 0.4); }
.action-btn.accent:hover { background: rgba(16, 185, 129, 0.4); }
.action-btn.danger { background: rgba(220, 38, 38, 0.25); border-color: rgba(220, 38, 38, 0.4); }
.action-btn.danger:hover { background: rgba(220, 38, 38, 0.45); }
.action-btn.toggle-btn.active { background: rgba(99, 102, 241, 0.35); border-color: rgba(99, 102, 241, 0.6); color: white; }
#stage-select { color: white; background: rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.15); border-radius: 0 6px 6px 0; padding: 6px 10px; font-size: 0.78rem; min-width: 70px; border-right: 1px solid rgba(255,255,255,0.15) !important; }
.btn-group #stage-select { border-radius: 0 6px 6px 0; border-right: 1px solid rgba(255,255,255,0.15); }

.glass-panel {
  pointer-events: auto; background: var(--glass-bg); backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border); border-radius: 12px; margin: 20px; padding: 10px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

#toolbar { width: 260px; max-height: calc(100vh - 120px); overflow-y: auto; height:fit-content; }
#toolbar h3 { margin-bottom: 10px; margin-left: 10px; padding-top: 10px; font-weight: 600; font-size: 1rem; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 8px; color:var(--primary-color); }
.category { margin-bottom: 2px; }
.cat-header { background: rgba(255,255,255,0.03); padding: 10px 15px; border-radius: 5px; cursor: pointer; font-weight: 500; transition: 0.2s; }
.cat-header:hover { background: rgba(255,255,255,0.1); }
.cat-items { display: none; padding-left: 10px; padding-top: 5px; }
.cat-items.show { display: block; } 

.tool-item { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.05); padding: 8px; margin: 5px 0; border-radius: 4px; cursor: grab; font-size: 0.85rem; font-weight: 500; transition: all 0.2s ease; }
.tool-item:hover { background: rgba(255, 255, 255, 0.15); border-color: var(--primary-color); transform: translateX(5px); }
.tool-item:active { cursor: grabbing; }

/* CSS Icons */
.css-icon { width: 20px; height: 20px; border: 1px solid #222; border-radius: 2px; box-shadow:inset 0 0 5px rgba(0,0,0,0.5); }
.target-brown { background: #c4a484; }
.target-white { background: #ffffff; }
.target-hardcover { background: #c4a484; border-left: 5px solid #222; border-right: 5px solid #222; }
.steel-popper { background: #fff; border-radius: 50% 50% 10% 10%; width:12px; margin-left:4px; }
.steel-mini-popper { background: #ddd; border-radius: 50% 50% 10% 10%; width:10px; height:14px; margin-left:5px; }
.steel-rack { background: repeating-linear-gradient(90deg, #fff, #fff 4px, transparent 4px, transparent 6px); height:6px; margin-top:7px; border:none; box-shadow:none;}
.steel-star { background: radial-gradient(circle, #fff 40%, transparent 40%); border-radius:50%;}
.steel-stop { background: #fff; border-radius: 50%; width:18px; height:18px; border: 2px solid #f00; }
.barrel { background: #1d4ed8; border-radius: 50%; }
.barrel-stack { background: #1d4ed8; border-radius: 5px; height: 24px;}
.wall-solid { background: #c19a6b; }
.wall-mesh { background: rgba(255,165,0,0.4); border: 2px solid #c19a6b; }
.wall-port { background: radial-gradient(circle, transparent 30%, #c19a6b 30%); }

.table-icon { background: #8B4513; border-radius: 2px; }
.door-icon { background: #a0522d; border-left: 3px solid #333; }
.cone-icon { background: transparent; width: 0; height: 0; border: none; box-shadow: none; border-left: 10px solid transparent; border-right: 10px solid transparent; border-bottom: 18px solid #ff6600; border-radius: 0; }
.fault-line { background: #ff0000; height: 6px; margin-top: 7px; border:none; box-shadow:none;}
.start-box { background: transparent; border: 2px dashed #ff0000; }

/* D-Pad controls */
#dpad { position: absolute; bottom: 20px; right: 20px; display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 15px; width: auto; }
.dpad-row { display: flex; gap: 5px; }
.dpad-btn { background: rgba(0,0,0,0.5); border: 1px solid var(--glass-border); color: white; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; transition: 0.1s; display:flex; justify-content:center; align-items:center; }
.dpad-btn:hover { background: var(--primary-color); }
.dpad-btn:active { transform: scale(0.9); }

/* Trash Bin */
#trash-bin {
  position: absolute; bottom: -100px; left: 50%; transform: translateX(-50%);
  background: rgba(200, 0, 0, 0.8); color: white; border: 2px solid white;
  padding: 15px 40px; border-radius: 8px 8px 0 0; font-weight: bold; font-size: 1.1rem;
  transition: all 0.2s ease-in-out; z-index: 100; pointer-events: none;
}
#trash-bin.show { bottom: 0; }
#trash-bin.hover { background: rgba(255, 0, 0, 1); transform: translateX(-50%) scale(1.1); padding: 25px 50px; }

/* Undo / Redo Buttons */
.undo-redo-group {
  position: absolute; bottom: 20px; left: 20px; z-index: 100;
  display: flex; gap: 8px;
}
.undo-btn {
  background: var(--glass-bg); backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border); border-radius: 8px;
  color: white; padding: 12.5px 25px; font-weight: 600; font-size: 1.19rem;
  cursor: pointer; transition: all 0.2s;
}
.undo-btn:hover { background: rgba(255,255,255,0.2); }

/* Side Panels */
.side-panel {
  position: absolute; top: 70px; right: 20px; width: 240px; padding: 15px;
  max-height: calc(100vh - 100px); overflow-y: auto;
}
.panel-title { margin-bottom: 12px; font-size: 0.95rem; color: var(--primary-color); font-weight: 600; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 8px; }
.panel-label { font-size: 0.8rem; color: #aaa; margin-top: 8px; display: block; }
.panel-slider { width: 100%; margin: 5px 0 10px 0; }
.panel-btn {
  width: 100%; padding: 8px; margin-bottom: 6px; background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 6px; color: white;
  font-size: 0.8rem; font-weight: 500; cursor: pointer; transition: all 0.15s;
}
.panel-btn:hover { background: rgba(255,255,255,0.18); }
.panel-select {
  width: 100%; padding: 6px 8px; margin: 4px 0 8px; background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 4px; color: white;
  font-size: 0.8rem;
}
.panel-textarea {
  width: 100%; padding: 8px; margin-top: 4px; background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 4px; color: white;
  font-size: 0.8rem; resize: vertical; font-family: inherit;
}
.panel-textarea::placeholder { color: rgba(255,255,255,0.3); }

/* Layer Toggle */
.layer-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 0;
  font-size: 0.85rem; color: #ccc; cursor: pointer;
}
.layer-row input[type="checkbox"] { accent-color: var(--primary-color); }

/* Inventory Table */
.inv-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.inv-table th { text-align: left; color: #aaa; font-weight: 500; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.1); }
.inv-table td { padding: 4px 0; color: #ddd; }
.inv-table td:last-child { text-align: center; font-weight: 600; color: var(--primary-color); }

/* Toast */
.toast {
  position: fixed; bottom: -80px; left: 50%; transform: translateX(-50%);
  background: rgba(16, 185, 129, 0.95); color: white; padding: 12px 24px;
  border-radius: 8px; font-weight: 600; font-size: 0.95rem; z-index: 500;
  transition: bottom 0.3s ease; pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  max-width: 90vw; text-align: center;
}
.toast.show { bottom: 88px; }

kbd {
  background: #0f172a;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 11px;
  color: #e2e8f0;
  margin: 0 2px;
}

/* Floating bottom design-controls bar */
.design-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  z-index: 200;
  pointer-events: auto;
}

.design-bar .action-btn {
  white-space: nowrap;
}

.design-bar-divider {
  width: 1px;
  height: 22px;
  background: rgba(255,255,255,0.2);
  margin: 0 4px;
}

.selected-panel {
  position: fixed;
  bottom: 80px;
  left: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  z-index: 200;
  pointer-events: auto;
  min-width: 220px;
}

.selected-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.selected-panel-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}

.selected-panel-sublabel {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.7);
  flex: 1;
}

.selected-panel-value {
  font-weight: bold;
  font-size: 1rem;
  min-width: 24px;
  text-align: center;
  color: white;
}

.selected-panel .action-btn {
  padding: 4px 10px;
  font-size: 1rem;
  font-weight: bold;
  min-width: 32px;
}

.legal-footer {
  position: fixed;
  bottom: 4px;
  right: 12px;
  z-index: 100;
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.legal-footer a {
  color: rgba(255,255,255,0.55);
  text-decoration: none;
}

.legal-footer a:hover {
  color: rgba(255,255,255,0.9);
  text-decoration: underline;
}

.controls-section-title {
  color: var(--primary-color);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 14px;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.controls-content .controls-section-title:first-child {
  margin-top: 0;
}

.shortcuts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.shortcuts-table td {
  padding: 4px 0;
  color: #cbd5e1;
}

.shortcuts-table td:last-child {
  text-align: right;
  white-space: nowrap;
}

.controls-footnote {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
  margin-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 8px;
}
