:root {
    --ink: #241012;
    --red: #A61D25;
    --red-bright: #C4222B;
    --red-dark: #7A151B;
    --cream: #FBF5EF;
    --white: #FFFFFF;
    --muted: rgba(36, 16, 18, .62);
    --muted2: rgba(36, 16, 18, .42);
    --line-on-red: rgba(255, 255, 255, .22);
    --line-on-cream: rgba(36, 16, 18, .14);
    --font-display: 'Bodoni Moda', Georgia, 'Times New Roman', serif;
    --font-main: 'Inter', -apple-system, 'Segoe UI', sans-serif;
    --font-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

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

@media (scripting: enabled) {
    .preload * { transition: none !important; animation: none !important; }
}

html, body { min-height: 100%; }

body {
    font-family: var(--font-main);
    background: var(--cream);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

h1, h2, h3 { font-family: var(--font-display); }

/* ---------------- MASTHEAD ---------------- */

.masthead {
    position: relative;
    background: var(--red);
    overflow: hidden;
    padding: calc(46px + env(safe-area-inset-top)) 20px 40px;
    text-align: center;
}

.masthead::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.035;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.mastheadInner { position: relative; max-width: 30rem; margin: 0 auto; }

.mastheadKicker {
    font-size: .72rem;
    font-weight: 500;
    letter-spacing: .24em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .72);
}

.mastheadWordmark {
    display: block;
    font-family: var(--font-display);
    font-size: clamp(3rem, 12vw, 4.5rem);
    font-weight: 600;
    letter-spacing: .01em;
    color: var(--white);
    text-decoration: none;
    margin: .8rem 0 1.1rem;
}

.mastheadRule { width: 44px; height: 1px; background: var(--line-on-red); margin: 0 auto 1.1rem; }

.mastheadMeta {
    font-size: .95rem;
    font-weight: 400;
    color: rgba(255, 255, 255, .78);
    letter-spacing: .01em;
    max-width: 26ch;
    margin: 0 auto;
}

/* ---------------- MAIN / CARD ---------------- */

.container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2.75rem 1.25rem 3rem;
}

.card {
    width: 100%;
    max-width: 22rem;
    background: var(--white);
    border: 1px solid var(--line-on-cream);
    border-radius: 3px;
    box-shadow: 0 1px 2px rgba(0,0,0,.03), 0 18px 44px rgba(0,0,0,.08);
    padding: 2rem 1.75rem 1.75rem;
    text-align: center;
}

.fieldLabel {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted2);
    text-align: left;
    margin-bottom: .6rem;
}

form { display: contents; }

input#secret {
    width: 100%;
    background: rgba(36, 16, 18, .03);
    border: 1px solid var(--line-on-cream);
    border-radius: 2px;
    padding: .85rem .9rem;
    text-align: center;
    font-size: .95rem;
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--ink);
    transition: border-color 200ms var(--ease-out), background 200ms var(--ease-out);
}

input#secret::placeholder { color: var(--muted2); font-family: var(--font-main); }

input#secret:focus {
    outline: none;
    border-color: var(--red);
    background: var(--white);
}

layflags-rolling-number {
    font-family: var(--font-display);
    font-size: 3.6rem;
    font-weight: 600;
    display: block;
    color: var(--red);
    opacity: .18;
    margin-top: 1.6rem;
    line-height: 1.2;
    letter-spacing: .02em;
    --roll-duration: .8s;
    transition-duration: .8s;
    cursor: default;
}

.hint {
    font-size: .78rem;
    color: var(--muted);
    font-weight: 500;
    margin-top: .4rem;
    letter-spacing: .01em;
}

.hint b { color: var(--ink); font-weight: 700; }

/* ---------------- SAVE ROW ---------------- */

.saveRow {
    display: none;
    gap: .5rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line-on-cream);
}
.saveRow.visible { display: flex; }

.saveRow input#nickname {
    flex: 1;
    min-width: 0;
    background: rgba(36, 16, 18, .03);
    border: 1px solid var(--line-on-cream);
    border-radius: 2px;
    padding: .65rem .75rem;
    font-size: .82rem;
    font-family: var(--font-main);
    color: var(--ink);
    transition: border-color 200ms var(--ease-out), background 200ms var(--ease-out);
}
.saveRow input#nickname::placeholder { color: var(--muted2); }
.saveRow input#nickname:focus { outline: none; border-color: var(--red); background: var(--white); }
.saveRow input#nickname.shake { animation: shake 400ms var(--ease-out); }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

#saveBtn {
    flex-shrink: 0;
    background: var(--red);
    color: var(--white);
    border: none;
    border-radius: 2px;
    padding: .65rem 1.1rem;
    font-size: .8rem;
    font-weight: 700;
    font-family: var(--font-main);
    cursor: pointer;
    transition: background 200ms var(--ease-out);
}
#saveBtn:hover { background: var(--red-bright); }
#saveBtn:active { background: var(--red-dark); }

/* ---------------- SAVED CODES LIST ---------------- */

.savedSection { width: 100%; max-width: 22rem; margin-top: 1.5rem; }

.savedHeader {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: .6rem;
}
.savedHeader .fieldLabel { margin-bottom: 0; }
.savedTimer { font-size: .68rem; color: var(--muted2); font-weight: 500; }
.savedTimer b { color: var(--muted); font-weight: 700; }

