:root {
    --bg-color: #050505;
    --ui-bg: #111;
    --ui-border: #333;
    --text-primary: #eee;
    --text-dim: #888;
    --accent-color: #0ff;
    --accent-warn: #f00;
    --font-mono: 'Share Tech Mono', monospace;
    --font-head: 'Orbitron', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-mono);
    height: 100vh;
    /* dynamic viewport height fix in JS? */
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Background Effects */
.scanline {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0.5;
    animation: scanline 6s linear infinite;
    pointer-events: none;
    z-index: 900;
}

.noise {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 800;
}

#matrix-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    opacity: 0.2;
    pointer-events: none;
    background: radial-gradient(circle at center, #111 0%, #000 100%);
}

@keyframes scanline {
    0% {
        top: -10%;
    }

    100% {
        top: 110%;
    }
}

/* Layout */
.container {
    width: 100%;
    max-width: 800px;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: rgba(10, 10, 10, 0.9);
    border-bottom: 1px solid var(--ui-border);
    backdrop-filter: blur(5px);
}

h1 {
    font-family: var(--font-head);
    font-size: 1.2rem;
    letter-spacing: 1px;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    /* Better for emoji */
    padding: 0;
}

.hide-mobile {
    display: none;
}

@media(min-width: 600px) {
    .hide-mobile {
        display: inline;
        font-size: 0.8rem;
        color: var(--accent-color);
        margin-right: 15px;
    }

    h1 {
        font-size: 1.5rem;
    }
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.canvas-wrapper {
    flex: 1;
    /* Takes remaining space */
    background: #000;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    touch-action: none;
    /* Critical for mobile touch handling */
}

canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    position: absolute;
    /* Stack over each other */
    z-index: 1;
}

#matrix-canvas {
    z-index: 2;
    /* Overlay on top of image when needed */
    pointer-events: none;
    mix-blend-mode: screen;
}

.placeholder {
    position: absolute;
    text-align: center;
    color: var(--text-dim);
    pointer-events: none;
    z-index: 5;
    width: 100%;
}

.sub-text {
    font-size: 0.8rem;
    opacity: 0.6;
}

/* Decoder Lens - Enhanced */
#decoder-lens {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 2px solid #fff;
    /* Red Glass Effect */
    background: rgba(255, 0, 0, 0.1);
    box-shadow:
        0 0 10px var(--accent-warn),
        inset 0 0 20px var(--accent-warn);
    backdrop-filter: brightness(1.5) contrast(1.5) sepia(100%) hue-rotate(-50deg) saturate(500%);
    pointer-events: none;
    /* JS handles movement, but pointers pass through? No, needs to be handled via document touch */
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    transform: translate(-50%, -50%);
    /* Centered on coord */
    transition: transform 0.05s linear;
    /* Smooth follow */

    /* Secret Reveal Properties */
    background-repeat: no-repeat;
    background-size: 0 0;
    /* Hidden by default */
}

/* Crosshair in lens */
#decoder-lens::before,
#decoder-lens::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
}

#decoder-lens::before {
    width: 100%;
    height: 1px;
}

#decoder-lens::after {
    height: 100%;
    width: 1px;
}

/* Controls Area */
.controls {
    background: var(--ui-bg);
    border-top: 1px solid var(--ui-border);
    display: flex;
    flex-direction: column;
    min-height: 200px;
    /* Fixed height for controls */
    z-index: 20;
}

.mode-switch {
    display: flex;
    border-bottom: 1px solid var(--ui-border);
    background: #080808;
}

.mode-switch .btn {
    flex: 1;
    padding: 15px 0;
    font-size: 0.9rem;
    border-bottom: 3px solid transparent;
}

.mode-switch .btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    background: rgba(0, 255, 255, 0.05);
}

.control-panel {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: var(--font-mono);
    cursor: pointer;
    text-transform: uppercase;
    font-weight: bold;
    outline: none;
    transition: 0.2s;
}

.cyber-input {
    width: 100%;
    background: #000;
    border: 1px solid var(--ui-border);
    color: var(--accent-color);
    padding: 10px;
    font-family: var(--font-mono);
    outline: none;
    font-size: 0.9rem;
}

.cyber-input:focus {
    border-color: var(--accent-color);
}

textarea {
    width: 100%;
    height: 60px;
    background: #000;
    border: 1px solid var(--ui-border);
    color: var(--accent-color);
    font-family: var(--font-mono);
    padding: 8px;
    resize: none;
    outline: none;
}

textarea:focus {
    border-color: var(--accent-color);
}

.encode-actions,
.btn-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 5px;
    gap: 10px;
}

.btn.primary {
    background: var(--text-primary);
    color: #000;
    padding: 10px 20px;
    border-radius: 2px;
}

.btn.secondary {
    border: 1px solid var(--text-primary);
    color: var(--text-primary);
    padding: 10px 20px;
}

.btn.warning {
    border: 1px solid var(--accent-warn);
    color: var(--accent-warn);
    padding: 10px 20px;
}

.btn.warning:hover {
    background: rgba(255, 0, 0, 0.2);
}

.decode-status {
    background: #000;
    border: 1px solid var(--accent-warn);
    color: var(--accent-warn);
    padding: 10px;
    font-size: 1rem;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: 0 0 5px var(--accent-warn);
    text-align: center;
    word-break: break-all;
}

.hidden {
    display: none !important;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #111;
    border: 1px solid var(--text-dim);
    width: 90%;
    max-width: 500px;
    padding: 20px;
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
}

.manual-text h3 {
    color: var(--accent-color);
    margin-top: 15px;
    margin-bottom: 5px;
}

.manual-text p {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #ccc;
}

/* Glitch Text */
.glitch {
    position: relative;
}

.glitch::before,
.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
}

.glitch::before {
    left: 2px;
    text-shadow: -1px 0 #f00;
    animation: glitch-1 2s infinite linear alternate-reverse;
    clip-path: inset(20% 0 80% 0);
}

.glitch::after {
    left: -2px;
    text-shadow: -1px 0 #0ff;
    animation: glitch-2 3s infinite linear alternate-reverse;
    clip-path: inset(10% 0 60% 0);
}

@keyframes glitch-1 {
    0% {
        clip-path: inset(20% 0 80% 0);
    }

    100% {
        clip-path: inset(50% 0 30% 0);
    }
}

@keyframes glitch-2 {
    0% {
        clip-path: inset(10% 0 60% 0);
    }

    100% {
        clip-path: inset(0% 0 60% 0);
    }
}