:root {
    --bg-app: #f8fafc;
    --bg-panel: #ffffff;
    --bg-panel-hover: #f1f5f9;
    --primary: #3b82f6; /* Blue-500 */
    --primary-dark: #2563eb; /* Blue-600 */
    --primary-light: #eff6ff; /* Blue-50 */
    --accent: #f43f5e; /* Rose-500 */
    --text-main: #1e293b; /* Slate-800 */
    --text-muted: #64748b; /* Slate-500 */
    --border: #e2e8f0; /* Slate-200 */
    --radius: 12px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-family);
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    box-sizing: border-box;
}

/* Layout - Bento Grid */
.app-wrapper {
    max-width: 95vw; /* 增加宽度利用率 */
    margin: 0 auto;
    display: grid;
    grid-template-columns: 300px 1fr; /* 侧边栏稍微加宽 */
    grid-template-rows: auto 1fr auto;
    gap: 24px;
    height: calc(100vh - 40px);
}

/* Header */
.app-header {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    margin-bottom: 10px;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0;
    color: var(--text-main);
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-header h1 i {
    color: var(--primary);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

/* Panels */
.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
    overflow: hidden;
}

.panel:hover {
    box-shadow: var(--shadow-md);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.panel-header h2 i {
    color: var(--primary);
}

/* Settings Panel (Left Sidebar) */
.settings-panel {
    grid-column: 1;
    grid-row: 2 / 4;
    overflow-y: auto;
}

.control-group {
    margin-bottom: 24px;
}

.control-group label {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Inputs */
select, input[type="number"] {
    width: 100%;
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: all 0.2s;
    box-sizing: border-box;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

input[type="number"] {
    background-image: none;
}

select:focus, input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Toggles */
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-app);
    border-radius: 8px;
}

.toggle-label {
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 500;
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    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: #cbd5e1;
    transition: .3s;
    border-radius: 22px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

input:checked + .slider {
    background-color: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(18px);
}

/* Generate Button */
.btn-generate {
    width: 100%;
    background: var(--text-main);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-generate:hover {
    background: #0f172a;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

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

/* Preview Panel (Top Right) */
.preview-panel {
    grid-column: 2;
    grid-row: 2;
    min-height: 280px;
    background: #fff;
    position: relative;
    justify-content: center;
    border: 1px solid var(--border);
}

.staff-container {
    width: 100%;
    overflow-x: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    min-height: 200px;
}

.staff-container svg {
    /* No filter needed for light mode */
}

.staff-container text {
    fill: var(--text-main) !important;
    font-family: var(--font-family) !important;
}

.staff-container path {
    stroke: var(--text-main) !important;
    fill: var(--text-main) !important;
}

.preview-actions {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
}

.btn-icon {
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.btn-icon:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-light);
}

.btn-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f1f5f9;
}

/* Library & Patterns (Bottom Right Split) */
.bottom-section {
    grid-column: 2;
    grid-row: 3;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    height: 400px;
}

.patterns-panel {
    overflow-y: auto;
}

.library-panel {
    overflow-y: auto;
}

/* Pattern Grid */
.pattern-section {
    margin-bottom: 20px;
}

.pattern-section h4 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.pattern-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); /* 加宽格子，确保能放下长节奏型 */
    gap: 16px;
}

.pattern-item {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    height: 110px; /* 稍微增加高度 */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.pattern-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.pattern-item.selected {
    background: var(--primary-light);
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

.pattern-item.selected::after {
    content: "";
    position: absolute;
    top: 6px;
    right: 6px;
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
}

.pattern-preview {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px;
}

.pattern-preview svg {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

.pattern-item path, .pattern-item text {
    fill: var(--text-main) !important;
    stroke: var(--text-main) !important;
}

/* Saved List */
.saved-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.saved-item {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.saved-item:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.saved-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.saved-item-canvas {
    flex: 1;
    overflow: hidden;
}

.saved-item-canvas svg {
    height: 50px;
    width: auto;
}

.saved-item-canvas path, .saved-item-canvas text {
    fill: var(--text-main) !important;
    stroke: var(--text-main) !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Responsive */
@media (max-width: 1024px) {
    .app-wrapper {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        height: auto;
    }
    
    .settings-panel {
        grid-column: 1;
        grid-row: auto;
    }
    
    .preview-panel {
        grid-column: 1;
        grid-row: auto;
    }
    
    .bottom-section {
        grid-column: 1;
        grid-row: auto;
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .patterns-panel, .library-panel {
        height: 300px;
    }
}

/* Toast */
#toast-container {
    position: fixed;
    top: 20px; /* 改为顶部显示，避免遮挡底部内容 */
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none; /* 允许点击穿透 */
}

.toast {
    background: #fff;
    color: var(--text-main);
    padding: 12px 24px;
    border-radius: 8px;
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease, fadeOut 0.5s ease 2.5s forwards; /* 增加自动消失动画 */
    font-weight: 500;
    font-size: 0.9rem;
    pointer-events: auto; /* 恢复自身点击 */
}

.toast.success { border-left-color: #10b981; }
.toast.error { border-left-color: #ef4444; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-20px); }
}

/* Orientation Warning Overlay */
#orientation-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(31, 41, 55, 0.95);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: white;
    backdrop-filter: blur(5px);
}

.orientation-content {
    padding: 20px;
    animation: fadeInUp 0.5s ease-out;
}

.orientation-content i {
    font-size: 4rem;
    margin-bottom: 20px;
    color: var(--primary);
    animation: rotatePhone 2s infinite ease-in-out;
}

.orientation-content h2 {
    font-size: 1.8rem;
    margin-bottom: 10px;
    color: white;
    border-bottom: none;
}

.orientation-content p {
    font-size: 1.1rem;
    color: #d1d5db;
    line-height: 1.6;
}

@keyframes rotatePhone {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(-90deg); }
}

/* Show overlay only on portrait mobile devices */
@media screen and (orientation: portrait) and (max-width: 768px) {
    #orientation-warning {
        display: flex;
    }
    
    /* Hide main content to prevent scrolling behind overlay */
    .app-wrapper {
        display: none;
    }
}

/* Animations */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
