/* bcd.day - Abstract Glitch Art Tech */
/* Palette: #0a0f0d, #141f1a, #00ff41, #ffb000, #ff0040, #1a3328, #c8e6c9, #4a6b5a */

:root {
    --matrix: #0a0f0d;
    --cell: #141f1a;
    --green: #00ff41;
    --amber: #ffb000;
    --red: #ff0040;
    --grid: #1a3328;
    --text: #c8e6c9;
    --dim: #4a6b5a;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--matrix);
    color: var(--text);
    font-family: 'Roboto', sans-serif;
    font-weight: 400;
    line-height: 1.65;
    overflow-x: hidden;
    position: relative;
}

/* ========================================
   SCAN LINES OVERLAY
======================================== */
.scanlines {
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.03) 2px,
        rgba(0, 0, 0, 0.03) 4px
    );
    pointer-events: none;
    z-index: 100;
}

/* ========================================
   DIGIT MATRIX BACKGROUND
======================================== */
.digit-matrix {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(40, 1fr);
    grid-template-rows: repeat(25, 1fr);
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    color: var(--green);
    overflow: hidden;
    animation: matrixFadeIn 3s ease forwards 0.5s;
}

@keyframes matrixFadeIn {
    0% { opacity: 0; }
    100% { opacity: 0.06; }
}

.digit-matrix span {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: digitAppear 0.5s ease forwards;
}

@keyframes digitAppear {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.digit-matrix span.flipping {
    animation: digitFlip 0.3s ease;
    color: var(--amber);
}

@keyframes digitFlip {
    0% { transform: scaleY(1); }
    50% { transform: scaleY(0); color: var(--amber); }
    100% { transform: scaleY(1); }
}

/* ========================================
   BINARY RAIL (Data Bus)
======================================== */
.binary-rail {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 28px;
    background: rgba(10, 15, 13, 0.95);
    border-bottom: 1px solid var(--grid);
    display: flex;
    align-items: center;
    overflow: hidden;
    z-index: 50;
    font-family: 'Fira Code', monospace;
    font-size: 11px;
    color: var(--green);
    opacity: 0.6;
}

.rail-stream {
    white-space: nowrap;
    animation: railScroll 30s linear infinite;
}

@keyframes railScroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

.block-cursor {
    width: 8px;
    height: 14px;
    background: var(--green);
    animation: cursorBlink 1s step-end infinite;
    flex-shrink: 0;
}

@keyframes cursorBlink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* ========================================
   BCD CLOCK
======================================== */
.bcd-clock {
    position: fixed;
    top: 34px;
    right: 1.5rem;
    z-index: 50;
    font-family: 'Fira Code', monospace;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    opacity: 0;
    animation: clockFadeIn 1s ease forwards 2s;
}

@keyframes clockFadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.clock-label {
    font-size: 0.6rem;
    color: var(--dim);
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.clock-value {
    font-size: 0.7rem;
    color: var(--dim);
    letter-spacing: 0.08em;
}

/* ========================================
   SECTIONS (General)
======================================== */
.section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6rem 2rem;
    position: relative;
    z-index: 1;
}

/* ========================================
   HERO SECTION
======================================== */
.hero {
    padding-top: 80px;
    gap: 2rem;
}

.brand-container {
    text-align: center;
}

.brand-nibbles {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 2rem;
}

.nibble-char-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    opacity: 0;
    animation: charReveal 0.4s ease forwards;
}

.nibble-char-wrap:nth-child(1) { animation-delay: 0.8s; }
.nibble-char-wrap:nth-child(2) { animation-delay: 1.0s; }
.nibble-char-wrap:nth-child(3) { animation-delay: 1.2s; }
.nibble-char-wrap:nth-child(4) { animation-delay: 1.3s; }
.nibble-char-wrap:nth-child(5) { animation-delay: 1.5s; }
.nibble-char-wrap:nth-child(6) { animation-delay: 1.7s; }
.nibble-char-wrap:nth-child(7) { animation-delay: 1.9s; }

@keyframes charReveal {
    0% { opacity: 0; transform: translateY(15px); }
    100% { opacity: 1; transform: translateY(0); }
}

.nibble-binary {
    font-family: 'Fira Code', monospace;
    font-size: 0.55rem;
    color: var(--dim);
    letter-spacing: 0.1em;
}

