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

body {
    font-family: 'MS Sans Serif', Arial, sans-serif;
    background: #008080;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    min-height: 100vh;
    padding: 0;
    margin: 0;
    width: 100%;
    height: 100vh;
}

.container {
    background: #c0c0c0;
    border: 3px outset #dfdfdf;
    box-shadow: 2px 2px 0 #000;
    width: calc(100vw - 20px);
    max-width: none;
    height: calc(100vh - 44px);
    margin: 10px;
    display: flex;
    flex-direction: column;
}

@media (max-width: 768px) {
    body {
        padding: max(5px, env(safe-area-inset-bottom));
        padding-left: max(5px, env(safe-area-inset-left));
        padding-right: max(5px, env(safe-area-inset-right));
        align-items: flex-start;
        min-height: 0;
        overflow-y: auto;
    }

    .container {
        border-width: 2px;
        margin: 5px 0;
        width: calc(100vw - 10px);
        height: auto;
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    body {
        padding: max(3px, env(safe-area-inset-bottom));
        padding-left: max(3px, env(safe-area-inset-left));
        padding-right: max(3px, env(safe-area-inset-right));
        min-height: 0;
        overflow-y: auto;
    }

    .container {
        border-width: 1px;
        margin: 3px 0;
        width: calc(100vw - 6px);
        height: auto;
    }
}

.title-bar {
    background: linear-gradient(to right, #000080, #1084d0);
    color: white;
    padding: 3px 5px;
    font-weight: bold;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    flex-shrink: 0;
    width: 100%;
    height: 32px;
}

.title-bar-left {
    display: flex;
    align-items: center;
    gap: 5px;
}

.title-icon {
    width: 16px;
    height: 16px;
    background: white;
    border: 1px solid #000;
}

.title-bar-nav {
    display: flex;
    gap: 2px;
    align-items: center;
}

.nav-button {
    display: inline-block;
    background: #c0c0c0;
    border: 2px outset #dfdfdf;
    padding: 3px 8px;
    font-family: 'MS Sans Serif', Arial, sans-serif;
    font-size: 11px;
    font-weight: bold;
    color: #000;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.1s;
}

.nav-button:hover {
    background: #d0d0d0;
}

.nav-button:active {
    border-style: inset;
    background: #a0a0a0;
}

.nav-button.active {
    border-style: inset;
    background: #808080;
    color: white;
}

/* === 3-COLUMN LAYOUT === */
.app-layout {
    display: flex;
    flex: 1;
    gap: 0;
    min-height: 0;
    overflow: hidden;
}

/* LEFT TOOLS PANEL */
.left-tools-panel {
    width: 90px;
    background: #c0c0c0;
    border-right: 2px groove #fff;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.left-tools-panel .tool-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 8px;
    border-bottom: 1px solid #808080;
}

.left-tools-panel .tool-section:last-child {
    border-bottom: none;
}

.section-label {
    font-size: 11px;
    font-weight: bold;
    color: #000;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.help-section {
    border-bottom: 1px solid #dfdfdf;
    padding-bottom: 4px;
    margin-bottom: 4px;
}

.help-icon-btn {
    width: 36px;
    height: 36px;
    font-weight: bold;
    font-size: 16px;
}

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

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

.color-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.color-input-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.color-input-row label {
    font-size: 10px;
    min-width: 30px;
}

.color-input-row input[type="color"] {
    width: 40px;
    height: 30px;
    border: 2px inset #808080;
    flex: 1;
}

.effect-btn,
.action-btn {
    width: 100%;
    padding: 6px 6px;
    font-size: 11px;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.2;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* CENTER CANVAS AREA */
.canvas-area {
    flex: 1;
    background-image:
        linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
        linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
        linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: #fff;
    border: 2px inset #808080;
    position: relative;
    min-height: 0;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    overflow: hidden;
    padding: 0;
}

canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: crosshair;
    display: block;
    touch-action: none;
    width: 100%;
    height: 100%;
    flex: 1;
}

/* RIGHT PANEL */
.right-panel {
    width: 220px;
    background: #c0c0c0;
    border-left: 2px groove #fff;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.frames-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-height: 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #808080;
}

.frames-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.add-frame-btn {
    width: 100%;
    padding: 4px 6px;
    font-size: 11px;
}

.frame-item {
    background: #fff;
    border: 2px outset #dfdfdf;
    padding: 4px;
    cursor: move;
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.frame-item:hover {
    background: #f5f5f5;
}

.frame-item.active {
    border: 2px inset #808080;
    background: #e0e0e0;
}

.frame-preview {
    width: 50px;
    height: 40px;
    border: 1px solid #000;
    background-image:
        linear-gradient(45deg, #d0d0d0 25%, transparent 25%),
        linear-gradient(-45deg, #d0d0d0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d0d0d0 75%),
        linear-gradient(-45deg, transparent 75%, #d0d0d0 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
    background-color: #fff;
    image-rendering: pixelated;
    flex-shrink: 0;
}

.frame-label {
    flex: 1;
    font-size: 11px;
    min-width: 0;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.frame-delete {
    position: absolute;
    right: 2px;
    top: 2px;
    width: 16px;
    height: 16px;
    min-width: 16px;
    padding: 0;
    font-size: 10px;
    line-height: 1;
}

/* RIGHT PANEL SECTIONS */
.right-panel .tool-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 8px;
    border-bottom: 1px solid #808080;
}

.right-panel .tool-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}


.playback-controls {
    display: flex;
    gap: 4px;
}

.playback-btn {
    flex: 1;
    padding: 4px 6px;
    font-size: 11px;
}

.fps-label {
    font-size: 11px;
    margin-bottom: 2px;
}

.fps-slider {
    width: 100%;
    height: 10px;
    cursor: pointer;
}

.export-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.export-btn {
    width: 100%;
    padding: 4px 6px;
    font-size: 11px;
}

/* BUTTONS */
button {
    background: #c0c0c0;
    border: 2px outset #dfdfdf;
    padding: 6px 12px;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    min-width: 50px;
}

button:active,
button.active {
    border-style: inset;
    background: #a0a0a0;
}

button:hover {
    background: #d0d0d0;
}

.brush-type-btn,
.brush-size-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 2px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

/* INPUTS */
input[type="color"] {
    width: 40px;
    height: 40px;
    border: 2px inset #808080;
    cursor: pointer;
}

input[type="range"] {
    width: 100%;
    height: 8px;
}

/* BOTTOM: COLOR PALETTE */
.color-palette {
    padding: 8px;
    border-top: 2px groove #fff;
    border-bottom: none;
    background: #c0c0c0;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    flex-shrink: 0;
}

.palette-label {
    font-weight: bold;
    font-size: 12px;
    min-width: 50px;
}

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

.color-block {
    width: 28px;
    height: 28px;
    border: 2px outset #dfdfdf;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 1px 1px 0 #fff inset, -1px -1px 0 #808080 inset;
}

.color-block:hover {
    border-style: outset;
    box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.5);
}

.color-block.selected {
    border: 2px inset #000;
    box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.8), 0 0 3px rgba(0, 0, 0, 0.5);
}

/* STATUS BAR */
.status-bar {
    background: #c0c0c0;
    border-top: 2px groove #fff;
    padding: 4px 8px;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    gap: 20px;
    flex-shrink: 0;
}

/* HELP MODAL */
.help-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.help-modal.active {
    display: flex;
}

.help-modal-content {
    background: #c0c0c0;
    border: 3px outset #dfdfdf;
    padding: 20px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 2px 2px 0 #000;
    border-radius: 0;
}

.help-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 2px groove #fff;
    padding-bottom: 10px;
}

.help-modal-header h2 {
    margin: 0;
    font-size: 16px;
}

.help-close-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    cursor: pointer;
    font-weight: bold;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* MOBILE TOOLBAR (hidden on desktop, shown on mobile) */
.mobile-toolbar {
    display: none;
}

.drawer-overlay {
    display: none;
}

/* TABLET / MOBILE RESPONSIVE */
@media (max-width: 1024px) {
    .left-tools-panel {
        width: 80px;
        padding: 6px;
        gap: 6px;
    }

    .right-panel {
        width: 180px;
        padding: 6px;
        gap: 6px;
    }

    .brush-type-btn,
    .brush-size-btn {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    button {
        padding: 4px 8px;
        font-size: 11px;
    }
}

@media (max-width: 768px) {
    /* MOBILE: Full-screen immersive drawing */

    /* Reset HTML and Body completely */
    html {
        width: 100%;
        height: 100%;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Hide navbar on mobile */
    .navbar {
        display: none !important;
    }

    body {
        width: 100%;
        height: 100%;
        padding: 0 !important;
        margin: 0 !important;
        overflow: hidden !important;
        background: #008080 !important;
    }

    /* CONTAINER: Full viewport - override shared-styles.css */
    .container {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        min-height: 100vh !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        display: block !important;
        background: transparent !important;
        flex-direction: column !important;
    }

    .app-layout {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        pointer-events: none !important;
    }

    /* CANVAS: Full screen minus bottom toolbar only */
    .canvas-area {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 56px !important;
        width: 100vw !important;
        height: calc(100vh - 56px) !important;
        border: none !important;
        z-index: 1 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    canvas {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        pointer-events: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Hide resize handles on mobile */
    .resize-handle {
        display: none !important;
    }

    /* LEFT TOOLS PANEL: Slide-in drawer from left */
    .left-tools-panel {
        position: fixed !important;
        left: -100vw !important;
        top: 0 !important;
        width: 90vw !important;
        max-width: 360px !important;
        height: calc(100vh - 56px) !important;
        background: #c0c0c0 !important;
        border-right: 3px groove #fff !important;
        padding: 16px !important;
        gap: 12px !important;
        z-index: 200 !important;
        transition: left 0.3s ease !important;
        overflow-y: auto !important;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3) !important;
        pointer-events: auto !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .left-tools-panel.open {
        left: 0 !important;
    }

    /* RIGHT PANEL: Bottom drawer on mobile - hidden by default, slides up */
    .right-panel {
        position: fixed !important;
        bottom: -100vh !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        height: auto !important;
        max-height: 40vh !important;
        background: #c0c0c0 !important;
        border-top: 3px groove #fff !important;
        padding: 12px !important;
        gap: 12px !important;
        z-index: 99 !important;
        overflow-y: auto !important;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.3) !important;
        pointer-events: auto !important;
        display: flex !important;
        flex-direction: column !important;
        transition: bottom 0.3s ease !important;
    }

    .right-panel.open {
        bottom: 56px !important;
    }

    /* DRAWER OVERLAY */
    .drawer-overlay {
        display: none !important;
    }

    .drawer-overlay.visible {
        display: none !important;
    }

    /* MOBILE TOOLBAR: Bottom quick access bar */
    .mobile-toolbar {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: #c0c0c0 !important;
        border-top: 2px groove #fff !important;
        gap: 0 !important;
        align-items: stretch !important;
        z-index: 999 !important;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2) !important;
        height: 56px !important;
        margin: 0 !important;
        padding: 0 !important;
        pointer-events: auto !important;
        width: 100vw !important;
    }

    .mobile-toolbar-btn {
        flex: 1;
        background: #c0c0c0;
        border: 1px outset #dfdfdf;
        border-top: 2px groove #fff;
        border-right: 1px solid #808080;
        border-bottom: none;
        padding: 0;
        margin: 0;
        font-size: 18px;
        font-weight: bold;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
        min-width: 0;
    }

    .mobile-toolbar-btn:last-child {
        border-right: none;
    }

    .mobile-toolbar-btn:active {
        border-top-style: inset;
        border-left-style: inset;
        background: #a0a0a0;
    }

    .mobile-toolbar-btn:hover {
        background: #d0d0d0;
    }

    .mobile-toolbar-current-tool {
        flex: 1;
        background: #c0c0c0;
        border: 1px outset #dfdfdf;
        border-top: 2px groove #fff;
        border-right: 1px solid #808080;
        border-bottom: none;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        cursor: default;
        margin: 0;
        padding: 0;
        min-width: 0;
    }

    .mobile-color-btn {
        flex: 1 !important;
        border-radius: 0 !important;
    }

    /* Hide original layout elements on mobile */
    .title-bar {
        display: none;
    }

    .status-bar {
        display: none;
    }

    .color-palette {
        display: none;
    }


    /* Mobile tool sections */
    .left-tools-panel .tool-section {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        padding-bottom: 16px !important;
        border-bottom: 2px groove #fff !important;
    }

    .left-tools-panel .tool-section:last-child {
        border-bottom: none !important;
        padding-bottom: 0 !important;
    }

    .section-label {
        font-size: 13px !important;
        font-weight: bold !important;
        text-transform: uppercase !important;
        letter-spacing: 1px !important;
        color: #000 !important;
        padding-bottom: 6px !important;
    }

    .brush-grid,
    .size-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
    }

    .brush-grid .brush-type-btn,
    .size-grid .brush-size-btn {
        height: 50px !important;
        width: 100% !important;
        min-width: auto !important;
        font-size: 16px !important;
        padding: 0 !important;
    }

    /* Mobile color controls */
    .color-controls {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    .color-input-row {
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
    }

    .color-input-row label {
        font-size: 12px !important;
        font-weight: 600 !important;
        min-width: 50px !important;
    }

    .color-input-row input[type="color"] {
        width: auto !important;
        height: 44px !important;
        min-width: 80px !important;
        flex: 1 !important;
        border: 2px inset #808080 !important;
        cursor: pointer !important;
    }

    /* Mobile button styles */
    .left-tools-panel .effect-btn,
    .left-tools-panel .action-btn {
        width: 100% !important;
        padding: 12px 8px !important;
        font-size: 13px !important;
        font-weight: 600 !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        white-space: normal !important;
    }

    /* Mobile help section */
    .left-tools-panel .help-section {
        border-bottom: 2px groove #fff !important;
        padding-bottom: 12px !important;
        margin-bottom: 12px !important;
    }

    .left-tools-panel .help-icon-btn {
        width: 100% !important;
        height: 44px !important;
        min-height: 44px !important;
        font-weight: bold !important;
        font-size: 18px !important;
        padding: 0 !important;
    }

    .right-panel .tool-section {
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding-bottom: 8px;
        border-bottom: 1px solid #808080;
    }

    .right-panel .tool-section:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    /* Frames as horizontal filmstrip - one line */
    .frames-section {
        display: flex !important;
        flex-direction: row !important;
        gap: 6px !important;
        align-items: center !important;
        flex: none !important;
        padding: 0 !important;
        border: none !important;
        border-bottom: 2px groove #fff !important;
        padding-bottom: 12px !important;
        margin-bottom: 12px !important;
    }

    .frames-section .section-label {
        display: none !important;
    }

    .frames-list {
        display: flex !important;
        flex-direction: row !important;
        gap: 6px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        flex: 1 !important;
        align-items: center !important;
    }

    .add-frame-btn {
        display: none !important;
    }

    .frame-item {
        flex-direction: column !important;
        min-width: 45px !important;
        width: 45px !important;
        height: 60px !important;
        padding: 3px !important;
        gap: 2px !important;
        flex-shrink: 0 !important;
        position: relative !important;
    }

    .frame-preview {
        width: 100% !important;
        height: 48px !important;
        border: 1px outset #dfdfdf !important;
    }

    .frame-label {
        font-size: 8px !important;
        text-align: center !important;
        flex: none !important;
        display: none !important;
    }

    .frame-delete {
        position: absolute !important;
        width: 14px !important;
        height: 14px !important;
        top: 0 !important;
        right: 0 !important;
        padding: 0 !important;
        font-size: 9px !important;
        min-width: 14px !important;
    }

    /* Right panel sections - compact layout */
    .right-panel .tool-section {
        display: flex !important;
        flex-direction: row !important;
        gap: 8px !important;
        align-items: center !important;
        padding-bottom: 0 !important;
        border-bottom: none !important;
        margin-bottom: 8px !important;
    }

    .right-panel .tool-section:last-child {
        margin-bottom: 0 !important;
    }

    /* Compact playback controls - one line */
    .playback-controls {
        display: flex !important;
        gap: 6px !important;
        flex: 1 !important;
    }

    .playback-btn {
        flex: 1 !important;
        padding: 8px 4px !important;
        font-size: 12px !important;
        min-height: 36px !important;
    }

    /* Compact FPS control - one line */
    .fps-label {
        font-size: 12px !important;
        margin-bottom: 0 !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }

    .fps-slider {
        width: auto !important;
        flex: 1 !important;
        min-width: 100px !important;
    }

    /* Compact export buttons - one line */
    .export-section {
        display: flex !important;
        flex-direction: row !important;
        gap: 6px !important;
        margin-bottom: 0 !important;
    }

    .export-btn {
        flex: 1 !important;
        padding: 8px 4px !important;
        font-size: 11px !important;
        min-height: 36px !important;
        white-space: nowrap !important;
    }
}

@media (max-width: 480px) {
    .container {
        border-width: 1px;
    }

    .left-tools-panel,
    .right-panel {
        gap: 2px;
        padding: 4px;
    }

    .brush-type-btn,
    .brush-size-btn {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }

    button {
        padding: 3px 6px;
        font-size: 10px;
    }

    .canvas-area {
        min-height: 200px;
        height: 40vh;
    }

    .color-palette {
        padding: 4px;
        gap: 2px;
    }

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

    .color-block {
        width: 16px;
        height: 16px;
    }

    .status-bar {
        font-size: 10px;
        padding: 2px 4px;
    }

    .help-modal-content {
        padding: 12px;
    }
}
