:root {
    --ink: #16324f;
    --muted: #64748b;
    --surface: #ffffff;
    --background: #edf3f8;
    --line: #cbd5e1;
    --primary: #1769aa;
    --primary-dark: #0f4f82;
    --radius: 22px;
    --shadow: 0 18px 45px rgba(22, 50, 79, .14);
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 0%, rgba(23, 105, 170, .12), transparent 34%),
        var(--background);
}

button,
input {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

.signature-card {
    width: min(100%, 680px);
    padding: clamp(20px, 5vw, 34px);
    background: var(--surface);
    border: 1px solid rgba(148, 163, 184, .35);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    margin-bottom: 24px;
}

.eyebrow {
    display: inline-block;
    margin-bottom: 7px;
    color: var(--primary);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .09em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(1.75rem, 7vw, 2.45rem);
    line-height: 1.08;
}

.card-header p {
    margin: 10px 0 0;
    color: var(--muted);
    line-height: 1.55;
}

.form-nav {
    margin-top: 16px;
}

.form-nav a {
    min-height: 44px;
    padding: 10px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-dark);
    background: #edf6fc;
    border: 1px solid #b9d8ee;
    border-radius: 12px;
    font-size: .9rem;
    font-weight: 850;
    text-decoration: none;
}

.form-nav a:focus-visible {
    outline: 3px solid rgba(23, 105, 170, .25);
    outline-offset: 2px;
}

.field-group {
    margin-bottom: 24px;
}

label,
legend {
    font-weight: 800;
}

label {
    display: block;
    margin-bottom: 8px;
}

input[type="text"] {
    width: 100%;
    min-height: 52px;
    padding: 12px 14px;
    color: var(--ink);
    background: #fff;
    border: 2px solid var(--line);
    border-radius: 14px;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}

input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(23, 105, 170, .13);
}

small {
    display: block;
    margin-top: 7px;
    color: var(--muted);
}

.signature-fieldset,
.photo-fieldset {
    margin: 0;
    padding: 0;
    border: 0;
}

.signature-fieldset legend,
.photo-fieldset legend {
    margin-bottom: 10px;
}

.canvas-frame {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: #fff;
    border: 2px dashed #94a3b8;
    border-radius: 14px;
    touch-action: none;
    overscroll-behavior: contain;
}

#signatureCanvas {
    display: block;
    width: 100%;
    height: auto;
    background: #fff;
    cursor: crosshair;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.canvas-placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    pointer-events: none;
    color: #94a3b8;
    font-weight: 700;
    transition: opacity .15s;
}

.canvas-placeholder.hidden {
    opacity: 0;
}

.canvas-size {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: .85rem;
    text-align: right;
}

.photo-fieldset {
    margin-top: 26px;
    padding-top: 24px;
    border-top: 1px solid #e2e8f0;
}

.optional-text {
    color: var(--muted);
    font-size: .85em;
    font-weight: 650;
}

.field-help {
    margin: -2px 0 14px;
    color: var(--muted);
    line-height: 1.45;
}

.photo-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.photo-action-button {
    min-height: 52px;
    margin: 0;
    padding: 12px 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--primary-dark);
    background: #eef6fc;
    border: 2px solid #b9d8ee;
    border-radius: 14px;
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: transform .15s, border-color .15s, background-color .15s;
}

.photo-action-button:hover,
.photo-action-button:focus-within {
    background: #e2f1fb;
    border-color: var(--primary);
}

.photo-action-button:active {
    transform: scale(.98);
}

.photo-action-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.visually-hidden-file {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.photo-preview-box {
    margin-top: 14px;
    padding: 10px;
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    background: #f8fafc;
    border: 1px solid #dbe4ec;
    border-radius: 14px;
}

.photo-preview-box[hidden] {
    display: none;
}

.photo-preview {
    display: block;
    width: 92px;
    height: 92px;
    object-fit: cover;
    background: #e2e8f0;
    border-radius: 11px;
}

.photo-preview-data {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
}

.photo-preview-data span {
    max-width: 100%;
    color: var(--muted);
    font-size: .84rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.remove-photo-button {
    padding: 0;
    color: #9f2936;
    background: transparent;
    border: 0;
    font-size: .86rem;
    font-weight: 800;
    cursor: pointer;
}

.button-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 26px;
}

.button {
    min-height: 52px;
    padding: 12px 18px;
    border: 0;
    border-radius: 14px;
    font-weight: 850;
    cursor: pointer;
    transition: transform .15s, opacity .15s, background-color .15s;
}

.button:active {
    transform: scale(.98);
}

.button:disabled {
    opacity: .6;
    cursor: wait;
}

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

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

.button-secondary {
    color: var(--ink);
    background: #e8eef4;
}

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

@media (min-width: 560px) {
    .button-row {
        grid-template-columns: .8fr 1.2fr;
    }
}
