/* =========================================================
   voting.wiki — styles.css
   pixel-art / card-grid / earth-tones / mysterious-moody
   Fonts: Libre Baskerville, Lora, Silkscreen (Google Fonts)
   Counter trigger uses IntersectionObserver at 0.5 threshold.
   ========================================================= */

@property --tally {
    syntax: "<integer>";
    inherits: false;
    initial-value: 0;
}

:root {
    --parchment:       #E8DCC8;
    --vellum:          #F2E9D8;
    --umber:           #2C2416;
    --charcoal:        #3C3529;
    --bronze:          #7A6C4F;
    --ballot-red:      #8B3A2A;
    --gold:            #B8963E;
    --sage:            #A0946F;

    --gutter: 4px;
    --border: 2px;

    --font-serif: "Libre Baskerville", Lora, Georgia, serif;
    --font-body:  "Lora", Georgia, serif;
    --font-pixel: "Silkscreen", "Courier New", monospace;
}

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

html, body {
    width: 100%;
    min-height: 100vh;
    background: var(--parchment);
    color: var(--umber);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.7;
    -webkit-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
    padding-bottom: 32px;
    position: relative;
}

/* ---------- Noise overlay ---------- */
.noise-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9000;
    opacity: 0.06;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='128' height='128'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.17 0 0 0 0 0.14 0 0 0 0 0.08 0 0 0 0.9 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 128px 128px;
    background-repeat: repeat;
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9001;
    background-image:
        repeating-linear-gradient(
            to bottom,
            rgba(60, 53, 41, 0.035) 0px,
            rgba(60, 53, 41, 0.035) 1px,
            transparent 1px,
            transparent 3px
        );
    opacity: 0.5;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
    font-family: var(--font-serif);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--umber);
}

h1 { font-size: clamp(1.8rem, 4vw, 3rem); line-height: 1.15; }
h2 { font-size: clamp(1.3rem, 2.5vw, 2rem); line-height: 1.25; }
h3 { font-size: clamp(1rem, 1.6vw, 1.25rem); line-height: 1.3; }

p {
    font-family: var(--font-body);
    font-size: clamp(0.95rem, 1.6vw, 1.1rem);
    color: var(--umber);
}

.pixel, .tally-number, .tally-label,
.master-meta, .master-cell-k, .master-cell-v,
.card-meta, .section-kicker, .sidebar-label, .sidebar-dot,
.sidebar-meta, .tab-text, .tab-bullet,
.status-prompt, .status-section, .status-entry,
.status-coord, .status-time, .status-sep, .status-blink,
.form-label, .form-meta, .form-submit-text, .form-submit-mark,
.edit-time, .edit-author, .edit-diff,
.closing-line, .closing-meta,
.master-scroll {
    font-family: var(--font-pixel);
    font-smooth: never;
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: auto;
    letter-spacing: 0;
}

/* Links with underline-draw */
a {
    color: var(--umber);
    text-decoration: none;
    background-image: linear-gradient(to right, var(--ballot-red), var(--ballot-red));
    background-repeat: no-repeat;
    background-size: 0% 2px;
    background-position: 0 calc(100% + 2px);
    transition: background-size 300ms ease;
    padding-bottom: 2px;
}
a:hover {
    background-size: 100% 2px;
}

em, i {
    font-style: italic;
    color: var(--charcoal);
}

/* ---------- Layout shell ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 32px;
    width: 180px;
    padding: 28px 18px 18px 18px;
    background: var(--vellum);
    border-right: var(--border) solid var(--charcoal);
    z-index: 100;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px dashed var(--charcoal);
}
.sidebar-label {
    font-size: 12px;
    color: var(--charcoal);
    letter-spacing: 0.08em;
}
.sidebar-dot {
    font-size: 12px;
    color: var(--ballot-red);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border: 1px dashed var(--bronze);
    background: transparent;
    color: var(--charcoal);
    font-size: 12px;
    background-image: none;
    padding-bottom: 6px;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.tab .tab-bullet {
    color: var(--bronze);
    font-size: 12px;
}
.tab .tab-text {
    color: var(--charcoal);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.tab:hover,
.tab.active {
    background: var(--charcoal);
    border-color: var(--charcoal);
    border-style: solid;
}
.tab:hover .tab-bullet,
.tab:hover .tab-text,
.tab.active .tab-bullet,
.tab.active .tab-text {
    color: var(--parchment);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px dashed var(--charcoal);
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--bronze);
}

/* ---------- Main ---------- */
.main {
    margin-left: 180px;
    padding: 0 32px 80px 32px;
    max-width: 1400px;
}

