/* ===== Music Creator Cloud - Braun SK4 Style ===== */
/* Based on ST_Music aesthetic with SillyTavernBook layouts */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&family=JetBrains+Mono:wght@300;400&display=swap');

/* ===== CSS Variables ===== */
:root {
    /* Braun SK4 "Snow White's Coffin" Color Palette */
    --surface: #F4F4F0;
    --surface-dark: #e8e8e5;
    --surface-mesh: #efefeb;
    --text-dark: #333333;
    --text-sub: #666666;
    --text-muted: #999999;
    --accent: #FF4400;
    --accent-hover: #e63d00;
    --mesh-dot: #a0a09d;
    --border: #dcdcdc;
    --shadow: rgba(0, 0, 0, 0.05);
    --shadow-lg: rgba(0, 0, 0, 0.15);
    --panel-bg: #fff;

    /* Typography */
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-serif: 'Noto Serif SC', serif;
    --font-mono: 'JetBrains Mono', monospace;
}

/* Dark Mode */
body.dark-mode {
    --surface: #1a1a1a;
    --surface-dark: #141414;
    --surface-mesh: #222222;
    --text-dark: #e0e0e0;
    --text-sub: #a0a0a0;
    --text-muted: #666666;
    --accent: #ff6b4a;
    --accent-hover: #ff8066;
    --mesh-dot: #444444;
    --border: #333333;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-lg: rgba(0, 0, 0, 0.5);
    --panel-bg: #252525;
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--surface);
    color: var(--text-dark);
    min-height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

@media (max-width: 768px) {
    body {
        overflow-y: auto;
        overflow-x: hidden;
        height: auto;
    }
}

/* Remove text shadows (override any inherited styles) */
#app-root,
#app-root * {
    text-shadow: none !important;
}

/* ===== App Layout ===== */
#app-root {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    background: var(--surface);
    box-shadow: 0 0 60px var(--shadow-lg);
}

/* ===== Header ===== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.disc-icon {
    font-size: 20px;
    color: var(--text-dark);
    animation: spin-slow 8s linear infinite paused;
}

.disc-icon.spinning {
    animation-play-state: running;
}

@keyframes spin-slow {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.brand {
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--text-dark);
    letter-spacing: -0.5px;
}

.model {
    font-weight: 300;
    font-size: 0.9rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    margin-left: 4px;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    gap: 8px;
}

.tab-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-sub);
    padding: 8px 16px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tab-btn:hover {
    border-color: var(--text-sub);
}

.tab-btn.active {
    background: var(--text-dark);
    color: #fff;
    border-color: var(--text-dark);
}

.tab-text {
    display: inline;
}

/* Header Controls */
.header-controls {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-sub);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--text-dark);
    color: #fff;
    border-color: var(--text-dark);
}

/* ===== Main Layout ===== */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 80px;
    min-width: 80px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px 0;
    align-items: center;
    border-right: 1px solid var(--border);
    background: rgba(244, 244, 240, 0.5);
    z-index: 2;
}

body.dark-mode .sidebar {
    background: rgba(30, 30, 30, 0.5);
}

.sidebar-top {
    text-align: center;
}

.sidebar-title {
    writing-mode: vertical-rl;
    text-orientation: upright;
    font-family: var(--font-serif);
    font-size: 18px;
    letter-spacing: 6px;
    color: var(--text-dark);
    font-weight: 700;
    border-left: 3px solid var(--accent);
    padding-left: 8px;
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.menu-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 1px dashed var(--text-muted);
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
}

.menu-btn:hover,
.menu-btn.active {
    border-color: var(--text-dark);
    border-style: solid;
    color: var(--text-dark);
    background: var(--panel-bg);
    box-shadow: 0 4px 12px var(--shadow);
}

.menu-btn i {
    font-size: 16px;
}

.menu-label {
    font-size: 9px;
    font-family: var(--font-serif);
    margin-top: 2px;
}

