/**
 * Site styles: index (home) and wzor (pattern) pages.
 * Wzor page uses body.page-wzor and CSS variables for grid dimensions.
 */

* { box-sizing: border-box; }

body {
    font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
    margin: 0;
    padding: 24px 16px;
    background: #e8f4f8;
    min-height: 100vh;
    color: #2c3e50;
}

.wrap {
    max-width: 880px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ----- Index (home) page ----- */
.site-header { text-align: center; margin-bottom: 40px; }
.site-nav {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.site-nav a {
    color: #1a365d;
    font-weight: 600;
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    font-size: 0.95rem;
}
.site-nav a:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}
.site-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0 0 12px 0;
    color: #1a365d;
}
.site-header p { font-size: 1rem; line-height: 1.6; margin: 0; color: #475569; }

.intro {
    background: #fff;
    padding: 20px 24px;
    border-radius: 12px;
    margin-bottom: 36px;
    border: 1px solid #e2e8f0;
    font-size: 0.95rem;
    line-height: 1.65;
    color: #334155;
}
.intro p { margin: 0; }
.intro p + p { margin-top: 1em; }

.content-block {
    background: #fff;
    padding: 24px 24px;
    border-radius: 12px;
    margin-bottom: 36px;
    border: 1px solid #e2e8f0;
    font-size: 0.95rem;
    line-height: 1.7;
    color: #334155;
}
.content-block h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: #1a365d;
    margin: 0 0 12px 0;
}
.content-block ul { margin: 0.5em 0 0 1.2em; padding: 0; }
.content-block li { margin: 0.35em 0; }

.faq { margin-top: 28px; }
.faq h2 { margin-bottom: 16px; }
.faq-list { list-style: none; margin: 0; padding: 0; }
.faq-item {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
}
.faq-item:last-child { margin-bottom: 0; }
.faq-q {
    font-weight: 700;
    color: #1a365d;
    padding: 14px 16px;
    background: #f8fafc;
    font-size: 0.95rem;
}
.faq-a { padding: 14px 16px; color: #475569; }

.topic-list-wrap { margin-bottom: 40px; }
.topic-list-wrap h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1a365d;
    margin: 0 0 20px 0;
}
.topic-scale-group { margin-bottom: 32px; }
.topic-scale-group:last-child { margin-bottom: 0; }
.topic-scale-title {
    font-size: 1rem;
    font-weight: 700;
    color: #334155;
    margin: 0 0 14px 0;
    padding-bottom: 6px;
    border-bottom: 2px solid #e2e8f0;
}

