/* =====================================================
   voting.wiki -- Ballot-Paper Civic Design System
   ===================================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --ballot-cream: #F5F0E8;
    --civic-midnight: #1A1A2E;
    --slate-authority: #4A4A5E;
    --election-red: #B5121B;
    --precinct-blue: #1B4F8A;
    --tally-gold: #E8C94A;
    --parchment-tan: #EDE7D9;
    --ink-brown: #2D1810;

    --font-display: 'Bebas Neue', sans-serif;
    --font-body: 'Libre Baskerville', serif;
    --font-mono: 'IBM Plex Mono', monospace;

    --stub-width: 15%;
    --main-width: 55%;
    --tally-width: 30%;
    --column-rule: 3px solid var(--civic-midnight);
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--ballot-cream);
    color: var(--civic-midnight);
    font-family: var(--font-body);
    font-size: clamp(0.95rem, 1.1vw, 1.15rem);
    line-height: 1.72;
    font-weight: 400;
    overflow-x: hidden;
}

/* --- Scroll Progress Bar --- */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 4px;
    background-color: var(--election-red);
    z-index: 1000;
    transition: width 50ms linear;
}

/* --- Ballot Header / Masthead --- */
.ballot-header {
    position: relative;
    min-height: 100vh;
    border-top: 6px solid var(--civic-midnight);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ballot-header-columns {
    display: flex;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    position: relative;
    z-index: 2;
}

.header-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 2rem;
}

.masthead-title {
    font-family: var(--font-display);
    font-size: clamp(4rem, 10vw, 10rem);
    letter-spacing: 0.15em;
    line-height: 1;
    text-transform: uppercase;
    color: var(--civic-midnight);
    margin-bottom: 1.5rem;
}

.masthead-subtitle {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.8vw, 1.4rem);
    font-style: italic;
    color: var(--slate-authority);
    margin-bottom: 2rem;
    max-width: 600px;
}

.masthead-rule {
    width: 120px;
    height: 3px;
    background-color: var(--election-red);
    margin: 0 auto 2rem;
}

.masthead-descriptor {
    font-family: var(--font-body);
    font-size: clamp(0.85rem, 1vw, 1rem);
    color: var(--slate-authority);
    max-width: 560px;
    line-height: 1.8;
}

/* --- Seal Watermark --- */
.seal-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30vw;
    height: 30vw;
    max-width: 500px;
    max-height: 500px;
    z-index: 1;
    opacity: 0.05;
}

.seal-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 50%;
    border-style: dashed;
    border-color: var(--civic-midnight);
}

.seal-ring-outer {
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    border-width: 3px;
    border-dash: 8px 4px;
    animation: sealRotate 60s linear infinite;
}

.seal-ring-middle {
    width: 75%;
    height: 75%;
    transform: translate(-50%, -50%);
    border-width: 2px;
    animation: sealRotate 90s linear infinite reverse;
}

.seal-ring-inner {
    width: 50%;
    height: 50%;
    transform: translate(-50%, -50%);
    border-width: 1.5px;
    animation: sealRotate 120s linear infinite;
}

@keyframes sealRotate {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* --- Column Layout --- */
.ballot-columns {
    display: flex;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

.stub-column {
    width: var(--stub-width);
    background-color: var(--parchment-tan);
    border-right: var(--column-rule);
    padding: 2rem 0.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    position: relative;
}

.main-column {
    width: var(--main-width);
    padding: 3rem 2.5rem;
    border-right: var(--column-rule);
}

.tally-column {
    width: var(--tally-width);
    padding: 3rem 1.5rem;
    background-color: var(--parchment-tan);
}

.header-tally {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

/* --- Stub Column Elements --- */
.stub-text {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 0.05em;
    color: var(--slate-authority);
}

.stub-vertical {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    white-space: nowrap;
}

.stub-timestamp {
    margin-top: auto;
}

/* --- Rubber Stamps --- */
.stamp {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-brown);
    opacity: 0.6;
    font-family: var(--font-mono);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.stamp-circle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 3px double var(--ink-brown);
}

.stamp-rect {
    padding: 8px 16px;
    border: 3px double var(--ink-brown);
}

.stamp-small {
    padding: 4px 10px;
    border-width: 2px;
    font-size: 0.7rem;
}

.stamp-large {
    width: 120px;
    height: 120px;
    font-size: 1rem;
}

.stamp-text {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    text-align: center;
    line-height: 1.3;
    letter-spacing: 0.08em;
}

.stamp-large .stamp-text {
    font-size: 1rem;
    font-weight: 600;
}

/* Stamp animation classes */
.stamp[data-stamp] {
    opacity: 0;
    transform: scale(1.3);
    transition: opacity 200ms cubic-bezier(0.0, 0.0, 0.2, 1),
                transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1);
}

.stamp[data-stamp].stamp-visible {
    opacity: 0.6;
    transform: scale(1);
    animation: stampBounce 250ms cubic-bezier(0.0, 0.0, 0.2, 1) forwards;
}

@keyframes stampBounce {
    0% { transform: scale(1.3); opacity: 0; }
    70% { transform: scale(1); opacity: 0.6; }
    85% { transform: scale(0.97); }
    100% { transform: scale(1); opacity: 0.6; }
}

/* --- Date Stamp --- */
.date-stamp {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    font-family: var(--font-mono);
}

.date-stamp-label {
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    color: var(--slate-authority);
    text-transform: uppercase;
}

.date-stamp-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink-brown);
    letter-spacing: 0.05em;
}