/* ===== Content Area ===== */
.content-area {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.tab-content {
    display: none;
    height: 100%;
    flex-direction: column;
    overflow: hidden;
}

.tab-content.active {
    display: flex;
}

/* ===== Player Section ===== */
.player-section {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: 100%;
}

/* Playlist Area (Speaker Mesh Texture) */
.playlist-area {
    flex: 1;
    border-radius: 12px;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    background-image: radial-gradient(var(--mesh-dot) 1.5px, transparent 1.5px);
    background-size: 6px 6px;
    background-color: var(--surface-mesh);
}

.playlist-overlay {
    position: absolute;
    inset: 0;
    background: rgba(244, 244, 240, 0.8);
    backdrop-filter: blur(1px);
    padding: 12px;
    overflow-y: auto;
}

body.dark-mode .playlist-overlay {
    background: rgba(30, 30, 30, 0.85);
}

.playlist-empty {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 8px;
    opacity: 0.6;
}

.music-icon {
    font-size: 24px;
}

.empty-text {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Track Item */
.track-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
    color: var(--text-dark);
    background: transparent;
}

.track-item:last-child {
    border-bottom: none;
}

.track-item:hover {
    background: rgba(255, 255, 255, 0.6);
}

body.dark-mode .track-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.track-item.active {
    background: var(--text-dark);
    color: #fff;
    border-radius: 4px;
    margin: 4px 0;
}

.track-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.track-num {
    width: 20px;
    font-size: 10px;
    color: var(--text-muted);
}

.track-item.active .track-num {
    color: var(--accent);
}

.track-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.track-delete {
    opacity: 0;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.track-item:hover .track-delete {
    opacity: 1;
}

.track-delete:hover {
    color: #ff4d4f;
    background: rgba(255, 77, 79, 0.1);
}

/* Player Controls */
.player-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.btn-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ctrl-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-dark);
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1), inset 0 1px 2px rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-sub);
    transition: all 0.2s;
}

.ctrl-btn:hover {
    background: #dedede;
}

body.dark-mode .ctrl-btn {
    background: #333;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

body.dark-mode .ctrl-btn:hover {
    background: #444;
}

.ctrl-btn:active {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.ctrl-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-muted);
}

.playback-group {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface-dark);
    padding: 8px 16px;
    border-radius: 50px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

body.dark-mode .playback-group {
    background: #2a2a2a;
}

.playback-group .ctrl-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    box-shadow: none;
}

.play-btn {
    width: 48px !important;
    height: 48px !important;
    background: var(--text-dark) !important;
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

.play-btn:hover {
    background: #222 !important;
}

/* ===== Reader Section ===== */
.reader-header {
    padding: 20px 30px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-title {
    font-family: var(--font-serif);
    font-size: 20px;
    color: var(--text-dark);
}

.page-indicator {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-sub);
    cursor: pointer;
    padding: 4px 8px;
    border: 1px solid transparent;
    border-radius: 4px;
}

.page-indicator:hover {
    border-color: var(--border);
}

.chat-container {
    flex: 1;
    padding: 30px 40px 80px;
    overflow-y: auto;
    overflow-x: hidden;
}

.chat-container .empty-state {
    text-align: center;
    color: var(--text-muted);
    margin-top: 80px;
}

.chat-container .empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-container .empty-state p {
    margin-bottom: 20px;
}

/* Message Row */
.message-row {
    margin-bottom: 24px;
    animation: fadeIn 0.4s ease;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.char-name-tag {
    font-family: var(--font-serif);
    font-size: 13px;
    color: var(--accent);
    margin-bottom: 6px;
    font-weight: 600;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.char-name-tag::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0.5;
}

.message-row.user .char-name-tag {
    color: #586650;
    justify-content: flex-end;
    flex-direction: row-reverse;
}

.message-row.user .char-name-tag::before {
    background: #586650;
}

.memory-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 12px;
    opacity: 0;
    transition: all 0.2s;
}

.message-row:hover .memory-btn {
    opacity: 1;
}

.memory-btn.active {
    color: var(--accent);
    opacity: 1;
}

.memory-btn:hover {
    color: var(--accent);
}

/* Bookmark button in message row */
.bookmark-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 12px;
    opacity: 0;
    transition: all 0.2s;
}

.message-row:hover .bookmark-btn {
    opacity: 1;
}

.bookmark-btn.active {
    color: #e67e22;
    opacity: 1;
}

.bookmark-btn:hover {
    color: #e67e22;
}

/* Bookmark card in panel */
.bookmark-card {
    background: var(--panel-bg);
    border-left: 3px solid #e67e22;
    padding: 12px 14px;
    margin-bottom: 10px;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    transition: all 0.2s;
}

.bookmark-card:hover {
    background: rgba(230, 126, 34, 0.08);
    transform: translateX(3px);
}

.bookmark-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.bookmark-char {
    color: #e67e22;
    font-weight: 600;
    font-size: 13px;
}

.bookmark-page {
    color: var(--text-muted);
    font-size: 11px;
}

