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

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    font-family: 'Courier New', monospace;
    background: #1a1a1a;
    color: #e0e0e0;
    min-height: 100vh;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* CSS Variable for rainbow mode */
:root {
    --rainbow-hue: 0;
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
    body {
        padding: 10px;
        align-items: flex-start;
        padding-top: 20px;
    }

    h1 {
        font-size: 1.8em;
        margin-bottom: 20px;
        letter-spacing: 4px;
    }

    h2 {
        font-size: 1.2em;
        margin-bottom: 15px;
        letter-spacing: 2px;
    }

    .section {
        padding: 20px;
        margin-bottom: 20px;
    }

    .splitflap-display {
        padding: 15px 8px;
        gap: 3px;
    }

    .flap {
        width: 38px;
        height: 52px;
        font-size: 30px;
    }

    .input-group {
        flex-direction: row;
    }

    #clearButton {
        padding: 14px 20px;
        font-size: 16px;
        flex: 1;
        letter-spacing: 1.5px;
    }

    #sendButton {
        padding: 14px 25px;
        font-size: 16px;
        flex: 2;
        letter-spacing: 1.5px;
    }
}

/* Medium smartphone screens */
@media (max-width: 480px) {
    .section {
        padding: 15px 8px;
    }

    .splitflap-display {
        padding: 10px 4px;
        gap: 1px;
    }

    .flap {
        width: calc((100vw - 60px) / 12);
        height: calc((100vw - 60px) / 12 * 1.35);
        font-size: calc((100vw - 60px) / 12 * 0.65);
    }
}

/* Small smartphone screens (iPhone SE, etc.) */
@media (max-width: 400px) {
    body {
        padding: 4px;
        padding-top: 10px;
    }

    h1 {
        font-size: 1.5em;
        margin-bottom: 15px;
        letter-spacing: 3px;
    }

    h2 {
        font-size: 1.1em;
        margin-bottom: 12px;
        letter-spacing: 1.5px;
    }

    .section {
        padding: 10px 6px;
        margin-bottom: 15px;
        border-radius: 10px;
    }

    .splitflap-display {
        padding: 8px 3px;
        gap: 1px;
        border-radius: 8px;
        border-width: 2px;
    }

    .flap {
        width: calc((100vw - 46px) / 12);
        height: calc((100vw - 46px) / 12 * 1.35);
        font-size: calc((100vw - 46px) / 12 * 0.65);
        border-radius: 3px;
        border-width: 1px;
    }

    .input-hint {
        font-size: 11px;
        margin-top: -12px;
        margin-bottom: 6px;
    }

    .character-counter {
        font-size: 12px;
        margin-bottom: 8px;
    }

    #sendButton {
        padding: 12px 20px;
        font-size: 15px;
        border-radius: 5px;
    }

    .status-message {
        padding: 10px;
        font-size: 13px;
    }

    .connection-status {
        padding: 10px;
        font-size: 13px;
    }

    .connection-status::before {
        width: 6px;
        height: 6px;
        left: 12px;
    }

    .connection-status.connected,
    .connection-status.disconnected,
    .connection-status.connecting {
        padding-left: 25px;
    }
}

.container {
    max-width: 900px;
    width: 100%;
    position: relative;
    z-index: 1;
    animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h1 {
    text-align: center;
    margin-bottom: 40px;
    font-size: 2.8em;
    font-family: 'Courier New', monospace;
    text-transform: uppercase;
    letter-spacing: 6px;
    color: #d4d0c8;
    font-weight: 700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

h2 {
    margin-bottom: 20px;
    font-size: 1.4em;
    font-family: 'Courier New', monospace;
    color: #999;
    text-align: center;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    position: relative;
}

.section {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    animation: slideInFade 0.8s ease-out;
    animation-fill-mode: both;
}

.section:nth-child(1) {
    animation-delay: 0.1s;
}

.section:nth-child(2) {
    animation-delay: 0.2s;
}

@keyframes slideInFade {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-subtitle {
    text-align: center;
    font-size: 13px;
    color: #888;
    font-family: 'Courier New', monospace;
    font-weight: 400;
    letter-spacing: 0.5px;
    margin-top: -12px;
    margin-bottom: 16px;
}

.splitflap-display {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 25px 20px;
    background: #0a0a0a;
    border: 3px solid #333;
    border-radius: 10px;
    box-shadow:
        inset 0 2px 4px rgba(0, 0, 0, 0.6),
        0 2px 8px rgba(0, 0, 0, 0.4);
    margin-bottom: 20px;
    position: relative;
    transition: border-color 0.3s ease;
    perspective: 1000px;
    transform-style: preserve-3d;
}

.splitflap-display.editable {
    cursor: text;
    outline: none;
}

.splitflap-display.editable:focus {
    border-color: #b8960c;
    box-shadow:
        inset 0 2px 4px rgba(0, 0, 0, 0.6),
        0 0 12px rgba(184, 150, 12, 0.25);
}

.splitflap-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.03) 0%,
        transparent 50%,
        rgba(0, 0, 0, 0.2) 100%
    );
    pointer-events: none;
    border-radius: 4px;
}

