/* Fallback styles and root styles */
:root {
    background-color: black;
    font-family: Arial, Helvetica, sans-serif;
}

/* Center the body content */
body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding-bottom: 15vh;

}

body.adv-open {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding-bottom: 35vh;

}

/* Logo styles */
.logo {
    color: white;
    text-align: center;
    font-family: 'Libre Franklin', sans-serif;
}

/* Mode Selector */
.mode-selector {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    justify-content: center;
    width: 45vw;
    /* Match canvas width */
    max-width: 1200px;
}

.mode-btn {
    background: black;
    border: 2px solid white;
    color: white;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    flex: 1;
    /* Equal width */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    height: 50px;
    /* Fixed height for consistency */
}

.mode-btn svg {
    height: 2rem;
    width: 2rem;
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.mode-btn.active {
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

/* container for the canvas */
#canvasHolder {
    position: relative;
    /* Needed for absolute positioning of hint */
    display: block;
    justify-content: center;
    align-items: center;
    border: 2px solid white;
    box-shadow: 0 0 10px white;
    border-radius: 1%;
    width: 45vw;
    height: auto;
    overflow: hidden;
    margin-top: 0%;
    cursor: pointer;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

#canvasHolder.drag-hover {
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.8);
    border-color: rgba(0, 255, 0, 0.9);
}

/* canvas element styles */
#memeEditor {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
    overflow: inherit;
}

/* controls container */
.controls {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);

    width: 45vw;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;

    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
    border-radius: 5%;
    z-index: 99999;
    --controls-h: calc(100%);
}

/* Text input styles */
.textInput {
    width: 100%;
    padding: 10px;
    font-size: 1rem;
    border: 2px solid white;
    border-radius: 5px;
    background-color: black;
    color: white;
    font-family: 'Libre Franklin', sans-serif;
    box-sizing: border-box;
    text-align: center;
}

#exportBtn {
    padding: 10px 20px;
    font-size: 1rem;
    border: 2px solid white;
    border-radius: 5px;
    background-color: black;
    color: white;
    font-family: 'Libre Franklin', sans-serif;
    cursor: pointer;
}

.horizGroupImpact {
    display: flex;
    flex-direction: row;
    gap: 1rem;
}

#advBtn {
    padding: 10px 20px;
    font-size: 1rem;
    border: 2px solid white;
    border-radius: 5px;
    background-color: black;
    color: white;
    font-family: 'Libre Franklin', sans-serif;
    cursor: pointer;
}

button {
    transition: transform 0.15s ease, background 0.15s ease;
}

button:active {
    transform: scale(0.97);
}

#advancedSettingsHandler {
    /* hidden state */
    max-height: 0;
    opacity: 0;
    transform: translateY(10px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: max-height 0.5s ease-in-out, opacity 0.1s ease-in-out, transform 0.1s ease-in-out;
    pointer-events: none;
}

#advancedSettingsHandler.visible {
    /* visible state */
    max-height: 400px;
    /* large enough to fit contents — adjust if needed */
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.advGroup {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.advLabel {
    color: white;
    font-family: 'Libre Franklin', sans-serif;
}

.advInput {
    padding: 10px 20px;
    font-size: 1rem;
    border: 2px solid white;
    border-radius: 5px;
    background-color: black;
    color: white;
    font-family: 'Libre Franklin', sans-serif;
    cursor: pointer;
}

/* Pill control styles */
.pill-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 2px solid white;
    border-radius: 25px;
    background-color: black;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.pill-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    padding: 5px 20px;
    cursor: pointer;
    transition: background 0.2s;
    width: auto;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pill-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.pill-input {
    background: none;
    border: none;
    color: white;
    font-family: 'Libre Franklin', sans-serif;
    font-size: 1rem;
    text-align: center;
    width: 100%;
    -moz-appearance: textfield;
    appearance: textfield;
}

.pill-input::-webkit-outer-spin-button,
.pill-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#mobilePlaceholder {
    color: white;
    text-align: center;
    padding: 2rem;
    font-family: sans-serif;
}

.hidden {
    display: none;
}