/* ---------- Master card ---------- */
.master-section {
    min-height: calc(100vh - 32px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 0;
}

.master-card {
    width: 80%;
    max-width: 900px;
    min-height: 70vh;
    background: var(--vellum);
    border: var(--border) solid var(--charcoal);
    padding: 28px 36px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-shadow: 6px 6px 0 0 var(--charcoal);
}

.master-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--charcoal);
}
.master-meta {
    font-size: 12px;
    color: var(--bronze);
    letter-spacing: 0.06em;
}

.master-body {
    display: flex;
    flex-direction: column;
    gap: 18px;
    flex: 1;
    padding: 8px 0;
}

.master-logomark {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}
.master-logomark canvas {
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    -ms-interpolation-mode: nearest-neighbor;
    width: 240px;
    height: 48px;
}

.master-title {
    font-size: clamp(2.2rem, 6vw, 4rem);
    line-height: 1;
    color: var(--charcoal);
    letter-spacing: 0.01em;
}
.master-dot {
    color: var(--ballot-red);
}
.master-sub {
    font-style: italic;
    color: var(--bronze);
    max-width: 60ch;
}

.tally {
    display: flex;
    align-items: baseline;
    gap: 14px;
    padding: 14px 16px;
    background: var(--parchment);
    border: 1px solid var(--charcoal);
    margin-top: 10px;
}
.tally-label {
    font-size: 12px;
    color: var(--bronze);
    letter-spacing: 0.12em;
}
.tally-number {
    font-size: 28px;
    color: var(--charcoal);
    letter-spacing: 0.04em;
}
.tally-pulse {
    display: inline-block;
    width: 10px;
    height: 10px;
    background: var(--ballot-red);
    margin-left: auto;
    animation: pulse 1.4s steps(2) infinite;
}
@keyframes pulse {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0.2; }
}

.master-rule {
    height: 2px;
    background:
        repeating-linear-gradient(
            to right,
            var(--charcoal) 0 6px,
            transparent 6px 12px
        );
    margin: 4px 0;
}

.master-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    border: 1px solid var(--charcoal);
}
.master-cell {
    padding: 10px 12px;
    border-right: 1px solid var(--charcoal);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.master-cell:last-child { border-right: none; }
.master-cell-k {
    font-size: 12px;
    color: var(--bronze);
    letter-spacing: 0.08em;
}
.master-cell-v {
    font-size: 16px;
    color: var(--charcoal);
}

.master-foot {
    border-top: 1px solid var(--charcoal);
    padding-top: 10px;
    display: flex;
    justify-content: center;
}
.master-scroll {
    font-size: 12px;
    color: var(--ballot-red);
    letter-spacing: 0.2em;
    animation: scrollBlink 1.6s steps(2) infinite;
}
@keyframes scrollBlink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0.35; }
}

/* ---------- Archive sections ---------- */
.archive-section {
    padding: 80px 0 40px 0;
    border-top: 2px solid var(--charcoal);
    margin-top: 40px;
}
.archive-section:first-of-type { border-top: none; margin-top: 0; }

