/* =========================================================
   TOWNTUNE V2 - COLOURING STUDIO
   Permanent app-style viewport. No page scrolling.
   ========================================================= */

html,
body.studio-v2-page {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body.studio-v2-page {
    margin: 0;
    overscroll-behavior: none;
    background: #061524;
}

.studio-app {
    --studio-topbar-h: 60px;
    --studio-dock-h: 76px;

    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    display: grid;
    grid-template-rows:
        calc(var(--studio-topbar-h) + env(safe-area-inset-top))
        minmax(0, 1fr)
        calc(var(--studio-dock-h) + env(safe-area-inset-bottom));
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 0%, rgba(54, 109, 146, .20), transparent 34%),
        #061524;
}


/* =========================================================
   TOPBAR
   ========================================================= */

.studio-topbar {
    position: relative;
    z-index: 30;
    display: grid;
    grid-template-columns: minmax(72px, .7fr) minmax(0, 1fr) minmax(132px, .7fr);
    align-items: center;
    gap: 8px;
    padding:
        env(safe-area-inset-top)
        max(10px, env(safe-area-inset-right))
        0
        max(10px, env(safe-area-inset-left));
    border-bottom: 1px solid rgba(255,255,255,.07);
    background: rgba(7, 23, 44, .96);
    backdrop-filter: blur(16px);
}

.studio-back-button {
    justify-self: start;
    min-width: 68px;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0 11px;
    border: 1px solid rgba(255,255,255,.10);
    border-radius: 14px;
    background: rgba(255,255,255,.07);
    color: #fff !important;
    font-size: 13px;
    font-weight: 950;
    text-decoration: none;
}

.studio-heading {
    min-width: 0;
    display: grid;
    justify-items: center;
    line-height: 1.1;
}

.studio-heading strong {
    max-width: 100%;
    overflow: hidden;
    color: #fff;
    font-size: clamp(15px, 2.2dvh, 20px);
    font-weight: 950;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.studio-heading span {
    margin-top: 3px;
    color: #7f91aa;
    font-size: 9px;
    font-weight: 900;
    letter-spacing: .09em;
    text-transform: uppercase;
}

.studio-page-controls {
    justify-self: end;
    display: grid;
    grid-template-columns: 34px minmax(60px, 76px) 34px;
    gap: 4px;
}

.studio-page-arrow,
.studio-page-select {
    min-height: 38px;
    border: 1px solid rgba(255,255,255,.09);
    border-radius: 11px;
    background: rgba(255,255,255,.065);
    color: #fff;
    font-family: inherit;
    font-weight: 900;
}

.studio-page-arrow {
    padding: 0;
    font-size: 25px;
    line-height: 1;
    cursor: pointer;
}

.studio-page-arrow:disabled {
    opacity: .28;
    cursor: default;
}

.studio-page-select {
    min-width: 0;
    padding: 0 6px;
    color-scheme: dark;
    font-size: 11px;
    cursor: pointer;
}


/* =========================================================
   CANVAS WORKSPACE
   ========================================================= */

.studio-workspace {
    position: relative;
    min-height: 0;
    overflow: hidden;
    padding: clamp(5px, 1.1dvh, 10px);
}

.studio-canvas-card {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 16px;
    background:
        radial-gradient(circle at 50% 20%, rgba(255,255,255,.055), transparent 34%),
        rgba(3, 12, 24, .38);
}

.canvas-stage {
    position: relative;
    overflow: hidden;
    border-radius: 11px;
    background: #fff;
    box-shadow: 0 18px 48px rgba(0,0,0,.42);
    touch-action: none;
    transform-origin: center center;
    will-change: transform;
}

.canvas-stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#drawingCanvas {
    z-index: 1;
    cursor: crosshair;
}

#lineArtCanvas {
    z-index: 2;
    pointer-events: none;
    mix-blend-mode: multiply;
}


/* =========================================================
   BOTTOM TOOL DOCK
   ========================================================= */

.studio-dock {
    position: relative;
    z-index: 35;
    min-width: 0;
    overflow: hidden;
    padding:
        7px
        max(8px, env(safe-area-inset-right))
        env(safe-area-inset-bottom)
        max(8px, env(safe-area-inset-left));
    border-top: 1px solid rgba(255,255,255,.07);
    background: rgba(7, 23, 44, .97);
    backdrop-filter: blur(16px);
}

.studio-dock-scroll {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 1px;
    scrollbar-width: none;
}

.studio-dock-scroll::-webkit-scrollbar {
    display: none;
}

.studio-tool-button {
    min-width: 58px;
    height: 56px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    padding: 4px 8px;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 13px;
    background: rgba(255,255,255,.055);
    color: #dfe9f6;
    font-family: inherit;
    cursor: pointer;
}

.studio-tool-button:hover {
    background: rgba(255,255,255,.09);
}

.studio-tool-button.active {
    border-color: rgba(111, 224, 211, .42);
    background: rgba(111, 224, 211, .15);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(111,224,211,.08);
}

.studio-tool-button:disabled {
    opacity: .28;
    cursor: default;
}

.studio-tool-icon {
    font-size: 20px;
    line-height: 1;
}

.studio-tool-label {
    font-size: 9px;
    font-weight: 900;
    line-height: 1;
}

.studio-dock-divider {
    width: 1px;
    height: 38px;
    flex: 0 0 1px;
    margin: 0 2px;
    background: rgba(255,255,255,.10);
}

.studio-size-button {
    min-width: 50px;
}

.studio-size-dot {
    display: block;
    border-radius: 50%;
    background: currentColor;
}

