/* --- GLOBAL STYLES & RESET --- */
:root {
    --bg-color: #eef2f7;
    --panel-bg: #ffffff;
    --border-color: #dde3ec;
    --text-color: #1e2a3a;
    --text-muted: #6b7a99;
    --primary-color: #3b7dd8;
    --primary-hover: #2c65bb;
    --primary-light: #eaf1fb;
    --secondary-color: #5c6b84;
    --secondary-hover: #465266;
    --shadow-sm: 0 1px 3px rgba(30,42,58,0.07), 0 1px 2px rgba(30,42,58,0.04);
    --shadow-md: 0 4px 12px rgba(30,42,58,0.09), 0 2px 4px rgba(30,42,58,0.05);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body { font-family: var(--font-family); background-color: var(--bg-color); color: var(--text-color); line-height: 1.6; }

/* --- APP LAYOUT --- */
.app-container { max-width: 1600px; margin: 0 auto; padding: 24px; }

.app-header {
    text-align: center;
    margin-bottom: 24px;
    padding: 36px 40px 32px;
    background: linear-gradient(135deg, #1a3a6e 0%, #2d65c2 60%, #4a8de8 100%);
    border-radius: var(--radius-lg);
    box-shadow: 0 6px 20px rgba(30, 70, 160, 0.25);
}
.app-header h1 { font-size: 2.4rem; font-weight: 700; color: #ffffff; letter-spacing: -0.5px; }
.app-header p { font-size: 1.05rem; color: rgba(255,255,255,0.78); margin-top: 4px; }

.main-grid { display: grid; grid-template-columns: 320px 1fr 320px; gap: 20px; }

/* --- PANELS --- */
.panel {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
}
.panel-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    background: #f7f9fc;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.panel-header h2 { font-size: 1.1rem; font-weight: 700; color: var(--text-color); letter-spacing: -0.2px; }
.panel-content { padding: 18px 20px; overflow-y: auto; flex-grow: 1; }
.panel-footer { padding: 16px 20px; border-top: 1px solid var(--border-color); background-color: #f7f9fc; margin-top: auto; border-radius: 0 0 var(--radius-md) var(--radius-md); }

/* --- INFO BOXES --- */
.info-box {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px 22px;
    margin: -8px auto 22px auto;
    max-width: 1040px;
    font-size: 0.9rem;
    color: var(--text-muted);
    box-shadow: var(--shadow-sm);
}
.info-box h3 { font-size: 0.95rem; font-weight: 700; color: var(--text-color); margin-bottom: 7px; }
.info-box p { margin-bottom: 5px; }
.info-box .usage-list { display: flex; justify-content: space-around; padding: 10px 0 4px 0; }
.info-box .usage-list span { font-weight: 500; }

.notes-box {
    background-color: #fffbeb;
    border: 1px solid #f0d980;
    border-radius: var(--radius-md);
    padding: 11px 20px;
    margin: 22px auto -8px auto;
    max-width: 1040px;
    font-size: 0.85rem;
    text-align: center;
    color: #7a5c00;
    box-shadow: var(--shadow-sm);
}
.notes-box b { font-weight: 600; }

/* Export footer */
.export-footer { display: flex; flex-direction: column; gap: 10px; }

/* --- ACCORDION & FORMS --- */
.accordion-item { border-bottom: 1px solid var(--border-color); }
.accordion-item:last-child { border-bottom: none; }
.accordion-header {
    padding: 13px 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-color);
    position: relative;
    letter-spacing: 0.1px;
    transition: color 0.15s;
}
.accordion-header:hover { color: var(--primary-color); }
.accordion-header::after { content: '\25B2'; position: absolute; right: 4px; transition: transform 0.2s; font-size: 0.72em; color: var(--text-muted); }
.accordion-item:not(.is-open) > .accordion-header::after { transform: rotate(180deg); }
.accordion-content { display: none; padding-bottom: 14px; }
.accordion-item.is-open > .accordion-content { display: block; }

.control-group { margin-bottom: 13px; }
.control-group label { display: block; margin-bottom: 5px; font-weight: 500; font-size: 0.875rem; color: var(--text-color); }
.control-group.inline { display: flex; align-items: center; }
.control-group.inline input[type="checkbox"] { margin-right: 8px; }
.answer-key-sub { padding-left: 16px; }

input[type="text"], input[type="number"], select {
    width: 100%;
    padding: 9px 11px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.925rem;
    font-family: var(--font-family);
    color: var(--text-color);
    background: #fff;
    transition: border-color 0.18s, box-shadow 0.18s;
    appearance: auto;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59,125,216,0.12);
}
input[type="range"] {
    width: 100%;
    accent-color: var(--primary-color);
    cursor: pointer;
}
input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--primary-color);
    cursor: pointer;
    flex-shrink: 0;
}

