/* === BASE === */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background: #f5f5f5;
    height: 100vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* === HEADER BAR === */
h2 {
    margin: 0;
    padding: 0 20px;
    height: 52px;
    line-height: 52px;
    background: #1d4ed8;
    color: #ffffff;
    font-size: 1.35em;
    font-weight: 700;
    letter-spacing: 0.3px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.18);
    flex-shrink: 0;
}

/* === APP LAYOUT === */
#app-layout { display: flex; gap: 12px; flex: 1; min-height: 0; padding: 12px; box-sizing: border-box; }

/* === SIMULATOR SIDEBAR === */
.sim-sidebar {
    width: 300px;
    background: #ffffff;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    flex-shrink: 0;
    transition: width 0.3s ease, margin 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
    align-self: flex-start;
}
.sim-sidebar.collapsed { width: 0px; opacity: 0; }

.sim-inner { width: 300px; padding: 0; display: flex; flex-direction: column; align-items: center; }

/* Remove the purple header strip */
.sim-inner::before { display: none; }

.board-container {
    position: relative; display: inline-block; margin: 16px auto 0;
    filter: drop-shadow(0 6px 16px rgba(0,0,0,0.7));
    order: 1;
}
.board-img { width: 256px; height: auto; display: block; user-select: none; -webkit-user-drag: none; }

.sim-controls {
    order: 2;
    width: 100%; display: flex; gap: 8px; padding: 10px 14px 14px;
    box-sizing: border-box; border-top: 1px solid #e5e7eb;
}

.sim-btn {
    flex: 1; padding: 7px; border-radius: 6px; border: none;
    font-weight: bold; cursor: pointer; color: white;
    background: #5b21b6; transition: 0.2s; font-size: 0.82em;
    display: inline-flex; align-items: center; justify-content: center; gap: 5px;
}
.stop-icon {
    display: inline-block; width: 9px; height: 9px;
    background: white; border-radius: 1px; flex-shrink: 0;
}
.sim-btn:hover { background: #4c1d95; }
#stopSimBtn { background: #dc2626; }
#stopSimBtn:hover { background: #b91c1c; }

#sim-pixel {
    position: absolute; top: 52.5%; left: 49.7%; width: 22px; height: 22px; transform: translate(-50%, -50%);
    border-radius: 50%; background-color: #1a1a1a; transition: all 0.1s ease-in-out;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.8); z-index: 10;
}

#sim-motors {
    display: none;
    width: 100%;
    padding: 8px 14px 12px;
    box-sizing: border-box;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid #e5e7eb;
}
.sim-motor-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78em;
    font-weight: 600;
}
.sim-motor-label {
    width: 48px;
    color: #6b7280;
    flex-shrink: 0;
}
.sim-motor-bar-wrap {
    flex: 1;
    height: 12px;
    background: #f3f4f6;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    border: 1px solid #e5e7eb;
}
.sim-motor-bar {
    position: absolute;
    top: 0;
    height: 100%;
    width: 0%;
    left: 50%;
    border-radius: 6px;
    transition: all 0.15s ease-in-out;
    background: #6b7280;
}
.sim-motor-value {
    width: 36px;
    text-align: right;
    color: #374151;
    font-family: 'Consolas', monospace;
    flex-shrink: 0;
}

.sim-servo-overlay {
    position: absolute;
    width: 17.03%;
    height: 3.50%;
    transform: translate(-50%, -50%);
    border-radius: 2px;
    background-color: transparent;
    transition: all 0.15s ease-in-out;
    z-index: 10;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 2px;
    box-sizing: border-box;
}
.sim-servo-overlay.active {
    background-color: rgba(139, 92, 246, 0.65);
    box-shadow: 0 0 8px 3px rgba(139, 92, 246, 0.5);
}
#sim-servos {
    display: none;
    width: 100%;
    padding: 8px 14px 12px;
    box-sizing: border-box;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid #e5e7eb;
}
#sim-servo-io4  { top: 63.48%; left: 11.69%; }
#sim-servo-io5  { top: 66.98%; left: 11.69%; }
#sim-servo-io18 { top: 70.49%; left: 11.69%; }
#sim-servo-io19 { top: 74.01%; left: 11.69%; }
#sim-servo-io23 { top: 77.52%; left: 11.69%; }

