:root {
    --primary: #7861ff;
    --primary-dark: #684df5;
    --primary-soft: #f3f0ff;

    --text: #222;
    --muted: #777;
    --line: #e6e6ef;
    --bg: #fafaff;
    --card: #fff;

    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 10px;

    --shadow-card: 0 12px 36px rgba(40, 35, 90, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family:
        -apple-system, BlinkMacSystemFont, 'Pretendard', 'Segoe UI', sans-serif;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

.app {
    min-height: 100vh;
    padding: 20px 16px 96px;
}

.app-header {
    max-width: 760px;
    margin: 0 auto 18px;
}

.app-kicker {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
}

.app-header h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.25;
    letter-spacing: -0.04em;
}

.app-header p {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.step-tabs {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    gap: 8px;
    max-width: 760px;
    margin: 0 auto 16px;
    padding: 10px 0;
    background: rgba(250, 250, 255, 0.92);
    backdrop-filter: blur(12px);
}

.step-tab {
    flex: 1;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.step-tab.is-active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.app-main {
    max-width: 760px;
    margin: 0 auto;
}

.step-panel {
    display: none;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--card);
    box-shadow: var(--shadow-card);
}

.step-panel.is-active {
    display: block;
}

.panel-head {
    margin-bottom: 18px;
}

.panel-head h2 {
    margin: 0;
    font-size: 20px;
    letter-spacing: -0.03em;
}

.panel-head p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.upload-box {
    display: flex;
    min-height: 230px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    border: 1.5px dashed #b5a9ff;
    border-radius: 22px;
    background: linear-gradient(180deg, #fff, #f8f6ff);
    text-align: center;
}

.upload-box input {
    display: none;
}

.upload-icon {
    font-size: 42px;
}

.upload-box strong {
    font-size: 18px;
}

.upload-box small {
    color: var(--muted);
}

.preview-card {
    margin-top: 18px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
}

.preview-card img {
    display: block;
    width: 100%;
    max-height: 360px;
    object-fit: contain;
    border-radius: 14px;
    background: #111;
}

.preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.source-layout {
    display: grid;
    gap: 24px;
}

.source-block {
    min-width: 0;
}

.source-block-head {
    margin-bottom: 12px;
}

.source-block-head h3 {
    margin: 0;
    font-size: 16px;
}

.source-status {
    margin: 18px 0 0;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.source-status.is-ready {
    border-color: rgba(54, 196, 154, 0.45);
    background: #f7fff9;
    color: #20755d;
    font-weight: 800;
}

.text-btn {
    border: 0;
    background: transparent;
    color: var(--primary);
    font-weight: 800;
}

.category-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 12px;
    scrollbar-width: none;
}

.category-scroll::-webkit-scrollbar {
    display: none;
}

.category-btn {
    flex: 0 0 auto;
    height: 34px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: #555;
    font-size: 13px;
    font-weight: 700;
}

.category-btn.is-active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.template-card {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    text-align: left;
}

.template-card.is-active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(120, 97, 255, 0.16);
}

.upload-box.is-active {
    border-color: var(--primary);
    background: #f7fff9;
    box-shadow: 0 0 0 3px rgba(54, 196, 154, 0.16);
}

.template-thumb {
    position: relative;
    background: #fff;
}

.template-thumb img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 0.72;
    object-fit: contain;
    background: #fff;
}

.template-card-body {
    padding: 10px;
}

.template-card strong {
    display: block;
    font-size: 14px;
}

.template-card span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.template-card .template-badge {
    position: absolute;
    left: 8px;
    top: 8px;
    display: inline-flex;
    margin: 0;
    padding: 4px 7px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #444;
    font-size: 11px;
    font-weight: 800;
}

.template-check {
    position: absolute;
    right: 8px;
    top: 8px;
    display: none;
    width: 24px;
    height: 24px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
}

.template-card.is-active .template-check {
    display: flex;
}

.result-layout {
    display: grid;
    gap: 16px;
}

.result-canvas-wrap {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 22px;
    background:
        linear-gradient(45deg, #f3f3f8 25%, transparent 25%),
        linear-gradient(-45deg, #f3f3f8 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f3f3f8 75%),
        linear-gradient(-45deg, transparent 75%, #f3f3f8 75%);
    background-size: 20px 20px;
    background-position:
        0 0,
        0 10px,
        10px -10px,
        -10px 0;
}

#resultCanvas {
    display: block;
    width: 100%;
    height: auto;
    cursor: default;
}

.line-art-layout {
    grid-template-columns: minmax(0, 1fr);
}

.palette-section {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
}

.palette-head {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
}

.palette-head span {
    color: var(--muted);
    font-size: 12px;
    text-align: right;
}

.palette-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.palette-dot {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 999px;
    color: #111;
    font-size: 12px;
    font-weight: 900;
    line-height: 1;
    text-shadow:
        0 1px 0 rgba(255, 255, 255, 0.8),
        1px 0 0 rgba(255, 255, 255, 0.8),
        0 -1px 0 rgba(255, 255, 255, 0.8),
        -1px 0 0 rgba(255, 255, 255, 0.8);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.62);
}

.palette-dot.is-active {
    border-color: #222;
    box-shadow:
        0 0 0 3px #fff,
        0 0 0 5px var(--primary);
}

.bottom-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    gap: 10px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.92);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.bottom-actions.dual {
    grid-template-columns: 1fr 1.4fr;
}

.primary-btn,
.secondary-btn {
    height: 50px;
    border-radius: 16px;
    font-weight: 900;
}

.primary-btn {
    border: 0;
    background: var(--primary);
    color: #fff;
}

.primary-btn:disabled {
    background: #c9c3f5;
    cursor: not-allowed;
}

.secondary-btn {
    border: 1px solid var(--line);
    background: #fff;
    color: #333;
}

.is-hidden {
    display: none !important;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 86px;
    z-index: 100;
    transform: translateX(-50%) translateY(20px);
    max-width: calc(100% - 32px);
    padding: 12px 16px;
    border-radius: 999px;
    background: #222;
    color: #fff;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: 0.2s ease;
}

.toast.is-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (min-width: 900px) {
    .app {
        padding: 40px 24px;
    }

    .app-main,
    .app-header,
    .step-tabs {
        max-width: 1080px;
    }

    .step-panel {
        padding: 28px;
    }

    .template-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .result-layout {
        grid-template-columns: minmax(0, 1fr) 280px;
        align-items: start;
    }

    .line-art-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .source-layout {
        grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
        align-items: start;
    }

    .bottom-actions {
        position: static;
        max-width: 1080px;
        margin: 20px auto 0;
        padding: 0;
        border-top: 0;
        background: transparent;
        backdrop-filter: none;
    }
}