.bookmark-preview {
    color: var(--text-sub);
    font-size: 12px;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bubble {
    font-size: 15px;
    line-height: 1.8;
    color: var(--text-dark);
    text-align: justify;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-row.user .bubble {
    color: var(--text-sub);
    text-align: right;
}

.bubble p {
    margin-bottom: 12px;
}

.bubble p:last-child {
    margin-bottom: 0;
}

/* Pagination Bar */
.pagination-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(244, 244, 240, 0.9);
    backdrop-filter: blur(4px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 40px;
}

body.dark-mode .pagination-bar {
    background: rgba(26, 26, 26, 0.9);
}

.page-btn {
    background: none;
    border: none;
    font-family: var(--font-serif);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.page-btn:hover {
    color: var(--accent);
}

.page-dots {
    font-family: var(--font-serif);
    color: var(--text-muted);
    font-size: 12px;
}

/* ===== Creator Section ===== */
.creator-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1px;
    background: var(--border);
    height: 100%;
    overflow: hidden;
}

/* Left Sidebar Panel - Container for Memory & Background Info */
.left-sidebar-panel {
    background: var(--surface);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Memory Preview Panel */
.memory-preview-panel {
    background: var(--surface);
    display: flex;
    flex-direction: column;
    flex: 0 0 50%;
    min-height: 0;
    overflow: hidden;
}

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

.memory-preview-panel .panel-header h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
}

.btn-text {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 12px;
    cursor: pointer;
}

.btn-text:hover {
    text-decoration: underline;
}

.memory-list-compact {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.memory-mini-card {
    background: var(--panel-bg);
    border-left: 3px solid var(--accent);
    padding: 10px 12px;
    margin-bottom: 8px;
    border-radius: 0 4px 4px 0;
    box-shadow: 0 1px 3px var(--shadow);
    position: relative;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.memory-mini-card:hover {
    background: rgba(205, 164, 94, 0.1);
    border-left-width: 4px;
}

.memory-mini-card .char {
    color: var(--accent);
    font-weight: 600;
    margin-right: 6px;
}

.memory-mini-card .text {
    color: var(--text-sub);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.memory-mini-card .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.2s;
}

.memory-mini-card:hover .remove-btn {
    opacity: 1;
}

.memory-mini-card .remove-btn:hover {
    color: #ff4d4f;
}

/* Message row highlight animation for jump-to */
.message-row.highlight-flash {
    animation: highlight-pulse 2s ease-out;
}

@keyframes highlight-pulse {

    0%,
    100% {
        background: transparent;
    }

    20% {
        background: rgba(205, 164, 94, 0.3);
    }

    50% {
        background: rgba(205, 164, 94, 0.15);
    }
}

.memory-preview-panel .empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 12px;
    padding: 20px;
}

.memory-preview-panel .empty-state i {
    font-size: 32px;
    opacity: 0.5;
}

.memory-preview-panel .empty-state p {
    font-size: 12px;
}

/* Style Selector Panel */
.style-selector-panel {
    background: var(--surface);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.form-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
}

/* Form Groups */
.form-group {
    margin-bottom: 28px;
}

.form-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-dark);
    opacity: 0.6;
    margin-bottom: 12px;
}

.input-wrapper {
    position: relative;
}

.form-input {
    width: 100%;
    background: transparent !important;
    border: none !important;
    border-bottom: 2px solid var(--border) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 8px 0 !important;
    font-size: 1.4rem !important;
    font-weight: 500 !important;
    color: var(--text-dark) !important;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none !important;
    border-bottom-color: var(--accent) !important;
}

.form-input::placeholder {
    color: #ccc !important;
}

.input-hint {
    position: absolute;
    right: 0;
    top: 1rem;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.input-wrapper:hover .input-hint {
    opacity: 1;
}

.form-note {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 8px;
    font-style: italic;
}

.form-note a {
    color: var(--accent);
    text-decoration: none;
}

.form-note a:hover {
    text-decoration: underline;
}

/* Button Grids */
.btn-grid {
    display: grid;
    gap: 8px;
}

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

.genre-grid {
    grid-template-columns: repeat(3, 1fr);
}

.subgenre-grid {
    grid-template-columns: repeat(2, 1fr);
}

/* Toggle Buttons */
.toggle-btn {
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease-out;
    border: 1px solid transparent;
    padding: 10px 12px;
    background: var(--panel-bg);
    color: var(--text-sub);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toggle-btn:hover {
    background: #fafafa;
}

body.dark-mode .toggle-btn:hover {
    background: #333;
}

.toggle-btn.active {
    background: var(--surface-dark);
    color: var(--text-dark);
    font-weight: 600;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.toggle-btn.active::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
}

.toggle-btn.full-width {
    grid-column: span 2;
}

/* Gender Selector */
.gender-selector {
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.5);
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #eee;
}

body.dark-mode .gender-selector {
    background: rgba(255, 255, 255, 0.05);
    border-color: #333;
}

.gender-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-sub);
}