.version-indicator {
    position: absolute;
    top: 1rem;
    right: 1rem;
    color: #444;
    font-family: 'Libre Franklin', sans-serif;
    font-size: 1rem;
    z-index: 100;
    pointer-events: auto;
    cursor: pointer;
}

/* Modal Overlay */
@keyframes modalFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modalContentScale {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal {
    display: none;
    position: fixed;
    z-index: 2000000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
    animation: modalFadeIn 0.3s ease-out forwards;
}

.modal.show .modal-content {
    animation: modalContentScale 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.modal-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    width: 100%;
    max-width: 900px;
    padding: 20px;
}

/* Modal Content Box */
.modal-content {
    background-color: #1a1a1a;
    color: #eee;
    padding: 30px;
    border: 1px solid #333;
    border-radius: 15px;
    width: 100%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    font-family: sans-serif;
    min-height: 300px;
    display: flex;
    flex-direction: column;
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.5rem;
    text-align: center;
    font-weight: normal;
    border-bottom: 1px solid #333;
    padding-bottom: 15px;
}

.modal-content ul {
    padding-left: 20px;
    line-height: 1.6;
    font-size: 1rem;
    color: #ccc;
}

.modal-content li {
    margin-bottom: 10px;
}

/* Close Button */
.close-btn {
    color: #666;
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 24px;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #fff;
}

/* Navigation Controls */
.nav-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: opacity 0.2s;
    user-select: none;
    min-width: 80px;
}

.nav-group.hidden {
    opacity: 0;
    pointer-events: none;
}

.nav-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: transparent;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}

.nav-group:hover .nav-btn {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

.nav-label {
    color: #fff;
    font-size: 1.2rem;
    font-weight: bold;
}

/* Upload Hint Overlay */
.upload-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    pointer-events: none;
    /* Let clicks pass through to canvas/container */
    opacity: 0.7;
    transition: opacity 0.2s;
}

.upload-hint span {
    color: white;
    font-family: 'Libre Franklin', sans-serif;
    font-size: 1.2rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.upload-hint.hidden {
    display: none;
}

/* Export Modal Styles */
.export-options-content {
    max-width: 700px;
    text-align: center;
    background: #000;
    border: 1px solid #333;
}

.modal-title {
    margin-bottom: 2rem;
    font-family: 'Libre Franklin', sans-serif;
}

.export-choices {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.export-choice-btn {
    flex: 1;
    min-width: 250px;
    background: transparent;
    border: 2px solid #fff;
    border-radius: 8px;
    padding: 2rem;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.export-choice-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.export-choice-btn h3 {
    font-size: 1.5rem;
    margin: 0;
    font-family: 'Libre Franklin', sans-serif;
}

.export-choice-btn p {
    font-size: 1rem;
    opacity: 0.8;
    line-height: 1.4;
    margin: 0;
    font-family: 'Libre Franklin', sans-serif;
}

@media (max-width: 600px) {
    .export-choices {
        flex-direction: column;
    }
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .modal-wrapper {
        flex-direction: column;
        gap: 15px;
    }

    .nav-group {
        flex-direction: row;
        gap: 15px;
    }

    .modal-content {
        order: 2;
        max-height: 60vh;
        overflow-y: auto;
    }

    .nav-group.left {
        order: 1;
    }

    .nav-group.right {
        order: 3;
    }
}

@media (max-width: 600px) {

    /* Center the body content */
    body {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding-bottom: 30vh;

    }

    body.adv-open {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding-bottom: 55vh;
    }

    /* Mobile layout: show canvas and controls, hide the placeholder */

    #canvasHolder {
        display: block;
        width: 95vw;
        max-width: 1200px;
        margin: 0.5rem auto;
        border-radius: 8px;
        border: 1px solid white;
        box-shadow: 0 0 10px white;
        cursor: pointer;
    }

    .mode-selector {
        width: 95vw;
        max-width: 1200px;
    }

    /* Make canvas scale to container width while keeping aspect ratio */
    #memeEditor {
        width: 100%;
        height: auto;
        touch-action: manipulation;
        /* improve touch responsiveness */
    }

    .controls {
        display: flex;
        width: 95vw;
        max-width: 1200px;
        left: 50%;
        transform: translateX(-50%);
        bottom: 0.5rem;
        padding: 0.75rem;
        gap: 0.5rem;
        border-radius: 10px;
    }

    .horizGroupImpact {
        flex-direction: column;
        gap: 0.5rem;
    }

    .textInput {
        width: 100%;
        padding: 0.85rem 0.75rem;
        font-size: 1.05rem;
        border-radius: 8px;
    }

    button,
    .advInput {
        width: 100%;
        padding: 0.8rem;
        font-size: 1.05rem;
        border-radius: 8px;
    }

    .pill-btn {
        width: auto;
        border-radius: 0;
        padding: 5px 20px;
    }

    #mobilePlaceholder {
        display: none;
    }

    /* Keyboard open state */
    body.keyboard-open {
        justify-content: flex-start;
        padding-bottom: 80px;
        padding-top: 10px;
    }

    body.keyboard-open #exportBtn,
    body.keyboard-open #advBtn,
    body.keyboard-open #advancedSettingsHandler {
        display: none !important;
    }

    body.keyboard-open .controls {
        position: fixed;
        background: transparent;
        box-shadow: none;
        backdrop-filter: none;
        bottom: 0;
        height: auto;
        padding: 10px;
        z-index: 999999;
        left: 0;
        width: 100%;
        transform: none;
        border-radius: 0;
        box-sizing: border-box;
    }

    body.keyboard-open .textInput {
        display: none;
    }

    body.keyboard-open .textInput.active-input {
        display: block;
        width: 100%;
        border: 2px solid white;
        background: black;
    }
}