.flap {
    width: 60px;
    height: 80px;
    background: linear-gradient(180deg, #f8f8f8 0%, #f0f0f0 30%, #e8e8e8 50%, #d8d8d8 70%, #d0d0d0 100%);
    border: 2px solid #333;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    font-weight: bold;
    color: #1a1a1a;
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
    position: relative;
    box-shadow:
        inset 0 1px 2px rgba(255, 255, 255, 0.3),
        0 2px 4px rgba(0, 0, 0, 0.4);
    transform-style: preserve-3d;
    perspective: 400px;
    user-select: none;
}

.splitflap-display.editable .flap.active {
    box-shadow:
        inset 0 1px 2px rgba(255, 255, 255, 0.3),
        0 2px 4px rgba(0, 0, 0, 0.4),
        0 0 0 2px #b8960c;
    border-color: #b8960c;
}

.splitflap-display.editable .flap.active::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    background: #b8960c;
    border-radius: 50%;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.flap::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.15) 0%, transparent 100%);
    border-radius: 4px 4px 0 0;
    pointer-events: none;
}

.flap::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.08) 100%);
    border-radius: 0 0 4px 4px;
    pointer-events: none;
}

/* ============================================
   SPLIT-FLAP INNER STRUCTURE
   ============================================ */

/* Upper half - shows top half of current (settled) character */
.flap-upper,
.flap-lower {
    position: absolute;
    left: 0;
    right: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flap-upper {
    top: 0;
    height: 50%;
    border-radius: 3px 3px 0 0;
}

.flap-lower {
    bottom: 0;
    height: 50%;
    border-radius: 0 0 3px 3px;
}

.flap-upper span,
.flap-lower span {
    display: flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    text-transform: inherit;
    line-height: 1;
    pointer-events: none;
    position: absolute;
    left: 0;
    width: 100%;
    height: 200%; /* full flap height = 2x the half-height container */
}

/* Upper span: top-aligned so container clips to show top half of character */
.flap-upper span {
    top: 0;
}

/* Lower span: bottom-aligned so container clips to show bottom half of character */
.flap-lower span {
    bottom: 0;
}

/* The animated leaf that folds down */
.flap-leaf {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    transform-origin: center bottom;
    transform-style: preserve-3d;
    z-index: 2;
    will-change: transform;
    border-radius: 3px 3px 0 0;
}

.flap-leaf-front,
.flap-leaf-back {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flap-leaf-front {
    background: linear-gradient(180deg, #f8f8f8 0%, #f0f0f0 60%, #e8e8e8 100%);
    border-radius: 3px 3px 0 0;
}

.flap-leaf-back {
    background: linear-gradient(180deg, #d4d4d4 0%, #d8d8d8 40%, #d0d0d0 100%);
    transform: rotateX(180deg);
    border-radius: 0 0 3px 3px;
}

.flap-leaf-front span,
.flap-leaf-back span {
    display: flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    text-transform: inherit;
    line-height: 1;
    pointer-events: none;
    position: absolute;
    left: 0;
    width: 100%;
    height: 200%; /* full flap height = 2x the half-height container */
}

/* Front shows top half of old char (same clipping as .flap-upper) */
.flap-leaf-front span {
    top: 0;
}

/* Back shows bottom half of new char (same clipping as .flap-lower) */
.flap-leaf-back span {
    bottom: 0;
}

/* Split line - the signature horizontal divider */
.flap::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(0, 0, 0, 0.25);
    z-index: 5;
    pointer-events: none;
    margin-top: -0.5px;
}

/* Leaf shadow during animation */
.flap.animating .flap-leaf {
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15));
}

/* Hide inner structure for simple (non-initialized) flaps like the input display */
.flap:not(.flap-initialized)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.15) 0%, transparent 100%);
    border-radius: 4px 4px 0 0;
    pointer-events: none;
}

