:root {
    color-scheme: light;
    --bg: #f6eee9;
    --card: #fffcfa;
    --ink: #2b2220;
    --muted: #8c7e79;
    --line: #eee2dc;
    --hover: #faf3ef;
    --accent: #d4466c;
    --accent-dark: #b9355a;
    --accent-soft: #fcebef;
    --radius: 24px;
    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-sig: 'Caveat', 'Segoe Script', cursive;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-body);
    color: var(--ink);
    background:
        radial-gradient(60rem 40rem at 10% -10%, #fadbe2 0%, transparent 60%),
        radial-gradient(50rem 40rem at 110% 110%, #fde5d6 0%, transparent 60%),
        var(--bg);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}

button,
input {
    font: inherit;
    color: inherit;
}

svg {
    display: block;
}

/* Hide the card until we know whether it's already signed, so it doesn't flash the unsigned version. */
.is-loading .contract {
    visibility: hidden;
    animation: none;
}

.page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 48px 16px;
}

/* ---------- Card ---------- */

.contract {
    width: 100%;
    max-width: 560px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(60, 30, 25, 0.04), 0 24px 60px -20px rgba(120, 50, 60, 0.18);
    overflow: hidden;
    animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: none; }
}

/* ---------- Header ---------- */

.contract__head {
    position: relative;
    padding: 36px 32px 28px;
    text-align: center;
    border-bottom: 1px dashed var(--line);
}

.eyebrow {
    margin: 0 0 12px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
}

.title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.75rem, 6vw, 2.35rem);
    line-height: 1.15;
    letter-spacing: -0.01em;
    text-wrap: balance;
}

.parties {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 14px;
    max-width: 400px;
    margin: 26px auto 0;
    padding: 14px 20px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fdf7f4;
}

.party {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.party--from {
    text-align: right;
}

.party--to {
    text-align: left;
}

.party__label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
}

.party__name {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 1.05rem;
    line-height: 1.2;
}

/* Heart badge joined to both names by thin lines */
.parties__link {
    display: flex;
    align-items: center;
    gap: 8px;
}

.parties__link::before,
.parties__link::after {
    content: '';
    width: 18px;
    height: 1px;
    background: #e3d2cb;
}

.parties__heart {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-soft);
}

.parties__heart svg {
    width: 15px;
    height: 15px;
    fill: var(--accent);
}

.is-signed .parties__heart {
    animation: beat 1.6s ease-in-out 0.6s 2;
}

@keyframes beat {
    0%, 100% { transform: scale(1); }
    20% { transform: scale(1.15); }
    40% { transform: scale(1); }
}

/* Stamp shown after signing */
.stamp {
    position: absolute;
    top: 18px;
    right: 18px;
    padding: 6px 12px;
    border: 2px solid var(--accent);
    border-radius: 8px;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    transform: rotate(8deg) scale(1.6);
    opacity: 0;
    pointer-events: none;
}

.is-signed .stamp {
    animation: stamp 0.45s cubic-bezier(0.3, 1.5, 0.5, 1) 0.15s forwards;
}

@keyframes stamp {
    to { opacity: 0.9; transform: rotate(8deg) scale(1); }
}

/* ---------- Clauses ---------- */

.clauses {
    padding: 24px 20px 8px;
}

.clauses__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 0 12px;
}

.clauses__head h2 {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 1.2rem;
}

.clauses__count {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.clauses__count.is-complete {
    color: var(--accent);
}

.progress {
    height: 4px;
    margin: 12px 12px 0;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}

.progress__bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 0.35s ease;
}

.hint {
    margin: 12px 12px 4px;
    font-size: 0.8rem;
    color: var(--muted);
}

.clause-list {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
}

.clause {
    position: relative; /* anchors the visually hidden checkbox so focusing it doesn't jump the page */
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px 2px 0;
    border-radius: 14px;
    transition: background-color 0.15s ease;
}

.clause:hover {
    background: var(--hover);
}

.clause.is-checked {
    background: var(--accent-soft);
}

.clause__main {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
}

.is-signed .clause__main {
    cursor: default;
}