.studio-size-small {
    width: 7px;
    height: 7px;
}

.studio-size-medium {
    width: 12px;
    height: 12px;
}

.studio-size-large {
    width: 18px;
    height: 18px;
}

.studio-colour-preview {
    width: 22px;
    height: 22px;
    display: block;
    border: 2px solid rgba(255,255,255,.85);
    border-radius: 50%;
    background: #ef476f;
    box-shadow: 0 0 0 1px rgba(0,0,0,.35);
}

.studio-download-button {
    border-color: rgba(111,224,211,.27);
    background: linear-gradient(135deg, rgba(55, 181, 166, .40), rgba(72, 121, 222, .42));
    color: #fff;
}


/* =========================================================
   COLOUR PALETTE
   ========================================================= */

.studio-palette-panel {
    position: fixed;
    z-index: 60;
    left: 50%;
    bottom: calc(var(--studio-dock-h) + env(safe-area-inset-bottom) + 12px);
    width: min(720px, calc(100vw - 20px));
    max-height: min(250px, 36dvh);
    overflow: auto;
    padding: 13px;
    border: 1px solid rgba(255,255,255,.10);
    border-radius: 18px;
    background: rgba(8, 25, 46, .97);
    box-shadow: 0 22px 50px rgba(0,0,0,.42);
    backdrop-filter: blur(18px);
    transform: translate(-50%, 18px) scale(.98);
    opacity: 0;
    pointer-events: none;
    transition: opacity .16s ease, transform .16s ease;
}

.studio-palette-panel.open {
    transform: translate(-50%, 0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.studio-palette-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 11px;
}

.studio-palette-head strong {
    color: #fff;
    font-size: 13px;
}

#colourPicker {
    width: 42px;
    height: 32px;
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 9px;
    background: transparent;
    cursor: pointer;
}

.colour-swatches {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.colour-swatch {
    width: 31px;
    height: 31px;
    padding: 0;
    border: 3px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 1px rgba(0,0,0,.35);
}

.colour-swatch.active {
    transform: scale(1.08);
    box-shadow:
        0 0 0 3px #6de0d4,
        0 0 0 5px rgba(109,224,212,.16);
}


/* =========================================================
   TOAST
   ========================================================= */

.studio-toast {
    position: absolute;
    z-index: 80;
    left: 50%;
    bottom: 12px;
    max-width: calc(100% - 28px);
    padding: 9px 13px;
    border-radius: 999px;
    background: rgba(6, 21, 36, .92);
    color: #fff;
    font-size: 12px;
    font-weight: 850;
    text-align: center;
    box-shadow: 0 10px 28px rgba(0,0,0,.30);
    transform: translate(-50%, 18px);
    opacity: 0;
    pointer-events: none;
    transition: transform .18s ease, opacity .18s ease;
}

.studio-toast.show {
    transform: translate(-50%, 0);
    opacity: 1;
}


/* =========================================================
   SHORT / SMALL SCREENS
   ========================================================= */

@media (max-width: 760px) {
    .studio-app {
        --studio-topbar-h: 54px;
        --studio-dock-h: 66px;
    }

    .studio-topbar {
        grid-template-columns: 58px minmax(0, 1fr) 112px;
        gap: 5px;
        padding-left: max(6px, env(safe-area-inset-left));
        padding-right: max(6px, env(safe-area-inset-right));
    }

    .studio-back-button {
        min-width: 54px;
        min-height: 38px;
        padding: 0 8px;
        border-radius: 12px;
    }

    .studio-back-button span {
        display: none;
    }

    .studio-heading strong {
        font-size: 14px;
    }

    .studio-heading span {
        display: none;
    }

    .studio-page-controls {
        grid-template-columns: 28px minmax(52px, 64px) 28px;
        gap: 3px;
    }

    .studio-page-arrow,
    .studio-page-select {
        min-height: 34px;
        border-radius: 10px;
    }

    .studio-page-select {
        font-size: 10px;
    }

    .studio-workspace {
        padding: 4px;
    }

    .studio-canvas-card,
    .canvas-stage {
        border-radius: 8px;
    }

    .studio-dock {
        padding-top: 5px;
    }

    .studio-dock-scroll {
        justify-content: flex-start;
        gap: 5px;
    }

    .studio-tool-button {
        min-width: 50px;
        height: 50px;
        padding: 3px 6px;
        border-radius: 12px;
    }

    .studio-tool-icon {
        font-size: 19px;
    }

    .studio-tool-label {
        font-size: 8px;
    }

    .studio-palette-panel {
        bottom: calc(var(--studio-dock-h) + env(safe-area-inset-bottom) + 7px);
        max-height: 32dvh;
        padding: 11px 9px;
        border-radius: 15px;
    }

    .colour-swatch {
        width: 28px;
        height: 28px;
    }
}

@media (max-width: 430px) {
    .studio-tool-label {
        display: none;
    }

    .studio-tool-button {
        min-width: 43px;
        width: 43px;
        height: 46px;
    }

    .studio-size-button {
        min-width: 41px;
        width: 41px;
    }

    .studio-dock-divider {
        height: 32px;
    }

    .studio-app {
        --studio-dock-h: 60px;
    }
}

@media (max-height: 620px) {
    .studio-app {
        --studio-topbar-h: 48px;
        --studio-dock-h: 56px;
    }

    .studio-back-button,
    .studio-page-arrow,
    .studio-page-select {
        min-height: 32px;
    }

    .studio-tool-button {
        height: 43px;
    }

    .studio-palette-panel {
        max-height: 30dvh;
    }
}