.nibble-char {
    font-family: 'Major Mono Display', monospace;
    font-size: clamp(2.5rem, 7vw, 5rem);
    color: var(--green);
    border: 1px solid var(--grid);
    padding: 0.15em 0.25em;
    text-shadow: 0 0 20px rgba(0, 255, 65, 0.3);
    line-height: 1;
}

.nibble-char.dot {
    border: none;
    padding: 0.15em 0.08em;
}

.dot-wrap .nibble-binary {
    visibility: hidden;
}

.hero-sub {
    font-family: 'Fira Code', monospace;
    font-size: 0.8rem;
    color: var(--dim);
    letter-spacing: 0.05em;
    opacity: 0;
    animation: fadeUp 0.8s ease forwards 2.4s;
}

@keyframes fadeUp {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ========================================
   LED DOT MATRIX DISPLAY
======================================== */
.led-display {
    display: flex;
    gap: 10px;
    margin-top: 2rem;
    opacity: 0;
    animation: fadeUp 1s ease forwards 2.8s;
}

.led-char {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(7, 1fr);
    gap: 2px;
}

.led-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--cell);
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

.led-dot.on {
    background: var(--green);
    box-shadow: 0 0 4px rgba(0, 255, 65, 0.6);
}

.led-closing {
    display: flex;
    gap: 8px;
    margin-bottom: 2rem;
    opacity: 0;
}

.led-closing .led-char {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(7, 1fr);
    gap: 2px;
}

.led-closing .led-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--cell);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.led-closing .led-dot.on {
    background: var(--green);
    box-shadow: 0 0 3px rgba(0, 255, 65, 0.5);
}

/* ========================================
   CONTENT BLOCKS (Z-pattern)
======================================== */
.content-block {
    max-width: 600px;
    width: 100%;
}

.align-left {
    margin-right: auto;
    margin-left: 10vw;
}

.align-right {
    margin-left: auto;
    margin-right: 10vw;
}

.section-heading {
    font-family: 'Major Mono Display', monospace;
    font-size: clamp(1.5rem, 3vw, 2.2rem);
    color: var(--green);
    margin-bottom: 1.5rem;
    text-shadow: 0 0 10px rgba(0, 255, 65, 0.2);
}

.body-text {
    font-family: 'Roboto', sans-serif;
    font-size: 1rem;
    line-height: 1.65;
    color: var(--text);
}

/* ========================================
   ENCODING DISPLAY
======================================== */
.encoding-display {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 3rem;
    flex-wrap: wrap;
    justify-content: center;
}

.decimal-big {
    font-family: 'Major Mono Display', monospace;
    font-size: clamp(3rem, 8vw, 6rem);
    color: var(--amber);
    text-shadow: 0 0 15px rgba(255, 176, 0, 0.3);
}

.amber-glow {
    color: var(--amber);
    text-shadow: 0 0 20px rgba(255, 176, 0, 0.4);
}

.green-glow {
    color: var(--green);
    text-shadow: 0 0 20px rgba(0, 255, 65, 0.4);
}

.arrow-encode {
    font-size: 2rem;
    color: var(--dim);
}

.nibble-frame {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    border: 1px solid var(--grid);
}

.nibble-wide {
    grid-template-columns: repeat(4, 1fr);
}

.nibble-spacer {
    width: 12px;
}

.bit {
    font-family: 'Fira Code', monospace;
    font-size: 1.2rem;
    color: var(--green);
    background: var(--cell);
    padding: 0.75rem 1rem;
    text-align: center;
    border: 1px solid var(--grid);
}

.bit.err {
    color: var(--red);
    animation: errFlash 1.2s ease-in-out infinite;
}

@keyframes errFlash {
    0%, 100% { opacity: 1; background: var(--cell); }
    50% { opacity: 0.4; background: rgba(255, 0, 64, 0.08); }
}