.gender-btn {
    padding: 6px 16px;
    font-size: 12px;
    border-radius: 50px;
    border: 1px solid #ccc;
    background: var(--panel-bg);
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.gender-btn:hover {
    border-color: var(--text-sub);
}

.gender-btn.active {
    background: var(--text-dark);
    color: #fff;
    border-color: var(--text-dark);
}

/* Subgenre Panel */
.subgenre-panel {
    background: var(--panel-bg);
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #eee;
    margin-top: 12px;
}

body.dark-mode .subgenre-panel {
    border-color: #333;
}

.subgenre-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.subgenre-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-sub);
}

.genre-desc {
    flex: 1;
    text-align: right;
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toggle-desc {
    margin-top: 4px;
    font-size: 10px;
    color: var(--text-sub);
    line-height: 1.4;
    padding-left: 4px;
}

/* Sub-Genre Description Display */
.subgenre-desc {
    margin-top: 12px;
    padding: 12px 14px;
    background: rgba(139, 90, 43, 0.1);
    border-left: 3px solid var(--accent);
    border-radius: 0 6px 6px 0;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-dark);
    animation: fadeIn 0.3s ease;
}

body.dark-mode .subgenre-desc {
    background: rgba(205, 164, 94, 0.15);
}

/* ===== Voice Timbre Panel ===== */
.timbre-panel {
    background: var(--panel-bg);
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #eee;
    margin-top: 12px;
}

body.dark-mode .timbre-panel {
    border-color: #333;
}

.timbre-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.timbre-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-sub);
}

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

/* ===== Lyrics Concept Panel ===== */
.lyrics-panel {
    background: var(--panel-bg);
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #eee;
}

body.dark-mode .lyrics-panel {
    border-color: #333;
}

.lyrics-section {
    margin-bottom: 16px;
}

.lyrics-section:last-child {
    margin-bottom: 0;
}

.lyrics-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.lyrics-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-sub);
}

.lang-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.rhyme-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.rhyme-wrapper {
    display: flex;
    flex-direction: column;
}

.rhyme-wrapper .toggle-btn {
    width: 100%;
}

.rhyme-wrapper .toggle-desc {
    padding: 8px 12px;
    background: rgba(139, 90, 43, 0.08);
    border-left: 3px solid var(--accent);
    border-radius: 0 4px 4px 0;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-dark);
    animation: fadeIn 0.3s ease;
}

body.dark-mode .rhyme-wrapper .toggle-desc {
    background: rgba(205, 164, 94, 0.12);
}

.lyrics-custom-input {
    margin-top: 8px;
    width: 100%;
}

/* Background Info Panel */
.background-info-panel {
    background: var(--surface);
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
    flex: 1;
    min-height: 120px;
    max-height: 50%;
    overflow: hidden;
}

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

.background-info-panel .panel-header h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dark);
}

.bg-info-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.bg-info-card {
    background: var(--panel-bg);
    border-left: 3px solid #6B8E5E;
    padding: 8px 10px;
    margin-bottom: 6px;
    border-radius: 0 4px 4px 0;
    box-shadow: 0 1px 2px var(--shadow);
    position: relative;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.bg-info-card:hover {
    background: rgba(107, 142, 94, 0.1);
    border-left-width: 4px;
}

.bg-info-card .bg-info-title {
    color: #6B8E5E;
    font-weight: 600;
    margin-bottom: 2px;
}

.bg-info-card .bg-info-text {
    color: var(--text-sub);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bg-info-card .bg-info-actions {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.bg-info-card:hover .bg-info-actions {
    opacity: 1;
}

.bg-info-card .edit-btn,
.bg-info-card .remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 4px;
    border-radius: 2px;
    transition: all 0.15s;
}

.bg-info-card .edit-btn:hover {
    color: #6B8E5E;
    background: rgba(107, 142, 94, 0.1);
}

.bg-info-card .remove-btn:hover {
    color: #ff4d4f;
    background: rgba(255, 77, 79, 0.1);
}

/* Selected state for bg-info card */
.bg-info-card.selected {
    background: rgba(107, 142, 94, 0.15);
    border-left-color: #4a7040;
    border-left-width: 4px;
}

.bg-info-card.selected .bg-info-title {
    color: #4a7040;
}

.bg-info-card.selected::after {
    content: '\f00c';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    bottom: 4px;
    right: 6px;
    color: #6B8E5E;
    font-size: 10px;
    opacity: 0.7;
}

.background-info-panel .empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 8px;
    padding: 16px;
}

.background-info-panel .empty-state i {
    font-size: 24px;
    opacity: 0.5;
}

.background-info-panel .empty-state p {
    font-size: 11px;
}

/* ===== Story Panel ===== */
.story-panel {
    background: var(--surface);
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
    max-height: 160px;
    overflow: hidden;
}

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

.story-panel .panel-header h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dark);
}