/* Override ::after for non-initialized flaps to keep original bottom gradient */
.flap:not(.flap-initialized)::after {
    top: 50%;
    height: auto;
    bottom: 0;
    background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.08) 100%);
    border-radius: 0 0 4px 4px;
    z-index: 0;
    margin-top: 0;
}

.input-hint {
    text-align: center;
    font-size: 12px;
    color: #666;
    font-style: italic;
    margin-top: -15px;
    margin-bottom: 8px;
    opacity: 1;
    transition: opacity 0.3s ease;
    font-family: 'Courier New', monospace;
    letter-spacing: 0.5px;
}

.input-hint.hidden {
    opacity: 0;
    pointer-events: none;
}

.character-counter {
    text-align: center;
    font-size: 14px;
    color: #888;
    margin-bottom: 10px;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    letter-spacing: 1px;
}

.character-counter.full {
    color: #cc3333;
}

.input-group {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

#sendButton {
    padding: 14px 35px;
    font-size: 18px;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    background: #b8960c;
    border: 2px solid #8a700a;
    border-radius: 6px;
    color: #1a1a1a;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#sendButton:hover {
    background: #c9a40e;
    border-color: #b8960c;
}

#sendButton:focus {
    outline: 2px solid #b8960c;
    outline-offset: 2px;
}

#sendButton.success {
    background: #2a9a2a;
    border-color: #1e7a1e;
    animation: successPulse 0.6s ease-out;
}

@keyframes successPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.03);
    }
    100% {
        transform: scale(1);
    }
}

#sendButton kbd {
    font-family: inherit;
    font-size: 0.85em;
    opacity: 0.6;
    margin-left: 4px;
}

#clearButton {
    padding: 14px 25px;
    font-size: 18px;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    background: transparent;
    border: 2px solid #555;
    border-radius: 6px;
    color: #999;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#clearButton:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: #888;
    color: #ccc;
}

#clearButton:focus {
    outline: 2px solid #888;
    outline-offset: 2px;
}

#clearButton:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#sendButton:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #555;
    border-color: #444;
}

#sendButton.loading {
    position: relative;
    color: transparent;
    cursor: wait;
}

#sendButton.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    border: 2px solid #1a1a1a;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.status-message {
    text-align: center;
    padding: 12px;
    border-radius: 6px;
    font-size: 14px;
    min-height: 20px;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(-10px);
    max-height: 0;
    overflow: hidden;
}

.status-message.success,
.status-message.error,
.status-message.warning {
    opacity: 1;
    transform: translateY(0);
    max-height: 100px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
        max-height: 0;
    }
    to {
        opacity: 1;
        transform: translateY(0);
        max-height: 100px;
    }
}

.status-message.success {
    background: rgba(0, 150, 0, 0.15);
    color: #4caf50;
    border: 1px solid #4caf50;
}

.status-message.error {
    background: rgba(150, 0, 0, 0.15);
    color: #e05555;
    border: 1px solid #e05555;
}

.status-message.warning {
    background: rgba(150, 120, 0, 0.15);
    color: #ccaa33;
    border: 1px solid #ccaa33;
}

.connection-status {
    text-align: center;
    padding: 12px;
    border-radius: 6px;
    font-size: 14px;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    letter-spacing: 0.5px;
    position: relative;
}

.connection-status::before {
    content: '';
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.connection-status.connected {
    background: rgba(0, 150, 0, 0.12);
    color: #4caf50;
    border: 1px solid #4caf50;
    padding-left: 30px;
}

.connection-status.disconnected {
    background: rgba(150, 0, 0, 0.12);
    color: #e05555;
    border: 1px solid #e05555;
    padding-left: 30px;
}

.connection-status.connecting {
    background: rgba(150, 150, 0, 0.12);
    color: #ccaa33;
    border: 1px solid #ccaa33;
    padding-left: 30px;
}

.connection-status.connecting::before {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: translateY(-50%) scale(1);
    }
    50% {
        opacity: 0.5;
        transform: translateY(-50%) scale(0.8);
    }
}

