:root {
    --font-body: 'Barlow', sans-serif;
    --font-display: 'DM Serif Display', serif;

    --bg: #eef2f7;
    --surface: #ffffff;
    --surface-muted: #f7f9fc;
    --surface-strong: #eef4ff;
    --text: #101828;
    --text-muted: #475467;
    --line: #d0d9e5;

    --primary: #184a86;
    --primary-soft: #e7effd;
    --on-primary: #ffffff;
    --accent: #166534;
    --on-accent: #ffffff;
    --danger: #b42318;
    --overlay: rgba(255, 255, 255, 0.82);

    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 11px;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 12px 26px rgba(16, 24, 40, 0.11);

    --ease: 0.18s ease;
}

[data-theme="dark"] {
    --bg: #0f141b;
    --surface: #141b24;
    --surface-muted: #192230;
    --surface-strong: #1f2b3d;
    --text: #edf2f8;
    --text-muted: #b3bfce;
    --line: #2e3a4d;

    --primary: #87b7f0;
    --primary-soft: rgba(135, 183, 240, 0.18);
    --on-primary: #0f1a2a;
    --accent: #8ce0ae;
    --on-accent: #0d2419;
    --danger: #f97066;
    --overlay: rgba(18, 22, 29, 0.84);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 16px 30px rgba(0, 0, 0, 0.44);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    min-height: 100%;
}

body {
    font-family: var(--font-body);
    font-size: clamp(16px, 0.2vw + 15px, 18px);
    background: radial-gradient(circle at 0% 0%, color-mix(in srgb, var(--surface-strong) 64%, var(--bg)) 0%, var(--bg) 40%);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
    padding-bottom: 90px;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input {
    font: inherit;
}

button {
    border: none;
    background: none;
    cursor: pointer;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.app-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    backdrop-filter: blur(11px);
    border-bottom: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
}

.app-bar-container {
    max-width: 1440px;
    margin: 0 auto;
    min-height: 70px;
    padding: 0 1rem;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 1rem;
    align-items: center;
}

.logo-img {
    width: auto;
    max-width: 196px;
    height: auto;
}

.nav-links {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.nav-link {
    font-size: 0.97rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.44rem 0.66rem;
    border-radius: 999px;
    transition: color var(--ease), background var(--ease), transform var(--ease);
}

.nav-link:hover {
    color: var(--primary);
    background: var(--primary-soft);
}

.nav-dropdown {
    position: relative;
}

.nav-dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.dropdown-arrow {
    fill: currentColor;
    transition: transform var(--ease);
}

.nav-dropdown:hover .dropdown-arrow {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    list-style: none;
    position: absolute;
    right: 0;
    top: 100%;
    min-width: 222px;
    padding: 0.45rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    display: none;
}

.nav-dropdown:hover .nav-dropdown-menu {
    display: block;
}

.nav-dropdown-menu a {
    display: block;
    padding: 0.52rem 0.62rem;
    border-radius: 9px;
    font-size: 0.95rem;
    color: var(--text-muted);
    transition: background var(--ease), color var(--ease);
}

.nav-dropdown-menu a:hover {
    color: var(--primary);
    background: var(--primary-soft);
}

.app-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.3rem;
}

.icon-btn,
.cart-btn,
.icon-btn-small {
    width: 2.3rem;
    height: 2.3rem;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border: 1px solid transparent;
    transition: color var(--ease), border-color var(--ease), background var(--ease);
}

.icon-btn:hover,
.cart-btn:hover,
.icon-btn-small:hover {
    color: var(--primary);
    border-color: var(--line);
    background: var(--surface);
}

.cart-btn {
    position: relative;
}

.cart-count {
    position: absolute;
    top: -5px;
    right: -4px;
    min-width: 1rem;
    height: 1rem;
    padding: 0 0.2rem;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 0.62rem;
    line-height: 1rem;
    text-align: center;
    font-weight: 700;
}

.mobile-menu-btn {
    display: none;
}

.main-layout {
    max-width: 1440px;
    margin: 0.9rem auto 0;
    padding: 0 1rem;
    display: grid;
    grid-template-columns: 308px minmax(0, 1fr);
    gap: 0.8rem;
}

.sidebar {
    position: sticky;
    top: 80px;
    height: calc(100vh - 90px);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, var(--surface) 0%, var(--surface-muted) 100%);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 0.74rem 0.82rem;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface-strong) 62%, var(--surface));
}

.sidebar-header h2 {
    font-family: var(--font-display);
    font-size: 1.24rem;
    font-weight: 400;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.62rem 0.72rem;
    display: flex;
    flex-direction: column;
    gap: 0.52rem;
}

.sidebar-footer {
    border-top: 1px solid var(--line);
    padding: 0.62rem 0.72rem 0.72rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--surface);
}

.control-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    padding: 0.68rem;
    transition: border-color var(--ease), box-shadow var(--ease), opacity var(--ease), transform var(--ease);
}

