* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    touch-action: manipulation;
    overscroll-behavior-x: none;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: Inter, Arial, sans-serif;
    background: radial-gradient(circle at top left, #dff7ff 0, #f6fbff 35%, #eef4f8 100%);
    color: #102330;
}

.page {
    width: min(1180px, calc(100% - 28px));
    max-width: 100%;
    margin: 0 auto;
    padding: 22px 0 40px;
    overflow-x: hidden;
}

.hero {
    min-height: 170px;
    display: flex;
    align-items: center;
    padding: 24px 28px;
    border-radius: 28px;
    background: radial-gradient(circle at 85% 20%, rgba(54,212,199,.9), transparent 34%), linear-gradient(135deg, #06364a, #0b7fa3 58%, #18c8b8);
    color: #fff;
    box-shadow: 0 22px 60px rgba(3, 43, 62, .18);
}

.hero-link {
    text-decoration: none;
    color: #fff;
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease;
}

.hero-link:active {
    transform: scale(.99);
}

.brandline {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 6px 16px;
    border-radius: 999px;
    background: rgba(255,255,255,.18);
    border: 1px solid rgba(255,255,255,.28);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    font-weight: 950;
    letter-spacing: -.8px;
    text-transform: lowercase;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.22);
}

.brand-by {
    color: rgba(255,255,255,.8);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .3px;
    text-transform: uppercase;
}

.badge {
    width: fit-content;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    border: 1px solid rgba(255,255,255,.22);
    margin-bottom: 12px;
    font-size: 12px;
    font-weight: 700;
}

.hero h1 {
    max-width: 760px;
    margin: 0 0 10px;
    font-size: clamp(24px, 3.5vw, 42px);
    line-height: 1.02;
    letter-spacing: -1px;
}

.hero p {
    max-width: 720px;
    margin: 0;
    font-size: 14px;
    line-height: 1.45;
    color: rgba(255,255,255,.78);
}

.stats {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    margin-top: 16px;
}

.stats div {
    padding: 14px;
    border-radius: 18px;
    background: rgba(255,255,255,.84);
    border: 1px solid rgba(9,78,105,.08);
    box-shadow: 0 12px 30px rgba(21,60,78,.06);
}

.stats strong {
    display: block;
    font-size: 22px;
    line-height: 1;
}

.stats span {
    display: block;
    margin-top: 5px;
    color: #607887;
    font-size: 12px;
    font-weight: 800;
}

.panel {
    margin-top: 22px;
    padding: 24px;
    border-radius: 28px;
    background: rgba(255,255,255,.82);
    border: 1px solid rgba(9,78,105,.08);
    box-shadow: 0 18px 50px rgba(21,60,78,.08);
    backdrop-filter: blur(16px);
}

.panel h2 {
    margin: 0 0 16px;
    font-size: 24px;
}

.upload-form {
    display: grid;
    grid-template-columns: 1.2fr 1fr auto;
    gap: 12px;
}

input, select, button {
    width: 100%;
    border: 0;
    border-radius: 18px;
    font-size: 16px;
}

input, select {
    background: #f1f7fa;
    padding: 16px 18px;
    color: #102330;
    outline: 1px solid rgba(9,78,105,.08);
}

