<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>{{ slide_title | default('슬라이드') }}</title>
<link rel="stylesheet" href="/static/base.css">
<style>
{% for page in pages %}
.slide-{{ page.page_number }} {
    grid-template-areas: {{ page.grid_areas }};
    grid-template-columns: {{ page.grid_columns | default('1fr') }};
    grid-template-rows: {{ page.grid_rows | default('auto 1fr auto') }};
}
{% for block in page.blocks %}
.slide-{{ page.page_number }} .area-{{ block.area }} {
    grid-area: {{ block.area }};
}
{% endfor %}
{% endfor %}

/* 다중 페이지: 페이지 간 간격 */
.slide + .slide {
    margin-top: 40px;
}

/* 인쇄 시 페이지 분리 */
@media print {
    .slide {
        page-break-after: always;
    }
    .slide + .slide {
        margin-top: 0;
    }
}
</style>
</head>
<body>
{% for page in pages %}
<div class="slide slide-{{ page.page_number }}">
    {% if loop.first and slide_title %}
    <div class="slide-title" style="grid-area: header;">{{ slide_title }}</div>
    {% endif %}

    {% for block in page.blocks %}
    <div class="area-{{ block.area }}" style="{{ block.style_override | default('') }}">
        {{ block.html }}
    </div>
    {% endfor %}
</div>
{% endfor %}
<script>
/* 인쇄 시 <details> 자동 펼침, 인쇄 후 복원 */
window.onbeforeprint = function() {
    document.querySelectorAll('details').forEach(function(d) { d.open = true; });
};
window.onafterprint = function() {
    document.querySelectorAll('details').forEach(function(d) { d.open = false; });
};
</script>
</body>
</html>
