/* =========================================================
   voting.wiki — an axonometric atlas of democratic machinery
   Palette (strict):
     #f2ead6 paper base, #2b1f14 deep ink, #5a4a3a oxidized ink,
     #7a3e2a tally ink, #3c5a3c civic green, #c9b994 shadow umber,
     #d6cab0 faint rule, #8a6f4d marginalia
   Fonts: Rozha One (display), Fraunces (body), Azeret Mono (labels),
          Special Elite (marginalia).
   ========================================================= */

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

html, body {
    background: #f2ead6;
    color: #2b1f14;
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 300;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    cursor: none;
}

body {
    position: relative;
    min-height: 100vh;
    padding-bottom: 32px; /* room for tally strip */
}

/* Paper grain overlay */
.paper-noise {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1000;
    mix-blend-mode: multiply;
    opacity: 0.6;
}

/* Isometric grid background (subtle blueprint substrate) */
.iso-grid-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image:
        linear-gradient(30deg, transparent 49.5%, #d6cab0 49.5%, #d6cab0 50.5%, transparent 50.5%),
        linear-gradient(-30deg, transparent 49.5%, #d6cab0 49.5%, #d6cab0 50.5%, transparent 50.5%),
        linear-gradient(90deg, transparent 49.5%, #d6cab0 49.5%, #d6cab0 50.5%, transparent 50.5%);
    background-size: 64px 37px, 64px 37px, 64px 37px;
    background-position: 0 0, 0 0, 0 0;
    opacity: 0.28;
}

/* Custom cursor (compass) */
.compass-cursor {
    position: fixed;
    left: 0;
    top: 0;
    width: 24px;
    height: 24px;
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%);
    transition: transform 80ms linear;
    mix-blend-mode: multiply;
}

.compass-cursor.state-magnify #compassShape {
    transition: opacity 200ms ease;
}

.compass-cursor svg {
    width: 100%;
    height: 100%;
}

/* =============== PLATE structure =============== */

.plate {
    position: relative;
    min-height: 100vh;
    padding: 80px 200px 80px 160px;
    display: grid;
    grid-template-columns: 1fr;
    z-index: 1;
    border-bottom: 1px solid #d6cab0;
}

.plate-margin-left {
    position: absolute;
    top: 80px;
    bottom: 80px;
    left: 40px;
    width: 100px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: flex-start;
    z-index: 2;
}

.margin-number {
    font-family: 'Azeret Mono', monospace;
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    color: #2b1f14;
    font-weight: 500;
    text-transform: uppercase;
}

.margin-key {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
}

.margin-key svg {
    display: block;
}

.margin-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-family: 'Special Elite', monospace;
    font-size: 0.72rem;
    color: #8a6f4d;
    opacity: 0.75;
    letter-spacing: 0.04em;
}