.section-head {
    max-width: 70ch;
    margin-bottom: 32px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.section-kicker {
    font-size: 12px;
    color: var(--bronze);
    letter-spacing: 0.14em;
}
.section-title {
    color: var(--charcoal);
}
.section-lede {
    font-style: italic;
    color: var(--umber);
    max-width: 60ch;
}

/* Dark variant (futures) */
.archive-section[data-variant="dark"] {
    background: var(--charcoal);
    color: var(--parchment);
    padding: 80px 32px 40px 32px;
    margin-left: -32px;
    margin-right: -32px;
}
.archive-section[data-variant="dark"] .section-title,
.archive-section[data-variant="dark"] .section-lede { color: var(--parchment); }
.archive-section[data-variant="dark"] .section-kicker { color: var(--gold); }

/* ---------- Card grid ---------- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--gutter);
}

.ballot-card {
    aspect-ratio: 3 / 4;
    background: var(--vellum);
    border: var(--border) solid var(--charcoal);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    transition: transform 160ms ease, background 160ms ease;
}
.ballot-card:hover {
    transform: translate(-2px, -2px);
    background: var(--parchment);
    box-shadow: 4px 4px 0 0 var(--charcoal);
}

.ballot-card .card-art {
    flex: 0 0 40%;
    background: var(--parchment);
    border-bottom: 1px solid var(--charcoal);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}
.pixel-canvas {
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    -ms-interpolation-mode: nearest-neighbor;
    width: 75%;
    height: 75%;
    max-width: 180px;
    max-height: 180px;
}

.ballot-card .card-body {
    flex: 1;
    padding: 14px 14px 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}
.card-title {
    font-family: var(--font-serif);
    font-weight: 700;
    color: var(--charcoal);
    font-size: 1.05rem;
    line-height: 1.2;
}
.card-desc {
    font-family: var(--font-body);
    font-size: 0.88rem;
    color: var(--umber);
    line-height: 1.45;
    flex: 1;
    overflow: hidden;
}
.card-meta {
    margin-top: auto;
    font-size: 12px;
    color: var(--bronze);
    letter-spacing: 0.08em;
    padding-top: 8px;
    border-top: 1px dashed var(--bronze);
}

/* Future cards (dark section) */
.ballot-card--future {
    background: #2A251B;
    color: var(--parchment);
    border-color: var(--gold);
}
.ballot-card--future .card-art {
    background: var(--charcoal);
    border-bottom-color: var(--gold);
}
.ballot-card--future .card-title { color: var(--parchment); }
.ballot-card--future .card-desc { color: var(--parchment); opacity: 0.9; }
.ballot-card--future .card-meta { color: var(--gold); border-top-color: var(--gold); }
.ballot-card--future:hover {
    background: #1E1A13;
    box-shadow: 4px 4px 0 0 var(--gold);
}

/* ---------- Edit log ---------- */
.edit-log {
    border: 2px solid var(--charcoal);
    background: var(--vellum);
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.edit-row {
    display: grid;
    grid-template-columns: 90px 140px 1fr 110px;
    gap: 14px;
    padding: 10px 12px;
    border-bottom: 1px dashed var(--bronze);
    align-items: baseline;
    font-family: var(--font-body);
    font-size: 0.95rem;
}
.edit-row:last-child { border-bottom: none; }
.edit-row:hover {
    background: var(--parchment);
}
.edit-time {
    font-size: 12px;
    color: var(--bronze);
}
.edit-author {
    font-size: 12px;
    color: var(--ballot-red);
    letter-spacing: 0.04em;
}
.edit-change {
    color: var(--umber);
}
.edit-change em {
    font-family: var(--font-serif);
    font-style: italic;
    color: var(--charcoal);
}
.edit-diff {
    font-size: 12px;
    color: var(--sage);
    text-align: right;
}

/* ---------- Form ---------- */
.ballot-form {
    border: 2px solid var(--charcoal);
    background: var(--vellum);
    padding: 22px 22px 18px 22px;
    max-width: 780px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.form-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.form-label {
    font-size: 12px;
    color: var(--bronze);
    letter-spacing: 0.1em;
}
.form-input {
    font-family: var(--font-body);
    font-size: 1rem;
    padding: 10px 12px;
    background: var(--parchment);
    border: 1px solid var(--charcoal);
    color: var(--umber);
    border-radius: 0;
    outline: none;
    width: 100%;
    transition: border-color 120ms ease, background 120ms ease;
}
.form-input:focus {
    border-color: var(--ballot-red);
    background: #FFF8E8;
}
.form-textarea {
    resize: vertical;
    min-height: 120px;
    font-family: var(--font-body);
    line-height: 1.6;
}
select.form-input {
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--charcoal) 50%),
        linear-gradient(-45deg, transparent 50%, var(--charcoal) 50%);
    background-position:
        calc(100% - 18px) 18px,
        calc(100% - 12px) 18px;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 36px;
}
.form-row--actions {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 6px;
    border-top: 1px dashed var(--bronze);
    padding-top: 14px;
}
.form-meta {
    font-size: 12px;
    color: var(--bronze);
    letter-spacing: 0.08em;
}
.form-submit {
    font-family: var(--font-pixel);
    font-size: 12px;
    letter-spacing: 0.14em;
    padding: 10px 18px;
    background: var(--charcoal);
    color: var(--parchment);
    border: 2px solid var(--charcoal);
    border-radius: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: background 150ms ease, color 150ms ease;
}
.form-submit:hover {
    background: var(--ballot-red);
    border-color: var(--ballot-red);
}
.form-submit-mark {
    font-size: 14px;
    color: var(--gold);
}
.form-submit.sent {
    background: var(--bronze);
    border-color: var(--bronze);
}

/* ---------- Closing ---------- */
.closing {
    padding: 60px 0 40px 0;
    border-top: 2px solid var(--charcoal);
    margin-top: 40px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.closing-line {
    font-size: 12px;
    color: var(--ballot-red);
    letter-spacing: 0.3em;
}
.closing-meta {
    font-size: 12px;
    color: var(--bronze);
    letter-spacing: 0.1em;
}

/* ---------- Status bar (footer) ---------- */
.status-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 32px;
    background: var(--charcoal);
    color: var(--parchment);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 14px;
    z-index: 10000;
    border-top: 1px solid var(--bronze);
    font-family: var(--font-pixel);
    font-size: 12px;
}
.status-left,
.status-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.status-right { justify-content: flex-end; }
.status-center {
    display: flex;
    align-items: center;
    justify-content: center;
}
.status-prompt { color: var(--gold); }
.status-section { color: var(--parchment); letter-spacing: 0.12em; }
.status-entry { color: var(--sage); letter-spacing: 0.06em; }
.status-sep { color: var(--bronze); }
.status-blink {
    color: var(--ballot-red);
    animation: pulse 1.2s steps(2) infinite;
}
.status-coord { color: var(--sage); }
.status-time { color: var(--parchment); }

/* Walking pixel sprite */
.sprite {
    position: relative;
    width: 24px;
    height: 22px;
    image-rendering: pixelated;
}
.sprite-body {
    position: absolute;
    left: 2px;
    bottom: 0;
    width: 12px;
    height: 16px;
    background:
        /* head */
        linear-gradient(var(--parchment), var(--parchment)) 2px 0 / 8px 4px no-repeat,
        /* torso */
        linear-gradient(var(--gold), var(--gold)) 0 4px / 12px 6px no-repeat,
        /* legs */
        linear-gradient(var(--charcoal), var(--charcoal)) 0 10px / 4px 6px no-repeat,
        linear-gradient(var(--charcoal), var(--charcoal)) 8px 10px / 4px 6px no-repeat;
    animation: spriteWalk 0.8s steps(2) infinite;
}
.sprite-ballot {
    position: absolute;
    right: 0;
    bottom: 8px;
    width: 8px;
    height: 6px;
    background: var(--parchment);
    border: 1px solid var(--bronze);
    animation: spriteBallot 0.8s steps(2) infinite;
}
@keyframes spriteWalk {
    0%   { transform: translateY(0); }
    50%  { transform: translateY(-1px); }
    100% { transform: translateY(0); }
}
@keyframes spriteBallot {
    0%   { transform: translateY(0) rotate(0deg); }
    50%  { transform: translateY(-2px) rotate(-3deg); }
    100% { transform: translateY(0) rotate(0deg); }
}

/* ---------- Animations ---------- */
.master-card.enter {
    animation: cardEnter 600ms ease-out;
}
@keyframes cardEnter {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ballot-card.reveal {
    animation: cardReveal 500ms ease-out both;
}
@keyframes cardReveal {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
    .card-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
@media (max-width: 900px) {
    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 2px solid var(--charcoal);
        padding: 14px 14px 10px 14px;
        flex-direction: row;
        align-items: center;
        gap: 10px;
        overflow-x: auto;
        overflow-y: hidden;
    }
    .sidebar-header,
    .sidebar-footer { display: none; }
    .sidebar-nav {
        flex-direction: row;
        gap: 6px;
        flex: 1;
        overflow-x: auto;
    }
    .tab { flex: 0 0 auto; white-space: nowrap; }
    .main {
        margin-left: 0;
        padding: 0 16px 80px 16px;
    }
    .master-card {
        width: 95%;
        padding: 20px;
    }
    .master-grid { grid-template-columns: repeat(2, 1fr); }
    .master-cell:nth-child(2) { border-right: none; }
    .master-cell:nth-child(1),
    .master-cell:nth-child(2) {
        border-bottom: 1px solid var(--charcoal);
    }
    .card-grid { grid-template-columns: repeat(2, 1fr); }
    .edit-row {
        grid-template-columns: 80px 1fr;
        row-gap: 4px;
    }
    .edit-diff { grid-column: 2; text-align: left; }
    .archive-section[data-variant="dark"] {
        margin-left: -16px;
        margin-right: -16px;
        padding: 60px 16px 40px 16px;
    }
}
@media (max-width: 560px) {
    .card-grid { grid-template-columns: 1fr; }
    .master-grid { grid-template-columns: 1fr; }
    .master-cell { border-right: none; border-bottom: 1px solid var(--charcoal); }
    .master-cell:last-child { border-bottom: none; }
    .status-left .status-entry,
    .status-right .status-coord { display: none; }
}