#sim-motor1-overlay, #sim-motor2-overlay {
    position: absolute;
    width: 5.81%;
    height: 7.34%;
    transform: translate(-50%, -50%);
    border-radius: 3px;
    background-color: rgba(0, 0, 0, 0.15);
    transition: all 0.15s ease-in-out;
    z-index: 10;
    pointer-events: none;
}
#sim-motor1-overlay { top: 38.12%; left: 90.96%; }
#sim-motor2-overlay { top: 38.12%; left: 9.81%; }

.sim-analog-overlay {
    position: absolute;
    width: 17.03%;
    height: 3.50%;
    transform: translate(-50%, -50%);
    border-radius: 2px;
    background-color: transparent;
    transition: all 0.15s ease-in-out;
    z-index: 10;
    pointer-events: none;
}
.sim-analog-overlay.active {
    background-color: rgba(245, 158, 11, 0.65);
    box-shadow: 0 0 8px 3px rgba(245, 158, 11, 0.5);
}
#sim-analog-io33 { top: 67.17%; left: 89.15%; }
#sim-analog-io32 { top: 70.67%; left: 89.15%; }
#sim-analog-io35 { top: 74.17%; left: 89.15%; }
#sim-analog-io34 { top: 77.67%; left: 89.15%; }
#sim-analog-io39 { top: 81.18%; left: 89.15%; }
#sim-analog-io36 { top: 84.68%; left: 89.15%; }

#sim-analogs {
    display: none;
    width: 100%;
    padding: 8px 14px 12px;
    box-sizing: border-box;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid #e5e7eb;
}
.sim-analog-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.78em;
    font-weight: 600;
}
.sim-analog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #6b7280;
}
.sim-analog-value {
    color: #d97706;
    font-family: 'Consolas', monospace;
}
.sim-analog-slider {
    width: 100%;
    accent-color: #f59e0b;
    cursor: pointer;
    height: 4px;
}

.sim-digital-overlay {
    position: absolute;
    width: 17.03%;
    height: 3.50%;
    transform: translate(-50%, -50%);
    border-radius: 2px;
    background-color: transparent;
    transition: all 0.15s ease-in-out;
    z-index: 11;
    pointer-events: none;
}
.sim-digital-overlay.active {
    background-color: rgba(13, 148, 136, 0.35);
    box-shadow: 0 0 6px 2px rgba(13, 148, 136, 0.35);
}
.sim-digital-overlay.active.input {
    pointer-events: auto;
    cursor: pointer;
}
.sim-digital-overlay.high {
    background-color: rgba(13, 148, 136, 0.7);
    box-shadow: 0 0 10px 4px rgba(13, 148, 136, 0.6);
}
/* Left side: IO4/5/18/19/23/25/26 */
#sim-digital-io4  { top: 63.48%; left: 11.69%; }
#sim-digital-io5  { top: 66.98%; left: 11.69%; }
#sim-digital-io18 { top: 70.49%; left: 11.69%; }
#sim-digital-io19 { top: 74.01%; left: 11.69%; }
#sim-digital-io23 { top: 77.52%; left: 11.69%; }
#sim-digital-io25 { top: 81.02%; left: 11.69%; }
#sim-digital-io26 { top: 84.55%; left: 11.69%; }
/* Right side: IO27/33/32/35/34/39/36 */
#sim-digital-io27 { top: 63.61%; left: 88.78%; }
#sim-digital-io33 { top: 67.17%; left: 89.15%; }
#sim-digital-io32 { top: 70.67%; left: 89.15%; }
#sim-digital-io35 { top: 74.17%; left: 89.15%; }
#sim-digital-io34 { top: 77.67%; left: 89.15%; }
#sim-digital-io39 { top: 81.18%; left: 89.15%; }
#sim-digital-io36 { top: 84.68%; left: 89.15%; }