.story-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.story-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.story-item:hover {
    background: rgba(255, 255, 255, 0.6);
}

body.dark-mode .story-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.story-item.active {
    background: var(--text-dark);
    color: #fff;
    border-color: var(--text-dark);
}

.story-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.story-info i {
    font-size: 12px;
    color: var(--accent);
}

.story-item.active .story-info i {
    color: #fff;
}

.story-title {
    font-size: 12px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-item .remove-btn {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s;
}

.story-item:hover .remove-btn {
    opacity: 1;
}

.story-item.active .remove-btn {
    color: rgba(255, 255, 255, 0.7);
}

.story-item .remove-btn:hover {
    color: #ff4d4f;
    background: rgba(255, 77, 79, 0.1);
}

.story-panel .empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 6px;
    padding: 12px;
}

.story-panel .empty-state i {
    font-size: 20px;
    opacity: 0.5;
}

.story-panel .empty-state p {
    font-size: 11px;
    text-align: center;
}

/* Form Textarea */
.form-textarea {
    resize: vertical;
    min-height: 100px;
    font-size: 14px !important;
    line-height: 1.6 !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    padding: 12px !important;
    background: var(--surface) !important;
}

/* ===== Works Tab ===== */
.works-layout {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    overflow-y: auto;
}

.works-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 16px;
    padding: 40px;
    text-align: center;
}

.works-empty-state i {
    font-size: 48px;
    color: var(--accent);
    opacity: 0.5;
}

.works-empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
}

.works-empty-state p {
    font-size: 14px;
    color: var(--text-sub);
    margin: 0;
}

/* Works Layout - Side by Side Container */
.works-layout {
    display: flex !important;
    flex-direction: row !important;
    gap: 24px;
    padding: 24px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    align-items: flex-start;
}

/* Results Container (left side) */
.results-container {
    flex: 1;
    min-width: 0;
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* Raw Output Container (right side) */
.raw-output-container {
    flex: 1;
    min-width: 0;
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

/* Mobile: Stack vertically */
@media (max-width: 1024px) {
    .works-layout {
        flex-direction: column;
    }

    .raw-output-container {
        max-height: 400px;
    }
}

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

.raw-output-header span {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-sub);
    display: flex;
    align-items: center;
    gap: 8px;
}

.raw-output-header span i {
    color: var(--text-muted);
}

.raw-output-content {
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-sub);
    background: rgba(0, 0, 0, 0.04);
    padding: 16px;
    border-radius: 8px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.raw-output-content.collapsed {
    max-height: 0;
    padding: 0 16px;
    overflow: hidden;
}

body.dark-mode .raw-output-content {
    background: rgba(255, 255, 255, 0.05);
}

/* Toggle icon for collapsible header */
.raw-toggle-icon {
    transition: transform 0.3s ease;
    font-size: 10px;
    margin-right: 4px;
}

.raw-toggle-icon.rotated {
    transform: rotate(90deg);
}

.raw-output-header {
    cursor: pointer;
}

.raw-output-header:hover {
    opacity: 0.8;
}

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

.results-header span {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.results-header span i {
    color: var(--accent);
}

.copy-all-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.copy-all-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Result Sections */
.result-section {
    background: var(--panel-bg);
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

.result-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.result-label-row span {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
}

.copy-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-sub);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.copy-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.result-content {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-dark);
    white-space: pre-wrap;
}

.result-content.lyrics-content {
    font-family: var(--font-mono);
    background: rgba(0, 0, 0, 0.03);
    padding: 16px;
    border-radius: 6px;
    font-size: 13px;
}

body.dark-mode .result-content.lyrics-content {
    background: rgba(255, 255, 255, 0.05);
}

/* Instrument Container */
.instrument-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.instrument-btn {
    padding: 6px 14px;
    border-radius: 50px;
    font-size: 13px;
    border: 1px solid #ccc;
    background: transparent;
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.instrument-btn:hover {
    border-color: var(--text-sub);
}

.instrument-btn.active {
    background: var(--text-dark);
    color: #fff;
    border-color: var(--text-dark);
}

.instrument-btn.recommend {
    border-style: dashed;
    border-color: var(--accent);
    color: var(--accent);
}

.instrument-btn.recommend:hover,
.instrument-btn.recommend.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.instrument-input {
    border: none !important;
    border-bottom: 1px solid #ccc !important;
    padding: 6px 8px !important;
    font-size: 13px !important;
    width: 120px !important;
    background: transparent !important;
    color: var(--text-dark) !important;
    font-family: inherit;
}

.instrument-input:focus {
    outline: none !important;
    border-bottom-color: var(--text-dark) !important;
}

/* Action Footer */
.action-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-top: 1px solid var(--border);
    margin-top: 20px;
}

.author-info {
    font-size: 10px;
    color: var(--text-muted);
}

.create-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.create-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.02);
}

