:root {
    color-scheme: light;
    --green: #18392e;
    --green-light: #eef2e8;
    --red: #a3313e;
    --paper: #fffdf9;
    --background: #f6f1e9;
    --border: #e2dbce;
    --muted: #635e54;
    font: 16px/1.5 system-ui, sans-serif;
    color: #26392e;
    background: var(--background);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
    outline: 3px solid #b2702e;
    outline-offset: 3px;
}

.site-header {
    background: var(--green);
    color: #fffcf4;
    border-bottom: 3px solid #bda36d;
}
.header-inner {
    width: min(1150px, calc(100% - 3rem));
    min-height: 68px;
    margin-inline: auto;
    display: flex;
    align-items: center;
    gap: 0.7rem;
}
h1, h2 { font-family: Georgia, serif; font-weight: 600; line-height: 1.15; }
h1 { font-size: clamp(1.8rem, 4vw, 2.25rem); margin: 0; letter-spacing: -0.025em; }
h2 { font-size: clamp(1.4rem, 3vw, 1.65rem); margin: 0; letter-spacing: -0.015em; }
.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--red);
    transform: rotate(-7deg);
}
.envelope {
    width: 22px;
    height: 15px;
    border: 1.5px solid #fff4df;
    border-radius: 3px;
    position: relative;
    overflow: hidden;
}
.envelope::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    border: solid #fff4df;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
    left: 2.6px;
    top: -8px;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr);
    align-items: start;
    gap: 1rem;
    width: min(1150px, calc(100% - 3rem));
    margin: clamp(0.75rem, 2vw, 1.5rem) auto;
}
.card {
    border: 1px solid var(--border);
    border-radius: 17px;
    background: var(--paper);
    box-shadow: 0 9px 24px #442e1410;
    padding: clamp(0.85rem, 1.75vw, 1.35rem);
    min-width: 0;
}
.editor-heading { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.8rem; }
.drafts-button { flex: none; font-size: 0.875rem; }
.editor form { display: grid; gap: 0.65rem; }
.field-meta, .status { font-size: 0.875rem; color: var(--muted); }
input[type="text"], input[type="password"], textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid #cec6b8;
    border-radius: 8px;
    color: #26392e;
    background: #fffefa;
}
input::placeholder, textarea::placeholder { color: #746d63; }
textarea { display: block; min-height: clamp(21rem, 38dvh, 25rem); resize: vertical; line-height: 1.55; }
.field-meta { margin-top: 0.25rem; display: flex; justify-content: space-between; align-items: center; gap: 0.4rem; }
#text-length { white-space: nowrap; font-variant-numeric: tabular-nums; }
.text-button {
    padding: 0.15rem 0;
    border: 0;
    border-radius: 2px;
    background: transparent;
    color: #3b584b;
    text-align: left;
    text-decoration: underline;
    text-underline-offset: 0.18em;
}
.text-button:hover { color: var(--red); }
.button {
    min-height: 45px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.59rem 1rem;
    font-weight: 650;
    transition: background 150ms ease;
}
.button-red { background: var(--red); color: #fffaf5; }
.button-red:hover:not(:disabled) { background: #862434; }
.button-red:disabled { background: #76545a; }
#create-preview { position: relative; }
#create-preview[aria-busy="true"] span { opacity: 0; }
#create-preview[aria-busy="true"]::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 1.2rem;
    height: 1.2rem;
    border: 2px solid #fffaf566;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: rotate-spinner 650ms linear infinite;
}
@keyframes rotate-spinner { to { transform: rotate(360deg); } }
.button-green { background: var(--green); color: white; }
.button-green:hover:not(:disabled) { background: #294f41; }
.button-green:disabled { background: #e9ece4; color: #5a6259; border-color: #dde3d8; }
.button-secondary { background: var(--paper); color: var(--green); border-color: #d8e0d2; }
.button-secondary:hover { background: var(--green-light); }
.login { width: min(25rem, calc(100% - 1.5rem)); margin: clamp(2rem, 12vh, 7rem) auto; }
.login form { display: grid; gap: 0.65rem; margin-top: 1.15rem; }
.login .button { margin-top: 0.3rem; }
.status { margin: 0; }
.status:not(:empty) { margin-top: 0.45rem; }
.status.error { color: #9d2533; }

.draft-dialog {
    width: min(37rem, calc(100% - 1.5rem));
    max-height: calc(100% - 1.5rem);
    padding: clamp(1rem, 4vw, 1.5rem);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--green);
    background: var(--paper);
    box-shadow: 0 12px 40px #182b2540;
}
.draft-dialog::backdrop { background: #182b2570; }
.draft-dialog h2 { font: 500 1rem/1.5 system-ui, sans-serif; overflow-wrap: anywhere; }
.draft-review { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 0.85rem; margin-top: 0.85rem; }
.draft-list { margin: 0; padding: 0; border: 0; min-width: 0; }
.draft-list legend, .draft-review h3 { margin: 0 0 0.35rem; padding: 0; font-size: 0.875rem; font-weight: 650; }
.draft-versions { display: grid; gap: 0.35rem; max-height: 18rem; overflow-y: auto; }
.draft-version {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 44px;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
}
.draft-version:has(input:checked) { border-color: #8caa96; background: var(--green-light); }
.draft-version input { margin: 0; flex: none; accent-color: var(--green); }
.draft-version-name, .draft-version-time { display: block; overflow-wrap: anywhere; }
.draft-version-name { font-size: 0.875rem; }
.draft-version-time { color: var(--muted); font-size: 0.8125rem; }
.draft-preview {
    min-height: 7rem;
    max-height: 17rem;
    overflow: auto;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #fffefa;
    font-size: 0.875rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.draft-preview:focus-visible { outline: 2px solid #b2702e; outline-offset: 2px; }
.draft-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.draft-actions .button { flex: 1 1 auto; }

@media (max-width: 520px) {
    .draft-review { grid-template-columns: minmax(0, 1fr); }
    .draft-versions { max-height: 11rem; }
    .draft-preview { max-height: 13rem; }
}

.preview { container-type: inline-size; }
.preview-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 0.4rem; flex-wrap: wrap; }
.preview-notice { color: var(--muted); font-size: 0.875rem; }
.preview-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.8rem;
}
.preview-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
    min-width: 0;
    max-width: 100%;
}
.preview-actions .button { min-width: 0; overflow-wrap: anywhere; }
.preview-actions .compact-label { display: none; }
.preview-area {
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
    overflow: clip;
    min-height: 320px;
    margin: 0.65rem 0;
    padding: clamp(0.55rem, 1.5vw, 1rem);
    border: 1px solid #dfe4d9;
    border-radius: 10px;
    background: var(--green-light);
}
.preview-empty { color: var(--muted); text-align: center; }
.paper-icon {
    display: grid;
    place-items: center;
    position: relative;
    margin: 0 auto 1.35rem;
    width: 58px;
    height: 75px;
    color: var(--red);
    font-size: 1.55rem;
    border: 1px solid #ded4bc;
    border-radius: 5px;
    background: #fffdf8;
    box-shadow: 2px 5px 0 #dce1d3;
    transform: rotate(-9deg);
}
.paper-icon::before {
    content: "";
    position: absolute;
    top: 7px;
    right: 7px;
    bottom: 7px;
    left: 7px;
    border: 1px solid #e9dfc9;
    border-radius: 3px;
}
.preview-sheet { width: min(100%, 450px); aspect-ratio: 210 / 297; margin: 0; }
.preview-image-viewport {
    position: absolute;
    inset: 0;
    container-type: size;
}
.preview-sheet img {
    position: absolute;
    top: 0;
    left: 50%;
    width: 140%;
    width: min(140cqw, 145cqh);
    height: auto;
    transform: translateX(-50%);
    background: white;
}
.page-controls { display: flex; flex: none; gap: 0.55rem; align-items: center; margin-right: auto; white-space: nowrap; }
#page-indicator { color: #465a4e; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.pager {
    width: 36px;
    height: 36px;
    border: 1px solid #d8e0d2;
    border-radius: 7px;
    color: var(--green);
    background: #f0f3e9;
    font-size: 1.45rem;
    line-height: 1;
}
.pager:hover:not(:disabled) { background: #e2e9db; }
.pager:disabled { color: #8b958a; }

@container (max-width: 33rem) {
    .preview-footer { gap: 0.45rem; }
    .page-controls { gap: 0.35rem; }
    .preview-actions { display: flex; gap: 0.35rem; }
    .preview-actions .button { padding-inline: 0.5rem; font-size: 0.875rem; }
    .preview-actions .full-label { display: none; }
    .preview-actions .compact-label { display: inline; }
}

@container (max-width: 17.5rem) {
    .preview-actions .button { padding-inline: 0.375rem; }
    .preview-actions .compact-pdf-verb { display: none; }
}

@media (max-width: 790px) {
    .header-inner, .workspace { width: min(720px, calc(100% - 1.5rem)); }
    .header-inner { min-height: 58px; }
    .workspace { grid-template-columns: minmax(0, 1fr); gap: 0.75rem; }
    .preview-area { min-height: 215px; }
    textarea { min-height: clamp(16rem, 30dvh, 20rem); }
}

@media (prefers-reduced-motion: reduce) {
    .button { transition: none; }
    #create-preview[aria-busy="true"]::after { animation: none; }
}
