:root {
    color-scheme: dark;
    --bg: #101317;
    --panel: #1b2229;
    --panel-soft: #232b34;
    --text: #f4f7f8;
    --muted: #b4c0c7;
    --line: #37434d;
    --canvas: #fbfaf5;
    --primary: #1f9f8b;
    --primary-dark: #137667;
    --warning: #d7a53a;
    --danger: #b54747;
    --danger-dark: #8f3535;
}

* {
    box-sizing: border-box;
}

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

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

a {
    color: inherit;
}

.shell,
.terminal {
    min-height: 100vh;
}

.terminal {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.home {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.panel {
    width: min(720px, 100%);
    padding: 28px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.panel h1,
.waiting-view h1,
.details-pane h1 {
    margin: 0;
    line-height: 1.05;
    letter-spacing: 0;
}

.panel p,
.subtitle,
.notice,
.form-status {
    color: var(--muted);
}

.kicker {
    margin: 0 0 12px;
    color: var(--warning);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.home-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 26px;
}

.signature-layout {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
    gap: 18px;
    padding: 18px;
    overflow: hidden;
}

.details-pane {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 22px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: auto;
    overscroll-behavior: contain;
}

.details-pane h1 {
    font-size: clamp(1.55rem, 2.6vw, 2.45rem);
}

.subtitle {
    margin: 0;
    font-size: 1.05rem;
}

.details-list {
    display: grid;
    gap: 10px;
    margin: 6px 0 0;
}

.details-list div {
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}

.details-list dt {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
}

.details-list dd {
    margin: 4px 0 0;
    overflow-wrap: anywhere;
    font-size: 1.02rem;
}

.notice {
    margin: auto 0 0;
    padding: 12px;
    background: var(--panel-soft);
    border-left: 4px solid var(--warning);
    border-radius: 6px;
}

.signature-pad {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto auto;
    gap: 14px;
    overflow: hidden;
}

.canvas-frame {
    min-width: 0;
    min-height: 0;
    position: relative;
    overflow: hidden;
    border: 2px solid #d7d0c0;
    border-radius: 8px;
    background: var(--canvas);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

#signatureCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: block;
    background: var(--canvas);
    border: 0;
    border-radius: 6px;
    touch-action: none;
}

.toolbar {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.button {
    min-height: 58px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    border: 0;
    border-radius: 8px;
    color: #ffffff;
    font: inherit;
    font-size: 1.05rem;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
}

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

.button.primary {
    background: var(--primary);
}

.button.primary:not(:disabled):active {
    background: var(--primary-dark);
}

.button.secondary {
    background: #4a5561;
}

.button.danger {
    background: var(--danger);
}

.button.danger:active {
    background: var(--danger-dark);
}

.form-status {
    position: relative;
    z-index: 2;
    min-height: 24px;
    margin: 0;
}

.screen-app {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

.waiting-view {
    min-height: 100vh;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 14px;
    padding: 24px;
    text-align: center;
}

.waiting-view h1 {
    max-width: 760px;
    font-size: clamp(2rem, 6vw, 4.5rem);
}

.pulse {
    width: 74px;
    height: 74px;
    border: 5px solid rgba(31, 159, 139, 0.28);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1.4s linear infinite;
}

.hidden {
    display: none !important;
}

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

@media (max-width: 780px) {
    .signature-layout {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 34dvh) minmax(0, 1fr);
        padding: 12px;
        gap: 12px;
    }

    .details-pane {
        max-height: none;
        padding: 16px;
    }

    .details-pane h1 {
        font-size: 1.45rem;
    }

    .signature-pad {
        grid-template-rows: minmax(0, 1fr) auto auto;
    }

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

    .button {
        min-height: 54px;
    }
}

@media (orientation: landscape) and (max-height: 560px) {
    .signature-layout {
        grid-template-columns: minmax(220px, 34vw) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr);
        gap: 10px;
        padding: 10px;
    }

    .details-pane {
        gap: 8px;
        padding: 12px;
    }

    .details-pane h1 {
        font-size: 1.2rem;
    }

    .subtitle,
    .details-list dd {
        font-size: 0.92rem;
    }

    .details-list {
        gap: 6px;
    }

    .details-list div {
        padding-bottom: 6px;
    }

    .notice {
        margin-top: 0;
        padding: 8px;
        font-size: 0.86rem;
    }

    .signature-pad {
        gap: 8px;
    }

    .toolbar {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .button {
        min-height: 46px;
        padding: 8px 10px;
        font-size: 0.95rem;
    }

    .form-status {
        min-height: 18px;
        font-size: 0.85rem;
    }
}
