:root {
    --bg: #f4efe7;
    --bg-soft: #fbf9f5;
    --panel: #fffdf8;
    --line: #d4c6b1;
    --text: #2c231a;
    --muted: #746557;
    --primary: #1e6f5c;
    --primary-dark: #145040;
    --accent: #c97b34;
    --danger: #9e3d2f;
    --success: #2f7d4f;
    --shadow: 0 18px 50px rgba(50, 36, 21, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top right, rgba(201, 123, 52, 0.18), transparent 28%),
        linear-gradient(180deg, #efe6d9 0%, #f7f2ea 35%, #efe8de 100%);
}

body.is-loading {
    overflow: hidden;
}

code {
    font-family: "SFMono-Regular", Consolas, monospace;
}

.splash-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    padding: 24px;
    transition: opacity 0.55s ease, visibility 0.55s ease, transform 0.55s ease;
}

.splash-screen.is-hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(1.02);
}

.splash-backdrop {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(201, 123, 52, 0.3), transparent 28%),
        radial-gradient(circle at 80% 18%, rgba(30, 111, 92, 0.28), transparent 24%),
        linear-gradient(135deg, #1a3029 0%, #28483f 26%, #f0e0c7 100%);
}

.splash-content {
    position: relative;
    z-index: 1;
    width: min(980px, 100%);
    display: grid;
    justify-items: center;
    text-align: center;
    gap: 10px;
    align-items: center;
    padding: 0 12px;
}

.splash-portrait-frame {
    width: min(70vw, 520px);
    max-width: 100%;
    height: min(56vh, 620px);
    display: grid;
    place-items: center;
}

.splash-portrait {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    object-position: center;
    filter: drop-shadow(0 26px 36px rgba(0, 0, 0, 0.2));
}

.splash-portrait.is-missing {
    opacity: 0;
}
.splash-copy {
    color: #fff8ee;
    display: grid;
    justify-items: center;
    margin-top: -8px;
}

.splash-kicker {
    margin: 0 0 10px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.72rem;
    color: rgba(255, 248, 238, 0.76);
}

.splash-copy h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.4rem);
    line-height: 0.95;
}

.splash-copy h2 {
    margin: 10px 0 0;
    font-size: clamp(1.05rem, 2vw, 1.6rem);
    font-weight: 500;
    color: #f2d5ae;
}

.splash-loader {
    margin-top: 16px;
    min-height: 52px;
    display: grid;
    place-items: center;
}

.loading-dots {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.loading-dots span {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: linear-gradient(180deg, #f6d2a3 0%, #c97b34 100%);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
    animation: splash-dot 1.15s infinite ease-in-out;
}

.loading-dots span:nth-child(2) {
    animation-delay: 0.16s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0.32s;
}

.splash-status {
    margin: 4px 0 0;
    color: rgba(255, 248, 238, 0.82);
    font-size: 0.95rem;
}

.app-shell {
    width: min(1380px, calc(100% - 32px));
    margin: 24px auto 40px;
}

.hero {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: end;
    margin-bottom: 20px;
}

.eyebrow {
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.75rem;
    color: var(--muted);
}

.hero h1 {
    margin: 0;
    font-size: clamp(2rem, 3vw, 3.1rem);
}

.lead {
    max-width: 760px;
    color: var(--muted);
}

.hero-card {
    min-width: 280px;
    padding: 18px 20px;
    border: 1px solid rgba(44, 35, 26, 0.08);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow);
}

.hero-card span {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 6px;
}

.grid {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 20px;
}

.panel {
    background: var(--panel);
    border: 1px solid rgba(44, 35, 26, 0.08);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: 22px;
}

.stack {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
}

.field {
    display: grid;
    gap: 8px;
}

.field span,
.panel h2,
.panel h3 {
    margin: 0;
}

.field input[type="file"],
.field select {
    width: 100%;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
}

.btn {
    border: 0;
    border-radius: 999px;
    padding: 12px 16px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

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

.btn.primary {
    background: var(--primary);
    color: #fff;
}

.btn.secondary {
    background: var(--accent);
    color: #fff;
}

.btn.tertiary,
.btn.ghost {
    background: #f3ede3;
    color: var(--text);
}

.btn.success {
    background: var(--success);
    color: #fff;
}

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

.flash {
    border-radius: 18px;
    padding: 14px 18px;
    margin-bottom: 18px;
    font-weight: 600;
}

.flash-success {
    background: rgba(47, 125, 79, 0.12);
    color: #18502f;
}

.flash-error {
    background: rgba(158, 61, 47, 0.12);
    color: #6f251c;
}

.info-box,
.download-box {
    margin-top: 18px;
    padding: 16px;
    border-radius: 18px;
    background: var(--bg-soft);
    border: 1px solid rgba(44, 35, 26, 0.06);
}

.viewer-header,
.placements-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.viewer-header p {
    margin: 6px 0 0;
    color: var(--muted);
}

.page-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.toolbar {
    display: flex;
    gap: 12px;
    margin: 16px 0;
    flex-wrap: wrap;
}

.sign-form {
    display: grid;
    gap: 14px;
}

.mobile-tip {
    display: none;
    margin: 0;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(30, 111, 92, 0.08);
    color: var(--primary-dark);
    font-size: 0.92rem;
    line-height: 1.4;
}

.viewer-stage {
    position: relative;
    border-radius: 24px;
    overflow: hidden;
    background: #eadfcf;
    min-height: 560px;
    border: 1px dashed rgba(44, 35, 26, 0.16);
    padding: 14px;
}

.pdf-wrapper {
    position: relative;
    margin: 0 auto;
    width: fit-content;
    max-width: 100%;
}

#pdfCanvas {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    background: #fff;
}

#signatureLayer {
    position: absolute;
    inset: 0;
}