/* Error Modal Styles */
.error-content {
    max-width: 500px;
    text-align: center;
    background: #000;
    border: 1px solid #333;
    min-height: auto;
    padding-bottom: 40px;
}

.error-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;
    font-family: 'Libre Franklin', sans-serif;
    font-size: 1.1rem;
    line-height: 1.5;
    color: #ccc;
}

#errorOkBtn {
    background: transparent;
    border: 2px solid #fff;
    border-radius: 8px;
    padding: 12px 40px;
    color: white;
    cursor: pointer;
    font-family: 'Libre Franklin', sans-serif;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    min-width: 150px;
    margin-top: 10px;
}

#errorOkBtn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}


/* Custom Mode Styles */
.custom-toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.custom-dropdown {
    position: relative;
}

#customTextDropdown,
#customChangeImage {
    width: 100%;
}

#customTextMenu {
    position: absolute;
    z-index: 10;
}

#customTextMenu[hidden] {
    display: none;
}

#customTextMenu {
    max-height: 14.5rem;
    overflow-y: auto;
}

#customLayerList button {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#customDeleteText {
    position: absolute;
    z-index: 5;

    /* Match the app's black and white buttons */
    width: 32px;
    height: 32px;
    padding: 0;
    box-sizing: border-box;
    border: 2px solid white;
    border-radius: 50%;
    background: black;
    color: white;

    /* Center the X */
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Libre Franklin', sans-serif;
    font-size: 22px;
    line-height: 1;

    /* Center the circle on the text box's top-left corner */
    transform: translate(-50%, -50%);
    cursor: pointer;
}

#customDeleteText[hidden] {
    display: none;
}

/* Keep the button centered when the app's general active style applies */
#customDeleteText:active {
    transform: translate(-50%, -50%);
}