/* --- BUTTONS --- */
.primary-button, .secondary-button, .outline-button, .pagination-controls button {
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: var(--font-family);
    cursor: pointer;
    transition: background-color 0.18s, box-shadow 0.18s, opacity 0.18s;
    letter-spacing: 0.2px;
}
.primary-button, .secondary-button, .outline-button { width: 100%; padding: 11px; font-weight: 700; }

.primary-button {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(59,125,216,0.28);
}
.primary-button:hover { background: linear-gradient(135deg, var(--primary-hover) 0%, #245aac 100%); box-shadow: 0 3px 10px rgba(59,125,216,0.38); }

.secondary-button { background-color: var(--secondary-color); color: white; box-shadow: 0 2px 5px rgba(92,107,132,0.22); }
.secondary-button:hover { background-color: var(--secondary-hover); }

.outline-button { background-color: transparent; color: var(--secondary-color); border: 2px solid var(--secondary-color); }
.outline-button:hover:not(:disabled) { background-color: var(--secondary-color); color: white; }

.secondary-button:disabled, .outline-button:disabled, .pagination-controls button:disabled {
    background: #e8ecf2; color: #aab3c4; border-color: #dde3ec; cursor: not-allowed; opacity: 0.65; box-shadow: none;
}

/* --- PREVIEW & PAGINATION --- */
.preview-header { display: flex; justify-content: space-between; align-items: center; }
.pagination-controls { display: flex; align-items: center; gap: 8px; }
.pagination-controls button {
    padding: 5px 12px;
    background: var(--primary-color);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(59,125,216,0.22);
}
.pagination-controls button:hover:not(:disabled) { background-color: var(--primary-hover); }
.pagination-controls span { font-size: 0.875rem; color: var(--text-muted); font-weight: 500; }

.preview-area {
    padding: 20px;
    background: linear-gradient(135deg, #e8ecf2 0%, #dfe5ef 100%);
    flex-grow: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}
.no-preview p { text-align: center; color: var(--text-muted); margin-top: 50px; }

/* --- WORKSHEET STYLES --- */
.worksheet-page {
    background: white;
    width: var(--page-w, 210mm);
    --cols: 2;
    --font-size: 16px;
    --v-spacing: 20px;
    padding: 20mm 15mm; /* fallback — overridden by inline style from JS */
}

/* scale(0.85) 공간 보정 */
#worksheet-preview-container .worksheet-page {
    min-height: var(--page-h, 297mm);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
    transform: scale(0.85);
    transform-origin: top center;
    margin-bottom: calc(var(--page-h, 297mm) * -1 * 0.15);
}

.worksheet-header h1 { font-size: calc(var(--font-size) * 1.8); text-align: center; margin-bottom: 5px; }
.worksheet-header .subtitle { font-size: calc(var(--font-size) * 0.9); text-align: center; color: var(--text-muted); margin-bottom: var(--header-spacing, 20px); }
.worksheet-meta { display: flex; justify-content: space-between; margin-bottom: var(--meta-spacing, 25px); font-size: calc(var(--font-size) * 0.95); }
.problem-list { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: var(--v-spacing) 20px; font-size: var(--font-size); }
.problem-item { display: flex; align-items: flex-start; }
.problem-number { font-weight: 600; margin-right: 8px; white-space: nowrap; }
.problem-text { line-height: 1.8; overflow-wrap: break-word; }

/* --- FOOTER --- */
.app-footer {
    text-align: center;
    padding: 20px;
    margin-top: 28px;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.875rem;
}
.app-footer p { margin-bottom: 4px; }
.app-footer a { color: var(--primary-color); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

/* ── Answer Key ──────────────────────────────────────────────────────────── */
.answer-key-list {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px 10px;
    margin-top: 10px;
}
.answer-key-item {
    display: flex;
    align-items: baseline;
    gap: 4px;
    font-size: 13px;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: #f7f9fc;
}
.answer-num { font-weight: 700; color: #4a5568; white-space: nowrap; min-width: 22px; }
.answer-val { color: var(--text-color); font-weight: 500; }

/* PDF Progress Overlay */
#pdf-progress-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 25, 45, 0.65);
    justify-content: center; align-items: center;
    z-index: 10000; color: white;
    flex-direction: column; font-size: 1.5rem;
    display: none;
    backdrop-filter: blur(3px);
}
#pdf-progress-text { margin-top: 20px; font-size: 1rem; opacity: 0.85; }

/* Privacy page */
.main-content-page { max-width: 800px; margin: 0 auto; padding: 20px; }
.main-content-page h2 { font-size: 1.3rem; font-weight: 600; margin-top: 24px; margin-bottom: 8px; color: var(--text-color); }
.main-content-page p { margin-bottom: 12px; color: var(--text-color); line-height: 1.7; }
.main-content-page ul { padding-left: 24px; margin-bottom: 12px; }
.main-content-page ul li { margin-bottom: 6px; line-height: 1.6; }
.home-link {
    display: inline-block; margin-top: 24px; padding: 10px 20px;
    background-color: var(--primary-color); color: white;
    text-decoration: none; border-radius: var(--radius-sm);
    font-weight: 600; transition: background-color 0.2s;
}
.home-link:hover { background-color: var(--primary-hover); }

/* ── 반응형 ──────────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
    .main-grid { grid-template-columns: 280px 1fr 280px; }
}

@media (max-width: 900px) {
    .main-grid { grid-template-columns: 1fr; grid-template-rows: auto auto auto; }
    .center-panel { order: -1; }
    .app-header h1 { font-size: 1.8rem; }
    #worksheet-preview-container .worksheet-page {
        transform: scale(0.65);
        transform-origin: top center;
        margin-bottom: calc(var(--page-h, 297mm) * -1 * 0.35);
    }
}

@media (max-width: 600px) {
    .app-container { padding: 12px; }
    .app-header { padding: 24px 20px; }
    .app-header h1 { font-size: 1.5rem; }
    .app-header p { font-size: 0.95rem; }
    .main-grid { gap: 12px; }
    .panel-content { padding: 14px; }
    .panel-footer { padding: 14px; }
    .export-footer { flex-direction: column; }
    #worksheet-preview-container .worksheet-page {
        transform: scale(0.45);
        transform-origin: top center;
        margin-bottom: calc(var(--page-h, 297mm) * -1 * 0.55);
    }
}

/* ── 인쇄 스타일 ─────────────────────────────────────────────────────────── */
@media print {
    body * { visibility: hidden; }
    #worksheet-preview-container, #worksheet-preview-container * { visibility: visible; }
    #worksheet-preview-container { position: absolute; left: 0; top: 0; }
    #worksheet-preview-container .worksheet-page {
        transform: none !important;
        box-shadow: none !important;
        margin: 0 !important;
        min-height: unset !important;
        page-break-after: always;
    }
}

/* --- NAVIGATION --- */
.site-nav {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    box-shadow: 0 1px 6px rgba(30,42,58,0.07);
}
.nav-container {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    padding: 0 20px;
    min-height: 56px;
}
.nav-logo {
    font-weight: 800;
    font-size: 0.975rem;
    color: var(--text-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    letter-spacing: -0.4px;
    flex-shrink: 0;
    gap: 10px;
    margin-right: 20px;
    transition: color 0.15s;
}
.nav-logo::before {
    content: '';
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: var(--primary-color);
    flex-shrink: 0;
    box-shadow: 0 0 0 3px var(--primary-light);
}
.nav-logo:hover { color: var(--primary-color); }
.nav-links {
    list-style: none;
    display: flex;
    align-items: stretch;
    margin: 0;
    padding: 0;
}
.nav-links li { display: flex; align-items: stretch; }
.nav-links a {
    display: flex;
    align-items: center;
    padding: 0 18px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    position: relative;
    transition: color 0.18s;
    white-space: nowrap;
}
.nav-links a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 12px;
    right: 12px;
    height: 3px;
    background: var(--primary-color);
    border-radius: 3px 3px 0 0;
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
.nav-links a:hover { color: var(--primary-color); }
.nav-links a:hover::after, .nav-links a.active::after { transform: scaleX(1); }
.nav-links a.active { color: var(--primary-color); font-weight: 600; }

/* --- GUIDES SECTION (index page) --- */
.guides-section {
    margin: 32px auto 8px auto;
    max-width: 1040px;
}
.guides-section > h2 {
    font-size: 1.45rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-color);
}
.guides-section > p {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.6;
}
.guides-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}
.guide-card {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: var(--text-color);
    transition: box-shadow 0.15s, transform 0.15s;
    display: block;
}
.guide-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.guide-card .guide-tag {
    display: inline-block;
    font-size: 0.71rem;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--primary-color);
    background: var(--primary-light);
    padding: 2px 8px;
    border-radius: 20px;
    margin-bottom: 8px;
}
.guide-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-color);
}
.guide-card p {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* --- ARTICLE PAGE --- */
.article-page {
    max-width: 780px;
    margin: 0 auto;
    padding: 20px;
}
.article-page h1 {
    font-size: 1.9rem;
    font-weight: 700;
    margin-bottom: 18px;
    color: var(--text-color);
    line-height: 1.25;
}
.article-page h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-top: 32px;
    margin-bottom: 10px;
    color: var(--text-color);
    border-left: 4px solid var(--primary-color);
    padding-left: 12px;
}
.article-page h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-top: 20px;
    margin-bottom: 8px;
    color: var(--text-color);
}
.article-page p {
    margin-bottom: 14px;
    color: var(--text-color);
    line-height: 1.78;
}
.article-page ul, .article-page ol {
    padding-left: 24px;
    margin-bottom: 14px;
}
.article-page ul li, .article-page ol li {
    margin-bottom: 8px;
    line-height: 1.65;
    color: var(--text-color);
}
.article-page .tip-box {
    background: var(--primary-light);
    border-left: 4px solid var(--primary-color);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 14px 18px;
    margin: 18px 0;
}
.article-page .tip-box p { margin-bottom: 0; color: var(--text-color); }
.article-page table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 18px;
    font-size: 0.9rem;
}
.article-page table th {
    background: #f7f9fc;
    border: 1px solid var(--border-color);
    padding: 9px 12px;
    text-align: left;
    font-weight: 600;
}
.article-page table td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
}
.article-page .cta-box {
    background: linear-gradient(135deg, #1a3a6e 0%, #2d65c2 100%);
    border-radius: var(--radius-md);
    padding: 24px 28px;
    margin-top: 40px;
    text-align: center;
}
.article-page .cta-box h3 { color: #fff; margin-top: 0; margin-bottom: 10px; font-size: 1.2rem; }
.article-page .cta-box p { color: rgba(255,255,255,0.88); margin-bottom: 16px; }
.article-page .cta-btn {
    display: inline-block;
    background: #fff;
    color: var(--primary-color);
    font-weight: 700;
    padding: 11px 28px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 0.95rem;
    transition: background 0.15s;
}
.article-page .cta-btn:hover { background: var(--primary-light); }
.article-breadcrumb {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.article-breadcrumb a { color: var(--primary-color); text-decoration: none; }
.article-breadcrumb a:hover { text-decoration: underline; }
.article-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

/* --- CONTACT FORM --- */
.contact-form { max-width: 560px; }
.contact-form .form-group { margin-bottom: 18px; }
.contact-form label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; }
.contact-form input, .contact-form textarea {
    width: 100%; padding: 10px 13px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.925rem;
    font-family: var(--font-family);
    color: var(--text-color);
    background: #fff;
    transition: border-color 0.18s, box-shadow 0.18s;
}
.contact-form input:focus, .contact-form textarea:focus {
    outline: none; border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59,125,216,0.12);
}
.contact-form textarea { min-height: 140px; resize: vertical; }
.contact-form .submit-btn {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: #fff; border: none; border-radius: var(--radius-sm);
    padding: 11px 28px; font-size: 0.95rem; font-weight: 700;
    font-family: var(--font-family); cursor: pointer;
    transition: opacity 0.18s;
}
.contact-form .submit-btn:hover { opacity: 0.88; }

@media (max-width: 600px) {
    .nav-container {
        min-height: auto;
        flex-direction: column;
        align-items: stretch;
        padding: 14px 16px 0;
        gap: 0;
    }
    .nav-logo {
        padding-bottom: 12px;
        border-bottom: 1px solid var(--border-color);
    }
    .nav-links { flex-wrap: wrap; }
    .nav-links a {
        padding: 10px 14px 10px 0;
        font-size: 0.875rem;
    }
    .nav-links a::after { display: none; }
    .guides-grid { grid-template-columns: 1fr; }
    .article-page h1 { font-size: 1.5rem; }
    .article-page h2 { font-size: 1.15rem; }
}

/* ── AddToAny Share Buttons ─────────────────────────────────────────────── */
#a2a-float-right {
    position: fixed;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
}

#a2a-float-right .a2a_kit {
    display: flex;
    flex-direction: column;
    align-items: center;
}


#a2a-bar-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(6px);
    border-top: 1px solid var(--border-color);
    padding: 8px 16px;
    box-shadow: 0 -2px 8px rgba(30,42,58,0.08);
}

#a2a-bar-bottom .a2a_kit {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    align-items: center;
}

@media print {
    #a2a-float-right, #a2a-bar-bottom { display: none; }
}

/* Pictures inside problems (clock faces, fraction bars, number lines) */
.problem-text .ws-pic { vertical-align: middle; display: inline-block; }

.pro-pill {
    display: inline-block; margin-left: 4px; padding: 1px 7px; border-radius: 99px;
    background: #3b5bdb; color: #fff; font-size: 10px; font-weight: 700; vertical-align: 1px;
}