.step-card.active {
    border-color: color-mix(in srgb, var(--primary) 46%, var(--line));
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-soft) 74%, transparent);
}

.step-card.completed {
    opacity: 0.85;
}

.step-card.completed .step-badge {
    background: var(--accent);
    color: var(--on-accent);
}

.step-card.completed .step-number {
    display: none;
}

.step-card.completed .step-check {
    display: inline-flex;
}

.step-card.locked {
    opacity: 0.48;
    pointer-events: none;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.52rem;
    margin-bottom: 0.42rem;
}

.card-header h3 {
    font-size: 0.99rem;
    font-weight: 700;
}

.step-badge {
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.76rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.step-check {
    display: none;
    font-size: 0.92rem;
}

.upload-area {
    min-height: 112px;
    border: 1px dashed color-mix(in srgb, var(--primary) 38%, var(--line));
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    transition: border-color var(--ease), background var(--ease), transform var(--ease);
}

.upload-area * {
    cursor: pointer;
}

.upload-area:hover,
.upload-area.drag-active {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary-soft) 56%, var(--surface-muted));
    transform: translateY(-1px);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.28rem;
    color: var(--text-muted);
}

.upload-placeholder p {
    font-size: 0.92rem;
    font-weight: 600;
}

.icon-lg {
    font-size: 1.56rem;
    color: var(--primary);
}

.preview-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.upload-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: rgba(15, 23, 42, 0.34);
    opacity: 0;
    transition: opacity var(--ease);
}

.upload-area.has-image .preview-img {
    display: block;
}

.upload-area.has-image .upload-placeholder {
    display: none;
}

.upload-area.has-image:hover .upload-overlay {
    opacity: 1;
}

.notice-badge {
    margin-top: 0.48rem;
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.28rem 0.54rem;
    background: var(--surface-muted);
}

.privacy-note {
    margin-top: 0.52rem;
    font-size: 0.82rem;
    line-height: 1.35;
    color: var(--text-muted);
}

.instructions-card {
    background: var(--surface-muted);
}

.instructions-list {
    list-style: none;
    display: grid;
    gap: 0.4rem;
}

.instructions-list li {
    display: flex;
    align-items: center;
    gap: 0.42rem;
    font-size: 0.86rem;
    color: var(--text-muted);
}

.instructions-list .material-symbols-outlined {
    font-size: 1.04rem;
    color: var(--primary);
}

.btn {
    width: 100%;
    height: 2.28rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.38rem;
    font-weight: 700;
    font-size: 0.91rem;
    transition: transform var(--ease), opacity var(--ease), background var(--ease), color var(--ease);
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.btn-filled {
    color: var(--on-primary);
    background: var(--primary);
    box-shadow: var(--shadow-sm);
}

.btn-filled:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-text {
    color: var(--text);
    border: 1px solid var(--line);
    background: var(--surface);
}

.canvas-area {
    min-height: calc(100vh - 90px);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    padding: 0.7rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 152px;
    gap: 0.7rem;
}

.canvas-area:not(.has-image) {
    grid-template-columns: minmax(0, 1fr);
}

.canvas-area:not(.has-image) .ad-canvas-right {
    display: none;
}

.canvas-column {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.canvas-wrapper {
    width: 100%;
    height: calc(100vh - 146px);
    min-height: 490px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: linear-gradient(180deg, var(--surface-muted) 0%, color-mix(in srgb, var(--surface-muted) 82%, var(--surface-strong)) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.canvas-wrapper:not(.has-image) {
    aspect-ratio: auto;
    max-width: none;
    border: none;
    background: transparent;
}

#mainCanvas {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
}

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-muted);
    padding: 1rem;
    width: 100%;
}

.empty-state>* {
    margin-inline: auto;
}

.empty-icon-circle {
    width: 4.2rem;
    height: 4.2rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.empty-icon-circle span {
    font-size: 1.9rem;
}

.empty-state h2 {
    font-family: var(--font-display);
    font-size: 1.7rem;
    font-weight: 400;
    color: var(--text);
    margin-bottom: 0.18rem;
}

.empty-state p {
    font-size: 1rem;
}

.loader-overlay {
    position: absolute;
    inset: 0;
    background: var(--overlay);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
}

.loader-overlay.visible {
    display: flex;
}

.md-spinner {
    width: 2.2rem;
    height: 2.2rem;
    border: 3px solid var(--primary-soft);
    border-top-color: var(--primary);
    border-radius: 999px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.floating-controls {
    margin-top: 0.7rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    padding: 0.36rem 0.52rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--ease), visibility var(--ease), transform var(--ease);
    transform: translateY(8px);
}

.floating-controls.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.is-hidden {
    display: none !important;
}

.mobile-step-action {
    display: none;
    margin-top: 0.58rem;
}

.mobile-action-bar {
    display: none;
}

.floating-control-group {
    display: flex;
    align-items: center;
    gap: 0.36rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}

.floating-control-group .material-symbols-outlined {
    font-size: 1.05rem;
    color: var(--primary);
}

.mini-slider {
    width: 96px;
    appearance: none;
    -webkit-appearance: none;
    height: 5px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--line) 80%, transparent);
}