/* Desktop custom mode controls */
@media (min-width: 601px) {
    #customControls {
        width: 100%;
    }

    #customTextDropdown,
    #customChangeImage,
    #customAddText,
    #customLayerList button {
        box-sizing: border-box;
        padding: 10px;
        border: 2px solid white;
        border-radius: 5px;
        background: black;
        color: white;
        font: 1rem 'Libre Franklin', sans-serif;
        cursor: pointer;
    }

    #customTextDropdown,
    #customChangeImage {
        width: 100%;
        min-height: 44px;
    }

    #customTextMenu {
        top: calc(100% + 4px);
        left: 0;
        width: 100%;
        box-sizing: border-box;
        padding: 4px;
        border: 2px solid white;
        border-radius: 5px;
        background: black;
    }

    #customAddText {
        width: 100%;
    }

    #customLayerList button {
        margin-top: 4px;
        text-align: left;
    }

    #customLayerList button[aria-pressed="true"] {
        background: #333;
    }

    #customProperties:not(.hidden) {
        display: grid;
        gap: 1rem;
        margin-top: 1rem;
    }

    .custom-text-field,
    .custom-appearance label {
        display: grid;
        gap: 0.5rem;
        min-width: 0;
        text-align: left;
        font-size: 0.85rem;
        color: white;
    }

    .custom-appearance {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 1rem;
    }

    #customProperties textarea,
    #customProperties select,
    #customProperties input {
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
        min-height: 40px;
        padding: 8px;
        border: 2px solid white;
        border-radius: 5px;
        background: black;
        color: white;
        font: 1rem 'Libre Franklin', sans-serif;
    }

    #customProperties textarea {
        resize: vertical;
    }

    #customProperties input[type="color"] {
        padding: 4px;
        cursor: pointer;
    }

    .controls {
        gap: 1rem;
    }

}


/* Desktop uses the text dropdown. */
#customMobileAddText {
    display: none;
}

/* Mobile uses a direct Add Text button. */
@media (max-width: 600px) {
    .custom-dropdown {
        display: none;
    }

    #customMobileAddText {
        display: block;
    }

    #customMobileAddText,
    #customChangeImage {
        box-sizing: border-box;
        width: 100%;
        padding: 10px;
        border: 2px solid white;
        border-radius: 5px;
        background: black;
        color: white;
        font: 1rem 'Libre Franklin', sans-serif;
        cursor: pointer;
    }
}

#customTouchLayer {
    display: none;
}

.custom-mobile-handle {
    display: none;
}

@media (max-width: 600px) {
    body.custom-mode #customProperties:not(.hidden) {
        width: 100%;
        margin-top: 0.5rem;
    }

    body.custom-mode .custom-text-field {
        display: none;
    }

    body.custom-mode .custom-appearance {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.35rem;
    }

    body.custom-mode .custom-appearance label {
        display: grid;
        gap: 0.2rem;
        min-width: 0;
        color: white;
        font: 0.7rem 'Libre Franklin', sans-serif;
    }

    body.custom-mode .custom-appearance label:nth-child(1) { order: 1; }
    body.custom-mode .custom-appearance label:nth-child(2) { order: 3; }
    body.custom-mode .custom-appearance label:nth-child(3) { order: 2; }
    body.custom-mode .custom-appearance label:nth-child(4) { order: 4; }

    body.custom-mode .custom-appearance input,
    body.custom-mode .custom-appearance select,
    body.custom-mode #customText {
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
        min-height: 2.75rem;
        padding: 0.3rem;
        border: 2px solid white;
        border-radius: 5px;
        background: black;
        color: white;
        font: 1rem 'Libre Franklin', sans-serif;
    }

    body.custom-mode .custom-appearance input[type='color'] { padding: 0.2rem; }

    body.custom-mode #customMobileAddText,
    body.custom-mode #customChangeImage,
    body.custom-mode #exportBtn {
        box-sizing: border-box;
        min-height: 2.75rem;
        padding: 0.6rem;
        border: 2px solid white;
        border-radius: 5px;
        background: black;
        color: white;
        font: 1rem 'Libre Franklin', sans-serif;
    }

    body.custom-mode .custom-mobile-handle:not([hidden]) {
        position: absolute;
        z-index: 5;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 1.625rem;
        height: 1.625rem;
        padding: 0.25rem;
        box-sizing: border-box;
        border: 2px solid white;
        border-radius: 50%;
        background: black;
        color: white;
        transform: translate(-50%, -50%);
        touch-action: none;
    }

    body.custom-mode .custom-mobile-handle:active { transform: translate(-50%, -50%); }
    .custom-mobile-handle svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
    body.custom-mode.custom-editing .custom-appearance { display: none; }
    body.custom-mode.custom-editing .custom-mobile-handle { visibility: hidden; }
    body.custom-mode.custom-editing .custom-toolbar,
    body.custom-mode.custom-editing #exportBtn { display: none; }
    body.custom-mode.custom-editing #customProperties:not(.hidden) {
        display: block;
        margin-top: 0;
    }
    body.custom-mode.custom-editing .custom-text-field { display: block; min-width: 0; }
    body.custom-mode.custom-editing .custom-text-field span { display: none; }
    body.custom-mode.custom-editing .controls {
        position: fixed;
        background: transparent;
        box-shadow: none;
        backdrop-filter: none;
        bottom: var(--custom-keyboard-offset, 0px);
        height: auto;
        padding: 10px;
        z-index: 999999;
        left: 0;
        width: 100%;
        transform: none;
        border-radius: 0;
        box-sizing: border-box;
    }

    body.custom-mode.custom-editing #customText {
        display: block;
        height: calc(1.05rem * 1.2 + 1.7rem + 4px);
        min-height: 0;
        padding: 0.85rem 0.75rem;
        border-radius: 8px;
        font-size: 1.05rem;
        line-height: 1.2;
        text-align: center;
        resize: none;
        overflow-y: auto;
    }
}

