/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: #121214;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    overflow: hidden; /* Mobile page scroll block */
}

.app-header {
    background-color: #1f1f23;
    padding: 10px 16px;
    text-align: center;
    border-bottom: 1px solid #2d2d35;
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #ffffff;
}

/* Layout Container */
.app-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

/* ------------------------------------------------------------------
 * MOBILE PREVIEW SECTION (~46vh Height - First Card Visible)
 * ------------------------------------------------------------------ */
.preview-section {
    flex-shrink: 0;
    height: 46vh; /* Mobile fold problem fix */
    max-height: 420px;
    min-height: 280px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    background-color: #08080a;
    padding: 10px;
    border-bottom: 1px solid #2d2d35;
}

.canvas-wrapper {
    position: relative;
    height: 100%;
    aspect-ratio: 9 / 16;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    border: 1px solid #2d2d35;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none; /* Allows smooth drag controls on mobile */
}

/* ------------------------------------------------------------------
 * MOBILE CONTROLS PANEL (Scrollable)
 * ------------------------------------------------------------------ */
.controls-section {
    flex: 1;
    overflow-y: auto; /* Scrollable controls below canvas */
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 15px 25px 15px;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.control-card {
    background-color: #1f1f23;
    border-radius: 10px;
    padding: 12px 15px;
    border: 1px solid #2d2d35;
}

.control-card h2 {
    font-size: 0.9 rem;
    margin-bottom: 10px;
    color: #a0a0b0;
    font-weight: 500;
}

/* Character Selection Grid */
.character-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.char-thumb {
    background: #2d2d35;
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 4px;
    cursor: pointer;
    aspect-ratio: 1;
    overflow: hidden;
    transition: border-color 0.2s, background 0.2s;
}

.char-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
}

.char-thumb.active {
    border-color: #007bff;
    background: #1a385c;
}

/* Buttons and Inputs */
.btn {
    display: inline-block;
    width: 100%;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    border: none;
    outline: none;
    transition: opacity 0.2s, background 0.2s;
}

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

.primary-btn {
    background-color: #007bff;
    color: #ffffff;
}

.secondary-btn {
    background-color: #2d2d35;
    color: #e0e0e0;
}

.export-btn {
    background-color: #28a745;
    color: #ffffff;
    font-size: 0.95rem;
    padding: 12px;
}

/* Audio Section */
.audio-info {
    font-size: 0.8rem;
    color: #888899;
    margin: 8px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.seekbar-wrapper {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

input[type="range"] {
    width: 100%;
    accent-color: #007bff;
    height: 5px;
    background: #2d2d35;
    border-radius: 3px;
    outline: none;
}

.time-display {
    font-size: 0.75rem;
    color: #888899;
    text-align: right;
}

/* Slider Groups */
.slider-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.slider-group label {
    font-size: 0.8rem;
    color: #cccccc;
}

.button-row {
    display: flex;
    gap: 8px;
}

/* Actions Section */
.action-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.action-buttons .btn {
    flex: 1;
}

/* ------------------------------------------------------------------
 * DESKTOP LAYOUT (Retained original styles for width >= 768px)
 * ------------------------------------------------------------------ */
@media (min-width: 768px) {
    body {
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }

    .app-header {
        padding: 12px 20px;
    }

    .app-header h1 {
        font-size: 1.25rem;
    }

    .app-container {
        flex-direction: row;
        align-items: flex-start;
        gap: 20px;
        padding: 15px;
        height: auto;
        overflow: visible;
    }

    .preview-section {
        flex: 1;
        height: auto;
        max-height: none;
        min-height: 0;
        background-color: transparent;
        padding: 0;
        border-bottom: none;
        position: sticky;
        top: 15px;
    }

    .canvas-wrapper {
        width: 100%;
        max-width: 380px;
        height: auto;
    }

    .controls-section {
        flex: 1;
        overflow-y: visible;
        padding: 0;
        gap: 15px;
    }

    .control-card {
        padding: 15px;
    }

    .control-card h2 {
        font-size: 1rem;
        margin-bottom: 12px;
    }

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