.clause__cb {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.box {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border: 1.5px solid #d9c9c2;
    border-radius: 7px;
    background: #fff;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.clause:hover .box {
    border-color: var(--accent);
}

.clause__cb:checked + .box {
    border-color: var(--accent);
    background: var(--accent) url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2.5' d='m5.5 10.5 3 3 6-6.5'/%3e%3c/svg%3e") center / 16px no-repeat;
    animation: pop 0.2s ease;
}

@keyframes pop {
    50% { transform: scale(1.12); }
}

.clause__cb:focus-visible + .box {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.clause__num {
    flex-shrink: 0;
    width: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.clause.is-checked .clause__num {
    color: var(--accent);
}

.clause__text {
    font-size: 0.95rem;
    line-height: 1.45;
}

.clause__input {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border: 1.5px solid var(--accent);
    border-radius: 10px;
    background: #fff;
    font-size: 0.95rem;
    outline: none;
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.clause.is-editing .clause__main {
    flex: 0 0 auto;
}

.clause.is-editing .clause__text {
    display: none;
}

.icon-btn {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    opacity: 0.55;
    transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.icon-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.clause:hover .icon-btn,
.icon-btn:focus-visible,
.clause.is-editing .icon-btn {
    opacity: 1;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--ink);
}

.clause.is-editing .icon-btn {
    color: var(--accent);
}

.icon-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.icon-btn:disabled {
    cursor: not-allowed;
    opacity: 0.4;
    background: transparent;
    color: var(--muted);
}

@media (hover: none) {
    .icon-btn { opacity: 0.8; }
}

/* ---------- Footer / actions ---------- */

.contract__foot {
    padding: 28px 32px 32px;
    text-align: center;
    border-top: 1px dashed var(--line);
    margin-top: 16px;
}

.question {
    margin: 0 0 18px;
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 500;
}

.actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
}

.btn {
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.btn--primary {
    padding: 15px 40px;
    background: var(--accent);
    color: #fff;
    font-size: 1.1rem;
    box-shadow: 0 8px 24px -8px rgba(212, 70, 108, 0.6);
}

.btn--primary:hover {
    background: var(--accent-dark);
    transform: translateY(-1px);
}

.btn--primary:active {
    transform: translateY(0);
}

.btn--primary:focus-visible,
.btn--ghost:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.btn--no {
    padding: 4px 10px;
    background: transparent;
    color: var(--muted);
    font-size: 0.65rem;
    font-weight: 500;
    border: 1px solid var(--line);
    cursor: not-allowed;
    opacity: 0.7;
}

.btn--ghost {
    padding: 12px 22px;
    background: transparent;
    color: var(--muted);
}

.btn--ghost:hover {
    background: var(--hover);
    color: var(--ink);
}

.fineprint {
    margin: 20px 0 0;
    font-size: 0.75rem;
    color: var(--muted);
}

/* ---------- Signed state ---------- */

.signed {
    margin-top: 16px;
    padding: 28px 32px 32px;
    border-top: 1px dashed var(--line);
    text-align: center;
    animation: rise 0.5s ease both;
}

.signed__row {
    display: flex;
    gap: 24px;
    text-align: left;
}

.signed__field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.signed__field--date {
    flex: 0 0 auto;
}

.signed__sig,
.signed__date {
    padding-bottom: 6px;
    border-bottom: 1px solid var(--ink);
    overflow-wrap: anywhere;
}

.signed__sig {
    font-family: var(--font-sig);
    font-size: 2.1rem;
    line-height: 1.1;
    color: var(--accent-dark);
}

.signed__date {
    font-size: 0.95rem;
    font-weight: 500;
    padding-top: 14px;
}

.signed__label {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.status {
    display: inline-block;
    margin: 28px 0 0;
    padding: 10px 20px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-weight: 600;
    font-size: 0.95rem;
}

.locked {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 14px 0 0;
    font-size: 0.75rem;
    color: var(--muted);
}

.locked svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

.is-signed .clause:hover {
    background: transparent;
}

.is-signed .clause.is-checked:hover {
    background: var(--accent-soft);
}

.is-signed .clause:hover .box {
    border-color: #d9c9c2;
}

.is-signed .clause__cb:checked + .box {
    border-color: var(--accent);
}

/* ---------- Sign dialog ---------- */

.sheet {
    width: min(420px, calc(100% - 32px));
    padding: 28px;
    border: 0;
    border-radius: 20px;
    background: var(--card);
    color: var(--ink);
    box-shadow: 0 30px 80px -20px rgba(60, 20, 30, 0.35);
}

.sheet[open] {
    animation: rise 0.25s ease both;
}

.sheet::backdrop {
    background: rgba(43, 34, 32, 0.35);
    backdrop-filter: blur(4px);
}

.sheet__title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.4rem;
}

.sheet__warning {
    margin: 12px 0 20px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.45;
}

.field {
    display: block;
    margin-bottom: 16px;
}

.field__label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--muted);
}

.field__input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    background: #fff;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field__input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.field__error {
    min-height: 1.2em;
    margin: -4px 0 8px;
    font-size: 0.8rem;
    color: var(--accent-dark);
}

.sheet__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.sheet__actions .btn--primary {
    padding: 12px 26px;
    font-size: 1rem;
}

/* ---------- Admin panel (?admin) ---------- */

.page:has(.admin:not([hidden])) {
    align-content: center;
    gap: 16px;
}

.admin {
    width: 100%;
    max-width: 560px;
    padding: 16px 20px;
    border: 1px dashed #d9c9c2;
    border-radius: 16px;
    background: rgba(255, 252, 250, 0.7);
}

.admin__title {
    margin: 0 0 10px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.admin__row {
    display: flex;
    gap: 8px;
}

.admin__row .field__input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    font-size: 0.9rem;
}

.admin__btn {
    flex-shrink: 0;
    border: 1px solid var(--line);
    padding: 10px 16px;
    font-size: 0.85rem;
}

.admin__msg {
    min-height: 1.2em;
    margin: 8px 0 0;
    font-size: 0.8rem;
    color: var(--muted);
}

/* ---------- Floating hearts ---------- */

.hearts {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 10;
}

.hearts__item {
    position: absolute;
    bottom: -40px;
    opacity: 0;
    animation: floatUp linear forwards;
}

@keyframes floatUp {
    0% { transform: translateY(0) rotate(0deg); opacity: 0; }
    10% { opacity: 1; }
    80% { opacity: 1; }
    100% { transform: translateY(-110vh) rotate(25deg); opacity: 0; }
}

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
    .page { padding: 16px; }
    .contract__head { padding: 32px 20px 24px; }
    .clauses { padding: 20px 8px 4px; }
    .clause__main { gap: 10px; padding: 12px 8px 12px 12px; }
    .clause__text { font-size: 0.9rem; }
    .contract__foot,
    .signed { padding: 24px 20px 28px; }
    .parties { gap: 8px; padding: 12px 14px; }
    .parties__link::before,
    .parties__link::after { width: 8px; }
    .party__name { font-size: 0.95rem; }
    .signed__row { flex-direction: column; gap: 18px; }
    .stamp { top: 10px; right: 10px; padding: 4px 8px; font-size: 0.65rem; }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