@media (max-width: 600px) {
    body.custom-mode #memeEditor {
        touch-action: pan-y;
        -webkit-tap-highlight-color: transparent;
        outline: none;
    }
    body.custom-mode #canvasHolder {
    -webkit-tap-highlight-color: transparent;
}

    body.custom-mode #customTouchLayer {
        display: block;
        position: absolute;
        inset: 0;
        pointer-events: none;
    }

    .custom-touch-target {
        position: absolute;
        pointer-events: auto;
        touch-action: none;
        -webkit-tap-highlight-color: transparent;
    }
}
@media (max-width: 600px) {
    #customDeleteText {
        width: 1.625rem;
        height: 1.625rem;
        font-size: 1.125rem;
    }
}

/* WeChat sticker studio surface */
:root {
    --studio-bg: #f6f7fb;
    --studio-surface: rgba(255, 255, 255, 0.9);
    --studio-surface-strong: #ffffff;
    --studio-ink: #18212f;
    --studio-muted: #687386;
    --studio-border: #e4e8f0;
    --studio-accent: #5b5ce2;
    --studio-accent-dark: #4243bd;
    --studio-mint: #dff7ef;
    --studio-shadow: 0 18px 60px rgba(40, 49, 82, 0.1);
    --studio-radius: 22px;
}

html {
    background: var(--studio-bg);
}

body {
    display: block;
    min-height: 100vh;
    box-sizing: border-box;
    padding: 38px 24px 72px;
    overflow-x: hidden;
    color: var(--studio-ink);
    background:
        radial-gradient(circle at 8% 0%, rgba(115, 117, 235, 0.15), transparent 31rem),
        radial-gradient(circle at 94% 8%, rgba(255, 212, 151, 0.18), transparent 28rem),
        var(--studio-bg);
    font-family: 'Libre Franklin', Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.version-indicator {
    top: 31px;
    right: 28px;
    color: var(--studio-muted);
    font-size: 0.72rem;
    letter-spacing: 0.08em;
}

.app-header {
    max-width: 760px;
    margin: 0 auto 26px;
    text-align: center;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--studio-accent);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.17em;
}

.logo {
    margin: 0;
    color: var(--studio-ink);
    font-family: 'Libre Franklin', Inter, sans-serif;
    font-size: clamp(2rem, 5vw, 3.9rem);
    font-weight: 800;
    letter-spacing: -0.055em;
    line-height: 1.05;
}

.tagline {
    margin: 14px 0 16px;
    color: var(--studio-muted);
    font-size: 1rem;
    line-height: 1.6;
}

.privacy-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 13px;
    color: #41645e;
    border: 1px solid #c9eee1;
    border-radius: 999px;
    background: rgba(223, 247, 239, 0.8);
    font-size: 0.78rem;
    font-weight: 700;
}

