:root {
    --sidebar-bg: #1e1e1e;
    --sidebar-fg: #ffffff;
    --accent-color: #3478f6;
    --border-color-default: #ff4d4f;
    --page-bg: #ffffff;
    --text-muted: #a0a0a0;
    --input-bg: #2d2d2d;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: #121212;
    color: #f0f0f0;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: 320px;
    background: linear-gradient(180deg, #1f1f1f 0%, #151515 100%);
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.3);
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid #333;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--accent-color);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.control-group {
    margin-bottom: 24px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #ccc;
}

.control-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.value-display {
    font-size: 0.75rem;
    color: var(--accent-color);
}

.divider {
    border: none;
    border-top: 1px solid #333;
    margin: 20px 0;
}

.stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 10px;
    border: 1px solid #333;
    border-radius: 8px;
    background: #1a1a1a;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: #cfcfcf;
}

.stat-label {
    color: #8a8a8a;
}

.stat-value {
    font-weight: 600;
    color: #ffffff;
}

textarea {
    width: 100%;
    height: 100px;
    background: var(--input-bg);
    border: 1px solid #444;
    border-radius: 8px;
    color: #fff;
    padding: 12px;
    font-size: 0.9rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}

textarea:focus {
    border-color: var(--accent-color);
}

input[type="range"] {
    width: 100%;
    margin: 8px 0;
    cursor: pointer;
}

select,
input[type="text"] {
    width: 100%;
    padding: 10px;
    background: var(--input-bg);
    border: 1px solid #444;
    border-radius: 8px;
    color: #fff;
    outline: none;
}

.row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.button-row {
    gap: 10px;
}

.secondary-btn {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #444;
    background: transparent;
    color: #d7d7d7;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.secondary-btn:hover {
    border-color: var(--accent-color);
    color: #ffffff;
}

.status-tip {
    margin-top: 12px;
    font-size: 0.75rem;
    color: #a0a0a0;
    line-height: 1.4;
}

.status-tip.ok {
    color: #7bd88f;
}

.status-tip.warn {
    color: #f6c453;
}

.status-tip.error {
    color: #ff7a7a;
}

/* Switch Styling */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 22px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #444;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-color);
}

input:checked+.slider:before {
    transform: translateX(22px);
}

.primary-btn {
    width: 100%;
    padding: 14px;
    background-color: var(--accent-color);
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
}

.primary-btn:hover {
    opacity: 0.9;
}

.primary-btn:active {
    transform: scale(0.98);
}

/* Preview Area */
.preview-area {
    flex: 1;
    background: radial-gradient(circle at 15% 15%, #3a3a3a 0%, #2c2c2c 40%, #232323 100%);
    display: flex;
    justify-content: flex-start;
    /* 从顶部开始,避免负坐标 */
    padding: 40px;
    overflow-y: auto;
    scroll-behavior: smooth;
    flex-direction: column;
    align-items: center;
    /* 水平居中 */
}

/* Remove min-height constraint to let pagination control it, 
   but ensure each page is A4 size */
.a4-page {
    width: 210mm;
    min-height: 297mm;
    /* Force A4 height */
    background-color: #ffffff !important;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
    padding: 20mm 15mm;
    color: #333;
    display: block;
    position: relative;
    font-family: inherit;
    flex: none;
    /* Do not shrink */
    margin-bottom: 50px;
}

.page-header {
    text-align: center;
    margin-bottom: 20px;
}

.page-header h1 {
    font-size: 24px;
    margin: 0;
    outline: none;
}

.page-content {
    position: relative;
}

.empty-state {
    width: 100%;
    max-width: 520px;
    padding: 24px;
    border-radius: 12px;
    background: #1f1f1f;
    color: #d5d5d5;
    text-align: center;
    font-size: 0.95rem;
    border: 1px dashed #444;
}

/* Copybook Elements */
.copybook-row {
    margin-bottom: 20px;
}

.strokes-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid #efefef;
    border-radius: 4px;
    background: #fafafa;
}

.stroke-item {
    width: 40px;
    height: 40px;
    position: relative;
    border: 1px solid #f0f0f0;
    background: #ffffff;
    overflow: hidden;
}

.stroke-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999999;
    opacity: 0;
    pointer-events: none;
}

.practice-grid-container {
    display: flex;
    flex-wrap: wrap;
}

.char-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: 15px;
    margin-bottom: 15px;
}

.pinyin {
    font-size: 14px;
    height: 20px;
    color: #666;
    margin-bottom: 4px;
}

.grid-style-buttons {
    display: flex;
    gap: 8px;
}

.style-btn {
    flex: 1;
    padding: 8px;
    background: var(--input-bg);
    border: 1px solid #444;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 0.9rem;
}

.style-btn.active {
    border-color: var(--accent-color);
    background: rgba(52, 120, 246, 0.2);
}

.grid-box {
    position: relative;
    border: 2px solid var(--border-color-default);
    background-size: 100% 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-image 0.2s;
}

.grid-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: none;
    color: var(--border-color-default);
    pointer-events: none;
}

.grid-layer {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.grid-layer.text-layer {
    z-index: 1;
}

.grid-layer.anim-layer {
    z-index: 2;
    pointer-events: auto;
    cursor: pointer;
}

.stroke-layer {
    position: absolute;
    inset: 0;
}

/* Grid Patterns */
.grid-mi {
    background-image: var(--grid-bg-mi);
}

.grid-tian {
    background-image: var(--grid-bg-tian);
}

.grid-empty {
    background-image: none;
}

.char-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    /* Let clicks pass through if needed */
}

.hanzi-writer-target {
    width: 100%;
    height: 100%;
}

/* Print Specific */
@media print {
    @page {
        size: A4;
        margin: 10mm;
    }

    html,
    body {
        background: none;
        overflow: visible;
        height: auto;
        margin: 0;
        padding: 0;
    }

    .app-container {
        display: block;
        height: auto;
        overflow: visible;
    }

    .sidebar {
        display: none;
    }

    .preview-area {
        padding: 0;
        margin: 0;
        background: none;
        overflow: visible;
        display: block;
        height: auto;
    }

    #pages-root {
        display: block;
    }

    .grid-box.grid-mi,
    .grid-box.grid-tian {
        background-image: none !important;
    }

    .grid-lines {
        display: block;
    }

    .grid-lines line {
        stroke-dasharray: 4 4 !important;
        stroke-linecap: round;
    }

    .stroke-fallback {
        opacity: 0.35;
        color: #666666;
    }

    .char-content[data-tone='demo'] {
        color: #222 !important;
    }

    .char-content[data-tone='overlay'] {
        color: #666 !important;
    }

    .char-content[data-tone='trace'] {
        color: #888 !important;
    }

    .char-content[data-tone='fallback'] {
        color: #222 !important;
    }

    .a4-page {
        box-shadow: none;
        margin: 0 auto;
        width: 100%;
        min-height: calc(297mm - 20mm);
        height: auto;
        overflow: visible;
        page-break-after: always;
        break-after: page;
        page-break-inside: avoid;
        break-inside: avoid;
        border: none;
    }

    .copybook-row {
        break-inside: avoid;
        page-break-inside: avoid;
    }

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