:root {
    --primary: #4a90e2;
    --primary-hover: #357abd;
    --bg: #0f172a;
    --sidebar-bg: rgba(30, 41, 59, 0.7);
    --panel-bg: rgba(51, 65, 85, 0.5);
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #f59e0b;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: 'Noto Sans JP', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    backdrop-filter: blur(20px);
}

/* Sidebar Styling */
.controls {
    width: 360px;
    background: var(--sidebar-bg);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    overflow-y: auto;
    backdrop-filter: blur(10px);
}

header h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

header h1 span {
    display: block;
    font-size: 0.8rem;
    color: var(--primary);
    text-transform: uppercase;
}

header p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.control-group h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 1rem;
    letter-spacing: 1px;
}

.input-field {
    margin-bottom: 1.2rem;
}

.input-field label {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.input-field input[type="text"], 
.input-field select {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.8rem;
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    transition: all 0.3s;
    cursor: pointer;
}

/* 選択肢メニュー内の配色を修正 */
.input-field select option {
    background-color: #1e293b; /* 濃い紺色 */
    color: white;
}

.input-field select:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
}

.input-field input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.color-btn {
    aspect-ratio: 1;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s;
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    border-color: white;
    box-shadow: 0 0 15px rgba(255,255,255,0.3);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    margin-bottom: 0.8rem;
    cursor: pointer;
}

.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    transition: all 0.3s;
    margin-top: auto;
    font-size: 1rem;
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(74, 144, 226, 0.3);
}

.size-badge {
    background: var(--accent);
    color: var(--bg);
    padding: 1rem;
    border-radius: 12px;
    font-weight: 900;
    font-size: 1.2rem;
    text-align: center;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4);
    font-family: 'Outfit', sans-serif;
}

.result-info h3 {
    color: var(--accent);
}

/* Preview Area Styling */
.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    overflow: auto;
}

.canvas-wrapper {
    position: relative;
    box-shadow: var(--shadow);
    background: #000;
    /* A2 aspect ratio (420x594) -> approx 0.707 */
    width: 600px;
    height: 848px;
    max-height: 85vh;
    max-width: 60vw;
    transition: all 0.3s ease;
}

.canvas-wrapper.landscape {
    width: 848px;
    height: 600px;
}

.poster-canvas {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Themes */
.theme-sunset { background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d); }
.theme-nature { background: linear-gradient(135deg, #00b09b, #96c93d); }
.theme-royal { background: linear-gradient(135deg, #8e2de2, #4a00e0); }
.theme-dark { background: #222; }

.content-layer {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: white;
}

.text-content {
    padding: 2rem;
}

.text-content h1 {
    font-size: 5rem;
    font-weight: 900;
    line-height: 1.1;
    text-shadow: 0 10px 30px rgba(0,0,0,0.5);
    margin-bottom: 1rem;
}

.text-content h2 {
    font-size: 2rem;
    font-weight: 400;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 4px;
}

.image-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    z-index: -1;
}

/* Split Grid Overlay */
.split-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(var(--cols, 2), 1fr);
    grid-template-rows: repeat(var(--rows, 2), 1fr);
    z-index: 2;
    pointer-events: none;
}

.grid-cell {
    border: 1px dashed rgba(255, 255, 255, 0.2);
    position: relative;
}

body.show-crop-marks .grid-cell {
    border: 0.5mm dashed #ff00ff; /* プレビュー画面でもマゼンタの点線を表示 */
}

.grid-cell::after {
    content: attr(data-label);
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    background: rgba(0,0,0,0.3);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Print Styling */
@media print {
    @page {
        margin: 0;
        size: A4 portrait;
    }

    @page landscape {
        margin: 0;
        size: A4 landscape;
    }

    /* B4設定を追加 */
    body.is-b4-print @page {
        size: 257mm 364mm;
    }
    body.is-b4-print.is-landscape-print @page {
        size: 364mm 257mm;
    }

    body {
        background: white;
        margin: 0;
        padding: 0;
    }

    .app-container {
        display: none !important; /* 元の画面を完全に消す */
    }

    .print-container, .print-container * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .print-container {
        display: block !important;
        position: relative;
        width: 210mm;
        margin: 0;
        padding: 0;
    }

    .print-container.landscape-mode {
        width: 297mm;
    }
    
    .print-page {
        width: 210mm;
        height: 297mm;
        page-break-after: always;
        page-break-inside: avoid;
        position: relative;
        overflow: hidden;
        margin: 0;
        padding: 0;
    }

    /* 印刷時はガイド線を一切出さない */
    .print-page::after {
        display: none;
    }

    .print-container.landscape-mode .print-page {
        width: 297mm;
        height: 210mm;
        page: landscape;
    }

    /* B4印刷時のサイズ調整 */
    body.is-b4-print .print-page {
        width: 257mm;
        height: 364mm;
    }
    body.is-b4-print.landscape-mode .print-page {
        width: 364mm;
        height: 257mm;
    }

    .print-content {
        position: absolute;
        width: 420mm; /* A2 Width (Portrait) */
        height: 594mm; /* A2 Height (Portrait) */
        transform-origin: top left;
    }

    .print-container.landscape-mode .print-content {
        width: 594mm; /* A2 Width (Landscape) */
        height: 420mm; /* A2 Height (Landscape) */
    }

    /* Offsets for 4 pages */
    .page-1 .print-content { top: 0; left: 0; }
    .page-2 .print-content { top: 0; left: -210mm; }
    .page-3 .print-content { top: -297mm; left: 0; }
    .page-4 .print-content { top: -297mm; left: -210mm; }

    /* Crop Marks & Overlap */
    .overlap-mask {
        position: absolute;
        background: white;
        z-index: 10;
    }
}

.print-container {
    display: none;
}