/* --- Perforation Dividers --- */
.perforation-divider {
    position: relative;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.perforation-line {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 0;
    border-top: 2px dashed var(--civic-midnight);
    /* 8px dash, 4px gap */
    background: none;
}

.perforation-seal {
    position: relative;
    z-index: 2;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px double var(--civic-midnight);
    background-color: var(--ballot-cream);
    display: flex;
    align-items: center;
    justify-content: center;
}

.seal-number {
    font-family: var(--font-display);
    font-size: 0.9rem;
    color: var(--civic-midnight);
    letter-spacing: 0.05em;
}

/* --- Section Styling --- */
.ballot-section {
    min-height: 100vh;
    border-top: none;
}

.section-title {
    font-family: var(--font-display);
    font-size: clamp(1.6rem, 3vw, 3rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--civic-midnight);
    margin-bottom: 2rem;
    position: relative;
}

.section-number {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    color: var(--election-red);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}

.title-underline {
    display: block;
    width: 100%;
    height: 8px;
    margin-top: 0.5rem;
}

.wavy-line {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    transition: stroke-dashoffset 0.8s ease-out;
}

.wavy-line.animate-in {
    stroke-dashoffset: 0;
}

.subsection-title {
    font-family: var(--font-display);
    font-size: clamp(1.1rem, 1.8vw, 1.5rem);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--precinct-blue);
    margin: 2.5rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--precinct-blue);
}

.section-body p {
    margin-bottom: 2rem;
    color: var(--civic-midnight);
}

.section-body strong {
    font-weight: 700;
}

.section-body em {
    font-style: italic;
}

/* --- Tally Column Cards --- */
.tally-card {
    background-color: var(--ballot-cream);
    border: 2px solid var(--civic-midnight);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.tally-card-title {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--election-red);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--slate-authority);
}

.tally-entry {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.4rem 0;
    border-bottom: 1px dotted var(--slate-authority);
}

.tally-entry:last-child {
    border-bottom: none;
}

.tally-label {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--slate-authority);
}

.tally-value {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--civic-midnight);
    letter-spacing: 0.05em;
}

.tally-refs {
    list-style: none;
    padding: 0;
}

.tally-refs li {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--precinct-blue);
    padding: 0.3rem 0;
    border-bottom: 1px dotted var(--slate-authority);
    cursor: default;
}

.tally-refs li:last-child {
    border-bottom: none;
}

.tally-definition {
    font-family: var(--font-body);
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--slate-authority);
}

.tally-definition strong {
    color: var(--civic-midnight);
    font-weight: 700;
}

.tally-stamp {
    margin: 1.5rem auto;
    display: flex;
}

/* --- Tally Marks Data Viz --- */
.tally-marks-container {
    margin-bottom: 1rem;
}

.tally-marks-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    color: var(--slate-authority);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
}

.tally-marks {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 24px;
}

.tally-group {
    display: inline-flex;
    align-items: flex-end;
    position: relative;
    width: 28px;
    height: 24px;
}

.tally-group svg {
    width: 100%;
    height: 100%;
}

.tally-stroke {
    stroke: var(--civic-midnight);
    stroke-width: 1.5;
    stroke-linecap: round;
}

.tally-stroke-diagonal {
    stroke: var(--election-red);
    stroke-width: 1.5;
    stroke-linecap: round;
}

.tally-stroke,
.tally-stroke-diagonal {
    stroke-dasharray: 30;
    stroke-dashoffset: 30;
    transition: stroke-dashoffset 150ms ease-out;
}

