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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    height: 100vh;
    overflow: hidden;
}

#container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 30px;
}

.header-title {
    padding: 20px 0 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

header h1 {
    font-size: 28px;
    margin-bottom: 5px;
    font-weight: 600;
}

header p {
    font-size: 14px;
    opacity: 0.9;
}

/* タブスタイル（ヘッダー内） */
#tabs {
    display: flex;
    gap: 10px;
    padding: 15px 0 0;
}

.tab-button {
    padding: 12px 24px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.3s ease;
    border-radius: 8px 8px 0 0;
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(10px);
}

.tab-icon {
    font-size: 18px;
}

.tab-button:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.tab-button.active {
    background: white;
    color: #667eea;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

.tab-content {
    display: none !important;
    flex: 1;
    overflow: hidden;
    visibility: hidden;
    position: absolute;
    width: 0;
    height: 0;
}

.tab-content.active {
    display: flex !important;
    flex-direction: column;
    visibility: visible;
    position: relative;
    width: 100%;
    height: 100%;
}

#main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    background: #f5f5f5;
}

/* Audio Editor Styles */
#audio-tab {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#audio-editor {
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    padding: 30px;
}

.section-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 30px;
}

.section-card h2 {
    font-size: 24px;
    color: #333;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

.add-part-section {
    margin-bottom: 40px;
}

.add-part-section h3 {
    font-size: 18px;
    color: #555;
    margin-bottom: 20px;
}

.part-form {
    background: #f9f9f9;
    padding: 25px;
    border-radius: 8px;
    border: 1px solid #e5e5e5;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.form-field {
    display: flex;
    flex-direction: column;
}

.form-field label {
    font-size: 14px;
    font-weight: 600;
    color: #444;
    margin-bottom: 8px;
}

.required {
    color: #f44336;
}

.form-field input {
    padding: 10px 14px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s ease;
    background: white;
}

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

.form-field input:invalid {
    border-color: #f44336;
}

.form-field small {
    font-size: 12px;
    color: #888;
    margin-top: 5px;
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
}

.parts-list-section {
    margin-top: 20px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.section-header h3 {
    font-size: 18px;
    color: #555;
}

.toolbar-actions {
    display: flex;
    gap: 10px;
}

.parts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
    min-height: 200px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #888;
    font-size: 15px;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.5;
}

.part-item {
    background: white;
    border: 2px solid #e5e5e5;
    border-radius: 8px;
    padding: 18px;
    transition: all 0.3s ease;
    position: relative;
}

.part-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: #667eea;
    transform: translateY(-2px);
}

.part-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
}

.part-item-header h4 {
    color: #667eea;
    font-size: 14px;
    font-weight: 600;
}

.part-item-controls {
    display: flex;
    gap: 6px;
}

.part-item-controls button {
    padding: 6px 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.btn-edit {
    background: #4CAF50;
    color: white;
}

.btn-edit:hover {
    background: #45a049;
    transform: scale(1.05);
}

.btn-delete {
    background: #f44336;
    color: white;
}

.btn-delete:hover {
    background: #da190b;
    transform: scale(1.05);
}

.part-item-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.part-item-field {
    display: flex;
    flex-direction: column;
}

.part-item-field label {
    font-size: 11px;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.part-item-field .value {
    font-size: 14px;
    color: #333;
    padding: 6px 10px;
    background: #f9f9f9;
    border-radius: 4px;
    border: 1px solid #e5e5e5;
    word-break: break-all;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: #666;
    margin-bottom: 5px;
}

.form-group input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

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

.btn-success {
    background: #4CAF50;
    color: white;
}

.btn-success:hover {
    background: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

/* Template Blockly Section */
#template-tab {
    display: flex;
    flex: 1;
    width: 100%;
    height: 100%;
}

#blockly-section {
    display: flex;
    flex: 1;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

#blockly-area {
    flex: 1;
    position: relative;
    min-width: 400px;
    height: 100%;
}

#blocklyDiv {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#control-panel {
    width: 400px;
    background: white;
    border-left: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.button-group {
    padding: 20px;
    border-bottom: 1px solid #eee;
    background: #fafafa;
    display: flex;
    gap: 10px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:hover {
    background: #d0d0d0;
    transform: translateY(-2px);
}

#output-section,
#console-section {
    padding: 20px;
    overflow: auto;
}

#output-section {
    flex: 1;
    border-bottom: 1px solid #eee;
}

#parts-info-section {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    background: #f9f9f9;
}

#parts-info-section h3 {
    font-size: 14px;
    margin-bottom: 10px;
    color: #667eea;
    font-weight: 600;
}

.parts-info-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 8px;
}

.parts-info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: white;
    border-radius: 4px;
    font-size: 12px;
    border: 1px solid #e5e5e5;
}

.parts-info-id {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-weight: 600;
    color: #667eea;
    min-width: 80px;
}

.parts-info-text {
    color: #666;
    flex: 1;
}

.parts-info-count {
    font-size: 11px;
    color: #888;
    text-align: right;
    margin-top: 5px;
}

.parts-info-empty {
    text-align: center;
    padding: 20px;
    color: #999;
}

.parts-info-empty p {
    margin-bottom: 8px;
    font-weight: 500;
}

.parts-info-empty small {
    font-size: 11px;
}

.parts-info-items::-webkit-scrollbar {
    width: 6px;
}

.parts-info-items::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 3px;
}

.parts-info-items::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.parts-info-items::-webkit-scrollbar-thumb:hover {
    background: #999;
}

#console-section {
    flex: 1;
    background: #f9f9f9;
}

#output-section h3,
#console-section h3 {
    font-size: 16px;
    margin-bottom: 10px;
    color: #667eea;
    font-weight: 600;
}

#generatedCode,
#consoleOutput {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 15px;
    border-radius: 5px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    overflow-x: auto;
    min-height: 100px;
    max-height: 300px;
    overflow-y: auto;
}

#consoleOutput {
    background: #1e1e1e;
    color: #4ec9b0;
}

/* スクロールバーのスタイル */
#generatedCode::-webkit-scrollbar,
#consoleOutput::-webkit-scrollbar,
#output-section::-webkit-scrollbar,
#console-section::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#generatedCode::-webkit-scrollbar-track,
#consoleOutput::-webkit-scrollbar-track,
#output-section::-webkit-scrollbar-track,
#console-section::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

#generatedCode::-webkit-scrollbar-thumb,
#consoleOutput::-webkit-scrollbar-thumb,
#output-section::-webkit-scrollbar-thumb,
#console-section::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 4px;
}

#generatedCode::-webkit-scrollbar-thumb:hover,
#consoleOutput::-webkit-scrollbar-thumb:hover,
#output-section::-webkit-scrollbar-thumb:hover,
#console-section::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.7);
}

/* レスポンシブデザイン */
@media (max-width: 1024px) {
    #blockly-section {
        flex-direction: column;
    }

    #blockly-area {
        min-height: 400px;
    }

    #control-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid #ddd;
    }

    .part-item {
        padding: 12px;
    }

    .button-group {
        flex-wrap: wrap;
    }

    .parts-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .toolbar-actions {
        width: 100%;
        flex-direction: column;
    }

    .toolbar-actions .btn {
        width: 100%;
    }

    #audio-editor {
        padding: 20px 15px;
    }

    .section-card {
        padding: 20px 15px;
    }

    #tabs {
        flex-direction: column;
        gap: 0;
    }

    .tab-button {
        border-radius: 0;
        width: 100%;
    }
}