.status-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.status-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 14px;
    color: #888;
    margin-bottom: 8px;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.tooltip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #333;
    color: #aaa;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    cursor: help;
    position: relative;
    border: 1px solid #555;
}

.tooltip:hover,
.tooltip:focus {
    background: #444;
    border-color: #888;
    outline: none;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 130%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 10;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.tooltip::before {
    content: '';
    position: absolute;
    bottom: 115%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: rgba(0, 0, 0, 0.9) transparent transparent transparent;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.tooltip:hover::after,
.tooltip:focus::after,
.tooltip:hover::before,
.tooltip:focus::before {
    opacity: 1;
}

@media (max-width: 480px) {
    .status-row {
        flex-direction: column;
        gap: 8px;
    }

    .tooltip::after {
        white-space: normal;
        width: 220px;
        text-align: center;
    }
}

.hidden-input {
    position: fixed;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
    border: none;
    padding: 0;
    margin: 0;
    top: -1000px;
    left: -1000px;
    background: transparent;
    color: transparent;
    font-size: 16px;
    text-transform: uppercase;
}

/* Rejected character shake animation */
.splitflap-display.reject-shake {
    animation: rejectShake 0.4s ease-in-out;
}

@keyframes rejectShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(3px); }
}

/* ============================================
   CAMERA FEED
   ============================================ */

.camera-section {
    margin-top: 20px;
    margin-bottom: 20px;
}

.camera-heading {
    text-align: center;
    font-size: 1.1em;
    font-family: 'Courier New', monospace;
    color: #999;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 12px;
}

.camera-container {
    position: relative;
    background: #0a0a0a;
    border: 3px solid #333;
    border-radius: 10px;
    overflow: hidden;
    box-shadow:
        inset 0 2px 4px rgba(0, 0, 0, 0.6),
        0 2px 8px rgba(0, 0, 0, 0.4);
    max-width: 640px;
    margin: 0 auto;
}

.camera-canvas {
    display: block;
    width: 100%;
    height: auto;
    background: #000;
}

.camera-status {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #666;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1px;
    text-align: center;
    pointer-events: none;
}

.camera-status.connected {
    display: none;
}

.camera-status.error {
    color: #e05555;
}

@media (max-width: 768px) {
    .camera-container {
        border-width: 3px;
    }

    .camera-heading {
        font-size: 1em;
        letter-spacing: 1.5px;
    }
}

@media (max-width: 480px) {
    .camera-container {
        border-width: 2px;
        border-radius: 8px;
    }

    .camera-heading {
        font-size: 0.9em;
        margin-bottom: 8px;
    }

    .camera-status {
        font-size: 12px;
    }
}

@media (max-width: 400px) {
    .camera-container {
        border-radius: 6px;
    }
}

/* ============================================
   MESSAGE HISTORY
   ============================================ */

.message-history {
    margin-top: 20px;
    margin-bottom: 20px;
}

.history-heading {
    text-align: center;
    font-size: 1.1em;
    font-family: 'Courier New', monospace;
    color: #999;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 12px;
}

.history-list {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #333;
    border-radius: 8px;
    padding: 8px 12px;
    max-height: 300px;
    overflow-y: auto;
}