.dot-dash-rule {
    width: 80px;
    height: 4px;
    background-image: radial-gradient(circle, #5a4a3a 1px, transparent 1.2px),
                      linear-gradient(90deg, transparent 5px, #5a4a3a 5px, #5a4a3a 14px, transparent 14px);
    background-size: 6px 2px, 20px 1.5px;
    background-repeat: repeat-x, repeat-x;
    background-position: 0 1px, 0 1px;
    opacity: 0.7;
}

/* =============== OPENING PLATE =============== */

.plate-opening {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 160px 1fr 1fr 200px;
    align-items: center;
    padding: 40px 40px 60px 40px;
    position: relative;
}

.plate-opening .plate-margin-left {
    position: relative;
    top: auto;
    bottom: auto;
    left: auto;
    grid-column: 1;
    align-self: start;
    margin-top: 40px;
}

.opening-wordmark {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    gap: 24px;
    z-index: 2;
}

.kicker {
    font-family: 'Azeret Mono', monospace;
    font-size: 0.78rem;
    letter-spacing: 0.2em;
    color: #5a4a3a;
    text-transform: uppercase;
    font-weight: 500;
}

.wordmark {
    font-family: 'Rozha One', serif;
    font-size: clamp(5rem, 14vw, 12rem);
    line-height: 0.92;
    letter-spacing: -0.01em;
    color: #2b1f14;
    font-weight: 400;
    display: flex;
    flex-direction: column;
}

.wm-row {
    display: block;
    overflow: hidden;
}

.wm-row-second {
    padding-left: 0.1em;
}

.subtitle {
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-weight: 300;
    font-size: 1.25rem;
    color: #5a4a3a;
    max-width: 32em;
    line-height: 1.45;
    margin-top: 8px;
}

.opening-ballot {
    grid-column: 3;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ballot-hero {
    width: 100%;
    max-width: 480px;
    height: auto;
}

.lid-group {
    transform-origin: center;
    animation: lidBob 6s ease-in-out infinite;
}

.slip-group {
    transform-origin: 240px 260px;
    animation: slipFall 6s ease-in-out infinite;
}

@keyframes lidBob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@keyframes slipFall {
    0%, 100% { transform: translateY(-2px); opacity: 0.95; }
    50% { transform: translateY(2px); opacity: 1; }
}

/* Title block (bottom-right) */
.title-block {
    grid-column: 4;
    align-self: end;
    justify-self: end;
    width: 200px;
    padding: 12px 14px;
    border: 1px solid #2b1f14;
    background: #f2ead6;
    font-family: 'Azeret Mono', monospace;
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    color: #2b1f14;
    line-height: 1.5;
    text-transform: uppercase;
    margin-bottom: 60px;
    margin-right: 20px;
    z-index: 2;
    position: relative;
}

.tb-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 2px 0;
}

.tb-sep {
    height: 1px;
    background: #2b1f14;
    margin: 4px 0;
    opacity: 0.6;
}

.opening-scroll-hint {
    position: absolute;
    bottom: 64px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Azeret Mono', monospace;
    font-size: 0.68rem;
    letter-spacing: 0.14em;
    color: #5a4a3a;
    animation: hintPulse 2.4s ease-in-out infinite;
}

@keyframes hintPulse {
    0%, 100% { opacity: 0.6; transform: translate(-50%, 0); }
    50% { opacity: 1; transform: translate(-50%, 4px); }
}

/* =============== STANDARD PLATE BODY =============== */

.plate-body {
    display: grid;
    grid-template-columns: 1fr 380px;
    grid-template-rows: auto 1fr;
    gap: 40px 60px;
    padding-top: 20px;
    position: relative;
}

.plate-header {
    grid-column: 1 / -1;
    max-width: 920px;
    position: relative;
    z-index: 3;
}

.plate-kicker {
    font-family: 'Azeret Mono', monospace;
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    color: #5a4a3a;
    text-transform: uppercase;
    font-weight: 500;
    display: block;
    margin-bottom: 16px;
}

.plate-title {
    font-family: 'Rozha One', serif;
    font-size: clamp(3.5rem, 9vw, 7.2rem);
    line-height: 0.95;
    letter-spacing: -0.01em;
    color: #2b1f14;
    font-weight: 400;
    margin-bottom: 24px;
}

.plate-lede {
    font-family: 'Fraunces', serif;
    font-weight: 300;
    font-size: 1.2rem;
    line-height: 1.55;
    color: #2b1f14;
    max-width: 34em;
    font-variation-settings: "opsz" 144;
}

/* Diagram panel */
.plate-diagram {
    grid-column: 1;
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px 0;
}

.diagram {
    width: 100%;
    max-width: 720px;
    height: auto;
    display: block;
}

/* Diagram parts animate on scroll */
.dpart {
    transform-origin: center;
    transition: transform 900ms cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 600ms ease;
    opacity: 0;
    transform: translateY(22px);
}

.plate.in-view .dpart { opacity: 1; transform: translateY(0); }
.plate.in-view .dpart[data-drift="0"] { transition-delay: 0ms; }
.plate.in-view .dpart[data-drift="1"] { transition-delay: 120ms; }
.plate.in-view .dpart[data-drift="2"] { transition-delay: 240ms; }
.plate.in-view .dpart[data-drift="3"] { transition-delay: 360ms; }
.plate.in-view .dpart[data-drift="4"] { transition-delay: 480ms; }
.plate.in-view .dpart[data-drift="5"] { transition-delay: 600ms; }

/* Leader lines draw in */
.leader {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 900ms ease 500ms;
}

.plate.in-view .leader { stroke-dashoffset: 0; }

.leader-label {
    opacity: 0;
    transition: opacity 400ms ease 1400ms;
}

.plate.in-view .leader-label { opacity: 1; }

/* Annotations (orthogonal text block) */
.plate-annotations {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 10px 0;
    font-family: 'Fraunces', serif;
    font-weight: 300;
    font-size: 0.96rem;
    line-height: 1.55;
    color: #2b1f14;
    max-width: 34em;
    position: relative;
    z-index: 3;
}

.plate-annotations p {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.callout-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border: 1px solid #2b1f14;
    border-radius: 50%;
    font-family: 'Azeret Mono', monospace;
    font-size: 0.62rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: #2b1f14;
    background: #f2ead6;
    margin-top: 2px;
}

/* Plate stamp */
.plate-stamp {
    position: absolute;
    top: 40px;
    right: -30px;
    opacity: 0;
    transform: rotate(12deg) scale(0.6);
    transition: opacity 600ms ease 1200ms,
                transform 900ms cubic-bezier(0.34, 1.56, 0.64, 1) 1200ms;
    pointer-events: none;
    z-index: 4;
}

.plate.in-view .plate-stamp {
    opacity: 0.82;
    transform: rotate(-7deg) scale(1);
}

/* Plate marginalia (handwritten) */
.plate-marginalia {
    position: absolute;
    bottom: 30px;
    right: 20px;
    max-width: 260px;
    font-family: 'Special Elite', monospace;
    font-size: 0.86rem;
    letter-spacing: 0.02em;
    color: #8a6f4d;
    opacity: 0;
    transform: translateX(12px);
    transition: opacity 600ms ease, transform 600ms ease;
    font-style: italic;
    line-height: 1.4;
    z-index: 4;
}

.plate.in-view .plate-marginalia {
    opacity: 0.75;
    transform: translateX(0);
    transition-delay: 1600ms;
}

/* Revision stamp target */

/* =============== LEVER COUNTER =============== */

.lever-counter {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px 0;
    position: relative;
    z-index: 1;
    border-bottom: 1px dashed #d6cab0;
    background: #f2ead6;
}

.lever-counter svg {
    display: block;
}

.dial-glyph {
    opacity: 0;
    transition: opacity 200ms ease;
}

.lever-counter.spun .dial-glyph {
    opacity: 1;
}

.lever-counter.spinning .dial {
    filter: blur(0.4px);
}

.lever-counter.spinning .dial-glyph {
    opacity: 0.3;
    animation: dialFlicker 120ms linear infinite;
}

@keyframes dialFlicker {
    0%, 100% { opacity: 0.25; }
    50% { opacity: 0.6; }
}

/* =============== FINAL PLATE =============== */

.plate-final {
    min-height: 100vh;
    padding: 80px 160px 140px 160px;
}

.plate-body-final {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    gap: 40px;
    align-items: center;
    justify-items: center;
    text-align: center;
    max-width: 900px;
    margin: 0 auto;
}

.plate-header-final {
    grid-column: 1;
    text-align: center;
    max-width: 100%;
}

.plate-header-final .plate-title {
    text-align: center;
}

.plate-final-text {
    grid-column: 1;
    max-width: 32em;
    margin: 0 auto;
    font-family: 'Fraunces', serif;
    font-weight: 300;
    font-size: 1.15rem;
    line-height: 1.7;
    color: #2b1f14;
    text-align: left;
    padding: 40px 0 20px 0;
}

.plate-final-text p {
    margin-bottom: 28px;
}

.plate-final-coda {
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-size: 1.35rem;
    text-align: center;
    line-height: 1.4;
    color: #2b1f14;
    padding: 20px 0;
    font-variation-settings: "opsz" 144;
    font-weight: 300;
}

.final-ballot {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 0;
}

.fin-mark {
    font-family: 'Azeret Mono', monospace;
    font-size: 0.88rem;
    letter-spacing: 0.3em;
    color: #5a4a3a;
    text-align: center;
    padding: 20px 0;
}

.plate-stamp-final {
    position: absolute;
    bottom: 30px;
    right: 30px;
    top: auto;
    right: 40px;
}

/* =============== TALLY STRIP =============== */

.tally-strip {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 32px;
    background: #f2ead6;
    border-top: 1px solid #d6cab0;
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 100;
    font-family: 'Azeret Mono', monospace;
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    color: #5a4a3a;
    gap: 20px;
}

.tally-label {
    text-transform: uppercase;
    color: #5a4a3a;
    font-weight: 500;
}

.tally-marks {
    display: flex;
    gap: 20px;
    align-items: center;
    flex: 1;
    justify-content: center;
}

.tally-group {
    display: flex;
    gap: 4px;
    position: relative;
    padding: 0 4px;
}

.tally {
    display: inline-block;
    width: 12px;
    text-align: center;
    color: #d6cab0;
    font-size: 1.4rem;
    line-height: 1;
    transition: color 400ms ease, opacity 400ms ease;
    font-weight: 500;
}

.tally.filled {
    color: #7a3e2a;
}

.tally.current {
    color: #3c5a3c;
    animation: tallyPulse 1.2s ease-in-out infinite;
}

.tally.slash {
    transform: rotate(0);
    font-size: 1.6rem;
    margin-left: -40px;
    padding-left: 0;
    color: #d6cab0;
}

.tally.slash.filled {
    color: #7a3e2a;
}

@keyframes tallyPulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

.tally-caption {
    color: #2b1f14;
    font-weight: 500;
    min-width: 200px;
    text-align: right;
}

/* =============== RESPONSIVE =============== */

@media (max-width: 1100px) {
    .plate {
        padding: 60px 40px 60px 140px;
    }
    .plate-margin-left {
        left: 20px;
        width: 90px;
    }
    .plate-body {
        grid-template-columns: 1fr;
        gap: 30px;
    }
    .plate-annotations {
        grid-column: 1;
    }
    .plate-diagram {
        grid-column: 1;
    }
    .plate-stamp {
        right: 10px;
    }
    .plate-marginalia {
        right: 10px;
    }
    .plate-opening {
        grid-template-columns: 120px 1fr;
        grid-template-rows: auto auto auto;
    }
    .opening-wordmark {
        grid-column: 2;
        grid-row: 1;
    }
    .opening-ballot {
        grid-column: 1 / -1;
        grid-row: 2;
    }
    .title-block {
        grid-column: 1 / -1;
        grid-row: 3;
        justify-self: end;
    }
    .plate-final {
        padding: 60px 40px 120px 40px;
    }
}

@media (max-width: 640px) {
    body { cursor: auto; }
    .compass-cursor { display: none; }
    .plate {
        padding: 40px 20px 40px 90px;
    }
    .plate-margin-left {
        left: 10px;
        width: 70px;
    }
    .wordmark {
        font-size: clamp(3.2rem, 18vw, 5rem);
    }
    .plate-title {
        font-size: clamp(2.4rem, 14vw, 4rem);
    }
    .tally-label { display: none; }
    .tally-caption {
        min-width: auto;
        font-size: 0.6rem;
    }
}
