body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #1a1a1a 0%, #121212 100%);
    touch-action: none;
    color: #f5f5f7;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #262626;
    padding: 15px; 
    border-radius: 0; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.3), 0 8px 30px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 100%;
    border: 1px solid rgba(255,255,255,0.08);
    position: relative;  
    height: 100vh;
    box-sizing: border-box;
}

.app-container:before {
    content: "";
    display: none; 
}

.title-container {
    position: relative;
    display: inline-block;
    text-align: center;
}

.app-title {
    font-size: 1.8em;
    font-weight: 700;
    color: #f5f5f7;
    margin-bottom: 0;
    background: linear-gradient(90deg, #FF9500, #FF2D55, #5856D6, #007AFF);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
    text-align: center;
}

.by-mila {
    position: absolute;
    right: -45px;
    bottom: 0;
    font-family: 'Caveat', cursive;
    font-size: 1.2em;
    color: white;
    transform: rotate(-5deg);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.top-bar {
    width: 100%;
    display: flex;
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 15px; 
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.drawing-area-container {
    display: flex;
    flex-direction: column; 
    align-items: center;
    margin-bottom: 20px; 
    width: 100%;
}

.canvas-stack {
    position: relative;
    border: none;
    background-color: #fff; 
    border-radius: 12px; 
    overflow: hidden;
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
    /* width and height set by JS */
}

#coloringCanvas, #lineArtCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%; 
    height: 100%; 
}

#coloringCanvas {
    cursor: crosshair;
    z-index: 5; 
}

#lineArtCanvas {
    pointer-events: none; 
    z-index: 10; 
}

.icon-button {
    background: rgba(40, 40, 40, 0.9);
    border: none;
    border-radius: 50%; 
    width: 36px; 
    height: 36px; 
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.icon-button img {
    width: 18px; 
    height: 18px;
    filter: brightness(0) invert(1); 
}

.icon-button:hover {
    background: rgba(50, 50, 50, 1);
    box-shadow: 0 3px 12px rgba(0,0,0,0.3);
    transform: translateY(-2px);
}

.page-navigation-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px; 
    margin-top: 20px; 
    margin-bottom: 10px;
    width: 100%;
}