.mini-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 999px;
    background: var(--primary);
}

.mini-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: none;
    border-radius: 999px;
    background: var(--primary);
}

.mini-slider:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.icon-btn-small:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

.ad-zone {
    border: 1px dashed color-mix(in srgb, var(--line) 92%, transparent);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    overflow: hidden;
}

.ad-sidebar {
    min-height: 88px;
}

.ad-canvas-right {
    min-height: 540px;
    width: 152px;
}

.ad-sticky-bottom {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 90px;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(8px);
    z-index: 200;
}

@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 286px minmax(0, 1fr);
    }

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

    .ad-canvas-right {
        display: none;
    }
}

@media (max-width: 960px) {
    body {
        padding-bottom: 0;
    }

    .app-bar-container {
        grid-template-columns: 1fr auto;
    }

    .nav-links {
        display: none;
    }

    .mobile-menu-btn {
        display: inline-flex;
    }

    .main-layout {
        grid-template-columns: 1fr;
        margin-top: 0.55rem;
        padding: 0 0.62rem 0.62rem;
        min-height: calc(100vh - 82px);
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .canvas-area {
        min-height: 52vh;
        padding: 0.6rem;
    }

    .ad-sticky-bottom {
        display: none;
    }

    .mobile-step-action {
        display: inline-flex;
    }

    body.mobile-stage-body .canvas-area,
    body.mobile-stage-tattoo .canvas-area {
        display: none;
    }

    body.mobile-stage-body .sidebar-header,
    body.mobile-stage-body .sidebar-footer,
    body.mobile-stage-tattoo .sidebar-header,
    body.mobile-stage-tattoo .sidebar-footer {
        display: none;
    }

    body.mobile-stage-body .sidebar-content .step-card,
    body.mobile-stage-tattoo .sidebar-content .step-card {
        display: none;
    }

    body.mobile-stage-body #stepCard1,
    body.mobile-stage-tattoo #stepCard2 {
        display: block;
    }

    body.mobile-stage-body .sidebar,
    body.mobile-stage-tattoo .sidebar {
        border: 1px solid var(--line);
        border-radius: var(--radius-lg);
        background: var(--surface);
        box-shadow: var(--shadow-sm);
    }

    body.mobile-stage-body .sidebar-content,
    body.mobile-stage-tattoo .sidebar-content {
        padding: 0.7rem;
    }

    body.mobile-stage-editor .sidebar {
        display: none;
    }

    body.mobile-stage-editor .canvas-area {
        display: grid;
        height: calc(100vh - 86px);
        min-height: calc(100vh - 86px);
        padding: 0.52rem;
    }

    body.mobile-stage-editor .canvas-column {
        height: 100%;
        align-items: stretch;
    }

    body.mobile-stage-editor .canvas-wrapper {
        height: calc(100vh - 214px);
        min-height: 0;
    }

    body.mobile-stage-editor .mobile-action-bar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.48rem;
        margin-top: 0.45rem;
    }

    body.mobile-stage-editor .mobile-action-bar .btn {
        height: 2.25rem;
    }

    body.mobile-stage-editor #mobileClearButton {
        min-width: 118px;
    }
}

@media (max-width: 680px) {
    .app-bar-container {
        min-height: 66px;
    }

    .logo-img {
        max-width: 162px;
    }

    .main-layout {
        margin-top: 0.5rem;
        padding: 0 0.55rem 0.6rem;
        gap: 0.6rem;
    }

    .canvas-area,
    .sidebar {
        border-radius: var(--radius-md);
    }

    .canvas-wrapper {
        min-height: 360px;
        height: calc(100vh - 222px);
    }

    .floating-controls {
        width: 100%;
        border-radius: var(--radius-sm);
        flex-direction: column;
        align-items: stretch;
        gap: 0.44rem;
    }

    .floating-control-group {
        justify-content: space-between;
    }

    .mini-slider {
        flex: 1;
    }

    .ad-sticky-bottom {
        height: 60px;
    }

    body.mobile-stage-editor .canvas-area {
        height: calc(100vh - 78px);
        min-height: calc(100vh - 78px);
        padding: 0.45rem;
    }

    body.mobile-stage-editor .canvas-wrapper {
        height: calc(100vh - 222px);
        min-height: 0;
    }

    body.mobile-stage-editor .floating-controls {
        margin-top: 0.4rem;
        padding: 0.4rem 0.45rem;
    }

    body.mobile-stage-editor .mobile-action-bar {
        margin-top: 0.42rem;
        gap: 0.42rem;
    }
}
