@import url('https://fonts.googleapis.com/css2?family=Cherry+Bomb+One&display=swap');

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Cherry Bomb One', cursive, sans-serif;
    background: #3a56c5;
    color: #fff;
    display: flex;
    justify-content: center;
    height: 100dvh;
    overflow: hidden;
    touch-action: none;
}

/* ── APP SHELL ─────────────────────────────────────────────────────────── */
.app-container {
    width: 100%;
    max-width: 500px;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #3a56c5;
    position: relative;
}

/* ── HEADER ─────────────────────────────────────────────────────────────── */
.header {
    flex-shrink: 0;
    text-align: center;
    padding: 10px 12px 6px;
    position: relative;
    z-index: 10;
}

.logo {
    max-width: 180px;
    height: auto;
    margin: 0 auto 4px;
    display: block;
}

#page-title {
    font-size: 22px;
    color: #fff;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, .15);
}

/* ── SCREENS ────────────────────────────────────────────────────────────── */
.screen {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    padding-top: 0;
    z-index: 5;

    /* animation states */
    opacity: 0;
    transform: translateX(60px);
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.4,0,0.2,1),
                transform 0.35s cubic-bezier(0.4,0,0.2,1);
}

/* Screens live inside a flex column — need to account for header/footer */
.screen-wrapper {
    flex: 1;
    min-height: 0;
    position: relative;
    width: 100%;
    overflow: hidden;
}

.screen.active {
    display: flex;
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.screen.exit-left {
    display: flex;
    opacity: 0;
    transform: translateX(-60px);
    pointer-events: none;
}

.screen.enter-right {
    display: flex;
    opacity: 0;
    transform: translateX(60px);
    pointer-events: none;
}

/* Draw screen: no scroll, justify space-between */
#screen-draw {
    overflow: hidden;
    padding: 6px 12px 6px;
    justify-content: space-between;
    padding-top: 6px;
}

/* Screens 1 & 3 need top padding to sit below header */
#screen-template,
#screen-submit {
    padding: 8px 12px;
    justify-content: flex-start;
}

/* ── CONTENT BOX (screens 1 & 3) ─────────────────────────────────────── */
.content-box {
    background: #c5dcea;
    border-radius: 18px;
    padding: 16px 14px;
    width: 100%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
    margin-bottom: 12px;
    flex-shrink: 0;
}

.content-box h2 {
    color: #3a56c5;
    font-size: 20px;
    text-align: center;
    margin-bottom: 12px;
    text-transform: uppercase;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, .5);
}

.content-box .subtitle {
    color: #3a56c5;
    font-size: 13px;
    text-align: center;
    margin-top: -8px;
    margin-bottom: 10px;
}

/* ── SCREEN 1: Template list ─────────────────────────────────────────── */
.template-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.template-btn {
    background: #f76f2f;
    border: none;
    border-radius: 12px;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 0 #cc5720;
    transition: transform .1s, box-shadow .1s;
    touch-action: manipulation;
    width: 100%;
}

.template-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.template-btn .btn-text {
    color: #fff;
    font-size: 30px;
}

.template-btn img {
    height: 80px;
    background: #f76f2f;
    border-radius: 10px;
    border: 3px solid #333;
    pointer-events: none;
}

