:root {
    --bg: #f6f2ea;
    --card: #ffffff;
    --text: #161616;
    --muted: #646464;
    --line: #ded7cc;
    --accent: #2f6f5e;
    --accent-dark: #225244;
    --danger: #9b2c2c;
    --guide: #db6532;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app-shell {
    width: min(1500px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0;
}

.hero,
.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 12px 35px rgba(0,0,0,.06);
}

.hero {
    padding: 34px;
    margin-bottom: 18px;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--accent);
    font-weight: 700;
    margin: 0 0 8px;
}

h1 {
    max-width: 920px;
    font-size: clamp(30px, 4vw, 54px);
    line-height: 1.03;
    margin: 0;
}

h2 {
    margin: 0 0 16px;
    font-size: 20px;
}

h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.lead {
    max-width: 820px;
    color: var(--muted);
    font-size: 18px;
    margin-bottom: 0;
}

.upload-panel,
.panel {
    padding: 22px;
}

input[type="file"],
input[type="number"],
input[type="range"],
select {
    width: 100%;
}

select,
input[type="number"] {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 9px 10px;
    background: white;
}

button,
.json-upload {
    border: 0;
    border-radius: 999px;
    padding: 12px 18px;
    background: var(--accent);
    color: white;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

button:hover,
.json-upload:hover { background: var(--accent-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }

.json-upload input {
    display: none;
}

.small-btn {
    padding: 8px 12px;
    font-size: 12px;
}

.help {
    color: var(--muted);
    font-size: 14px;
}

.editor {
    display: grid;
    grid-template-columns: 440px 1fr;
    gap: 18px;
    margin-top: 18px;
}

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

.controls {
    align-self: start;
}

.tool-section {
    display: grid;
    gap: 10px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 18px;
}

.tool-section label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 14px;
}

.inline-check {
    display: flex !important;
    grid-template-columns: none !important;
    align-items: center;
    gap: 8px;
}

.inline-check input {
    width: auto;
}

.zoom-row,
.zoom-meta,
.project-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.zoom-row input {
    flex: 1;
}

.zoom-meta {
    justify-content: space-between;
    color: var(--muted);
    font-weight: 700;
}

.layer-card {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    margin-bottom: 12px;
    background: #fbfaf7;
}

.layer-card-header {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 10px;
}

.layer-card strong {
    display: block;
    word-break: break-word;
}

.layer-card label {
    display: grid;
    grid-template-columns: 90px 1fr 42px;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
    color: var(--muted);
    font-size: 14px;
}

.field-grid,
.crop-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

.field-grid label,
.crop-grid label {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    align-items: start;
}

.crop-title {
    margin-top: 14px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.layer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.layer-actions-secondary {
    margin-top: 10px;
    justify-content: flex-start;
}

.render-btn {
    width: 100%;
    margin-top: 10px;
}

.stage-wrap {
    overflow: auto;
}

.stage-scroll {
    position: relative;
    overflow: auto;
    min-height: 520px;
}

.stage {
    width: 1600px;
    height: 1000px;
    position: relative;
    overflow: hidden;
    background:
        linear-gradient(45deg, #e5e5e5 25%, transparent 25%),
        linear-gradient(-45deg, #e5e5e5 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e5e5e5 75%),
        linear-gradient(-45deg, transparent 75%, #e5e5e5 75%);
    background-size: 28px 28px;
    background-position: 0 0, 0 14px, 14px -14px, -14px 0;
    border: 2px dashed #bdb5aa;
    transform-origin: top left;
}

.layer {
    position: absolute;
    user-select: none;
    cursor: move;
    outline: 2px solid rgba(47,111,94,.35);
    border-radius: 10px;
}

.layer-content {
    position: absolute;
    left: 50%;
    top: 50%;
    overflow: hidden;
    transform-origin: center center;
    pointer-events: none;
}

.layer img {
    position: absolute;
    object-fit: fill;
    display: block;
    pointer-events: none;
}

.layer-badge {
    position: absolute;
    left: 8px;
    top: 8px;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(34, 82, 68, .92);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.resize-handle,
.rotate-handle {
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
}

.resize-handle {
    right: -9px;
    bottom: -9px;
    cursor: nwse-resize;
}

.rotate-handle {
    left: 50%;
    top: -26px;
    margin-left: -9px;
    cursor: grab;
}

.guide {
    position: absolute;
    z-index: 9999;
    display: none;
    pointer-events: none;
    background: var(--guide);
    box-shadow: 0 0 0 1px rgba(255,255,255,.9);
}

.guide.is-visible {
    display: block;
}

.guide-v {
    top: 0;
    width: 2px;
    height: 100%;
}

.guide-h {
    left: 0;
    width: 100%;
    height: 2px;
}

#result {
    margin-top: 14px;
    color: var(--muted);
}

#result a {
    display: inline-block;
    margin-top: 8px;
    color: var(--accent);
    font-weight: 700;
}

.error { color: var(--danger); }

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

    .stage-scroll {
        min-height: 420px;
    }
}

@media (max-width: 640px) {
    .app-shell {
        width: min(100%, calc(100% - 20px));
    }

    .hero,
    .panel,
    .upload-panel {
        padding: 18px;
    }

    .field-grid,
    .crop-grid {
        grid-template-columns: 1fr;
    }

    .layer-card-header,
    .layer-actions,
    .zoom-row,
    .zoom-meta,
    .project-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .layer-card label {
        grid-template-columns: 1fr;
    }
}