.create-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* ===== Results Container (styles now in .works-layout section above) ===== */

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--surface-dark);
    border-bottom: 1px solid var(--border);
}

.results-header span {
    font-weight: 600;
    color: var(--text-dark);
}

.copy-all-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--text-dark);
    color: #fff;
    border: none;
    padding: 8px 16px;
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.copy-all-btn:hover {
    background: var(--accent);
}

.result-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.result-section:last-child {
    border-bottom: none;
}

.result-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.result-label-row span {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-sub);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.copy-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.result-content {
    font-size: 14px;
    color: var(--text-dark);
    line-height: 1.7;
    white-space: pre-wrap;
}

.result-content.lyrics-content {
    font-family: var(--font-serif);
    max-height: 300px;
    overflow-y: auto;
}

/* ===== Overlay Panels ===== */
.overlay-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 500px;
    max-height: 70vh;
    background: var(--panel-bg);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: none;
    flex-direction: column;
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

.overlay-panel.active {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.overlay-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
}

.close-btn:hover {
    color: var(--accent);
}

.overlay-panel .panel-actions {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.overlay-panel .panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

/* List Items in Panels */
.list-item {
    padding: 12px;
    border-bottom: 1px dashed var(--border);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-item:hover {
    background: rgba(0, 0, 0, 0.02);
    padding-left: 20px;
}

body.dark-mode .list-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.list-item.active {
    border-left: 3px solid var(--accent);
    background: var(--panel-bg);
}

/* Radio Group */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
}

.radio-label input {
    accent-color: var(--accent);
}

.badge {
    font-size: 10px;
    padding: 2px 8px;
    background: var(--surface-dark);
    color: var(--text-muted);
    border-radius: 10px;
    margin-left: auto;
}

.api-status {
    padding: 12px;
    background: var(--surface-dark);
    border-radius: 8px;
    text-align: center;
    margin: 16px 0;
}

#api-status-text {
    font-size: 12px;
    color: var(--text-muted);
}

#api-status-text.configured {
    color: #52c41a;
}

.save-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--text-dark);
    color: #fff;
    border: none;
    padding: 12px;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.save-btn:hover {
    background: var(--accent);
}

/* Action Buttons */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--text-dark);
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.action-btn:hover {
    background: var(--accent);
}

.danger-btn {
    background: #888;
    color: #fff;
    border: none;
    padding: 8px 16px;
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
}