/* ── SCREEN 2: Draw toolbar ──────────────────────────────────────────── */
.toolbar-box {
    width: 100%;
    background: #c5dcea;
    border-radius: 14px;
    padding: 8px 10px 6px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Row 1: color picker + swatches */
.palette-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-pick-wrap {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.color-pick-wrap input[type="color"] {
    position: absolute;
    inset: -6px;
    width: calc(100% + 12px);
    height: calc(100% + 12px);
    opacity: 0;
    cursor: pointer;
    border: none;
    padding: 0;
}

.swatches {
    display: flex;
    gap: 5px;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 2px 0;
}

.swatches::-webkit-scrollbar {
    display: none;
}

.swatch-btn {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 7px;
    border: 2px solid transparent;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
    transition: transform .1s, border-color .1s;
    touch-action: manipulation;
}

.swatch-btn:active {
    transform: scale(0.85);
}

.swatch-btn.active {
    border-color: #fff;
    transform: scale(1.15);
    box-shadow: 0 0 0 2px #3a56c5;
}

/* Row 2: tools + size slider */
.tools-size-row {
    display: flex;
    align-items: center;
    gap: 5px;
}

.tool-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: #f76f2f;
    border: 2px solid transparent;
    border-radius: 8px;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    transition: transform .1s, border-color .1s;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-btn:active {
    transform: scale(0.88);
}

.tool-btn.active {
    border-color: #fff;
    background: #d45a18;
}

.size-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

input[type="range"] {
    flex: 1;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    border-radius: 3px;
    background: #3a56c5;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #aaa;
    cursor: pointer;
}

.size-val {
    font-size: 12px;
    color: #3a56c5;
    min-width: 22px;
    text-align: right;
    flex-shrink: 0;
}

/* ── CANVAS CONTAINER + ZOOM ─────────────────────────────────────────── */
.canvas-outer {
    flex: 1;
    min-height: 0;
    width: 100%;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.canvas-container {
    position: relative;
    border: 4px solid #3a56c5;
    border-radius: 8px;
    background: #fff;
    touch-action: none;
    transform-origin: center center;
    /* size set by JS */
    flex-shrink: 0;
}

/* base-canvas: template image → BELOW (z:1) */
#base-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    display: block;
}

/* draw-canvas: user colors → ON TOP (z:2) */
#draw-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: auto;
    cursor: crosshair;
    display: block;
    background: transparent;
}

/* Zoom controls */
.zoom-controls {
    position: absolute;
    bottom: 8px;
    right: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 20;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    background: rgba(58, 86, 197, 0.85);
    border: 2px solid #fff;
    border-radius: 8px;
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    box-shadow: 0 2px 6px rgba(0,0,0,.3);
    font-family: inherit;
    transition: background 0.1s, transform 0.1s;
}

.zoom-btn:active {
    background: rgba(58, 86, 197, 1);
    transform: scale(0.92);
}

/* Back button inside draw screen */
.back-btn-draw {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 30;
    background: rgba(58, 86, 197, 0.85);
    border: 2px solid #fff;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    padding: 5px 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
    touch-action: manipulation;
    transition: background 0.1s;
}

.back-btn-draw:active {
    background: #3a56c5;
}

/* NEXT button */
.bottom-actions {
    flex-shrink: 0;
    width: 100%;
}

.bottom-actions .primary-btn {
    width: 100%;
}

/* ── SCREEN 3: Submit ────────────────────────────────────────────────── */
.submit-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

input[type="text"] {
    width: 100%;
    padding: 13px;
    font-size: 18px;
    border: 4px solid #f76f2f;
    border-radius: 12px;
    text-align: center;
    font-family: inherit;
    color: #3a56c5;
    outline: none;
    background: #fff;
}

/* ── BUTTONS ─────────────────────────────────────────────────────────── */
.primary-btn {
    padding: 13px;
    border: none;
    border-radius: 12px;
    font-size: 20px;
    font-family: inherit;
    color: #fff;
    cursor: pointer;
    transition: transform .1s, box-shadow .1s;
    text-transform: uppercase;
    touch-action: manipulation;
    width: 100%;
}

.primary-btn:active {
    transform: translateY(4px);
    box-shadow: none !important;
}

.orange-btn {
    background: #f76f2f;
    box-shadow: 0 4px 0 #cc5720;
}

.blue-btn {
    background: #3a56c5;
    box-shadow: 0 4px 0 #2a3d96;
}

.message {
    font-size: 14px;
    text-align: center;
    color: #e91e63;
    min-height: 18px;
    width: 100%;
}

/* ── FOOTER ───────────────────────────────────────────────────────────── */
.footer {
    flex-shrink: 0;
    width: 100%;
    text-align: center;
    background: #3a56c5;
    padding: 7px 0 8px;
    border-top: 2px solid rgba(255, 255, 255, .15);
    position: relative;
    z-index: 20;
}

.footer img {
    max-height: 34px;
    max-width: 90%;
    object-fit: contain;
    display: inline-block;
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .footer {
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
}

/* ── RESPONSIVE TWEAKS ──────────────────────────────────────────────── */
@media (max-height: 500px) {
    .header { padding: 4px 12px 2px; }
    .logo { max-width: 100px; }
    #page-title { font-size: 16px; }
    .toolbar-box { padding: 4px 8px; gap: 4px; }
    .swatch-btn { width: 24px; height: 24px; }
    .tool-btn { width: 30px; height: 30px; font-size: 13px; }
    .color-pick-wrap { width: 30px; height: 30px; }
    .footer { padding: 4px 0; }
    .footer img { max-height: 26px; }
}

@media (max-width: 360px) {
    #page-title { font-size: 18px; }
    .logo { max-width: 150px; }
    .swatch-btn { width: 24px; height: 24px; }
    .tool-btn { width: 32px; height: 32px; font-size: 13px; }
}

@media (min-width: 700px) {
    .app-container { max-width: 680px; }
    #page-title { font-size: 28px; }
    .logo { max-width: 220px; }
}
