* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #764ba2;
    --secondary-color: #764ba2;
    --bg-start: #667eea;
    --bg-end: #764ba2;
}

body.theme-esp32 {
    --primary-color: #764ba2;
    --secondary-color: #764ba2;
    --bg-start: #667eea;
    --bg-end: #764ba2;
}

body.theme-microbit {
    --primary-color: #3454D1;
    --secondary-color: #3454D1;
    --bg-start: #3454D1;
    --bg-end: #3454D1;
}

body {
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
    min-height: 100vh;
}

.serial-connection .container {
    padding-top: 360px;
    transition: padding-top 0.3s ease;
}

.header-settings-bar.closed + .container {
    padding-top: 180px;
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgb(248, 249, 255);
    border-radius: 0px 0px 15px 15px;
    padding: 0;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    width: 100%;
    box-sizing: border-box;
    z-index: 3000;
}

.header-content {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    box-sizing: border-box;
    padding: 30px 36px 15px 36px;
    position: relative;
}

.header h1 {
    font-size: 1.8em;
    font-weight: 800;
    color: var(--primary-color);
    margin-bottom: 8px;
    text-align: center;
}

.header p {
    color: #4a5568;
    font-size: 1.1em;
    text-align: center;
    margin-bottom: 10px;
}

/* 헤더 컨트롤 영역 */
.header-controls {
    display: flex;
    justify-content: center;
    margin-top: 20px;
}

.header-settings-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
    margin: 0 auto;
    padding: 0 0 16px 0;
    background: none;
    border-radius: 16px;
    position: relative;
    gap: 16px;
    max-width: 100%;
}

.header-settings-left, .header-settings-center, .header-settings-right {
    width: 32%;
    min-width: 220px;
    height: 180px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex-shrink: 0;
}

@media screen and (max-width: 1200px) {
    .header-settings-left, .header-settings-center, .header-settings-right {
        width: 31%;
        min-width: 200px;
    }
}

@media screen and (max-width: 1000px) {
    .header-settings-left, .header-settings-center, .header-settings-right {
        width: 29%;
        min-width: 240px;
    }

    .header-settings-bar {
        gap: 8px;
    }

    .header-settings-bar .btn {
        font-size: 0.8em;
        padding: 8px 10px;
    }
    .header-settings-bar .toggle-switch {
        width: 60px;
        height: 32px;
    }
    .header-settings-bar .toggle-slider {
        width: 24px;
        height: 24px;
        top: 4px;
        left: 4px;
    }
    .header-settings-bar .toggle-label {
        font-size: 0.8em;
    }
    .header-settings-bar .form-input {
        font-size: 0.8em;
        padding: 8px 12px;
        height: 32px;
    }
    .header .serial-notice {
        font-size: 0.8em;
    }
}

@media screen and (max-width: 1200px) {
    .header-settings-bar .form-input {
        height: 28px;
        padding: 6px 10px;
    }
}

@media screen and (max-width: 1000px) {
    .header-settings-bar .form-input {
        height: 24px;
        padding: 5px 8px;
    }

    .status-panel .status-label {
        font-size: 0.8em;
    }

    .status-panel .status-value {
        padding: 2px 8px;
        border-radius: 7.5px;
        font-size: 0.7em;
        font-weight: 400;
    }
}

@media screen and (max-width: 800px) {
    .header-settings-left, .header-settings-center, .header-settings-right {
        width: 28%;
        min-width: 220px;
    }
    .header-settings-bar .btn {
        font-size: 0.7em;
        padding: 8px 10px;
    }
    .header-settings-bar .toggle-switch {
        width: 55px;
        height: 25px;
    }
    .header-settings-bar .toggle-slider {
        width: 19px;
        height: 19px;
        top: 3px;
        left: 3px;
    }
    
}

.header-settings-col {
    padding: 16px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: white;
}

.settings-title {
    font-size: 0.9em;
    font-weight: 600;
    text-align: center;
    color: #4a5568;
    margin-bottom: 12px;
    padding-bottom: 4px;
    border-bottom: 1px solid #e2e8f0;
}

.header-settings-center form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    align-items: stretch;
}

.header-settings-center form .form-input {
    flex: 1;
}

/* 토글 컨테이너 스타일링 */
.toggle-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
    margin-bottom: 12px;
}

.toggle-label {
    font-size: 0.9em;
    color: #4a5568;
}

.toggle-switch {
    width: 60px;
    height: 32px;
    background: var(--primary-color);
    border-radius: 16px;
    position: relative;
    cursor: pointer;
}

.toggle-slider {
    width: 24px;
    height: 24px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    left: 4px;
    top: 4px;
    transition: left 0.3s;
}

.toggle-switch.closed .toggle-slider {
    left: 32px;
}