.danger-btn:hover {
    background: #d00;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content,
.modal-box {
    background: var(--panel-bg);
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

/* Compact modal variant for simple dialogs */
.modal-box.compact {
    max-width: 320px;
}

.modal-box.compact .modal-header {
    padding: 12px 16px;
}

.modal-box.compact .modal-header h3 {
    font-size: 14px;
}

.modal-box.compact .modal-body {
    padding: 16px;
}

.modal-box.compact .modal-footer {
    padding: 12px 16px;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.btn-secondary {
    background: var(--surface-dark);
    color: var(--text-sub);
    border: none;
    padding: 10px 20px;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: #fff;
    font-size: 16px;
}

.loading-spinner i {
    font-size: 32px;
}

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

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

::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 20px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .creator-layout {
        grid-template-columns: 1fr;
    }

    .memory-preview-panel {
        max-height: 200px;
    }
}

@media (max-width: 768px) {
    .app-header {
        padding: 10px 12px;
    }

    .tab-text {
        display: none;
    }

    .sidebar {
        width: 60px;
        min-width: 60px;
    }

    .sidebar-title {
        font-size: 14px;
        letter-spacing: 4px;
    }

    .menu-btn {
        width: 40px;
        height: 40px;
    }

    .menu-label {
        display: none;
    }

    .chat-container {
        padding: 20px;
    }

    .form-scroll {
        padding: 16px;
    }

    .vocal-grid,
    .genre-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .subgenre-grid {
        grid-template-columns: 1fr;
    }

    .memory-btn {
        opacity: 1;
    }
}

/* ===== Small Phones (480px and below) ===== */
@media (max-width: 480px) {

    /* Hide sidebar completely on very small screens */
    .sidebar {
        display: none;
    }

    .app-content {
        width: 100%;
    }

    /* Smaller header */
    .app-header {
        padding: 8px 10px;
    }

    .app-title {
        font-size: 14px;
    }

    /* Full width tabs */
    .header-tabs {
        gap: 4px;
    }

    .tab-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    /* Form adjustments */
    .form-scroll {
        padding: 12px;
    }

    .form-section-title {
        font-size: 12px;
    }

    .toggle-btn {
        padding: 8px 12px;
        font-size: 11px;
    }

    /* Input fields */
    .form-input,
    .form-textarea {
        font-size: 16px;
        /* Prevent zoom on iOS */
        padding: 12px;
    }

    /* Button touch targets - minimum 44px */
    .copy-btn,
    .remove-btn,
    .edit-btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* Grids single column */
    .vocal-grid,
    .genre-grid,
    .instrument-grid {
        grid-template-columns: 1fr;
    }

    /* Works layout */
    .works-layout {
        padding: 12px;
        gap: 12px;
    }

    .results-container,
    .raw-output-container {
        padding: 12px;
    }

    .results-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .result-section {
        padding: 12px;
    }

    /* Chat messages */
    .chat-container {
        padding: 12px;
    }

    .message-bubble {
        max-width: 95%;
        padding: 10px 12px;
    }

    /* Overlay panels full width on small phones */
    .overlay-panel {
        width: 95%;
        max-height: 80vh;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95%;
        max-width: none;
        padding: 16px;
    }

    /* Page jump modal */
    .modal-box.compact {
        width: 90%;
    }

    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        gap: 4px;
    }

    .pagination button {
        min-width: 36px;
        min-height: 36px;
        font-size: 12px;
    }
}

/* ===== iPad Portrait (768px - 1024px) ===== */
@media (min-width: 768px) and (max-width: 1024px) {

    /* Two column grids for iPad */
    .vocal-grid,
    .genre-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .instrument-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Sidebar adjustments */
    .sidebar {
        width: 70px;
        min-width: 70px;
    }

    .menu-btn {
        width: 45px;
        height: 45px;
    }

    /* Works layout - stack on iPad portrait */
    .works-layout {
        flex-direction: column !important;
    }
}

/* ===== Touch Device Enhancements ===== */
@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    .toggle-btn {
        min-height: 44px;
    }

    .menu-btn {
        min-width: 48px;
        min-height: 48px;
    }

    /* Disable hover effects that don't work on touch */
    .toggle-btn:hover,
    .menu-btn:hover {
        transform: none;
    }

    /* Show memory button always on touch devices */
    .memory-btn {
        opacity: 1;
    }

    /* Scrollable areas with momentum */
    .form-scroll,
    .chat-container,
    .raw-output-content {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== Safe Area for Notched Phones ===== */
@supports (padding: env(safe-area-inset-bottom)) {
    .app-header {
        padding-top: env(safe-area-inset-top);
    }

    .form-footer,
    .panel-footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ===== Collapsible Panels ===== */
.collapsible-panel {
    margin-bottom: 8px;
}

.collapsible-panel .panel-header.clickable {
    cursor: pointer;
    user-select: none;
}

.collapsible-panel .panel-header.clickable:hover {
    opacity: 0.85;
}

.collapsible-panel .panel-header h3 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-toggle-icon {
    font-size: 10px;
    transition: transform 0.3s ease;
    color: var(--text-muted);
}

.panel-toggle-icon.rotated {
    transform: rotate(90deg);
}

.collapsible-panel .panel-content {
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    max-height: 500px;
    opacity: 1;
}

.collapsible-panel .panel-content.collapsed {
    max-height: 0;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    opacity: 0;
    overflow: hidden;
}

/* ===== Mobile Works Panel Layout Fix ===== */
@media (max-width: 768px) {

    /* Force Works layout to be vertical on mobile */
    .works-layout {
        flex-direction: column !important;
        padding: 12px;
        gap: 16px;
    }

    /* Full width panels */
    .works-layout .results-container,
    .works-layout .raw-output-container {
        width: 100%;
        flex: none;
    }

    /* Result sections stack properly */
    .result-section {
        margin-bottom: 12px;
    }

    .results-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .result-label-row {
        flex-wrap: wrap;
    }
}

/* ===== Mobile Sidebar Overlay (768px and below) ===== */
@media (max-width: 768px) {

    /* Make header sticky at top */
    .app-header {
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--surface);
    }

    /* Fix layout for proper scrolling */
    #app-root {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow: visible;
        display: block;
    }

    .main-layout {
        flex: none;
        overflow: visible;
        height: auto;
        display: block;
    }

    .content-area {
        overflow: visible;
        height: auto;
    }

    /* Sidebar as overlay */
    .sidebar {
        position: fixed;
        left: -100px;
        top: 0;
        height: 100vh;
        /* Fallback for browsers without proper dvh support */
        height: 100dvh;
        z-index: 200;
        transition: left 0.3s ease;
        background: var(--panel-bg);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
        width: 80px;
        min-width: 80px;
        display: flex !important;
    }

    .sidebar.mobile-visible {
        left: 0;
    }

    /* Sidebar overlay backdrop */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        z-index: 199;
    }

    .sidebar-backdrop.active {
        display: block;
    }
}