button {
    padding: 16px 22px;
    background: linear-gradient(135deg, #0582a8, #18c8b8);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 12px 28px rgba(0,130,168,.22);
}

button.secondary {
    background: #e9f2f6;
    color: #173545;
    box-shadow: none;
}

button.active {
    background: linear-gradient(135deg, #05a87c, #18c8b8);
    color: #fff;
}

button.ai {
    background: linear-gradient(135deg, #163f8f, #6a5cff);
}

button.danger {
    background: linear-gradient(135deg, #d8244a, #ff647c);
    color: #fff;
    box-shadow: 0 12px 28px rgba(216,36,74,.18);
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-head span {
    color: #607887;
    font-weight: 700;
}

.empty {
    padding: 30px;
    border-radius: 22px;
    background: #f4f9fb;
    color: #5e7480;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.card {
    display: block;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    border-radius: 24px;
    background: #fff;
    box-shadow: 0 12px 32px rgba(20,60,80,.08);
}

.card img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    background: #dce8ee;
}

.card-body {
    padding: 14px;
}

.card-body strong, .card-body small, .card-body em {
    display: block;
}

.card-body small {
    margin-top: 5px;
    color: #6b7f8a;
}

.card-body em {
    margin-top: 8px;
    font-style: normal;
    color: #078065;
    font-weight: 800;
}

.topbar {
    height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar-brand {
    gap: 12px;
}

.mini-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 6px 10px 6px 6px;
    border-radius: 999px;
    background: linear-gradient(135deg, #06364a, #0b7fa3 58%, #18c8b8);
    text-decoration: none;
    box-shadow: 0 10px 26px rgba(3,43,62,.16);
}

.mini-brand .brand-logo {
    min-height: 32px;
    padding: 5px 13px;
    font-size: 19px;
}

.mini-brand .brand-by {
    padding-right: 4px;
    font-size: 10px;
    white-space: nowrap;
}

.back-link {
    flex: 0 0 auto;
}

.topbar a {
    color: #0d7798;
    text-decoration: none;
    font-weight: 800;
}

.viewer-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 20px;
}

.viewer-panel, .side-panel {
    border-radius: 28px;
    background: rgba(255,255,255,.86);
    box-shadow: 0 18px 55px rgba(20,60,80,.1);
    border: 1px solid rgba(9,78,105,.08);
}

.viewer-panel {
    padding: 16px;
}

.viewer-tools {
    display: grid;
    grid-template-columns: 1fr 1fr 58px 58px 86px 58px;
    gap: 10px;
    margin-bottom: 12px;
}

.viewer-tools button {
    padding: 12px 10px;
    border-radius: 14px;
}

.side-panel {
    padding: 22px;
}

.side-panel h1 {
    margin: 0 0 8px;
    font-size: 28px;
    line-height: 1.05;
}

.side-panel p {
    margin: 0 0 22px;
    color: #617885;
}

.side-panel label {
    display: block;
    margin-bottom: 8px;
    color: #385464;
    font-weight: 800;
}

.side-panel select, .side-panel button {
    margin-bottom: 12px;
}

.hint {
    margin-top: 10px;
    padding: 14px;
    border-radius: 18px;
    background: #eef8fb;
    color: #45616e;
    line-height: 1.45;
}

#status {
    margin-top: 12px;
    font-weight: 800;
    color: #078065;
}

.image-wrap {
    position: relative;
    width: 100%;
    min-height: 420px;
    overflow: hidden;
    border-radius: 22px;
    background: #06151d;
    touch-action: none;
}

.image-stage {
    position: relative;
    width: 100%;
    transform-origin: 0 0;
}

.image-stage img {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
    pointer-events: none;
}

.image-stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

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

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

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

    .viewer-tools {
        grid-template-columns: 1fr 1fr 52px 52px 78px 52px;
    }

    .side-panel {
        position: sticky;
        bottom: 0;
        z-index: 5;
    }
}

@media (max-width: 520px) {
    .hero {
        min-height: 0;
        padding: 18px;
        border-radius: 22px;
    }

    .brandline {
        margin-bottom: 12px;
    }

    .brand-logo {
        min-height: 34px;
        padding: 5px 14px;
        font-size: 20px;
    }

    .brand-by {
        font-size: 10px;
    }

    .mini-brand {
        max-width: calc(100vw - 112px);
    }

    .mini-brand .brand-by {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .hero h1 {
        font-size: 24px;
        margin-bottom: 8px;
    }

    .hero p {
        font-size: 12px;
        line-height: 1.35;
    }

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

    .panel {
        padding: 16px;
        border-radius: 24px;
    }

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

    .viewer-panel, .side-panel {
        border-radius: 22px;
    }

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

    .side-panel h1 {
        font-size: 22px;
    }

    .image-wrap {
        min-height: 300px;
    }
}

button.danger {
    background: linear-gradient(135deg, #d8244a, #ff647c);
    color: #fff;
    box-shadow: 0 12px 28px rgba(216,36,74,.18);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.toolbar a,
.download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 12px 18px;
    border-radius: 16px;
    background: #e9f2f6;
    color: #173545;
    text-decoration: none;
    font-weight: 900;
}

.toolbar a.active-link {
    background: linear-gradient(135deg, #05a87c, #18c8b8);
    color: #fff;
}

.toolbar a.primary-link {
    background: linear-gradient(135deg, #0582a8, #18c8b8);
    color: #fff;
}

.toolbar a.export-link,
.download-btn {
    background: linear-gradient(135deg, #163f8f, #6a5cff);
    color: #fff;
}

@media (max-width: 900px) {
    .viewer-layout {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    .viewer-panel {
        order: 1;
    }

    .side-panel {
        order: 2;
        position: static !important;
        bottom: auto !important;
        z-index: auto !important;
    }

    .image-wrap {
        min-height: 0 !important;
        height: auto !important;
        overflow: hidden;
    }

    .image-stage {
        display: block;
    }

    .viewer-tools {
        position: static !important;
        display: grid;
        grid-template-columns: 1fr 1fr 52px 52px 78px;
        gap: 8px;
        margin-bottom: 10px;
    }
}

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

    .viewer-tools button {
        min-height: 46px;
        font-size: 14px;
        padding: 10px 8px;
    }

    .side-panel {
        margin-top: 0;
    }
}

@media (max-width: 900px) {
    .stats {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 520px) {
    .hero {
        min-height: 0;
        padding: 18px;
        border-radius: 22px;
    }

    .hero h1 {
        font-size: 24px;
        margin-bottom: 8px;
    }

    .hero p {
        font-size: 12px;
        line-height: 1.35;
    }

    .stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stats div {
        padding: 12px;
        border-radius: 16px;
    }

    .stats strong {
        font-size: 18px;
    }

    .stats span {
        font-size: 11px;
    }
}

.upload-form-advanced {
    grid-template-columns: 1fr 150px 180px 1fr auto;
}

.checkline {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 54px;
    padding: 0 14px;
    border-radius: 18px;
    background: #f1f7fa;
    color: #173545;
    font-weight: 900;
}

.checkline input {
    width: auto;
}

.title-edit {
    display: grid;
    grid-template-columns: 1fr 58px;
    gap: 8px;
    margin-bottom: 8px;
}

.title-edit input {
    font-size: 22px;
    font-weight: 900;
    padding: 12px 14px;
}

.title-edit button {
    padding: 10px;
}

.toggles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 4px 0 12px;
}

.toggles label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 14px;
    background: #eef8fb;
    font-size: 13px;
    font-weight: 900;
    color: #173545;
}

.toggles input {
    width: auto;
}

@media (max-width: 900px) {
    .upload-form-advanced {
        grid-template-columns: 1fr 1fr;
    }

    .upload-form-advanced button,
    .upload-form-advanced input[type="file"] {
        grid-column: 1 / -1;
    }
}

@media (max-width: 520px) {
    .upload-form-advanced {
        grid-template-columns: 1fr;
    }

    .checkline {
        min-height: 48px;
    }

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

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


.viewer-layout,
.viewer-panel,
.side-panel,
.viewer-tools,
.image-wrap,
.image-stage,
canvas,
img {
    max-width: 100%;
}

@media (max-width: 900px) {

    html,
    body {
        position: relative;
        overflow-x: hidden !important;
    }

    .viewer-layout {
        overflow-x: hidden;
    }

    .viewer-panel {
        overflow-x: hidden;
    }

    .image-wrap {
        overflow: hidden !important;
        touch-action: none;
    }

    .image-stage {
        max-width: 100%;
        transform-origin: top left;
    }

    .viewer-tools {
        width: 100%;
    }

    .viewer-tools button {
        user-select: none;
        -webkit-user-select: none;
        touch-action: manipulation;
    }
}

html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
    touch-action: pan-y !important;
    overscroll-behavior-x: none !important;
}

body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
    touch-action: pan-y !important;
    overscroll-behavior-x: none !important;
}

.page {
    width: 100% !important;
    max-width: 1180px !important;
    padding-left: 14px !important;
    padding-right: 14px !important;
    overflow-x: hidden !important;
}

.hero,
.stats,
.panel,
.viewer-layout,
.viewer-panel,
.side-panel,
.viewer-tools,
.image-wrap,
.image-stage,
.grid,
.toolbar,
.upload-form,
.upload-form-advanced {
    max-width: 100% !important;
    overflow-x: hidden !important;
}

img,
canvas {
    max-width: 100% !important;
}

@media (max-width: 900px) {
    html,
    body {
        position: fixed !important;
        inset: 0 !important;
        overflow: hidden !important;
        height: 100% !important;
        max-height: 100% !important;
    }

    body {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .page {
        width: 100vw !important;
        max-width: 100vw !important;
        padding-left: 10px !important;
        padding-right: 10px !important;
        overflow-x: hidden !important;
    }

    .viewer-tools {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }

    .viewer-tools button {
        min-width: 0 !important;
        max-width: 100% !important;
        touch-action: manipulation !important;
    }

    .image-wrap {
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden !important;
        touch-action: none !important;
    }

    .image-stage {
        width: 100% !important;
        max-width: 100% !important;
        will-change: transform;
    }

    .side-panel {
        width: 100% !important;
        max-width: 100% !important;
    }
}

.pwa-install-box {
    position: fixed;
    left: 14px;
    right: 14px;
    bottom: 18px;
    z-index: 99999;
    display: grid;
    gap: 6px;
    padding: 16px;
    border-radius: 22px;
    background: rgba(255,255,255,.94);
    box-shadow: 0 18px 60px rgba(10,40,60,.22);
    border: 1px solid rgba(9,78,105,.12);
    backdrop-filter: blur(18px);
}

.pwa-install-box strong {
    font-size: 18px;
    color: #102330;
}

.pwa-install-box span {
    font-size: 14px;
    color: #607887;
}

.pwa-install-box button {
    margin-top: 8px;
}


.viewer-fullscreen-mode {
    overflow: hidden !important;
}

.viewer-fullscreen-mode .topbar,
.viewer-fullscreen-mode .side-panel {
    display: none !important;
}

.viewer-fullscreen-mode .page {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    padding: 8px !important;
    margin: 0 !important;
}

.viewer-fullscreen-mode .viewer-layout {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
}

.viewer-fullscreen-mode .viewer-panel {
    width: 100% !important;
    height: calc(100vh - 16px) !important;
    padding: 8px !important;
    border-radius: 18px !important;
}

.viewer-fullscreen-mode .viewer-tools {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    top: 10px !important;
    z-index: 9999 !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr 46px 46px 68px 46px 46px !important;
    gap: 6px !important;
    padding: 6px !important;
    border-radius: 18px !important;
    background: rgba(255,255,255,.78) !important;
    backdrop-filter: blur(18px) !important;
    box-shadow: 0 12px 34px rgba(8,40,60,.14) !important;
}

.viewer-fullscreen-mode .viewer-tools button {
    min-height: 42px !important;
    padding: 8px 6px !important;
    border-radius: 13px !important;
    font-size: 13px !important;
}

.viewer-fullscreen-mode .image-wrap {
    width: 100% !important;
    height: calc(100vh - 32px) !important;
    min-height: 0 !important;
    border-radius: 16px !important;
    background: #031018 !important;
}

.viewer-fullscreen-mode .image-stage {
    margin-top: 68px !important;
}

@media (max-width: 620px) {
    .viewer-fullscreen-mode .viewer-tools {
        grid-template-columns: 1fr 1fr 42px 42px 62px 42px 42px !important;
    }

    .viewer-fullscreen-mode .viewer-tools button {
        font-size: 12px !important;
        min-height: 40px !important;
    }
}