:root {
    --red: #d71920;
    --red-dark: #9f1118;
    --red-soft: #fff0f1;
    --ink: #101b2b;
    --ink-soft: #5c6878;
    --paper: #ffffff;
    --canvas: #f2f4f7;
    --line: #dce1e8;
    --line-strong: #b9c1cc;
    --blue: #174a78;
    --error: #b42318;
    --display: Georgia, 'Times New Roman', serif;
    --body: Inter, 'Helvetica Neue', Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --utility: 'Arial Narrow', Arial, sans-serif;
    --radius: 4px;
    --shadow: 0 24px 70px rgba(17, 27, 43, .12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: var(--body); line-height: 1.55; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 100; top: 12px; left: 12px; padding: 10px 14px; color: white; background: var(--ink); }
:focus-visible { outline: 3px solid #1f6fa9; outline-offset: 3px; }

.site-header { min-height: 88px; padding: 13px max(24px, calc((100vw - 1320px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 24px; background: var(--paper); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; }
.brand img { width: 200px; height: auto; display: block; }
.header-meta { padding-left: 22px; display: grid; border-left: 1px solid var(--line); text-align: right; }
.header-meta span { color: var(--ink-soft); font: 700 .69rem/1.2 var(--utility); letter-spacing: .1em; text-transform: uppercase; }
.header-meta strong { font-family: var(--display); font-size: 1.02rem; }

main { width: min(1320px, 100%); margin: 0 auto; }
.intro { min-height: 240px; padding: 52px clamp(24px, 6vw, 86px); display: flex; align-items: center; color: white; background: var(--ink); position: relative; overflow: hidden; }
.intro::before { content: ''; position: absolute; inset: 0 0 0 auto; width: 43%; opacity: .12; background: repeating-linear-gradient(90deg, transparent 0 35px, #fff 35px 36px); transform: skewX(-10deg) translateX(8%); }
.intro > * { position: relative; }
.eyebrow, .section-heading p, .completion-panel p, .dialog-header p { margin: 0 0 10px; font: 700 .72rem/1.2 var(--utility); letter-spacing: .13em; text-transform: uppercase; }
.eyebrow { color: #ff9ea2; }
.intro h1 { max-width: 980px; margin: 0; font-family: var(--body); font-size: clamp(1.8rem, 3.5vw, 3.2rem); font-weight: 700; letter-spacing: -.025em; line-height: 1.42; text-wrap: balance; }

form { padding: 42px clamp(16px, 4vw, 54px) 72px; }
.error-summary { margin: 0 0 24px; padding: 18px 22px; color: var(--error); background: #fff5f4; border-left: 5px solid var(--error); }
.error-summary ul { margin: 8px 0 0; padding-left: 20px; }
.error-summary a { color: inherit; }
.form-section { margin-bottom: 28px; background: var(--paper); border: 1px solid var(--line); box-shadow: 0 7px 24px rgba(17,27,43,.04); }
.section-heading { min-height: 104px; display: grid; grid-template-columns: 82px minmax(0, 1fr); align-items: center; border-bottom: 1px solid var(--line); }
.section-index { height: 100%; display: grid; place-items: center; color: white; background: var(--red); font: 700 .78rem/1 var(--utility); letter-spacing: .09em; }
.section-heading > div:last-child { padding: 22px 28px; }
.section-heading p { color: var(--red-dark); margin-bottom: 3px; }
.section-heading h2 { margin: 0; font-family: var(--display); font-size: clamp(1.45rem, 2.7vw, 2.15rem); letter-spacing: -.025em; line-height: 1.2; }
.section-body { padding: clamp(22px, 4vw, 42px); }
.table-intro { margin-bottom: 20px; display: grid; }
.table-intro span:first-child { font-family: var(--display); font-size: 1.1rem; font-weight: 700; }
.table-intro span:last-child { color: var(--ink-soft); font-size: .88rem; }

.condition-table { border: 1px solid var(--line-strong); }
.condition-head, .condition-row { display: grid; grid-template-columns: minmax(240px, 1.35fr) 74px 74px minmax(220px, 1fr); }
.condition-head { color: white; background: var(--ink); font: 700 .71rem/1.25 var(--utility); letter-spacing: .045em; text-transform: uppercase; }
.condition-head span { padding: 13px 14px; border-right: 1px solid rgba(255,255,255,.18); }
.condition-head span:nth-child(2), .condition-head span:nth-child(3) { display: grid; place-items: center; padding-left: 0; padding-right: 0; text-align: center; }
.condition-row { min-width: 0; min-height: 64px; margin: 0; padding: 0; align-items: stretch; border: 0; border-top: 1px solid var(--line); }
.condition-row:first-of-type { border-top: 0; }
.condition-row > * { min-width: 0; }
.condition-label { display: flex; flex-direction: column; justify-content: center; padding: 13px 16px; }
.condition-label span { font-weight: 750; }
.condition-label small { color: var(--ink-soft); }
.box-choice { min-height: 64px; display: grid; place-items: center; border-left: 1px solid var(--line); cursor: pointer; }
.box-choice input { position: absolute; opacity: 0; pointer-events: none; }
.box-choice > span { width: 22px; height: 22px; display: grid; place-items: center; background: white; border: 2px solid #8d98a7; transition: .15s ease; }
.box-choice > span::after { content: ''; width: 10px; height: 6px; opacity: 0; border-left: 2px solid white; border-bottom: 2px solid white; transform: translateY(-1px) rotate(-45deg); }
.box-choice input:checked + span { background: var(--red); border-color: var(--red); }
.box-choice input:checked + span::after { opacity: 1; }
.box-choice input:focus-visible + span { outline: 3px solid #1f6fa9; outline-offset: 3px; }
.box-choice b { display: none; }
.state-field { padding: 10px 12px; display: flex; align-items: center; border-left: 1px solid var(--line); background: #fffafa; }
.state-field[hidden] { display: none; }
input[type='text'] { width: 100%; min-height: 48px; padding: 11px 13px; color: var(--ink); background: white; border: 1px solid var(--line-strong); border-radius: 2px; }
input::placeholder { color: #8b94a0; }
.state-field input { min-height: 42px; font-size: .87rem; }
.row-error { grid-column: 1 / -1; min-height: 0; padding: 0 16px; color: var(--error); background: #fff5f4; font-size: .76rem; font-style: normal; }
.condition-row.has-error .row-error { padding-top: 7px; padding-bottom: 7px; }
.condition-row.has-error { box-shadow: inset 4px 0 var(--error); }
.medical-note { margin-top: 20px; padding: 20px 22px; display: grid; grid-template-columns: 210px 1fr; gap: 24px; background: #f6f8fb; border-left: 4px solid var(--blue); }
.medical-note strong { font-family: var(--display); }
.medical-note p { margin: 0; color: var(--ink-soft); font-size: .87rem; }

.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; }
.field { display: grid; align-content: start; gap: 7px; }
.field > span { font-size: .84rem; font-weight: 750; }
.field b { color: var(--red); }
.field-error, .signature-error { min-height: 1em; color: var(--error); font-size: .76rem; font-style: normal; }
.field.has-error input { border-color: var(--error); box-shadow: 0 0 0 1px var(--error); }
.date-field { grid-row: span 1; }
.date-control { position: relative; display: grid; grid-template-columns: 1fr 48px; }
.date-control > input[type='text'] { border-radius: 2px 0 0 2px; }
.date-control button { display: grid; place-items: center; color: white; background: var(--blue); border: 0; border-radius: 0 2px 2px 0; }
.native-date { position: absolute; width: 1px; height: 1px; right: 44px; bottom: 0; opacity: 0; pointer-events: none; }

.signature-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr); gap: 28px; }
.signature-card { padding: 20px; border: 1px solid var(--line); }
.signature-preview { height: 150px; display: grid; place-items: center; overflow: hidden; color: #7a8492; background: #f8f9fb; border: 1px dashed var(--line-strong); }
.signature-preview img { max-width: 96%; max-height: 132px; object-fit: contain; }
.signature-actions { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 10px; }
.secondary-button, .text-button, .primary-button { min-height: 46px; padding: 10px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; border-radius: 2px; font-weight: 750; }
.secondary-button { color: var(--ink); background: white; border: 1px solid var(--line-strong); }
.text-button { color: var(--blue); background: transparent; border: 1px solid transparent; }
.resign-button { min-height: 46px; padding: 10px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; color: var(--red-dark); background: var(--red-soft); border: 1px solid #efb8bb; border-radius: 2px; font-weight: 750; }
.resign-button[hidden] { display: none; }
.primary-button { color: white; background: var(--red); border: 1px solid var(--red); }
.primary-button:disabled { cursor: wait; opacity: .55; }
.privacy-note { padding: 24px; align-self: stretch; color: white; background: var(--blue); }
.privacy-note strong { font-family: var(--display); font-size: 1.1rem; }
.privacy-note p { margin: 12px 0 0; color: #d6e4f0; font-size: .86rem; }
.signature-card.has-error { border-color: var(--error); box-shadow: inset 4px 0 var(--error); }

.export-bridge { margin-top: -6px; padding: 0 0 34px; display: flex; justify-content: center; }
.completion-panel { padding: clamp(28px, 5vw, 48px); display: flex; align-items: center; justify-content: space-between; gap: 32px; color: white; background: var(--ink); }
.completion-panel p { color: #ff969b; }
.completion-panel h2 { max-width: 650px; margin: 0; font-family: var(--display); font-size: clamp(1.35rem, 2.7vw, 2rem); }
.export-button { min-height: 58px; padding: 14px 22px; white-space: nowrap; }
.blank-form-button { min-height: 54px; padding: 12px 18px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; flex: 0 0 auto; color: #ff858a; background: transparent; border: 2px solid #ff4e57; border-radius: 2px; font-weight: 750; text-decoration: none; }
.blank-form-button:hover { color: white; background: var(--red); border-color: var(--red); }
.blank-form-button svg { width: 20px; height: 20px; }
.toast { position: fixed; z-index: 20; right: 22px; bottom: 22px; max-width: 420px; padding: 13px 18px; color: white; background: var(--ink); box-shadow: var(--shadow); transform: translateY(140%); transition: transform .22s ease; }
.toast.is-visible { transform: translateY(0); }
.toast.is-error { background: var(--error); }

dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 0; overflow: auto; color: var(--ink); background: white; border: 0; border-radius: var(--radius); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(9,16,27,.72); backdrop-filter: blur(3px); }
.dialog-header { min-height: 96px; padding: 22px 26px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); }
.dialog-header p { color: var(--red-dark); margin-bottom: 3px; }
.dialog-header h2 { margin: 0; font-family: var(--display); font-size: 1.5rem; }
.countdown { width: 56px; height: 56px; display: grid; place-items: center; flex: 0 0 auto; color: white; background: var(--red); border-radius: 50%; font-family: var(--display); font-size: 1.8rem; }
.declaration-copy { max-height: min(55dvh, 520px); padding: 24px 28px; overflow-y: auto; color: #273345; font-family: Georgia, 'Times New Roman', serif; font-size: .96rem; line-height: 1.68; }
.declaration-copy p { margin: 0 0 20px; }
.declaration-copy p:last-child { margin-bottom: 0; }
.dialog-body { padding: 22px 26px; }
.dialog-body p { margin: 0 0 14px; color: var(--ink-soft); font-size: .87rem; }
.signature-dialog canvas { width: 100%; height: 240px; display: block; background: #fbfbfc; border: 1px solid var(--line-strong); touch-action: none; cursor: crosshair; }
.dialog-footer { padding: 18px 26px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); }
.dialog-footer > span { color: var(--ink-soft); font-size: .82rem; }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; color: var(--ink); background: white; border: 1px solid var(--line); }

@media (max-width: 820px) {
    .site-header { min-height: 72px; padding: 10px 16px; }
    .brand img { width: 150px; }
    .header-meta span { display: none; }
    .header-meta strong { font-size: .84rem; }
    .intro { min-height: 220px; padding: 38px 22px; }
    form { padding: 22px 12px 42px; }
    .section-heading { grid-template-columns: 58px 1fr; }
    .section-heading > div:last-child { padding: 18px; }
    .section-body { padding: 18px; }
    .condition-head { display: none; }
    .condition-row { grid-template-columns: 1fr 1fr; padding: 14px; gap: 10px; }
    .condition-label { grid-column: 1 / -1; padding: 0 0 4px; }
    .box-choice { min-height: 48px; grid-template-columns: 22px auto; gap: 9px; border: 1px solid var(--line); }
    .box-choice b { display: block; font-size: .8rem; }
    .state-field { grid-column: 1 / -1; padding: 0; border: 0; }
    .row-error { grid-column: 1 / -1; margin: 0 -14px -14px; }
    .medical-note, .details-grid, .signature-layout { grid-template-columns: 1fr; }
    .completion-panel { align-items: stretch; flex-direction: column; }
    .export-button { white-space: normal; }
    .blank-form-button { width: 100%; }
    .dialog-footer { align-items: stretch; flex-direction: column; }
    .dialog-footer .primary-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; } }
