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

:root {
    --paper-color: #faf8f5;
    --paper-shadow: rgba(0, 0, 0, 0.15);
    --bg-gradient-start: #f5ede3;
    --bg-gradient-end: #e8dccf;
    --text-primary: #2d2d2d;
    --text-secondary: #6b6b6b;
    --accent-color: #d4733b;
    --accent-hover: #c4622a;
    --accent-light: #f5e6da;
    --border-color: #e0d5c9;
    --sidebar-bg: rgba(255, 255, 255, 0.85);
    --success-color: #2a9d8f;
    --danger-color: #e63946;
}

body {
    font-family: 'Noto Sans SC', sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    color: var(--text-primary);
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(212, 115, 59, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(74, 123, 157, 0.08) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.app {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 30px 20px;
}

.header {
    text-align: center;
    margin-bottom: 24px;
}

.title {
    font-family: 'Noto Serif SC', serif;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
    letter-spacing: 2px;
}

.subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 300;
    letter-spacing: 1px;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.sidebar {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 20px 18px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(10px);
    border-radius: 18px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.5);
    transition: opacity 0.3s ease;
    position: sticky;
    top: 20px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 0;
}

.sidebar-divider {
    height: 1px;
    background: var(--border-color);
    margin: 16px 0;
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.color-btn {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    padding: 0;
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    border-color: var(--text-primary);
    transform: scale(1.1);
    box-shadow: 0 0 0 3px rgba(212, 115, 59, 0.3);
}

.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
}

#colorPicker {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background: none;
    padding: 0;
    flex-shrink: 0;
}

#colorPicker::-webkit-color-swatch-wrapper {
    padding: 0;
}

#colorPicker::-webkit-color-swatch {
    border-radius: 50%;
    border: 2px solid var(--border-color);
}

.color-picker-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.size-display {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.size-display span:first-child {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
}

.size-unit {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.size-slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
}

.size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(212, 115, 59, 0.4);
    transition: transform 0.2s ease;
}

.size-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    width: 100%;
}

.tool-btn:hover:not(:disabled) {
    background: var(--accent-light);
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(212, 115, 59, 0.15);
}

.tool-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tool-btn.secondary {
    background: transparent;
}

.tool-btn.save-btn {
    background: linear-gradient(135deg, var(--success-color) 0%, #3db5a5 100%);
    color: white;
    border-color: var(--success-color);
}

.tool-btn.save-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #238a7e 0%, #2a9d8f 100%);
    box-shadow: 0 4px 12px rgba(42, 157, 143, 0.3);
}

.tool-btn.history-btn {
    background: linear-gradient(135deg, #6a4c93 0%, #8b6cb5 100%);
    color: white;
    border-color: #6a4c93;
}

.tool-btn.history-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #5a3d80 0%, #6a4c93 100%);
    box-shadow: 0 4px 12px rgba(106, 76, 147, 0.3);
}

.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-width: 800px;
}

.canvas-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    perspective: 2000px;
}

.paper-wrapper {
    position: relative;
    perspective: 2000px;
}

.paper {
    position: relative;
    width: 700px;
    height: 500px;
    display: flex;
    transform-style: preserve-3d;
    transition: transform 0.3s ease;
}

.paper-shadow {
    position: absolute;
    bottom: -20px;
    left: 5%;
    width: 90%;
    height: 30px;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.2) 0%, transparent 70%);
    filter: blur(10px);
    z-index: -1;
    transition: all 1.2s ease;
}

.paper.folded .paper-shadow {
    left: 5%;
    width: 50%;
    opacity: 0.6;
}

.paper-half {
    width: 50%;
    height: 100%;
    position: relative;
    background: var(--paper-color);
    box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.03);
}

.paper-half::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%' height='100%' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
    pointer-events: none;
}

.paper-left {
    border-radius: 4px 0 0 4px;
    box-shadow: 
        inset 0 0 80px rgba(0, 0, 0, 0.03),
        -2px 4px 20px var(--paper-shadow);
}