.history-entry {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

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

.history-timestamp {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #666;
    white-space: nowrap;
    flex-shrink: 0;
}

.history-message {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: #e0e0e0;
    letter-spacing: 1px;
}

.history-empty {
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #555;
    padding: 12px 0;
    font-style: italic;
}

@media (max-width: 768px) {
    .history-heading {
        font-size: 1em;
        letter-spacing: 1.5px;
    }

    .history-message {
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .history-list {
        padding: 6px 8px;
    }

    .history-entry {
        gap: 8px;
    }

    .history-timestamp {
        font-size: 11px;
    }

    .history-message {
        font-size: 12px;
    }
}

@media (max-width: 400px) {
    .history-list {
        padding: 4px 6px;
        border-radius: 6px;
    }

    .history-heading {
        font-size: 0.9em;
        margin-bottom: 8px;
    }
}

/* ============================================
   EASTER EGG EFFECTS
   ============================================ */

/* Strobe */
body.strobe {
    animation: strobe 0.15s steps(1) 13;
}

@keyframes strobe {
    0%, 49% { filter: invert(1); }
    50%, 100% { filter: none; }
}

/* Rainbow Mode */
body.rainbow-mode {
    animation: rainbowBackground 3s linear infinite;
}

body.rainbow-mode .flap {
    animation: rainbowFlap 2s linear infinite;
}

body.rainbow-mode h1 {
    animation: rainbowText 2s linear infinite;
}

body.rainbow-mode #sendButton {
    animation: rainbowButton 1.5s linear infinite;
}

@keyframes rainbowBackground {
    0% { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
}

@keyframes rainbowFlap {
    0% {
        background: hsl(var(--rainbow-hue), 70%, 45%);
        box-shadow: 0 0 15px hsl(var(--rainbow-hue), 70%, 50%);
    }
    100% {
        background: hsl(calc(var(--rainbow-hue) + 360), 70%, 45%);
        box-shadow: 0 0 15px hsl(calc(var(--rainbow-hue) + 360), 70%, 50%);
    }
}

@keyframes rainbowText {
    0% { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
}

@keyframes rainbowButton {
    0% {
        background: linear-gradient(180deg, hsl(var(--rainbow-hue), 100%, 50%) 0%, hsl(calc(var(--rainbow-hue) + 60), 100%, 40%) 100%);
    }
    100% {
        background: linear-gradient(180deg, hsl(calc(var(--rainbow-hue) + 360), 100%, 50%) 0%, hsl(calc(var(--rainbow-hue) + 420), 100%, 40%) 100%);
    }
}


/* ============================================
   COLOR FLAPS
   ============================================ */

.flap.color-flap {
    text-transform: none;
    color: transparent;
    font-size: 0;
}

/* Hide split line and gradients on non-initialized color flaps */
.flap.color-flap:not(.flap-initialized)::before,
.flap.color-flap:not(.flap-initialized)::after {
    display: none;
}

/* For initialized color flaps, keep the split line but style it subtly */
.flap.color-flap.flap-initialized::after {
    background: rgba(0, 0, 0, 0.15);
}

/* Hide text in inner elements for color flaps */
.flap.color-flap .flap-upper,
.flap.color-flap .flap-lower,
.flap.color-flap .flap-leaf-front,
.flap.color-flap .flap-leaf-back {
    color: transparent;
}

.flap.color-g {
    background: linear-gradient(180deg, #22c55e, #16a34a 50%, #15803d);
    border-color: #14532d;
}
.flap.color-g .flap-upper { background: linear-gradient(180deg, #22c55e, #16a34a); }
.flap.color-g .flap-lower { background: linear-gradient(180deg, #16a34a, #15803d); }
.flap.color-g .flap-leaf-front { background: linear-gradient(180deg, #22c55e, #16a34a); }
.flap.color-g .flap-leaf-back { background: linear-gradient(180deg, #16a34a, #15803d); }

.flap.color-p {
    background: linear-gradient(180deg, #c084fc, #a855f7 50%, #9333ea);
    border-color: #581c87;
}
.flap.color-p .flap-upper { background: linear-gradient(180deg, #c084fc, #a855f7); }
.flap.color-p .flap-lower { background: linear-gradient(180deg, #a855f7, #9333ea); }
.flap.color-p .flap-leaf-front { background: linear-gradient(180deg, #c084fc, #a855f7); }
.flap.color-p .flap-leaf-back { background: linear-gradient(180deg, #a855f7, #9333ea); }

.flap.color-r {
    background: linear-gradient(180deg, #f87171, #ef4444 50%, #dc2626);
    border-color: #7f1d1d;
}
.flap.color-r .flap-upper { background: linear-gradient(180deg, #f87171, #ef4444); }
.flap.color-r .flap-lower { background: linear-gradient(180deg, #ef4444, #dc2626); }
.flap.color-r .flap-leaf-front { background: linear-gradient(180deg, #f87171, #ef4444); }
.flap.color-r .flap-leaf-back { background: linear-gradient(180deg, #ef4444, #dc2626); }

.flap.color-w {
    background: linear-gradient(180deg, #fff, #f5f5f5 50%, #e5e5e5);
    border-color: #a3a3a3;
}
.flap.color-w .flap-upper { background: linear-gradient(180deg, #fff, #f5f5f5); }
.flap.color-w .flap-lower { background: linear-gradient(180deg, #f5f5f5, #e5e5e5); }
.flap.color-w .flap-leaf-front { background: linear-gradient(180deg, #fff, #f5f5f5); }
.flap.color-w .flap-leaf-back { background: linear-gradient(180deg, #f5f5f5, #e5e5e5); }

.flap.color-y {
    background: linear-gradient(180deg, #fde047, #eab308 50%, #ca8a04);
    border-color: #713f12;
}
.flap.color-y .flap-upper { background: linear-gradient(180deg, #fde047, #eab308); }
.flap.color-y .flap-lower { background: linear-gradient(180deg, #eab308, #ca8a04); }
.flap.color-y .flap-leaf-front { background: linear-gradient(180deg, #fde047, #eab308); }
.flap.color-y .flap-leaf-back { background: linear-gradient(180deg, #eab308, #ca8a04); }

/* ============================================
   COLOR PALETTE
   ============================================ */

.color-palette {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: -8px;
    margin-bottom: 8px;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #555;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
    padding: 0;
    outline: none;
}

.color-swatch:hover {
    transform: scale(1.15);
    border-color: #999;
}

.color-swatch:focus-visible {
    border-color: #b8960c;
    box-shadow: 0 0 0 2px #b8960c;
}

/* ============================================
   HISTORY COLOR DOT
   ============================================ */

.history-color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    vertical-align: middle;
    margin: 0 1px;
}

@media (max-width: 480px) {
    .color-palette {
        gap: 6px;
        margin-top: -6px;
    }

    .color-swatch {
        width: 24px;
        height: 24px;
    }
}

@media (max-width: 400px) {
    .color-palette {
        gap: 5px;
        margin-top: -4px;
    }

    .color-swatch {
        width: 22px;
        height: 22px;
        border-width: 1.5px;
    }
}

/* ============================================
   PIN OVERLAY
   ============================================ */

#pinOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.pin-form {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    text-align: center;
}

.pin-title {
    font-family: 'Courier New', monospace;
    font-size: 1.4em;
    font-weight: 700;
    color: #d4d0c8;
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-bottom: 8px;
}

.pin-form p {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: #888;
    margin-bottom: 24px;
    letter-spacing: 0.5px;
}

.pin-form form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pin-form input {
    font-family: 'Courier New', monospace;
    font-size: 18px;
    padding: 12px 16px;
    background: #0a0a0a;
    border: 2px solid #333;
    border-radius: 6px;
    color: #e0e0e0;
    text-align: center;
    letter-spacing: 6px;
    outline: none;
    transition: border-color 0.2s ease;
}

.pin-form input:focus {
    border-color: #b8960c;
    box-shadow: 0 0 8px rgba(184, 150, 12, 0.25);
}

.pin-form input::placeholder {
    color: #555;
    letter-spacing: 2px;
}

.pin-form button {
    font-family: 'Courier New', monospace;
    font-size: 16px;
    font-weight: 700;
    padding: 12px 24px;
    background: #b8960c;
    border: 2px solid #8a700a;
    border-radius: 6px;
    color: #1a1a1a;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: background 0.2s ease, border-color 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.pin-form button:hover {
    background: #c9a40e;
    border-color: #b8960c;
}

.pin-form button:focus {
    outline: 2px solid #b8960c;
    outline-offset: 2px;
}

.pin-error {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #e05555;
    margin-top: 12px;
    min-height: 18px;
    letter-spacing: 0.5px;
}

@media (max-width: 480px) {
    .pin-form {
        padding: 30px 20px;
        margin: 0 16px;
    }

    .pin-title {
        font-size: 1.2em;
        letter-spacing: 2px;
    }

    .pin-form input {
        font-size: 16px;
    }
}

/* ============================================
   RESPONSIVE OVERRIDES - Must be at end of file
   ============================================ */

@media (max-width: 480px) {
    .splitflap-display {
        padding: 10px 4px;
        gap: 1px;
    }

    .flap {
        width: calc((100vw - 60px) / 12);
        height: calc((100vw - 60px) / 12 * 1.35);
        font-size: calc((100vw - 60px) / 12 * 0.65);
    }
}

@media (max-width: 400px) {
    .splitflap-display {
        padding: 8px 3px;
        gap: 1px;
        border-width: 2px;
    }

    .flap {
        width: calc((100vw - 40px) / 12);
        height: calc((100vw - 40px) / 12 * 1.35);
        font-size: calc((100vw - 40px) / 12 * 0.65);
        border-width: 1px;
    }
}
