:root {
    --content-width: 1180px;
    --paper: #f4f4ef;
    --white: #ffffff;
    --ink: #181817;
    --muted: #686862;
    --line: #d3d3ca;
    --signal: #f3cb3e;
    --signal-dark: #d4a900;
    --wine: #8e3044;
    --teal: #17796f;
    --danger: #a72727;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    color: var(--ink);
    background-color: var(--paper);
    background-image:
        linear-gradient(rgba(24, 24, 23, .035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(24, 24, 23, .035) 1px, transparent 1px);
    background-size: 28px 28px;
    font-family: Bahnschrift, "Franklin Gothic Medium", sans-serif;
    letter-spacing: 0;
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button, label[for] { -webkit-tap-highlight-color: transparent; }

.site-header {
    width: min(calc(100% - 48px), var(--content-width));
    min-height: 76px;
    margin-inline: auto;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 1px solid var(--ink);
    background: rgba(244, 244, 239, .94);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
    font-weight: 800;
    font-size: 18px;
}

.brand small { font-size: 10px; color: var(--muted); font-weight: 500; }
.brand-mark { width: 24px; height: 24px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; }
.brand-mark span { background: var(--ink); }
.brand-mark span:nth-child(2), .brand-mark span:nth-child(3) { background: var(--signal); }

.security-stamp { display: flex; align-items: center; gap: 9px; font-size: 11px; font-weight: 700; }
.security-stamp span { width: 7px; height: 7px; background: var(--teal); border-radius: 50%; box-shadow: 0 0 0 4px rgba(23, 121, 111, .13); }

main { overflow: hidden; }

.intro {
    width: min(calc(100% - 48px), var(--content-width));
    min-height: 390px;
    margin-inline: auto;
    padding: 70px 0 62px;
    position: relative;
    border-bottom: 1px solid var(--ink);
}

.intro::after {
    content: "01001101";
    position: absolute;
    right: clamp(20px, 7vw, 110px);
    bottom: -17px;
    color: var(--paper);
    background: var(--wine);
    padding: 8px 14px;
    font-family: Consolas, monospace;
    font-size: 12px;
}

.eyebrow, .section-number { margin: 0 0 16px; font-size: 11px; font-weight: 800; color: var(--wine); }

h1 {
    max-width: 820px;
    margin: 0;
    font-family: Rockwell, "Roboto Slab", serif;
    font-size: clamp(46px, 6.4vw, 88px);
    line-height: .98;
    font-weight: 700;
}

.intro-copy { max-width: 610px; margin: 28px 0 0; color: var(--muted); font-size: 18px; line-height: 1.55; }

.workspace {
    width: min(calc(100% - 48px), var(--content-width));
    margin-inline: auto;
    background: var(--white);
}

.section-heading {
    padding: 40px clamp(20px, 4vw, 48px) 28px;
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 30px;
    border-bottom: 1px solid var(--line);
}

h2, h3 { margin: 0; font-family: Rockwell, "Roboto Slab", serif; }
h2 { font-size: 34px; }
h3 { font-size: 24px; }

.mode-tabs { width: 280px; display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--ink); }
.mode-tab { min-height: 46px; padding: 0 22px; border: 0; background: var(--white); color: var(--ink); cursor: pointer; font-weight: 700; }
.mode-tab + .mode-tab { border-left: 1px solid var(--ink); }
.mode-tab[aria-selected="true"] { background: var(--ink); color: var(--white); }
.mode-tab:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, .drop-zone:focus-within { outline: 3px solid var(--signal); outline-offset: 3px; }

.mode-panel[hidden] { display: none; }
.operation-grid { display: grid; grid-template-columns: minmax(320px, .9fr) minmax(390px, 1.1fr); }
.upload-column, .input-column { padding: clamp(28px, 4vw, 52px) clamp(20px, 4vw, 48px); }
.upload-column { border-right: 1px solid var(--line); }
.field-label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 11px; font-weight: 800; }

.drop-zone {
    min-height: 300px;
    padding: 30px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 1px dashed #99998f;
    background-color: #fafaf7;
    background-image: repeating-linear-gradient(45deg, transparent 0 12px, rgba(24, 24, 23, .025) 12px 13px);
    cursor: pointer;
    text-align: center;
    overflow: hidden;
}