.topic-list {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    list-style: none;
    margin: 0;
    padding: 0;
}
@media (max-width: 720px) {
    .topic-list { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 520px) {
    .topic-list { grid-template-columns: repeat(2, 1fr); gap: 16px; }
}
@media (max-width: 380px) {
    .topic-list { grid-template-columns: 1fr; gap: 12px; }
}

.topic-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: inherit;
    background: #fff;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.topic-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.18);
    transform: translateY(-2px);
}
.topic-thumb {
    display: block;
    margin: 0 auto 12px;
    border: 1px solid #cbd5e1;
    line-height: 0;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    flex-shrink: 0;
}
.topic-thumb img {
    display: block;
    width: 100%;
    max-width: 160px;
    height: auto;
    aspect-ratio: 1;
    object-fit: contain;
    background: #f8fafc;
}
.topic-title { display: block; font-size: 1rem; font-weight: 600; color: #334155; }
.topic-grid-size { display: block; font-size: 0.8rem; font-weight: 400; color: #64748b; margin-top: 2px; }

.site-footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
    font-size: 0.85rem;
    color: #64748b;
    text-align: center;
}
.site-footer a { color: #3b82f6; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* Index: mobile */
@media (max-width: 768px) {
    body { padding: 16px 12px; }
    .wrap { padding: 0 12px; }
    .site-header { margin-bottom: 28px; }
    .site-header h1 { font-size: 1.35rem; }
    .site-header p { font-size: 0.95rem; }
    .intro, .content-block { padding: 16px 18px; margin-bottom: 24px; }
    .content-block h2 { font-size: 1.05rem; }
    .faq-q, .faq-a { padding: 12px 14px; font-size: 0.9rem; }
    .topic-list-wrap h2 { font-size: 1rem; margin-bottom: 16px; }
    .topic-scale-group { margin-bottom: 24px; }
    .topic-scale-title { font-size: 0.95rem; margin-bottom: 12px; }
    .topic-card { padding: 14px 12px; min-height: 44px; }
    .topic-title { font-size: 0.95rem; }
    .topic-grid-size { font-size: 0.75rem; }
    .site-footer { margin-top: 28px; padding-top: 16px; font-size: 0.8rem; }
}
@media (max-width: 480px) {
    body { padding: 12px 10px; }
    .wrap { padding: 0 8px; }
    .site-header h1 { font-size: 1.2rem; }
    .intro, .content-block { padding: 14px 12px; }
    .topic-thumb { max-width: 100%; }
}

/* ----- Wzor (pattern) page ----- */
body.page-wzor .wrap { max-width: 960px; }

.breadcrumb { margin-bottom: 20px; font-size: 0.9rem; }
.breadcrumb a { color: #3b82f6; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb span { color: #64748b; }

.page-heading { font-size: 1.4rem; font-weight: 700; color: #1a365d; margin: 0 0 24px 0; text-align: center; }

.pages {
    margin-top: 8px;
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    gap: 32px;
    justify-content: center;
    align-items: flex-start;
    background-color: #fff;
    padding: 24px;
    border-radius: 0;
    border: none;
}
.page {
    background-color: #fff;
    margin-bottom: 0;
    padding: 28px 16px;
    border-radius: 0;
    border: none;
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
}
.page:first-child { padding-right: 16px; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.page:last-child { margin-bottom: 0; padding-left: 16px; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.page-title { text-align: center; font-size: 1.15rem; font-weight: 700; margin: 0 0 20px 0; color: #1a365d; padding-bottom: 12px; border-bottom: 2px solid #e2e8f0; }
.page-subtitle { text-align: center; font-size: 0.8rem; color: #64748b; margin: -12px 0 16px 0; }

.grid-container { width: 100%; text-align: center; margin-bottom: 4px; }
.grid-wrap { display: inline-block; border: 2px solid #334155; border-radius: 6px; overflow: hidden; }
.grid-table { border-collapse: collapse; border: none; table-layout: fixed; }
.grid-table td {
    width: var(--cell-size);
    height: var(--cell-size);
    min-width: var(--cell-size);
    min-height: var(--cell-size);
    border: 1px solid #cbd5e1;
    padding: 0;
    margin: 0;
    aspect-ratio: 1;
    box-sizing: border-box;
}
.grid-table td.axis-row,
.grid-table td.corner { aspect-ratio: auto; }
.grid-table .cell-empty { background-color: #fff; }
.grid-table .axis-row {
    font-size: var(--axis-font-size);
    font-weight: 700;
    text-align: center;
    vertical-align: middle;
    border: none;
    background-color: #fff;
    color: #1a365d;
}
.grid-table .axis-row.num { width: var(--label-width); }
.grid-table .axis-row.letter { height: var(--label-height); }
.grid-table .corner {
    border: none;
    background-color: #fff;
    width: var(--label-width);
    height: var(--label-height);
}

.page .legend { display: none; }
.legend-screen,
.description-screen {
    width: 100%;
    margin-top: 24px;
    padding: 20px 24px;
    background: #fff;
    border-radius: 0;
    border: none;
}
.legend-screen .legend { margin-top: 0; padding-top: 0; border-top: none; }
.description-screen .pattern-description-text { margin: 0; font-size: 0.95rem; line-height: 1.5; color: #334155; }
.legend { margin-top: 24px; padding-top: 20px; border-top: 1px solid #e2e8f0; }
.legend-title { font-size: 0.85rem; font-weight: 700; color: #475569; margin: 0 0 12px 0; }
.legend-item { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; padding: 8px 12px; background-color: #fff; border-radius: 8px; border: 1px solid #e2e8f0; }
.legend-item:last-child { margin-bottom: 0; }
.legend .color-swatch { flex-shrink: 0; width: 24px; height: 24px; border-radius: 4px; border: 1px solid #94a3b8; }
.legend .color-name { font-weight: 600; font-size: 0.9rem; color: #334155; min-width: 120px; }
.legend .cells { font-size: 0.85rem; color: #64748b; line-height: 1.4; }

.action-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: center; margin-top: 24px; }
.btn-print {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    color: #fff;
    background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}
.btn-print:hover { background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%); box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35); }
.btn-print:active { transform: translateY(1px); }
.back-link { font-size: 0.9rem; color: #3b82f6; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

/* Wzor: mobile */
@media (max-width: 768px) {
    body.page-wzor .wrap { padding: 0 8px; max-width: 100%; }
    .breadcrumb { font-size: 0.85rem; margin-bottom: 16px; }
    .page-heading { font-size: 1.2rem; margin-bottom: 16px; }
    .pages { flex-direction: column; gap: 24px; padding: 16px; align-items: center; }
    .page { flex: none; width: 100%; max-width: 100%; padding: 20px 12px; }
    .page:first-child, .page:last-child { padding: 20px 12px; }
    .page-title { font-size: 1.05rem; margin-bottom: 16px; padding-bottom: 10px; }
    .page-subtitle { font-size: 0.75rem; margin: -10px 0 12px 0; }
    .grid-container { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 8px; }
    .grid-wrap { max-width: 100%; }
    .legend-screen, .description-screen { padding: 16px 12px; margin-top: 16px; }
    .legend-item { padding: 10px 12px; gap: 10px; }
    .legend .color-name { min-width: 90px; font-size: 0.85rem; }
    .legend .cells { font-size: 0.8rem; }
    .action-bar { flex-direction: column; gap: 14px; margin-top: 20px; }
    .btn-print { min-height: 48px; padding: 14px 24px; width: 100%; max-width: 280px; justify-content: center; }
    .back-link { display: inline-block; min-height: 44px; line-height: 44px; }
}
@media (max-width: 480px) {
    body.page-wzor { padding: 12px 8px; }
    body.page-wzor .wrap { padding: 0 4px; }
    .page-heading { font-size: 1.1rem; }
    .page { padding: 16px 8px; }
    .grid-table td { min-width: 0; }
}