.bit.highlight {
    color: var(--amber);
    text-shadow: 0 0 8px rgba(255, 176, 0, 0.4);
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

/* ========================================
   NIBBLE BLOCK (2x2 Grid)
======================================== */
.nibble-block {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 1px;
    border: 1px solid var(--grid);
    max-width: 700px;
    width: 100%;
}

.nibble-cell {
    background: var(--cell);
    padding: 1.5rem;
    position: relative;
}

.cell-label {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-family: 'Fira Code', monospace;
    font-size: 0.65rem;
    color: var(--dim);
}

.cell-title {
    font-family: 'Major Mono Display', monospace;
    font-size: 1rem;
    color: var(--green);
    margin-bottom: 0.5rem;
}

.cell-text {
    font-size: 0.85rem;
    color: var(--text);
    line-height: 1.5;
}

/* ========================================
   GLITCH EFFECTS
======================================== */
.glitch-text {
    position: relative;
}

.glitch-text::before,
.glitch-text::after {
    content: attr(data-text);
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
}

.section-glitch .glitch-text::before,
.section-glitch-2 .glitch-text::before {
    color: var(--red);
    animation: glitchR 3s ease-in-out infinite;
}

.section-glitch .glitch-text::after,
.section-glitch-2 .glitch-text::after {
    color: rgba(0, 255, 65, 0.7);
    animation: glitchG 3s ease-in-out infinite;
}

@keyframes glitchR {
    0%, 88%, 100% { opacity: 0; transform: translate(0); clip-path: inset(0); }
    90% { opacity: 0.8; transform: translate(3px, -2px); clip-path: inset(10% 0 40% 0); }
    92% { opacity: 0; clip-path: inset(0); }
    94% { opacity: 0.6; transform: translate(-2px, 1px); clip-path: inset(50% 0 20% 0); }
    96% { opacity: 0; }
}

@keyframes glitchG {
    0%, 86%, 100% { opacity: 0; transform: translate(0); clip-path: inset(0); }
    89% { opacity: 0.6; transform: translate(-3px, 2px); clip-path: inset(30% 0 10% 0); }
    91% { opacity: 0; clip-path: inset(0); }
    93% { opacity: 0.5; transform: translate(2px, -1px); clip-path: inset(60% 0 5% 0); }
    95% { opacity: 0; }
}

/* Full section glitch effect triggered by JS */
.section-glitch.glitching {
    animation: sectionGlitch 0.5s ease;
}

@keyframes sectionGlitch {
    0%, 100% { transform: translate(0); filter: none; }
    10% { transform: translate(-3px, 0) skewX(-1deg); filter: hue-rotate(90deg); }
    20% { transform: translate(3px, 0) skewX(1deg); }
    30% { transform: translate(0) skewX(0); filter: none; }
    40% { transform: translate(-2px, 1px); filter: hue-rotate(-90deg); }
    50% { transform: translate(0); filter: none; }
}

/* ========================================
   CARRY DISPLAY
======================================== */
.carry-display {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 3rem;
    padding: 2rem;
    border: 1px solid var(--grid);
    background: var(--cell);
    max-width: 500px;
    width: 100%;
}

.carry-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.carry-label {
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    color: var(--dim);
    width: 2rem;
    text-align: right;
}

.carry-bits {
    display: flex;
    gap: 1px;
}

.carry-bits .bit {
    padding: 0.4rem 0.6rem;
    font-size: 1rem;
}

.carry-decimal {
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    color: var(--dim);
}

.carry-divider {
    height: 1px;
    background: var(--grid);
    margin: 0.25rem 0;
}

.amber-bit {
    color: var(--amber);
    text-shadow: 0 0 6px rgba(255, 176, 0, 0.3);
}

.correction-bit {
    color: var(--red);
}

.green-bit {
    color: var(--green);
    text-shadow: 0 0 6px rgba(0, 255, 65, 0.3);
}

.carry-invalid {
    color: var(--red);
}

.carry-fix {
    color: var(--red);
    font-style: italic;
}

.carry-valid {
    color: var(--green);
}

.carry-sum .carry-label,
.carry-final .carry-label {
    color: var(--text);
}

.carry-correction .carry-label {
    color: var(--red);
}

/* ========================================
   INVALID STATES GRID
======================================== */
.invalid-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    border: 1px solid var(--red);
    max-width: 360px;
    width: 100%;
    margin-top: 2rem;
}

.invalid-cell {
    background: rgba(255, 0, 64, 0.04);
    padding: 1.2rem;
    text-align: center;
    border: 1px solid rgba(255, 0, 64, 0.15);
    position: relative;
}

