/* Homepage Preview Grid Styles */

:root {
    --grid-border-color: #ef4444;
    /* Standard Red */
    --grid-guide-color: rgba(239, 68, 68, 0.3);
    /* Fainter red */
    --paper-width: 210mm;
    --paper-height: 297mm;
    --cell-size: 24mm;
}

#preview-container {
    width: 100%;
    height: 400px;
    /* background: #e5e7eb; Removed gray background */
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Center vertically again for 'contain' look */
    /* border: 1px solid #e5e7eb; Removed border */
    /* box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); Removed shadow */
}

/* Skeleton shown while cnchar + core-renderer.js are still loading (deferred
   scripts, ~6 requests before the first real render can happen) so the hero
   section doesn't sit on a blank rectangle. home-preview.js removes the
   .loading class the moment the first state finishes rendering. */
.preview-skeleton {
    display: none;
    width: min(100%, 420px);
    padding: 24px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

#preview-container.loading .preview-skeleton {
    display: block;
}

#preview-container.loading .a4-paper {
    display: none;
}

.preview-skeleton-line {
    height: 14px;
    margin-bottom: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, #eef0f3 25%, #f7f8fa 37%, #eef0f3 63%);
    background-size: 400% 100%;
    animation: preview-skeleton-shimmer 1.4s ease infinite;
}

.preview-skeleton-line:last-child {
    margin-bottom: 0;
}

@keyframes preview-skeleton-shimmer {
    0% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0 50%;
    }
}

.a4-paper {
    width: var(--paper-width);
    height: var(--paper-height);
    /* Crossfade between carousel states — see switchState() in
       home-preview.js, which toggles this via opacity before/after
       swapping content and rescaling, instead of the old instant jump. */
    transition: transform 0.3s ease, opacity 0.25s ease;
    /* #preview-container is a flex row, and flex items shrink below their
       set width by default (flex-shrink: 1). On a phone-width container
       that shrank this box down to the container's own width (e.g. 342px
       instead of the intended ~1122px landscape width) before scalePaper()
       ever got to apply its transform — so the mm-sized grid content inside
       (fixed regardless of the parent's shrunk box) genuinely overflowed
       and got clipped by overflow: hidden below, and scalePaper() read the
       already-wrong shrunk width for its own scale math on top of that.
       flex-shrink: 0 keeps this box at its true intrinsic size so the JS
       transform is the only thing scaling it down, proportionally. */
    flex-shrink: 0;
    background: white;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 10mm;
    display: flex;
    justify-content: center;
    align-items: center;
    transform-origin: center;
    overflow: hidden;
}

.a4-paper.landscape {
    width: var(--paper-height);
    height: var(--paper-width);
}

/* Internal Grid Wrapper */
.grid-container {
    display: grid;
    gap: 1px;
    background-color: var(--grid-border-color);
    border: 1px solid var(--grid-border-color);
    flex: none;
    grid-template-columns: repeat(var(--col-count, 7), var(--cell-size));
    grid-auto-rows: var(--cell-size);
}

/* Cell & Grid Styles */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background-color: white;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Increase font size slightly for preview visibility */
.cell-content {
    font-family: 'Times New Roman', serif, 'KaiTi', 'STKaiti', '楷体', 'SimKai';
    font-size: calc(var(--cell-size) * 0.85);
    line-height: 1;
    z-index: 2;
    pointer-events: none;
}

/* Grid Patterns */
.grid-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    pointer-events: none;
}

/* Mi Ge */
.type-mi .grid-bg::after {
    /* Horizontal */
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 1px;
    border-top: 1px dashed var(--grid-guide-color);
}

.type-mi .grid-bg::before {
    /* Vertical */
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    height: 100%;
    width: 1px;
    border-left: 1px dashed var(--grid-guide-color);
}

.type-mi .grid-diagonals {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.type-mi .grid-diagonals::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 150%;
    height: 1px;
    border-top: 1px dashed var(--grid-guide-color);
    transform: translate(-50%, -50%) rotate(45deg);
    transform-origin: center;
}

.type-mi .grid-diagonals::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 150%;
    height: 1px;
    border-top: 1px dashed var(--grid-guide-color);
    transform: translate(-50%, -50%) rotate(-45deg);
    transform-origin: center;
}

/* Preview Carousel Tabs */
.preview-tabs {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.75rem;
}

.preview-tab {
    padding: 0.5rem 0.5rem;
    background-color: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    /* default invisible underline */
    color: var(--text-light);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
    position: relative;
}

.preview-tab:hover {
    color: var(--primary-color);
}

.preview-tab.active {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    /* Underline for active */
    font-weight: 600;
}

/* --- Copied Poetry Mode Styles --- */

.poetry-container {
    display: flex;
    flex-direction: column;
    /* Default spacing for portrait rows */
    width: 100%;
    align-items: center;
}

.poetry-row {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-bottom: 3mm;
}

.poetry-row.title-row {
    margin-bottom: 8mm;
}

/* Cell Group for Pinyin + Grid */
.cell-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: -1px;
    /* Collapse adjacent borders */
}

.cell-group:last-child {
    margin-right: 0;
}

.pinyin-box {
    width: 100%;
    height: 8mm;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-family: 'Times New Roman', serif, 'KaiTi', 'STKaiti', '楷体', 'SimKai';
    font-size: 14px;
    padding-bottom: 2px;
    color: #333;
}

/* Add borders to cells in poetry mode (since not in grid-container) */
.cell-group .cell {
    border: 1px solid var(--grid-border-color);
}