.sticker-studio {
    width: min(100%, 760px);
    margin: 0 auto;
    padding: 24px;
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.92);
    border-radius: var(--studio-radius);
    background: var(--studio-surface);
    box-shadow: var(--studio-shadow);
    backdrop-filter: blur(18px);
}

.studio-heading,
.template-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.studio-heading h2,
.template-heading h3 {
    margin: 0;
    color: var(--studio-ink);
    font-weight: 800;
    letter-spacing: -0.03em;
}

.studio-heading h2 {
    font-size: 1.45rem;
}

.template-heading h3 {
    font-size: 1rem;
}

.studio-hint,
.template-heading span {
    color: var(--studio-muted);
    font-size: 0.78rem;
    line-height: 1.5;
    text-align: right;
}

.prompt-panel {
    margin-top: 20px;
    padding: 16px;
    border: 1px solid var(--studio-border);
    border-radius: 16px;
    background: rgba(250, 251, 255, 0.8);
}

.prompt-panel label {
    display: block;
    margin-bottom: 8px;
    color: var(--studio-ink);
    font-size: 0.83rem;
    font-weight: 800;
}

.prompt-row {
    display: flex;
    gap: 10px;
}

#stickerPrompt {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 0 15px;
    box-sizing: border-box;
    color: var(--studio-ink);
    border: 1px solid #d9ddea;
    border-radius: 13px;
    outline: none;
    background: var(--studio-surface-strong);
    font: 1rem 'Libre Franklin', Inter, sans-serif;
}

#stickerPrompt::placeholder {
    color: #a1a9b8;
}

#stickerPrompt:focus {
    border-color: var(--studio-accent);
    box-shadow: 0 0 0 4px rgba(91, 92, 226, 0.13);
}

.primary-action,
.text-action,
.quick-prompts button,
.template-card {
    min-height: 44px;
    font-family: inherit;
    cursor: pointer;
}

.primary-action {
    flex: 0 0 auto;
    padding: 0 18px;
    color: #ffffff;
    border: 0;
    border-radius: 13px;
    background: var(--studio-accent);
    font-size: 0.9rem;
    font-weight: 800;
    transition: background 0.2s ease, transform 0.2s ease;
}

.primary-action:hover {
    background: var(--studio-accent-dark);
    transform: translateY(-1px);
}

.quick-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.quick-prompts button {
    min-height: 34px;
    padding: 0 11px;
    color: #536071;
    border: 1px solid #dce2ec;
    border-radius: 999px;
    background: var(--studio-surface-strong);
    font-size: 0.78rem;
}

.quick-prompts button:hover {
    color: var(--studio-accent-dark);
    border-color: #b9baf3;
    background: #f4f4ff;
}

.studio-status {
    min-height: 20px;
    margin: 12px 0 0;
    color: var(--studio-muted);
    font-size: 0.76rem;
    line-height: 1.5;
}

.studio-status[data-tone='success'] {
    color: #277565;
}

.studio-status[data-tone='warning'] {
    color: #a35d15;
}

.template-heading {
    align-items: center;
    margin-top: 24px;
}

.template-heading > div {
    display: grid;
    gap: 4px;
}

.text-action {
    padding: 0;
    color: var(--studio-accent-dark);
    border: 0;
    background: transparent;
    font-size: 0.78rem;
    font-weight: 800;
}