.invalid-code {
    font-family: 'Fira Code', monospace;
    font-size: 1rem;
    color: var(--red);
    display: block;
    margin-bottom: 0.3rem;
    text-shadow: 0 0 8px rgba(255, 0, 64, 0.3);
}

.invalid-label {
    font-family: 'Fira Code', monospace;
    font-size: 0.6rem;
    color: rgba(255, 0, 64, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.2em;
}

.invalid-cell:hover {
    background: rgba(255, 0, 64, 0.08);
}

.invalid-cell:hover .invalid-code {
    animation: invalidFlicker 0.3s ease;
}

@keyframes invalidFlicker {
    0%, 100% { opacity: 1; }
    25% { opacity: 0.2; }
    50% { opacity: 0.8; }
    75% { opacity: 0.1; }
}

/* ========================================
   BCD TABLE
======================================== */
.bcd-table {
    border: 1px solid var(--grid);
    max-width: 280px;
    width: 100%;
}

.bcd-table-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--cell);
    border-bottom: 1px solid var(--grid);
}

.bcd-table-header span {
    font-family: 'Fira Code', monospace;
    font-size: 0.7rem;
    color: var(--dim);
    padding: 0.6rem 1rem;
    text-align: center;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.bcd-table-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-bottom: 1px solid var(--grid);
    transition: background 0.2s ease;
}

.bcd-table-row:last-child {
    border-bottom: none;
}

.bcd-table-row:hover {
    background: rgba(0, 255, 65, 0.03);
}

.bcd-table-row.active {
    background: rgba(0, 255, 65, 0.06);
}

.table-dec {
    font-family: 'Major Mono Display', monospace;
    font-size: 1.1rem;
    color: var(--amber);
    padding: 0.5rem 1rem;
    text-align: center;
}

.table-bcd {
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    color: var(--green);
    padding: 0.5rem 1rem;
    text-align: center;
}

/* ========================================
   CLOSING SECTION
======================================== */
.section-closing {
    padding-bottom: 8rem;
    gap: 1.5rem;
}

.closing-message {
    font-family: 'Major Mono Display', monospace;
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    color: var(--green);
    text-shadow: 0 0 15px rgba(0, 255, 65, 0.3);
}

.closing-binary {
    font-family: 'Fira Code', monospace;
    font-size: 0.7rem;
    color: var(--dim);
    letter-spacing: 0.1em;
    text-align: center;
    max-width: 600px;
    word-break: break-all;
    line-height: 1.8;
}

/* ========================================
   FADE IN ANIMATION
======================================== */
.fade-in {
    opacity: 0;
    transform: translateY(25px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.fade-in.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ========================================
   RESPONSIVE
======================================== */
@media (max-width: 768px) {
    .align-left,
    .align-right {
        margin-left: 5vw;
        margin-right: 5vw;
    }

    .nibble-block {
        grid-template-columns: 1fr;
    }

    .encoding-display {
        flex-direction: column;
        gap: 1rem;
    }

    .digit-matrix {
        grid-template-columns: repeat(20, 1fr);
        grid-template-rows: repeat(15, 1fr);
    }

    .bcd-clock {
        top: 34px;
        right: 0.5rem;
    }

    .clock-value {
        font-size: 0.55rem;
    }

    .brand-nibbles {
        gap: 3px;
    }

    .nibble-char {
        font-size: clamp(2rem, 6vw, 3.5rem);
        padding: 0.1em 0.15em;
    }

    .carry-display {
        padding: 1rem;
    }

    .carry-bits .bit {
        padding: 0.3rem 0.4rem;
        font-size: 0.85rem;
    }

    .invalid-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .led-display {
        gap: 6px;
    }

    .led-dot {
        width: 3px;
        height: 3px;
    }

    .section {
        padding: 4rem 1.5rem;
    }
}

@media (max-width: 480px) {
    .digit-matrix {
        grid-template-columns: repeat(12, 1fr);
        grid-template-rows: repeat(10, 1fr);
    }

    .nibble-spacer {
        width: 6px;
    }

    .bit {
        padding: 0.5rem 0.6rem;
        font-size: 1rem;
    }

    .decimal-big {
        font-size: clamp(2.5rem, 10vw, 4rem);
    }
}