/* 버튼 스타일링 */
.btn {
    font-size: 0.9em;
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.btn-secondary:hover {
    background: #c4d0e0;
}

.btn {
    background: #764ba2;
    color: white;
}

.btn:hover {
    background: #653f91;
}

.serial-notice {
    color: #555;
    padding: 0;
}

.header .serial-notice {
    font-size: 0.92em;
    margin: 0;
    margin-top: 8px;
}

.header-toggle-btn {
    position: absolute;
    top: 5px; right: 8px;
    z-index: 10;
    background: #eee;
    border-radius: 50%;
    border: none;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.header-toggle-btn::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 12px solid #764ba2;
    transition: transform 0.3s;
}
.header-toggle-btn.closed::before {
    transform: rotate(180deg);
}

/* 접혔을 때 숨김 */
.header-settings-bar.closed {
    max-height: 0 !important;
    overflow: hidden;
    padding: 0 !important;
    border: none !important;
}

.header-title-desc {
    text-align: center;
    margin-top: 0;
}

.device-toggle-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.toggle-switch {
    position: relative;
    width: 60px;
    height: 30px;
    background: var(--primary-color);
    transition: background 0.3s;
    border-radius: 15px;
    cursor: pointer;
}

.toggle-switch.active {
    background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
}

.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.toggle-switch.active .toggle-slider {
    transform: translateX(30px);
}

.toggle-label {
    font-weight: 500;
    color: #4a5568;
    font-size: 0.9em;
}

.editor-button {
    padding: 8px 20px;
    font-size: 0.9em;
    border-radius: 20px;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    box-sizing: border-box;
    padding: 200px 20px 20px 20px;
}

.main-section {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

/* 모바일 경고 메시지 */
.mobile-warning {
    display: none;
    background: linear-gradient(135deg, #fed7d7 0%, #fef5e7 100%);
    border: 2px solid #f56565;
    border-radius: 15px;
    padding: 25px;
    text-align: center;
    margin-bottom: 20px;
}

.warning-content h3 {
    color: #742a2a;
    margin-bottom: 10px;
    font-size: 1.3em;
}

.warning-content p {
    color: #744210;
    font-size: 1.1em;
    line-height: 1.5;
}

/* 데스크톱 전용 콘텐츠 */
.desktop-only {
    display: block;
}

.model-config-row {
    display: flex;
    flex-direction: row;
    gap: 24px;
    align-items: stretch; /* stretch로 맞추기 */
    margin-bottom: 15px;
}

/* 모델 설정 섹션 */
.model-config-section {
    background: #f7fafc;
    width: 100%;
    height: 100%;
    min-height: 220px; /* 필요시 조정 */
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    border-left: 4px solid #667eea;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* 버튼이 항상 하단에 오도록 */
}

.section-title {
    font-weight: bold;
    color: #4a5568;
    margin-bottom: 20px;
    font-size: 1.3em;
}

.section-subtitle {
    font-weight: bold;
    color: #4a5568;
    margin-bottom: 10px;
    font-size: 1.1em;
    margin-top: 25px;
}

.form-group {
    margin-bottom: 15px;
}

.form-label {
    display: block;
    font-weight: bold;
    color: #4a5568;
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1em;
    transition: border-color 0.3s;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.connection-notice {
    color: #4a5568;
    font-size: 0.95em;
    margin-bottom: 15px;
    background: #e6fffa;
    padding: 12px;
    border-radius: 8px;
    border-left: 3px solid #38b2ac;
}

.btn {
    background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    margin: 5px 5px 5px 0;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

/* Instructions styles */
.instructions ol {
    padding-left: 20px;
    margin: 10px 0;
}

.instructions li {
    margin-bottom: 8px;
    line-height: 1.5;
}

/* Code Examples Styles */
.code-examples {
    margin-top: 20px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.example-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    border-bottom: 2px solid #e2e8f0;
}

.example-tab {
    padding: 8px 16px;
    border: none;
    background: none;
    color: #4a5568;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.example-tab:hover {
    color: #667eea;
}

.example-tab.active {
    color: #667eea;
    border-bottom: 2px solid #667eea;
}

.example-content {
    position: relative;
}

.code-block {
    background: #2c2c2c;
    border-radius: 8px;
    padding: 15px;
    overflow-x: auto;
    margin-bottom: 10px;
}

.code-block code {
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
    line-height: 1.6;
}

.copy-btn {
    position: absolute;
    right: 15px;
    top: 15px;
    background: #e2e8f0;
    color: #4a5568;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
}

.copy-btn:hover {
    background: #cbd5e1;
}

.copy-btn.success {
    background: #dcfce7;
    color: #10b981;
}

.hidden {
    display: none;
}

.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.btn-secondary:hover {
    background: #cbd5e0;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

.content-section {
    margin-top: 20px;
}

.video-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
    margin-bottom: 30px;
}

.video-container {
    text-align: center;
}

/* 반응형 비디오 컨테이너: 비율 유지 */
#video-container .canvas-wrapper,
#video-container canvas {
    max-width: 100%;
    height: auto !important;
}

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

@media (max-width: 480px) {
    #video-container {
        width: 100%;
    }
}

.video-title {
    font-weight: bold;
    color: #4a5568;
    font-size: 1.1em;
}

.canvas-wrapper {
    border: 3px solid #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
    display: inline-block;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.status-panel {
    background: #f7fafc;
    border-radius: 10px;
    padding: 20px;
    margin-top: 30px;
}

.status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #e2e8f0;
}

.status-item:last-child {
    border-bottom: none;
}

.status-label {
    font-weight: 500;
    color: #4a5568;
}

.status-value {
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 0.9em;
    font-weight: 500;
}

.status-connected {
    background: #c6f6d5;
    color: #22543d;
}

.status-disconnected {
    background: #fed7d7;
    color: #742a2a;
}

.status-ready {
    background: #bee3f8;
    color: #2a4365;
}

.status-waiting {
    background: #fef5e7;
    color: #744210;
}

.instructions {
    background: #fef5e7;
    border-radius: 10px;
    padding: 20px;
    margin-top: 60px;
}

.instructions h3 {
    color: #744210;
    margin-bottom: 15px;
}

.instructions ol {
    color: #744210;
    padding-left: 20px;
}

.instructions li {
    margin-bottom: 8px;
}

.code-contents {
    background: #fffcf8;
    border-radius: 10px;
    padding: 20px;
    margin-top: 60px;
}

/* 모바일 반응형 */
@media (max-width: 768px) {
    .container {
        padding: 220px 15px 15px 15px;
    }

    .header h1 {
        font-size: 1.4em;
    }

    .header p {
        font-size: 0.95em;
    }

    .header-content {
        padding: 25px 20px;
    }

    .device-toggle-header {
        gap: 10px;
    }

    .toggle-label {
        font-size: 0.8em;
    }

    .editor-button {
        font-size: 0.8em;
        padding: 6px 15px;
    }

    /* 모바일에서 경고 메시지 표시 */
    .mobile-warning {
        display: block;
    }

    /* 모바일에서 메인 콘텐츠 숨김 */
    .desktop-only {
        display: none;
    }

    .video-section {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

@media (max-width: 480px) {
    .header-content {
        padding: 40px 20px 10px;
    }

    .header h1 {
        font-size: 1.2em;
    }

    .header p {
        font-size: 0.8em;
    }

    .main-section {
        padding: 20px;
    }

    .btn {
        font-size: 0.9em;
        padding: 10px 20px;
    }

    .toggle-container {
        gap: 10px;
    }

    .toggle-switch {
        width: 55px;
        height: 25px;
    }

    .toggle-slider {
        width: 19px;
        height: 19px;
        top: 3px;
        left: 3px;
    }

    .toggle-switch.active .toggle-slider {
        transform: translateX(25px);
    }

    .hamburger-btn {
        top: 10px;
        right: 10px;
    }
}

/* 오버레이에서 설정 바 세로 배치 및 상단 여백 (햄버거 오픈 시) */
.nav-overlay.open #overlaySettingsMount {
    width: 70%;
    max-width: 900px;
    padding: 0 16px;
    margin: 88px auto 0 auto; /* 닫기(X)/햄버거 영역과 간격 확보 */
}
.nav-overlay.open .header-settings-bar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    max-width: 680px;
    margin: 0 auto 24px auto;
    padding-bottom: 24px;
}
.nav-overlay.open .header-settings-bar .header-settings-col {
    width: 100%;
    min-width: 0;
    height: auto;
}

/* 오버레이 내부 버튼 폭 조정 (데스크톱/태블릿) */
.nav-overlay.open .header-settings-bar .header-settings-left .btn,
.nav-overlay.open .header-settings-bar .header-settings-center .btn,
.nav-overlay.open .header-settings-bar .header-settings-right .btn {
    width: 70%;
    margin-left: auto;
    margin-right: auto;
}

/* 폭이 매우 좁은 모바일에서는 100% */
@media (max-width: 480px) {
    .nav-overlay.open #overlaySettingsMount {
        width: 100%;
        padding: 0 12px;
        margin-top: 25px;
    }
    .nav-overlay.open .header-settings-bar {
        max-width: none;
    }
    .nav-overlay.open .header-settings-bar .header-settings-left .btn,
    .nav-overlay.open .header-settings-bar .header-settings-center .btn,
    .nav-overlay.open .header-settings-bar .header-settings-right .btn {
        width: 100%;
    }
}

/* 모바일 폭에서는 헤더 높이가 고정이므로 상단 패딩 제거 */
/* 모바일 상단 패딩은 JS에서 헤더 높이 기반으로 계산 적용 */