:root {
    --primary-color: #4a90e2;
    --border-color: #ddd;
    --bg-color: #f0f4f8;
    --text-color: #333;
    --paper-bg: #fff;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
    --sidebar-width: 320px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 16px;
}

.container {
    display: flex;
    height: 100%;
}

/* Sidebar (左側) */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--paper-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
    transition: transform 0.3s ease-in-out;
    flex-shrink: 0;
    z-index: 1002;
}

/* Preview Area (右側) */
.preview-container {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    display: flex;
    justify-content: center;
}

.test-sheet {
    background-color: var(--paper-bg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    overflow: visible;
}
.test-sheet.portrait { width: 210mm; min-height: 297mm; padding: 20mm; }
.test-sheet.landscape { width: 297mm; min-height: 210mm; padding: 15mm; }

/* サイドバー折りたたみ機能 */
.sidebar-toggle-btn {
    position: fixed;
    top: 20px;
    left: var(--sidebar-width);
    z-index: 1003;
    background-color: var(--primary-color);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 0 50% 50% 0;
    cursor: pointer;
    transition: left 0.3s ease-in-out, background-color 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
}
.sidebar-toggle-btn:hover { background-color: #357abd; }

body.sidebar-hidden .sidebar {
    transform: translateX(-100%);
}
body.sidebar-hidden .sidebar-toggle-btn {
    left: 0;
}

/* オーバーレイ（モバイル用） */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}
body:not(.sidebar-hidden) .overlay {
    opacity: 1;
    visibility: visible;
}

/* レスポンシブ対応 (モバイル) */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
        box-shadow: 4px 0 15px rgba(0,0,0,0.2);
    }
    body:not(.sidebar-hidden) .sidebar {
        transform: translateX(0);
    }
    .preview-container {
        padding: 15px;
        width: 100%;
    }
    .test-sheet {
        width: 100%;
        min-height: auto;
        padding: 15mm 10mm;
    }
    .sidebar-toggle-btn {
        left: 0;
    }
    body:not(.sidebar-hidden) .sidebar-toggle-btn {
        left: var(--sidebar-width);
    }
}

/* PCではオーバーレイは常に非表示 */
@media (min-width: 769px) {
    .overlay {
        display: none;
    }
}

/* 共通のUIスタイル */
.sidebar-header { margin-bottom: 2rem; }
.sidebar-header h1 { font-size: 1.5rem; margin-bottom: 1rem; }
.controls h2 { font-size: 1.1rem; margin-top: 1.5rem; margin-bottom: 0.8rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: flex; align-items: center; gap: 0.5rem; font-weight: bold; margin-bottom: 0.5rem; }
.form-group input[type="text"] { width: 100%; padding: 8px; border: 1px solid var(--border-color); border-radius: 4px; font-size: 1rem; }
.radio-group { display: flex; gap: 1rem; }
.button-group { margin-top: 1rem; }
.button-group .description { font-size: 0.8rem; color: #666; margin: 0.5rem 0 1rem 0; }
.btn { display: flex; align-items: center; justify-content: center; gap: 0.5rem; width: 100%; padding: 10px; font-size: 1rem; background-color: var(--primary-color); color: white; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s; }
.btn:hover { background-color: #357abd; }
.btn:disabled { background-color: #ccc; cursor: not-allowed; }
.sidebar-footer { margin-top: auto; text-align: center; font-size: 0.8rem; color: #999; padding-top: 1rem; }
.test-header { text-align: center; margin-bottom: 2rem; }
.test-header h1 { font-size: 2rem; font-weight: bold; }
.test-header h2 { font-size: 1.5rem; margin-top: 0.5rem; }
.test-header .info { display: flex; justify-content: flex-end; margin-top: 2rem; gap: 1.5rem; }
#test-body { padding-top: 1rem; }
.section, .question-item { page-break-inside: avoid; break-inside: avoid; }
.section { margin-bottom: 2rem; padding: 1rem; border: 1px solid transparent; border-radius: 5px; position: relative; }
.section.selected { border-color: var(--primary-color); background-color: #eaf2fa; }
.section-title { width: 100%; border: none; background: transparent; font-size: 1.2rem; font-weight: bold; padding: 5px; margin-bottom: 1rem; }
.question-item { display: flex; align-items: flex-start; margin-left: 2rem; position: relative; }
.question-item .q-number { margin-right: 0.5em; padding-top: 8px; }
.question-text { flex: 1; border: 1px solid #ccc; background: #fff; font-size: 1rem; padding: 8px; resize: vertical; font-family: inherit; line-height: 1.6; border-radius: 3px; min-height: 80px; }
.delete-btn { position: absolute; top: 5px; right: 5px; cursor: pointer; color: #999; background: white; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.delete-btn:hover { color: #e74c3c; }
.question-content { flex: 1; padding: 8px; border: 1px solid transparent; border-radius: 3px; line-height: 1.6; min-height: 38px; cursor: text; }
.question-content:hover { border-color: #ccc; background-color: #f9f9f9; }
.katex { font-size: 1.1em; vertical-align: middle; }