#sim-digital {
    display: none;
    width: 100%;
    padding: 8px 14px 12px;
    box-sizing: border-box;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid #e5e7eb;
}
.sim-digital-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78em;
    font-weight: 600;
}
.sim-digital-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 80px;
    color: #374151;
}
.sim-digital-pin {
    color: #9ca3af;
    flex-shrink: 0;
}
.sim-digital-badge {
    font-size: 0.72em;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
}
.sim-digital-badge.in  { background: #ccfbf1; color: #0d9488; }
.sim-digital-badge.out { background: #d1fae5; color: #059669; }
.sim-digital-state {
    margin-left: auto;
    font-family: 'Consolas', monospace;
    color: #6b7280;
}
.sim-digital-state.high { color: #0d9488; }
.sim-digital-btn {
    margin-left: auto;
    font-family: 'Consolas', monospace;
    font-size: 0.9em;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 4px;
    border: 1.5px solid #0d9488;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.12s;
}
.sim-digital-btn.high {
    background: #0d9488;
    color: #fff;
}
.sim-digital-btn:hover { opacity: 0.8; }

#sim-ultrasonic {
    display: none;
    width: 100%;
    padding: 8px 14px 12px;
    box-sizing: border-box;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid #e5e7eb;
}
.sim-ultrasonic-value {
    color: #ea580c;
    font-family: 'Consolas', monospace;
}
.sim-ultrasonic-slider {
    width: 100%;
    accent-color: #ea580c;
    cursor: pointer;
    height: 4px;
}

#sim-accel {
    display: none;
    width: 100%;
    padding: 8px 14px 12px;
    box-sizing: border-box;
    flex-direction: column;
    gap: 4px;
    border-top: 1px solid #e5e7eb;
}
.sim-accel-section-label {
    font-size: 0.72em;
    font-weight: 700;
    color: #ea580c;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.sim-accel-axis {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78em;
    font-weight: 600;
}
.sim-accel-axlabel {
    width: 12px;
    color: #6b7280;
    flex-shrink: 0;
}
.sim-accel-slider {
    flex: 1;
    accent-color: #ea580c;
    cursor: pointer;
    height: 4px;
}
.sim-accel-val {
    width: 38px;
    text-align: right;
    font-family: 'Consolas', monospace;
    color: #ea580c;
    flex-shrink: 0;
}

#sim-boot-hitbox {
    position: absolute; top: 16.7%; left: 93.1%; width: 20px; height: 32px;
    transform: translate(-50%, -50%); border-radius: 4px; cursor: pointer; z-index: 20;
    background-color: rgba(255, 255, 255, 0); border: none; transition: background-color 0.1s;
}
#sim-boot-hitbox:hover { background-color: rgba(255, 255, 255, 0.25); }
#sim-boot-hitbox:active { background-color: rgba(0, 0, 0, 0.5); }

/* === IDE PANEL === */
.ide-panel { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; height: 100%; }