.signature-box {
    position: absolute;
    border: 2px dashed rgba(30, 111, 92, 0.9);
    border-radius: 12px;
    overflow: visible;
    cursor: move;
    background: rgba(30, 111, 92, 0.08);
    touch-action: none;
    min-width: 56px;
    min-height: 26px;
}

.signature-box.active {
    box-shadow: 0 0 0 4px rgba(30, 111, 92, 0.18);
}

.signature-box img {
    display: block;
    width: 100%;
    height: 100%;
    user-select: none;
    pointer-events: none;
}

.resize-handle {
    position: absolute;
    right: -10px;
    bottom: -10px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid #fff;
    cursor: nwse-resize;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.empty-state {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    text-align: center;
    gap: 8px;
    color: var(--muted);
}

.hidden {
    display: none;
}

.placements-panel {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid rgba(44, 35, 26, 0.08);
}

.placements-list {
    list-style: none;
    padding: 0;
    margin: 16px 0 0;
    display: grid;
    gap: 10px;
}

.placements-list li {
    padding: 12px 14px;
    border-radius: 16px;
    background: var(--bg-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.placements-meta strong,
.placements-meta span {
    display: block;
}

.placements-meta span {
    color: var(--muted);
    font-size: 0.88rem;
}

.text-btn {
    border: 0;
    background: transparent;
    color: var(--danger);
    font-weight: 700;
    cursor: pointer;
}

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

    .hero {
        flex-direction: column;
        align-items: start;
    }
}

@media (max-width: 640px) {
    .splash-screen {
        padding: 14px;
    }

    .splash-content {
        gap: 6px;
        padding: 0 8px;
    }

    .splash-portrait-frame {
        width: min(88vw, 420px);
        height: min(48vh, 480px);
    }

    .app-shell {
        width: min(100% - 20px, 1380px);
        margin-top: 10px;
    }

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

    .viewer-stage {
        min-height: 320px;
        padding: 10px;
        border-radius: 18px;
    }

    .viewer-header,
    .placements-header {
        flex-direction: column;
        align-items: start;
    }

    .viewer-header {
        gap: 10px;
    }

    .mobile-tip {
        display: block;
    }

    .page-controls,
    .toolbar {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
    }

    .page-controls .btn,
    .toolbar .btn {
        width: 100%;
        min-height: 48px;
    }

    #pageIndicator {
        width: 100%;
        text-align: center;
        padding: 6px 0;
        font-weight: 700;
    }

    .pdf-wrapper {
        width: 100%;
        overflow: hidden;
    }

    #pdfCanvas {
        width: 100%;
    }

    #signatureLayer {
        overflow: hidden;
    }

    .signature-box {
        border-width: 3px;
        border-radius: 14px;
    }

    .resize-handle {
        right: -12px;
        bottom: -12px;
        width: 30px;
        height: 30px;
    }

    .placements-list li {
        align-items: flex-start;
        flex-direction: column;
    }

    .placements-list li > div:last-child {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .text-btn,
    .placements-list .btn {
        min-height: 42px;
        border-radius: 12px;
    }

    .text-btn {
        background: rgba(158, 61, 47, 0.08);
    }
}

@media (max-width: 420px) {
    .hero h1 {
        font-size: 1.8rem;
    }

    .panel h2,
    .panel h3 {
        font-size: 1.05rem;
    }

    .field input[type="file"],
    .field select,
    .btn {
        font-size: 0.92rem;
    }
}

@keyframes splash-dot {
    0% {
        transform: translateY(0) scale(0.85);
        opacity: 0.45;
    }

    35% {
        transform: translateY(-7px) scale(1.05);
        opacity: 1;
    }

    100% {
        transform: translateY(0) scale(0.85);
        opacity: 0.45;
    }
}