.tally-stroke.animate-in,
.tally-stroke-diagonal.animate-in {
    stroke-dashoffset: 0;
}

.tally-count-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--slate-authority);
    margin-left: 4px;
    letter-spacing: 0.05em;
}

/* --- Ballot Measure (Interactive) --- */
.ballot-measure {
    display: flex;
    gap: 1rem;
    padding: 1.5rem;
    margin: 2rem 0;
    border: 2px solid var(--civic-midnight);
    background-color: var(--ballot-cream);
    cursor: pointer;
    transition: background-color 300ms ease;
    user-select: none;
}

.ballot-measure.checked {
    background-color: rgba(232, 201, 74, 0.1);
}

.measure-checkbox {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: 2px solid var(--civic-midnight);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.2rem;
}

.checkmark-svg {
    width: 24px;
    height: 24px;
}

.checkmark-path {
    stroke-dasharray: 30;
    stroke-dashoffset: 30;
    transition: stroke-dashoffset 300ms ease-out;
}

.ballot-measure.checked .checkmark-path {
    stroke-dashoffset: 0;
}

.measure-number {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    color: var(--election-red);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}

.measure-title {
    font-family: var(--font-display);
    font-size: clamp(1rem, 1.5vw, 1.3rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--civic-midnight);
    margin-bottom: 0.5rem;
}

.measure-desc {
    font-family: var(--font-body);
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--slate-authority);
}

/* --- Suffrage / Checklist Items --- */
.suffrage-list {
    margin: 2rem 0;
}

.suffrage-item {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    padding: 1rem 0;
    border-bottom: 1px dotted var(--slate-authority);
}

.suffrage-item:last-child {
    border-bottom: none;
}

.check-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    margin-top: 0.15rem;
}

.small-check {
    width: 18px;
    height: 18px;
}

.check-path {
    stroke-dasharray: 30;
    stroke-dashoffset: 30;
    transition: stroke-dashoffset 300ms ease-out;
}

.check-path.animate-in {
    stroke-dashoffset: 0;
}

.suffrage-text {
    font-family: var(--font-body);
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--civic-midnight);
}

.suffrage-text strong {
    font-weight: 700;
}

.integrity-list {
    display: flex;
    flex-direction: column;
}

.integrity-list .suffrage-item {
    padding: 0.5rem 0;
    gap: 0.5rem;
}

.integrity-list .suffrage-text {
    font-size: 0.8rem;
    font-family: var(--font-mono);
}

/* --- Footer: Ballot Stub --- */
.ballot-footer {
    margin-top: 2rem;
    padding-bottom: 4rem;
}

.footer-perforation {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto 3rem;
    border-top: 3px dashed var(--civic-midnight);
}

.footer-stub {
    max-width: 480px;
    margin: 0 auto;
    padding: 2.5rem;
    border: 3px dashed var(--civic-midnight);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.footer-info {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.footer-line {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    color: var(--civic-midnight);
}

.footer-sub {
    font-size: 0.75rem;
    color: var(--slate-authority);
}

.footer-seal-row {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* --- Responsive (mobile collapses to single-column) --- */
@media (max-width: 900px) {
    :root {
        --stub-width: 0%;
        --main-width: 100%;
        --tally-width: 100%;
    }

    .ballot-columns {
        flex-direction: column;
    }

    .stub-column {
        display: none;
    }

    .main-column {
        width: 100%;
        border-right: none;
        padding: 2rem 1.5rem;
    }

    .tally-column {
        width: 100%;
        padding: 1.5rem;
        border-top: var(--column-rule);
    }

    .ballot-header-columns {
        flex-direction: column;
    }

    .header-tally {
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
    }

    .masthead-title {
        font-size: clamp(3rem, 12vw, 6rem);
    }

    .ballot-measure {
        flex-direction: row;
    }
}

@media (max-width: 600px) {
    .masthead-title {
        font-size: clamp(2.5rem, 14vw, 4rem);
        letter-spacing: 0.08em;
    }

    .main-column {
        padding: 1.5rem 1rem;
    }

    .tally-column {
        padding: 1rem;
    }

    .footer-stub {
        margin: 0 1rem;
        padding: 1.5rem;
    }

    .footer-seal-row {
        gap: 0.5rem;
    }
}

/* --- Selection styling --- */
::selection {
    background-color: var(--tally-gold);
    color: var(--civic-midnight);
}