.text-action:hover {
    color: var(--studio-accent);
    text-decoration: underline;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.template-card {
    display: grid;
    grid-template-columns: 45px 1fr auto;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 10px;
    color: var(--studio-ink);
    border: 1px solid var(--studio-border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.76);
    text-align: left;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.template-card:hover,
.template-card[aria-pressed='true'] {
    border-color: var(--card-accent, #b9baf3);
    box-shadow: 0 8px 24px rgba(51, 58, 98, 0.1);
    transform: translateY(-2px);
}

.template-card-icon {
    display: grid;
    place-items: center;
    width: 45px;
    height: 45px;
    border-radius: 13px;
    background: linear-gradient(145deg, var(--card-bg), #ffffff);
    font-size: 1.75rem;
}

.template-card-copy {
    display: grid;
    min-width: 0;
    gap: 3px;
}

.template-card-copy strong,
.template-card-copy span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-card-copy strong {
    font-size: 0.84rem;
}

.template-card-copy span {
    color: var(--studio-muted);
    font-size: 0.7rem;
}

.template-card-arrow {
    color: #a0a7b5;
    font-size: 1.15rem;
}

.mode-selector {
    display: none;
}

#canvasHolder {
    width: min(100%, 560px);
    margin: 28px auto 0;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 24px;
    background: #edf0f7;
    box-shadow: 0 22px 70px rgba(39, 49, 84, 0.16);
    cursor: default;
}

#memeEditor {
    border-radius: 23px;
}

.upload-hint {
    color: var(--studio-muted);
}

.controls {
    position: static;
    width: min(100%, 560px);
    margin: 16px auto 0;
    padding: 14px;
    box-sizing: border-box;
    transform: none;
    border: 1px solid var(--studio-border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 10px 32px rgba(40, 49, 82, 0.08);
    backdrop-filter: blur(16px);
}

.horizGroupImpact {
    gap: 10px;
}

.textInput,
#advBtn,
#exportBtn {
    min-height: 46px;
    box-sizing: border-box;
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.9rem;
}

.textInput {
    color: var(--studio-ink);
    border: 1px solid #d9ddea;
    background: #ffffff;
}

.textInput::placeholder {
    color: #9ba4b5;
}

#advBtn {
    color: var(--studio-muted);
    border: 1px solid var(--studio-border);
    background: #f8f9fc;
}

#exportBtn {
    width: 100%;
    margin-top: 2px;
    color: #ffffff;
    border: 0;
    background: var(--studio-accent);
    font-weight: 800;
}

#exportBtn:hover {
    background: var(--studio-accent-dark);
}

.modal-content,
.error-content {
    color: var(--studio-ink);
    border-color: var(--studio-border);
    border-radius: 22px;
    background: #ffffff;
}

.modal-title,
.export-choice-btn h3 {
    color: var(--studio-ink);
}

.export-choice-btn {
    color: var(--studio-ink);
    border-color: var(--studio-border);
    border-radius: 17px;
    background: #f8f9fc;
}

.export-choice-btn:hover {
    border-color: #b9baf3;
    background: #f4f4ff;
}

.export-choice-btn p {
    color: var(--studio-muted);
}

@media (max-width: 700px) {
    body {
        padding: 28px 14px 48px;
    }

    .version-indicator {
        top: 25px;
        right: 16px;
    }

    .app-header {
        margin-bottom: 20px;
        padding: 20px 26px 0;
    }

    .logo {
        font-size: clamp(2rem, 10vw, 3rem);
    }

    .tagline {
        margin-top: 12px;
        font-size: 0.9rem;
    }

    .sticker-studio {
        padding: 17px;
        border-radius: 18px;
    }

    .studio-heading {
        display: block;
    }

    .studio-hint {
        display: block;
        margin-top: 6px;
        text-align: left;
    }

    .prompt-row {
        display: grid;
        grid-template-columns: 1fr;
    }

    .primary-action {
        width: 100%;
    }

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

    .template-heading {
        align-items: flex-start;
    }

    .template-heading span {
        text-align: left;
    }

    #canvasHolder,
    .controls {
        width: 100%;
    }

    #canvasHolder {
        margin-top: 18px;
        border-radius: 18px;
    }

    #memeEditor {
        border-radius: 17px;
    }

    .controls {
        position: static;
        bottom: auto;
        left: auto;
        padding: 12px;
        transform: none;
    }

    .horizGroupImpact {
        gap: 8px;
    }
}

@media (max-width: 430px) {
    .template-grid {
        grid-template-columns: 1fr;
    }

    .template-card {
        grid-template-columns: 48px 1fr auto;
    }
}