.drop-zone.is-dragging { border-style: solid; border-color: var(--wine); background-color: #fff9e7; }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone strong, .drop-zone small, .drop-visual { position: relative; z-index: 2; }
.drop-zone small { color: var(--muted); }
.drop-zone img {
    position: absolute;
    inset: 14px;
    width: calc(100% - 28px);
    height: calc(100% - 28px);
    object-fit: contain;
    background-color: #e8e8e2;
    background-image:
        linear-gradient(45deg, #dcdcd4 25%, transparent 25%),
        linear-gradient(-45deg, #dcdcd4 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #dcdcd4 75%),
        linear-gradient(-45deg, transparent 75%, #dcdcd4 75%);
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-size: 16px 16px;
    box-shadow: 0 10px 28px rgba(24, 24, 23, .12);
    z-index: 1;
}
.drop-zone.has-preview {
    width: min(100%, var(--preview-width));
    min-height: 0;
    margin-inline: auto;
    padding: 0;
    aspect-ratio: var(--image-ratio);
    border-style: solid;
    background: #e8e8e2;
    box-shadow: 0 14px 36px rgba(24, 24, 23, .12);
}
.drop-zone.has-preview img {
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    box-shadow: none;
}
.drop-zone.has-preview strong, .drop-zone.has-preview small, .drop-zone.has-preview .drop-visual { opacity: 0; }

.drop-visual { width: 58px; height: 58px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; margin-bottom: 8px; transform: rotate(3deg); }
.drop-visual .pixel { background: var(--ink); }
.drop-visual .p2 { background: var(--signal); }
.drop-visual .p3 { background: var(--wine); }
.drop-visual .p4 { background: var(--teal); }
.decode-visual { transform: rotate(-3deg); }

.image-meta { width: min(100%, var(--preview-width)); margin-inline: auto; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-top: 0; background: var(--white); }
.image-meta[hidden] { display: none; }
.image-meta span { min-width: 0; padding: 10px 8px; color: var(--muted); font-size: 8px; text-align: center; }
.image-meta span + span { border-left: 1px solid var(--line); }
.image-meta b { display: block; margin-bottom: 3px; overflow: hidden; color: var(--ink); font-size: 11px; text-overflow: ellipsis; }
.capacity { min-height: 18px; margin: 12px 0 0; color: var(--teal); font-size: 12px; }
.field-row { display: flex; justify-content: space-between; gap: 16px; }
.char-count { color: var(--muted); font-size: 11px; }

textarea, .text-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 0;
    color: var(--ink);
    background: #fafaf7;
}

textarea { min-height: 184px; padding: 17px; resize: vertical; line-height: 1.5; }
.text-input { min-height: 52px; padding: 0 15px; }
.password-label { margin-top: 26px; }
.optional-label { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.optional-label .field-label { margin-bottom: 10px; }
.optional-label > span { margin-bottom: 10px; padding: 3px 7px; border: 1px solid var(--line); color: var(--muted); font-size: 8px; font-weight: 800; }
.check-control { display: flex; align-items: center; gap: 8px; width: max-content; margin-top: 10px; color: var(--muted); font-size: 12px; cursor: pointer; }
.check-control input { accent-color: var(--wine); }
.password-help { display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 10px; }
.password-help .check-control { flex: 0 0 auto; }

.primary-action {
    width: 100%;
    min-height: 58px;
    margin-top: 30px;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--ink);
    border-radius: 0;
    color: var(--ink);
    background: var(--signal);
    cursor: pointer;
    font-weight: 800;
    transition: background-color .18s ease, transform .18s ease;
}

.primary-action:hover { background: var(--signal-dark); transform: translateY(-2px); }
.primary-action:disabled { cursor: wait; opacity: .65; transform: none; }
.decode-inputs { display: flex; flex-direction: column; justify-content: center; }
.field-error { margin: 10px 0 0; color: var(--danger); font-size: 13px; line-height: 1.4; }

.comparison-result { padding: 46px clamp(20px, 4vw, 48px) 58px; border-top: 1px solid var(--ink); background: #edf2ee; scroll-margin-top: 20px; }
.comparison-result[hidden] { display: none; }
.comparison-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.comparison-heading .section-number { margin-bottom: 8px; color: var(--teal); }
.success-badge { padding: 8px 10px; border: 1px solid var(--teal); color: var(--teal); font-size: 9px; font-weight: 800; }
.comparison-grid { display: flex; align-items: flex-start; justify-content: center; gap: 24px; }
.comparison-grid figure { flex: 0 1 var(--comparison-card-width); width: min(calc(50% - 12px), var(--comparison-card-width)); min-width: 0; margin: 0; border: 1px solid var(--ink); background: var(--white); }
.comparison-media {
    width: 100%;
    height: auto;
    padding: 0;
    aspect-ratio: var(--image-ratio);
    display: grid;
    place-items: center;
    overflow: hidden;
    background-color: #deded7;
    background-image:
        linear-gradient(45deg, #d1d1c9 25%, transparent 25%),
        linear-gradient(-45deg, #d1d1c9 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d1d1c9 75%),
        linear-gradient(-45deg, transparent 75%, #d1d1c9 75%);
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    background-size: 20px 20px;
}
.comparison-media img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: center; }
.comparison-grid figcaption { min-height: 54px; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); }
.comparison-grid figcaption span { font-size: 10px; font-weight: 800; }
.comparison-grid figcaption small { overflow: hidden; color: var(--muted); font-size: 10px; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.comparison-footer { display: flex; align-items: center; justify-content: space-between; gap: 30px; margin-top: 22px; }
.comparison-footer p { max-width: 670px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.comparison-footer strong { color: var(--ink); }
.download-action { min-height: 48px; padding: 0 18px; display: flex; align-items: center; gap: 24px; border: 1px solid var(--ink); color: var(--white); background: var(--ink); text-decoration: none; font-size: 12px; font-weight: 800; }
.download-action:hover { color: var(--ink); background: var(--signal); }

.result-band { padding: 42px clamp(20px, 4vw, 48px) 54px; border-top: 1px solid var(--ink); background: #eef4f1; }
.result-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.result-heading .section-number { margin-bottom: 8px; color: var(--teal); }
.result-band textarea { min-height: 170px; background: var(--white); }
.copy-action { min-height: 40px; padding: 0 16px; border: 1px solid var(--ink); border-radius: 0; background: var(--white); cursor: pointer; font-weight: 700; }
.copy-action:hover { background: var(--ink); color: var(--white); }

.privacy-band { width: min(calc(100% - 48px), var(--content-width)); margin-inline: auto; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); background: var(--wine); color: var(--white); }
.privacy-band p { margin: 0; padding: 22px; text-align: center; font-size: 11px; font-weight: 800; }
.privacy-band p + p { border-left: 1px solid rgba(255, 255, 255, .4); }

footer { width: min(calc(100% - 48px), var(--content-width)); margin-inline: auto; padding: 26px 0; display: flex; justify-content: space-between; gap: 30px; color: var(--muted); font-size: 11px; line-height: 1.5; }

.error-page { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }
.error-main { display: grid; overflow: hidden; }
.error-content { width: min(calc(100% - 48px), var(--content-width)); min-height: 560px; margin-inline: auto; padding: clamp(64px, 10vw, 130px) 0; position: relative; }
.error-content::after { content: ""; position: absolute; width: 240px; height: 240px; right: 3vw; top: 50%; border: 28px solid var(--signal); transform: translateY(-50%) rotate(8deg); }
.error-code { margin: 0; position: absolute; right: 7vw; top: 50%; z-index: -1; color: rgba(142, 48, 68, .08); font-family: Rockwell, "Roboto Slab", serif; font-size: clamp(160px, 24vw, 360px); font-weight: 800; line-height: 1; transform: translateY(-52%); }
.error-content h1 { max-width: 720px; font-size: clamp(52px, 7vw, 92px); }
.error-content > p:not(.eyebrow, .error-code) { max-width: 520px; margin: 28px 0; color: var(--muted); font-size: 18px; line-height: 1.55; }
.error-action { width: min(100%, 280px); min-height: 52px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--ink); color: var(--ink); background: var(--signal); text-decoration: none; font-size: 12px; font-weight: 800; }
.error-action:hover { background: var(--signal-dark); }

@media (max-width: 800px) {
    .site-header, .intro, .workspace, .privacy-band, footer { width: 100%; }
    .site-header { min-height: 66px; }
    .site-header, .intro, footer { padding-inline: 20px; }
    .brand small, .security-stamp { display: none; }
    .intro { min-height: 330px; padding-top: 58px; }
    h1 { font-size: clamp(40px, 11vw, 46px); }
    .intro-copy { font-size: 16px; }
    .section-heading { align-items: stretch; flex-direction: column; }
    .mode-tabs { width: 100%; }
    .operation-grid { grid-template-columns: 1fr; }
    .upload-column { border-right: 0; border-bottom: 1px solid var(--line); }
    .drop-zone { min-height: 250px; }
    .comparison-heading, .comparison-footer { align-items: stretch; flex-direction: column; }
    .comparison-grid { align-items: center; flex-direction: column; }
    .comparison-grid figure { flex-basis: auto; width: min(100%, var(--comparison-card-width)); }
    .download-action { justify-content: space-between; }
    .privacy-band { grid-template-columns: 1fr; }
    .privacy-band p + p { border-left: 0; border-top: 1px solid rgba(255, 255, 255, .4); }
    footer { flex-direction: column; gap: 10px; }
    .error-content { width: 100%; min-height: 500px; padding: 72px 20px; }
    .error-content::after { width: 120px; height: 120px; right: -45px; top: 25%; border-width: 16px; }
    .error-code { right: -12px; top: 33%; font-size: 150px; }
}

@media (prefers-reduced-motion: no-preference) {
    .intro > * { animation: reveal .55s both; }
    .intro > *:nth-child(2) { animation-delay: .08s; }
    .intro > *:nth-child(3) { animation-delay: .16s; }
    @keyframes reveal { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
}