.hardware-controls {
    display: flex; gap: 8px; align-items: center;
    background: #ffffff; padding: 10px 16px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

button.hw-btn {
    padding: 8px 18px; border-radius: 20px; border: 1px solid #d1d5db;
    color: #374151; cursor: pointer; font-weight: 600;
    transition: background 0.2s; background: #f3f4f6; font-size: 0.85em;
}
button.hw-btn:hover { background: #e5e7eb; }
button.hw-btn:disabled { opacity: 0.45; cursor: not-allowed; }

#toggleSidebarBtn { margin-right: 6px; }
#connectBtn { background: #0ea5e9; color: white; border-color: #0ea5e9; }
#connectBtn:hover { background: #0284c7; border-color: #0284c7; }
#runBtn { background: #10b981; color: white; border-color: #10b981; }
#runBtn:hover { background: #059669; border-color: #059669; }
#stopBtn { background: #ef4444; color: white; border-color: #ef4444; }
#stopBtn:hover { background: #dc2626; border-color: #dc2626; }

.status { font-size: 0.85em; color: #6b7280; font-weight: 500; margin-left: auto; }

#blocklyDiv {
    flex: 1; border: 1px solid #e5e7eb; border-radius: 10px;
    background: #f9f9f9; overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

/* === CODE & CONSOLE PANELS === */
.code-container {
    background: #ffffff;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    padding: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.code-container summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    color: #374151;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
    outline: none;
}
.code-container summary::-webkit-details-marker { display: none; }
.code-container summary::before { content: "⌨"; font-size: 1.1em; }

#codePreview {
    background: #f8f9fa;
    color: #24292e;
    padding: 16px 16px 16px 20px;
    border-left: 3px solid #7c3aed;
    white-space: pre;
    font-family: 'Consolas', 'Courier New', monospace;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 320px;
    margin: 0;
    font-size: 0.9em;
    line-height: 1.6;
    min-height: 60px;
}

#copyCodeBtn {
    margin-left: auto;
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 0.78em;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
}
#copyCodeBtn:hover { background: #e5e7eb; color: #374151; }

#simConsole {
    background: #1a1a1a; color: #34d399; padding: 15px;
    border-left: 3px solid #10b981;
    height: 160px; overflow-y: auto; font-family: 'Consolas', monospace;
    margin: 0; white-space: pre-wrap; line-height: 1.5;
}
.error-text { color: #f87171; }
.sys-text { color: #9ca3af; font-style: italic; }

/* Clear console button (inline style overridden) */
#consoleDetails > button {
    display: block; margin: 10px 16px 12px;
    background: #f3f4f6 !important; color: #374151 !important;
    border: 1px solid #d1d5db !important; padding: 7px 16px; border-radius: 20px;
    cursor: pointer; font-weight: 600; font-size: 0.85em; transition: background 0.2s;
}
#consoleDetails > button:hover { background: #e5e7eb !important; }

/* === DROPDOWNS === */
.dropdown-wrapper { position: relative; }
.dropdown-menu {
    display: none; position: absolute; top: calc(100% + 4px); left: 0;
    background: #ffffff; border: 1px solid #e5e7eb;
    border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 1000; min-width: 180px; max-width: 400px;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
    padding: 10px 15px; cursor: pointer; font-size: 0.9em; color: #374151;
    display: flex; justify-content: space-between; align-items: center; white-space: nowrap; gap: 6px;
}
.dropdown-item:hover { background: #f3f4f6; }
.dropdown-item:first-child { border-radius: 8px 8px 0 0; }
.dropdown-item:last-child { border-radius: 0 0 8px 8px; }
.dropdown-item.save-item { color: #059669; font-weight: bold; }
.dropdown-item.no-projects { color: #9ca3af; cursor: default; font-style: italic; }
.dropdown-item.no-projects:hover { background: none; }
.dropdown-divider { border-top: 1px solid #e5e7eb; margin: 2px 0; }
.delete-btn {
    background: #fee2e2; border: none; color: #ef4444; cursor: pointer;
    font-size: 16px; padding: 4px 10px; border-radius: 4px; line-height: 1; flex-shrink: 0;
}
.delete-btn:hover { background: #ef4444; color: white; }
.dropdown-item > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.csv-view-btn {
    background: #d1fae5; border: none; color: #059669; cursor: pointer;
    font-size: 16px; padding: 4px 10px; border-radius: 4px; line-height: 1; flex-shrink: 0;
}
.csv-view-btn:hover { background: #059669; color: white; }
.csv-download-btn {
    background: #dbeafe; border: none; color: #2563eb; cursor: pointer;
    font-size: 16px; padding: 4px 10px; border-radius: 4px; line-height: 1; flex-shrink: 0;
}
.csv-download-btn:hover { background: #2563eb; color: white; }