@media (max-width: 700px) {
    html {
        min-width: 0;
    }

    body {
        min-height: 100svh;
        padding: calc(16px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }

    .version-indicator {
        top: calc(20px + env(safe-area-inset-top));
        right: max(14px, env(safe-area-inset-right));
    }

    .app-header {
        max-width: 520px;
        margin-bottom: 18px;
        padding: 30px 30px 0;
    }

    .eyebrow {
        margin-bottom: 8px;
        font-size: 0.68rem;
    }

    .logo {
        font-size: clamp(1.8rem, 9vw, 2.55rem);
        letter-spacing: -0.045em;
    }

    .tagline {
        margin: 10px 0 12px;
        font-size: 0.88rem;
        line-height: 1.5;
    }

    .privacy-pill {
        max-width: 100%;
        justify-content: center;
        padding: 8px 10px;
        font-size: 0.72rem;
    }

    .sticker-studio {
        width: 100%;
        padding: 16px;
        border-radius: 18px;
    }

    .studio-heading {
        display: block;
    }

    .studio-heading h2 {
        font-size: 1.3rem;
    }

    .studio-hint {
        display: block;
        margin-top: 6px;
        text-align: left;
    }

    .prompt-panel {
        margin-top: 16px;
        padding: 12px;
        border-radius: 14px;
    }

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

    #stickerPrompt {
        min-height: 48px;
        font-size: 16px;
    }

    .primary-action {
        width: 100%;
        min-height: 48px;
    }

    .quick-prompts {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .quick-prompts button {
        min-height: 44px;
        padding: 0 8px;
    }

    .template-heading {
        align-items: flex-start;
        gap: 12px;
        margin-top: 20px;
    }

    .template-heading > div {
        min-width: 0;
    }

    .template-heading span {
        display: block;
        max-width: 18em;
        text-align: left;
    }

    .text-action {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .template-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin-top: 12px;
    }

    .template-card {
        grid-template-columns: 38px minmax(0, 1fr);
        min-height: 68px;
        padding: 8px;
        border-radius: 14px;
        gap: 8px;
    }

    .template-card-icon {
        width: 38px;
        height: 38px;
        font-size: 1.5rem;
    }

    .template-card-arrow {
        display: none;
    }

    .template-card-copy strong {
        font-size: 0.82rem;
    }

    .template-card-copy span {
        font-size: 0.68rem;
    }

    #canvasHolder {
        width: 100%;
        margin-top: 18px;
        border-radius: 18px;
        background-image: conic-gradient(#e1e5eb 25%, #f8f9fb 0 50%, #e1e5eb 0 75%, #f8f9fb 0);
        background-size: 24px 24px;
        overscroll-behavior: contain;
    }

    #memeEditor {
        width: 100%;
        height: auto;
        border-radius: 17px;
    }

    .upload-hint span {
        font-size: 0.9rem;
    }

    .controls {
        position: static;
        width: 100%;
        margin: 12px auto 0;
        padding: 12px;
        transform: none;
        border-radius: 18px;
        gap: 10px;
    }

    .horizGroupImpact {
        gap: 8px;
    }

    .textInput,
    #advBtn,
    #exportBtn {
        min-height: 48px;
        font-size: 16px;
    }

    .controls input,
    .controls textarea,
    .controls select {
        font-size: 16px;
    }

    .modal {
        padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
        box-sizing: border-box;
    }

    .modal-content {
        max-height: calc(100svh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        padding: 20px;
    }

    .export-choices {
        gap: 10px;
    }

    .export-choice-btn {
        min-width: 0;
        min-height: 108px;
        padding: 16px;
    }

    body.adv-open {
        padding-bottom: calc(32px + env(safe-area-inset-bottom));
    }

    body.keyboard-open {
        justify-content: flex-start;
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }

    body.keyboard-open .controls {
        position: static;
        bottom: auto;
        left: auto;
        width: 100%;
        padding: 12px;
        transform: none;
        background: rgba(255, 255, 255, 0.88);
        box-shadow: 0 10px 32px rgba(40, 49, 82, 0.08);
        backdrop-filter: blur(16px);
    }
}

@media (max-width: 360px) {
    .app-header {
        padding-inline: 18px;
    }

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