.nav-arrow { 
    font-size: 1.8em; 
    padding: 10px 18px; 
    min-width: 50px;
    background: linear-gradient(to bottom, #3a3a3c, #2c2c2e);
    color: #f5f5f7;
    border-radius: 30px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

.nav-arrow:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(0,0,0,0.3);
    background: linear-gradient(to bottom, #404042, #323234);
}

.controls-bar {
    display: flex;
    flex-wrap: wrap; 
    justify-content: center;
    align-items: center;
    gap: 25px; 
    width: 100%;
    margin-top: 20px;
}

.control-group {
    display: flex;
    flex-direction: column; 
    align-items: center;
    gap: 12px;
    background-color: rgba(40, 40, 40, 0.7);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.control-group label {
    font-weight: 600; 
    color: #f5f5f7;
    font-size: 0.95em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.color-palette, .thickness-selector {
    display: flex;
    flex-wrap: wrap; 
    justify-content: center; 
    gap: 8px; 
}

.brush-divider {
    width: 1px;
    height: 30px;
    background-color: rgba(255, 255, 255, 0.3);
    margin: 0 4px;
}

.thickness-circle {
    width: 36px;
    height: 36px;
    border: 2px solid #3a3a3c;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    background-color: #262626;
    display: flex;
    justify-content: center;
    align-items: center;
}

.thickness-circle:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

.thickness-circle.active {
    border-color: #007AFF;
    transform: scale(1.2);
    box-shadow: 0 0 0 3px #007AFF, 0 4px 10px rgba(0,0,0,0.3);
}

.inner-circle {
    background-color: white;
    border-radius: 50%;
}

.color-button {
    width: 36px; 
    height: 36px; 
    border: 2px solid #3a3a3c; 
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.color-button:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

.color-button.active {
    border-color: #007AFF; 
    transform: scale(1.2);
    box-shadow: 0 0 0 3px #007AFF, 0 4px 10px rgba(0,0,0,0.3);
}

.thickness-button { 
    padding: 8px 14px;
    font-size: 0.9em;
}

.thickness-button.active {
    background: linear-gradient(135deg, #007AFF, #5AC8FA);
    color: white;
    border-color: transparent;
    box-shadow: 0 3px 8px rgba(0,122,255,0.3);
    transform: translateY(-2px);
}

.control-button { 
    padding: 10px 18px; 
    border: none;
    background: linear-gradient(to bottom, #3a3a3c, #2c2c2e);
    color: #f5f5f7;
    cursor: pointer;
    border-radius: 30px; 
    transition: all 0.2s ease;
    font-size: 0.95em; 
    font-weight: 500;
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
}

.control-button:hover {
    background: linear-gradient(to bottom, #404042, #323234);
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(0,0,0,0.3);
}

.control-button:disabled { 
    background-color: #1c1c1e;
    color: #636366;
    cursor: not-allowed;
    border-color: #2c2c2e;
}

.canvas-overlay-button {
    position: absolute;
    background: rgba(40, 40, 40, 0.8);
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    z-index: 20;
    transition: background-color 0.2s ease, opacity 0.3s ease;
}

.canvas-overlay-button img {
    width: 16px;
    height: 16px;
}

.canvas-overlay-button:hover {
    background: rgba(50, 50, 50, 1);
}

.canvas-overlay-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#undoBtnCanvas {
    top: 10px;
    left: 10px;
}

#redoBtnCanvas {
    top: 10px;
    right: 10px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .app-container {
        padding: 15px; 
        padding-top: 15px; 
        border-radius: 10px;
    }
    
    .app-title {
        font-size: 1.2em;
        white-space: nowrap;
    }
    
    .by-mila {
        font-size: 1em;
        right: -35px;
    }
    
    .top-bar {
        flex-wrap: nowrap; 
        gap: 8px; 
        margin-bottom: 10px;
        justify-content: space-between; 
        margin-top: 10px;
    }
    
    .drawing-area-container {
        margin-bottom: 15px;
    }

    .icon-button {
        width: 32px; 
        height: 32px;
    }
    .icon-button img {
        width: 16px; 
        height: 16px;
    }

    .page-navigation-controls {
        margin-top: 15px;
        gap: 10px;
    }

    .nav-arrow {
        font-size: 1.6em;
        padding: 6px 12px;
    }

    .controls-bar {
        flex-direction: column;
        gap: 20px; 
    }
    .control-group {
        width: 100%; 
        align-items: center;
        padding: 12px;
    }
    .control-group label {
        margin-bottom: 5px;
    }
    .color-palette {
        gap: 6px;
    }
    .color-button {
        width: 28px; 
        height: 28px;
    }
    .thickness-button {
        padding: 7px 10px;
    }
    .control-button {
        padding: 9px 14px; 
        font-size: 0.9em;
    }
}

/* Desktop and Tablet adjustments for page navigation */
@media (min-width: 769px) {
    .drawing-area-container {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto; /* prev button | canvas | next button */
        grid-template-areas: "prev-nav canvas-area next-nav";
        align-items: center; /* Vertically align buttons with canvas */
        justify-content: center; /* Center the whole assembly if there's spare horizontal space */
        gap: 20px; /* Space between buttons and canvas stack */
        /* flex-direction: column; is overridden by display: grid */
        /* margin-bottom: 20px; is fine */
        /* width: 100%; is fine */
    }

    .canvas-stack {
        grid-area: canvas-area;
        justify-self: center; /* Center canvas stack if its column is wider */
         /* border, background, radius, overflow are fine */
         /* position: relative is fine for overlay buttons */
    }

    .page-navigation-controls {
        display: contents; /* Makes children direct grid items of .drawing-area-container */
        /* All other properties (gap, margin-top, width, etc.) are ignored due to display: contents */
    }

    #prevPageBtn {
        grid-area: prev-nav;
    }

    #nextPageBtn {
        grid-area: next-nav;
    }

    .nav-arrow {
        /* Reset or adjust any mobile-specific styles if necessary, e.g., margins */
        /* Current .nav-arrow styles (font-size, padding) seem okay for desktop too */
        /* Example: margin-top: 0; if it had a mobile specific margin */
    }
}

/* Landscape tablet layout */
@media (min-width: 769px) and (orientation: landscape) {
    .app-container {
        padding: 10px;
        border-radius: 0; /* No rounded corners in fullscreen */
    }
    
    .drawing-area-container {
        display: block; /* Change from grid to block */
        position: relative;
        width: 100%;
        height: calc(100vh - 110px); /* Adjust based on top bar height */
    }
    
    .canvas-stack {
        position: relative;
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        margin: 0 auto;
    }
    
    .page-navigation-controls {
        display: block;
        position: absolute;
        top: 0;
        width: 100%;
        height: 100%;
        margin: 0;
        z-index: 15;
        pointer-events: none; /* Allow clicks to pass through to canvas */
    }
    
    #prevPageBtn, #nextPageBtn {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        pointer-events: auto; /* Make buttons clickable */
        background: rgba(40, 40, 40, 0.7);
        border-radius: 50%;
        width: 40px;
        height: 40px;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0;
        font-size: 1.5em;
        z-index: 20;
    }
    
    #prevPageBtn {
        left: 10px;
    }
    
    #nextPageBtn {
        right: 10px;
    }
    
    .control-group {
        max-height: 50vh; /* Limit height to avoid covering other elements */
        overflow-y: auto;
        opacity: 0.9;
        position: absolute;
        z-index: 25;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .control-group:first-child {
        position: fixed;
        bottom: 0px;
        top: auto;
        width: 90%;
        left: 50%;
        transform: translateX(-50%);
        z-index: 25;
        margin-left: 0;
        align-self: center;
    }
    
}

/* Desktop (non-landscape) layout */
@media (min-width: 769px) and (orientation: portrait) {
    .control-group:first-child {
        position: fixed;
        bottom: 0px;
        top: auto;
        width: 90%;
        left: 50%;
        transform: translateX(-50%);
        z-index: 25;
    }
}