.savedList { display: flex; flex-direction: column; gap: .5rem; }

.savedRow {
    position: relative;
    display: flex;
    align-items: stretch;
    background: var(--white);
    border: 1px solid var(--line-on-cream);
    border-radius: 3px;
    transition: border-color 200ms var(--ease-out), background 200ms var(--ease-out);
    overflow: hidden;
}
.savedRow:hover { border-color: rgba(166, 29, 37, .3); }
.savedRow.copied { background: rgba(166, 29, 37, .05); border-color: var(--red); }

.savedRowMain {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    background: none;
    border: none;
    padding: .75rem .9rem;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}

.savedRowName {
    font-size: .84rem;
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.savedRowCode {
    flex-shrink: 0;
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--red);
    letter-spacing: .02em;
    font-variant-numeric: tabular-nums;
}
.savedRowCode.invalid {
    font-family: var(--font-main);
    font-size: .74rem;
    font-weight: 600;
    color: var(--muted2);
    letter-spacing: normal;
}

.savedRowDelete {
    flex-shrink: 0;
    width: 2.2rem;
    background: transparent;
    border: none;
    border-left: 1px solid var(--line-on-cream);
    color: var(--muted2);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    transition: color 200ms var(--ease-out), background 200ms var(--ease-out);
}
.savedRowDelete:hover { color: var(--red); background: rgba(166, 29, 37, .05); }

.savedEmpty {
    font-size: .78rem;
    color: var(--muted2);
    text-align: center;
    padding: 1.4rem 1rem;
    border: 1px dashed var(--line-on-cream);
    border-radius: 3px;
}

/* ---------------- TOOLTIP THEME ---------------- */

.tippy-box canvas { filter: drop-shadow(0 0 4px rgba(0,0,0,.3)); }

.tippy-box[data-theme~=translucent] {
    background-color: var(--ink);
    color: var(--cream);
    border-radius: 3px;
    padding: .55rem .9rem;
    font-family: var(--font-main);
    font-size: .78rem;
    font-weight: 600;
}

.tippy-box[data-theme~=translucent][data-placement^=top] > .tippy-arrow:before { border-top-color: var(--ink); }
.tippy-box[data-theme~=translucent][data-placement^=bottom] > .tippy-arrow:before { border-bottom-color: var(--ink); }
.tippy-box[data-theme~=translucent][data-placement^=left] > .tippy-arrow:before { border-left-color: var(--ink); }
.tippy-box[data-theme~=translucent][data-placement^=right] > .tippy-arrow:before { border-right-color: var(--ink); }
.tippy-box[data-theme~=translucent] > .tippy-svg-arrow { fill: var(--ink); }

/* ---------------- FOOTER ---------------- */

.siteFooter { padding: 0 1.25rem calc(1.75rem + env(safe-area-inset-bottom)); }
.siteFooterRule { max-width: 30rem; margin: 0 auto; height: 1px; background: var(--line-on-cream); }
.siteFooterInner {
    max-width: 30rem;
    margin: 0 auto;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
    padding: 1.4rem 0 0;
}
.siteFooterWordmark { font-family: var(--font-display); font-size: 1.25rem; font-weight: 700; color: var(--ink); }
.siteFooterTagline { margin: .4rem 0 0; font-size: .78rem; color: var(--muted); max-width: 28ch; line-height: 1.5; }
.siteFooterNav { display: flex; flex-direction: column; gap: .5rem; font-size: .78rem; }
.siteFooterNav a { color: var(--muted); text-decoration: none; font-weight: 600; transition: color 200ms var(--ease-out); }
.siteFooterNav a:hover { color: var(--red-bright); }
.siteFooterBottom {
    margin-top: 1.1rem;
    padding-top: .9rem;
    border-top: 1px solid var(--line-on-cream);
    font-size: .68rem;
    font-weight: 500;
    letter-spacing: .04em;
    color: var(--muted2);
    justify-content: space-between;
}

/* ---------------- DOC PAGES (privacy / terms) ---------------- */

.docWrap { flex: 1; display: flex; justify-content: center; padding: 3rem 1.25rem 4rem; }
.doc { width: 100%; max-width: 34rem; }
.docBack { display: inline-block; font-size: .78rem; font-weight: 600; color: var(--muted); text-decoration: none; margin-bottom: 1.5rem; transition: color 200ms var(--ease-out); }
.docBack:hover { color: var(--red-bright); }
.doc h1 { font-size: 1.9rem; font-weight: 600; letter-spacing: -.01em; margin-bottom: .3rem; }
.docUpdated { font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted2); margin-bottom: 1.75rem; }
.doc h2 { font-size: 1.05rem; font-weight: 700; margin: 1.75rem 0 .6rem; }
.doc p { font-size: .92rem; line-height: 1.7; color: var(--muted); margin-bottom: .9rem; }
.doc p strong, .doc p b { color: var(--ink); }
.doc a { color: var(--red); }

@media (max-width: 480px) {
    .masthead { padding: calc(32px + env(safe-area-inset-top)) 16px 30px; }
    .card { padding: 1.6rem 1.25rem 1.4rem; }
    layflags-rolling-number { font-size: 2.9rem; }
    .saveRow { flex-direction: column; }
    #saveBtn { width: 100%; }
    .siteFooterInner { flex-direction: column; }
    .siteFooterBottom { flex-direction: column; gap: .4rem; }
}