/* ===== Very Small Phones - Override sidebar display:none ===== */
@media (max-width: 480px) {
    .sidebar {
        display: flex !important;
        left: -100px;
    }

    .sidebar.mobile-visible {
        left: 0;
    }
}

/* Mobile double-tap hint indicator */
.mobile-sidebar-hint {
    display: none;
}

@media (max-width: 768px) {
    .mobile-sidebar-hint {
        display: block;
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0, 0, 0, 0.7);
        color: #fff;
        padding: 8px 16px;
        border-radius: 20px;
        font-size: 12px;
        z-index: 50;
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .mobile-sidebar-hint.visible {
        opacity: 1;
    }
}

/* ===== Critical Mobile Fixes for Creator Panel ===== */
@media (max-width: 768px) {

    /* Fix app-root height */
    #app-root {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
    }

    /* Force Creator layout to single column */
    .creator-layout {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: none !important;
        height: auto !important;
        overflow: visible !important;
        gap: 0 !important;
    }

    /* Left sidebar panel (故事/记忆/背景信息) comes first */
    .left-sidebar-panel {
        order: 1;
        width: 100% !important;
        flex: none !important;
        overflow: visible !important;
        padding: 0;
        /* Remove padding here, let child containers handle it or parent */
        max-height: none !important;
        background: transparent;
    }

    /* Style selector panel (01/Creator Profile etc) comes second */
    .style-selector-panel {
        order: 2;
        width: 100% !important;
        flex: none !important;
        overflow: visible !important;
    }

    /* Allow content to scroll naturally */
    .form-scroll {
        height: auto !important;
        overflow: visible !important;
        max-height: none !important;
    }

    /* Collapsible panels adjust */
    .collapsible-panel {
        width: 100%;
    }

    .collapsible-panel .panel-content {
        max-height: none;
    }

    .collapsible-panel .panel-content.collapsed {
        max-height: 0;
    }

    /* Content area scrollable */
    .content-area {
        height: auto !important;
        overflow: visible !important;
    }

    /* Tab content auto height */
    .tab-content {
        height: auto !important;
        overflow: visible !important;
    }

    .tab-content.active {
        display: block !important;
    }

    /* Memory and story panels */
    .memory-preview-panel,
    .story-panel,
    .background-info-panel {
        max-height: none !important;
        flex: none !important;
    }
}

/* ===== Extra Small Phones ===== */
@media (max-width: 480px) {
    .creator-layout {
        flex-direction: column !important;
        display: flex !important;
    }

    .left-sidebar-panel {
        padding: 8px;
    }

    .form-scroll {
        padding: 8px;
    }

    /* Smaller grids */
    .vocal-grid,
    .genre-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .toggle-btn {
        padding: 8px;
        font-size: 11px;
    }
}