.paper-right {
    border-radius: 0 4px 4px 0;
    box-shadow: 
        inset 0 0 80px rgba(0, 0, 0, 0.03),
        2px 4px 20px var(--paper-shadow);
    transform-origin: left center;
    transition: transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    backface-visibility: visible;
    position: absolute;
    left: 50%;
    top: 0;
}

.paper.folded .paper-right {
    transform: rotateY(-180deg);
}

.paper-right canvas {
    backface-visibility: hidden;
}

.fold-crease {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, 
        transparent 0%, 
        rgba(0, 0, 0, 0.05) 20%, 
        rgba(0, 0, 0, 0.08) 50%, 
        rgba(0, 0, 0, 0.05) 80%, 
        transparent 100%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.paper.folded .fold-crease {
    opacity: 1;
}

.paper-center-line {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(0, 0, 0, 0.06);
    transform: translateX(-50%);
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.paper.folded .paper-center-line {
    opacity: 0;
}

#canvasLeft,
#canvasRight {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    z-index: 2;
}

#canvasLeft {
    cursor: default;
}

.paper.folded #canvasLeft {
    cursor: crosshair;
}

.status-text {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.6);
    padding: 10px 20px;
    border-radius: 25px;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.8);
}

.status-icon {
    font-size: 1.1rem;
}

.status-label {
    font-weight: 400;
}

.control-panel {
    display: flex;
    gap: 16px;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 32px;
    border-radius: 50px;
    border: none;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    letter-spacing: 0.5px;
}

.action-btn.primary {
    background: linear-gradient(135deg, var(--accent-color) 0%, #e88a4d 100%);
    color: white;
    box-shadow: 0 4px 20px rgba(212, 115, 59, 0.4);
}

.action-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(212, 115, 59, 0.5);
}

.action-btn.primary:active {
    transform: translateY(0);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.footer {
    text-align: center;
    margin-top: 24px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    opacity: 0.7;
}

.history-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
}

.history-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.history-modal-content {
    background: white;
    border-radius: 20px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s ease;
}

.history-modal.active .history-modal-content {
    transform: translateY(0) scale(1);
}

.history-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.history-modal-header h2 {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.3rem;
    font-weight: 600;
}

.close-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent-light);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: var(--accent-color);
    color: white;
    transform: rotate(90deg);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    align-content: start;
}

.empty-history {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    text-align: center;
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.6;
}

.empty-history p {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.empty-history span {
    font-size: 0.85rem;
    opacity: 0.7;
}

.history-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    background: var(--paper-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
    border-color: var(--accent-color);
}

.history-thumb {
    aspect-ratio: 7/5;
    background: var(--paper-color);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.history-thumb canvas {
    width: 100%;
    height: 100%;
}

.history-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.history-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.history-action-btn {
    flex: 1;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: white;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    color: var(--text-primary);
}

.history-action-btn:hover {
    background: var(--accent-light);
    border-color: var(--accent-color);
}

.history-action-btn.delete-btn:hover {
    background: #ffe0e0;
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 0.9rem;
    z-index: 200;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 1000px) {
    .main-content {
        flex-direction: column;
        align-items: center;
    }

    .sidebar {
        width: 100%;
        max-width: 500px;
        flex-direction: row;
        flex-wrap: wrap;
        position: static;
        gap: 0;
    }

    .sidebar-section {
        flex: 1;
        min-width: 140px;
    }

    .sidebar-divider {
        display: none;
    }

    .color-palette {
        grid-template-columns: repeat(4, 1fr);
    }

    .paper {
        width: 90vw;
        max-width: 600px;
        height: 400px;
    }
}

@media (max-width: 600px) {
    .app {
        padding: 20px 12px;
    }

    .title {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    .sidebar {
        padding: 14px;
    }

    .sidebar-section {
        min-width: 120px;
    }

    .section-title {
        font-size: 0.8rem;
    }

    .color-palette {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }

    .paper {
        height: 300px;
    }

    .action-btn {
        padding: 12px 24px;
        font-size: 0.9rem;
    }

    .history-list {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
        padding: 16px;
    }

    .history-modal-header {
        padding: 16px;
    }

    .history-modal-header h2 {
        font-size: 1.1rem;
    }
}
