body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #e0f7fa;
    font-family: 'Learninglings', 'Fredoka', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    touch-action: none;
}

#ui-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100; /* Increased to ensure it's above games */
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    max-height: 85vh;
    background: linear-gradient(to bottom, rgba(224, 247, 250, 0.98) 0%, rgba(224, 247, 250, 0.9) 95%, transparent 100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0);
}

#ui-container.stowed {
    transform: translateY(calc(-100% + 40px)); /* Leave a small sliver visible to pull back */
}

#ui-container.stowed #scroll-wrapper {
    opacity: 0;
    pointer-events: none;
}

.ui-pull-handle {
    width: 100%;
    height: 20px;
    background: rgba(44, 62, 80, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    cursor: ns-resize;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}

.ui-pull-handle::after {
    content: '';
    width: 40px;
    height: 4px;
    background: rgba(0,0,0,0.2);
    border-radius: 2px;
}

.main-nav {
    display: flex;
    width: 100%;
    pointer-events: auto;
    background: #2c3e50;
    border-bottom: 2px solid #1a252f;
    overflow-x: auto;
    scrollbar-width: thin;
    padding: 0;
}

.main-tab {
    flex: 0 0 auto;
    min-width: 90px;
    padding: 12px 10px;
    border: none;
    background: transparent;
    color: #bdc3c7;
    font-weight: 900;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    border-bottom: 4px solid transparent;
}

.main-tab.active {
    color: #fff;
    border-bottom-color: #2196f3;
    background: rgba(255,255,255,0.05);
}

.sub-nav {
    display: flex;
    width: 100%;
    pointer-events: auto;
    background: #fff;
    border-bottom: 1px solid #ddd;
    overflow-x: auto;
    scrollbar-width: thin;
    padding: 5px 0;
    gap: 8px;
    padding-left: 10px;
}

.sub-tab {
    padding: 6px 12px;
    border-radius: 20px;
    background: #f1f2f6;
    border: 1px solid #dfe4ea;
    font-size: 11px;
    font-weight: 700;
    color: #57606f;
    white-space: nowrap;
    cursor: pointer;
}

.sub-tab.active {
    background: #2196f3;
    color: #fff;
    border-color: #1976d2;
}

.sub-section {
    display: none;
    width: 100%;
    flex-direction: column;
}

.sub-section.active {
    display: flex;
}

.nav-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background: #f8f9fa;
    border-radius: 12px;
    border: 1px solid #eee;
    min-width: fit-content;
}

.group-label {
    font-size: 9px;
    text-transform: uppercase;
    font-weight: 800;
    color: #999;
    letter-spacing: 0.5px;
}

.nav-tab {
    padding: 6px 12px;
    border-radius: 8px;
    border: 2px solid transparent;
    font-size: 13px;
    white-space: nowrap;
}

.nav-tab.active {
    background: #2196f3;
    color: white;
    border-color: #1976d2;
}

#scroll-wrapper {
    pointer-events: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    max-height: 70vh;
    scrollbar-width: thin;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(2px);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: 20px;
}

#scroll-wrapper::-webkit-scrollbar {
    width: 8px;
}

#scroll-wrapper::-webkit-scrollbar-thumb {
    background: #2c3e50;
    border-radius: 10px;
}

#content-container {
    width: 100%;
    padding-bottom: 60px; /* Extra space to ensure the bottom row isn't cut off by the viewport */
}

.multi-row-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 2px;
}

.button-row {
    display: flex;
    gap: 12px;
    pointer-events: auto;
    flex-wrap: wrap;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    padding: 12px 16px;
    width: 100%;
    box-sizing: border-box;
    scrollbar-width: thin;
    min-height: 80px;
}

.button-row::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.button-row::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
}

.decimal-row {
    margin-top: 8px;
}

.input-row {
    display: flex;
    gap: 8px;
    padding: 5px 20px;
    width: 100%;
    box-sizing: border-box;
    pointer-events: auto;
    max-width: 600px;
}

.custom-maker-row {
    display: flex;
    gap: 8px;
    padding: 5px 20px;
    width: 100%;
    box-sizing: border-box;
    pointer-events: auto;
    max-width: 95%;
    align-items: center;
    background: rgba(255,255,255,0.7);
    border-radius: 15px;
    margin-bottom: 10px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.fan-form .form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
}

.fan-form .form-row-mini {
    display: flex;
    gap: 8px;
    align-items: center;
}

.fan-form input[type="text"] {
    padding: 8px;
    border-radius: 8px;
    border: 2px solid #ddd;
    font-size: 14px;
}

.fan-form select {
    padding: 6px;
    border-radius: 6px;
    border: 1px solid #ccc;
    font-size: 12px;
}

.fan-form input[type="color"] {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background: none;
}

.custom-maker-row input[type="number"] {
    width: 60px;
    padding: 5px;
    border-radius: 5px;
    border: 1px solid #ccc;
}

.custom-maker-row button {
    padding: 5px 15px;
    background: #4caf50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#custom-spawn-input {
    flex: 1;
    padding: 10px 15px;
    border: 3px solid white;
    border-radius: 20px;
    font-size: 16px;
    outline: none;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    font-family: inherit;
}

#custom-spawn-btn {
    padding: 10px 20px;
    background: #2196f3;
    color: white;
    border: 3px solid white;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}

#mode-fraction.active {
    background: #795548;
    color: white;
    border-color: #5d4037;
}

.root-row {
    margin-top: 8px;
    border-top: 1px solid rgba(0,0,0,0.1);
    padding-top: 10px;
}

.spawn-btn {
    width: 54px;
    height: 54px;
    flex-shrink: 0;
    border: 3px solid white;
    border-radius: 12px;
    color: white;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 3px 6px rgba(0,0,0,0.2);
    transition: transform 0.1s;
    user-select: none;
}

.spawn-btn:active {
    transform: scale(0.9);
}

.btn-terrible {
    position: relative;
}

.btn-terrible::before {
    content: "😈";
    position: absolute;
    top: -8px;
    right: -8px;
    font-size: 16px;
    z-index: 5;
}

.btn-sm {
    width: 40px;
    height: 40px;
    font-size: 16px;
    border-radius: 8px;
    flex-shrink: 0;
}

.btn-rainbow {
    background: linear-gradient(180deg, #ff0000, #ff8c00, #ffff00, #00cc00, #0066ff, #4b0082, #ee82ee);
    border: 3px solid white;
}

.btn-light-rainbow {
    background: linear-gradient(90deg, #ffb3b3, #ffdbb3, #ffffb3, #b3ffb3, #b3ffff, #b3b3ff, #ffb3ff);
    border: 3px solid white;
}

.mode-row {
    display: flex;
    gap: 8px;
    pointer-events: auto;
    width: 100%;
    padding: 4px 12px;
    box-sizing: border-box;
}

.scrollable-row {
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    justify-content: flex-start;
    display: flex;
    flex-wrap: nowrap !important;
    padding-bottom: 8px; /* Room for scrollbar */
}

.secondary-modes {
    margin-top: 5px;
}

.mode-btn {
    padding: 8px 16px;
    border: 2px solid #555;
    background: white;
    border-radius: 20px;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.mode-btn.active {
    background: #333;
    color: white;
}

#mode-split.active {
    background: #4caf50;
    border-color: #4caf50;
}

#mode-delete.active {
    background: #f44336;
    border-color: #f44336;
}

#mode-array.active {
    background: #00acc1;
    color: white;
    border-color: #00838f;
}

#mode-square.active {
    background: #ff5722;
    color: white;
    border-color: #e64a19;
}

#mode-root.active {
    background: #00bcd4;
    color: white;
    border-color: #0097a7;
}

#mode-tan.active {
    background: #e91e63;
    color: white;
    border-color: #ad1457;
}

#mode-power.active {
    background: #673ab7;
    color: white;
    border-color: #4527a0;
}

#mode-pow-xy.active {
    background: #3f51b5;
    color: white;
    border-color: #283593;
}

#mode-fibonacci.active {
    background: #ff9800;
    color: white;
    border-color: #ef6c00;
}

#mode-dozen.active {
    background: #ff9800;
    color: white;
    border-color: #e65100;
}

#mode-multiply.active {
    background: #ffc107;
    color: #333;
    border-color: #ffa000;
}

#mode-chess.active {
    background: #9c27b0;
    color: white;
    border-color: #4a148c;
}

#mode-basketball.active {
    background: #ff8c00;
    color: white;
    border-color: #e65100;
}

#mode-soccer.active {
    background: #4caf50;
    color: white;
    border-color: #2e7d32;
}

#exponent-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
}

#exponent-overlay.hidden {
    display: none;
}

#exponent-modal {
    background: white;
    padding: 20px;
    border-radius: 15px;
    max-width: 90%;
    max-height: 80%;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#exponent-modal h3 {
    margin: 0;
    color: #3f51b5;
    text-align: center;
}

#exponent-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 10px;
    overflow-y: auto;
    padding: 10px;
}

#exponent-options .exponent-btn {
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: #f8f8f8;
    cursor: pointer;
    font-weight: bold;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#exponent-options .exponent-btn:hover {
    background: #e0e0e0;
}

#close-exponent {
    padding: 10px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.game-ui {
    position: absolute;
    top: 250px;
    right: 20px;
    z-index: 5;
    pointer-events: none;
}

.game-ui.hidden {
    display: none;
}

.score-board {
    background: rgba(255, 255, 255, 0.95);
    padding: 10px 20px;
    border-radius: 15px;
    border: 3px solid #ff8c00;
    font-size: 22px;
    font-weight: bold;
    color: #333;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 140px;
}

.score-board.soccer-theme {
    border-color: #4caf50;
}

.game-label {
    font-size: 10px;
    letter-spacing: 1px;
    opacity: 0.6;
    margin-bottom: 2px;
}

.high-score-display {
    margin-top: 5px;
    font-size: 14px;
    color: #333;
    text-align: center;
    background: white;
    border-radius: 10px;
    padding: 2px 8px;
    border: 1px solid #ddd;
}

.timer-display {
    color: #f44336;
    font-size: 18px;
}

#chess-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}

#chess-overlay.hidden {
    display: none;
}

#chess-modal {
    background: white;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    max-width: 90vw;
}

#chess-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chess-header h3 {
    margin: 0;
    color: #9c27b0;
}

#close-chess {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}

#chess-board {
    display: grid;
    grid-template-columns: repeat(8, 40px);
    grid-template-rows: repeat(8, 40px);
    border: 4px solid #333;
}

#memory-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
}

#memory-overlay.hidden { display: none; }

#memory-modal {
    background: white;
    padding: 20px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

#memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 70px);
    grid-template-rows: repeat(4, 70px);
    gap: 10px;
}

@media (min-width: 600px) {
    #memory-grid {
        grid-template-columns: repeat(4, 90px);
        grid-template-rows: repeat(4, 90px);
    }
}

.memory-card {
    width: 100%;
    height: 100%;
    background: #2196f3;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: transform 0.3s, background 0.3s;
    user-select: none;
    border: 3px solid white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.memory-card.flipped {
    transform: rotateY(180deg);
    background: white;
    color: #333;
    border-color: #2196f3;
}

.memory-card.matched {
    background: #4caf50;
    border-color: #4caf50;
    cursor: default;
    visibility: hidden;
    transition: visibility 0.5s linear 0.5s;
}

#memory-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#close-memory {
    background: none;
    border: none;
    font-size: 30px;
    cursor: pointer;
    color: #666;
}

#memory-status {
    font-weight: bold;
    font-size: 18px;
    color: #333;
}

#tictactoe-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    display: flex; justify-content: center; align-items: center;
}

#tictactoe-overlay.hidden { display: none; }

#tictactoe-modal {
    background: white; padding: 25px; border-radius: 20px;
    display: flex; flex-direction: column; align-items: center; gap: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

#tictactoe-header {
    width: 100%; display: flex; justify-content: space-between; align-items: center;
}

#tictactoe-grid {
    display: grid; grid-template-columns: repeat(3, 80px); grid-template-rows: repeat(3, 80px);
    gap: 8px; background: #333; padding: 8px; border-radius: 10px;
}

.ttt-cell {
    background: white; border-radius: 5px; cursor: pointer;
    display: flex; justify-content: center; align-items: center;
    font-size: 40px; font-weight: bold; color: #2196f3;
    transition: background 0.2s;
}

.ttt-cell:hover { background: #f0f0f0; }
.ttt-cell.taken { cursor: default; }
.ttt-cell.ai { color: #f44336; }

#sumcatcher-ui {
    top: 150px; right: 20px;
}

.score-board.sum-theme {
    border-color: #f44336;
}

.target-display { font-size: 26px; color: #f44336; margin-bottom: 5px; }
.current-display { font-size: 20px; color: #333; }



@media (min-width: 600px) {
    #chess-board {
        grid-template-columns: repeat(8, 60px);
        grid-template-rows: repeat(8, 60px);
    }
}

.chess-square {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 30px;
    cursor: pointer;
    user-select: none;
}

@media (min-width: 600px) {
    .chess-square { font-size: 45px; }
}

.chess-square.purple-light { background-color: #d1c4e9; }
.chess-square.purple-dark { background-color: #9575cd; }
.chess-square.white-sq { background-color: #f0d9b5; }
.chess-square.black-sq { background-color: #b58863; }
.chess-square.selected { background-color: #ffeb3b !important; }
.chess-square.last-move { background-color: #ffff33aa !important; }

@keyframes validGlow {
    from { box-shadow: inset 0 0 5px #4caf50; background-color: #c8e6c9; }
    to { box-shadow: inset 0 0 20px #4caf50; background-color: #a5d6a7; }
}

.chess-square.valid-move {
    animation: validGlow 0.8s infinite alternate;
    z-index: 1;
    cursor: pointer;
}

.chess-square.invalid-move {
    background-color: #ffcdd2 !important; /* Soft red for invalid */
    opacity: 0.8;
    cursor: not-allowed;
}



.chess-square.black.invalid-move {
    background-color: #e57373 !important;
}

#chess-status, #chat-header h3 {
    font-weight: bold;
    color: #333;
    margin-bottom: 5px;
}

#chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}

#chat-modal {
    background: white;
    padding: 20px;
    border-radius: 15px;
    width: 350px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#chat-log {
    height: 300px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #fdfdfd;
}

#poker-ui {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    pointer-events: auto;
    width: 90vw;
    max-width: 600px;
}

#poker-table {
    background: #1b5e20;
    border: 10px solid #3e2723;
    border-radius: 30px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 300px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
}

#poker-lobby-list {
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
    margin: 10px 0;
    padding: 10px;
}

.poker-lobby-item {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    background: rgba(255,255,255,0.1);
    margin-bottom: 5px;
    border-radius: 5px;
    color: white;
}

.poker-lobby-item button {
    padding: 2px 10px;
    background: #4caf50;
    border: none;
    border-radius: 3px;
    color: white;
    cursor: pointer;
}

#poker-queue-status {
    color: #ffeb3b;
    font-weight: bold;
    margin: 10px 0;
}

.poker-status {
    color: white;
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

#poker-players {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.poker-player {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: white;
    background: rgba(0,0,0,0.2);
    padding: 15px;
    border-radius: 15px;
    width: 80px;
}

.poker-card-back {
    width: 50px;
    height: 70px;
    background: #b71c1c;
    border: 2px solid white;
    border-radius: 5px;
    margin-bottom: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    font-weight: bold;
}

.poker-card-played {
    width: 50px;
    height: 70px;
    background: white;
    color: black;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
    margin-top: 5px;
}

#poker-controls {
    display: flex;
    gap: 10px;
}

#poker-flip {
    padding: 15px 30px;
    background: #ffc107;
    border: none;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
}

#poker-quit {
    padding: 15px 30px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
}

#chat-input-row {
    display: flex;
    gap: 5px;
}

#chat-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

#chat-send {
    padding: 10px 20px;
    background: #2196f3;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#chess-chat-container {
    width: 100%;
    max-width: 400px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 8px;
}

#chess-chat-log {
    height: 80px;
    overflow-y: auto;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.chat-msg {
    line-height: 1.4;
}

.chat-msg.user { color: #555; font-style: italic; }
.chat-msg.bot { color: #9c27b0; font-weight: bold; }

#chess-chat-input-row {
    display: flex;
    gap: 5px;
}

#chess-chat-input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    outline: none;
}

#chess-chat-send {
    padding: 8px 15px;
    background: #9c27b0;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#chess-chat-send:disabled {
    background: #ccc;
}

@keyframes chessShake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    20% { transform: translate(-1px, -1px) rotate(1deg); }
    40% { transform: translate(-2px, 0px) rotate(-1deg); }
    60% { transform: translate(2px, 1px) rotate(0deg); }
    80% { transform: translate(1px, -1px) rotate(1deg); }
    100% { transform: translate(-1px, 1px) rotate(-1deg); }
}

.chess-piece {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

.chess-piece.shaking {
    animation: chessShake 0.15s infinite;
}

.chess-piece.cracked::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 10 L40 50 L10 80 M70 20 L50 60 L90 90 M30 30 L60 10' stroke='rgba(0,0,0,0.5)' stroke-width='3' fill='none'/%3E%3C/svg%3E");
    background-size: contain;
    pointer-events: none;
    z-index: 5;
}



#canvas-container {
    width: 100%;
    height: 100%;
}

#jumpscare-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: black;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
}

#jumpscare-overlay.hidden {
    display: none;
}

#jumpscare-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    animation: jitter 0.1s infinite;
}

@keyframes jitter {
    0% { transform: translate(0,0) scale(1); filter: hue-rotate(0deg); }
    25% { transform: translate(5px, -5px) scale(1.1); filter: hue-rotate(90deg) invert(1); }
    50% { transform: translate(-5px, 5px) scale(1.05); filter: hue-rotate(180deg); }
    75% { transform: translate(10px, 10px) scale(1.2); filter: hue-rotate(270deg) invert(1); }
    100% { transform: translate(-10px, -10px) scale(1.1); filter: hue-rotate(360deg); }
}

.glitch-active {
    animation: screenGlitch var(--glitch-speed, 0.2s) infinite;
}

.glitch-red {
    animation: screenGlitchRed var(--glitch-speed, 0.15s) infinite !important;
}

.shake-active {
    animation: screenShake var(--glitch-speed, 0.2s) infinite !important;
}

@keyframes screenShake {
    0% { transform: translate(0, 0) rotate(0); }
    10% { transform: translate(calc(var(--shake-intensity, 1) * -2px), calc(var(--shake-intensity, 1) * 2px)) rotate(calc(var(--shake-intensity, 1) * -0.5deg)); }
    20% { transform: translate(calc(var(--shake-intensity, 1) * -5px), 0px) rotate(calc(var(--shake-intensity, 1) * 0.5deg)); }
    30% { transform: translate(calc(var(--shake-intensity, 1) * 5px), calc(var(--shake-intensity, 1) * 4px)) rotate(0deg); }
    40% { transform: translate(calc(var(--shake-intensity, 1) * 2px), calc(var(--shake-intensity, 1) * -2px)) rotate(calc(var(--shake-intensity, 1) * 0.5deg)); }
    50% { transform: translate(calc(var(--shake-intensity, 1) * -2px), calc(var(--shake-intensity, 1) * 4px)) rotate(calc(var(--shake-intensity, 1) * -0.5deg)); }
    60% { transform: translate(calc(var(--shake-intensity, 1) * -5px), calc(var(--shake-intensity, 1) * 2px)) rotate(0deg); }
    70% { transform: translate(calc(var(--shake-intensity, 1) * 5px), calc(var(--shake-intensity, 1) * 2px)) rotate(calc(var(--shake-intensity, 1) * -0.5deg)); }
    80% { transform: translate(calc(var(--shake-intensity, 1) * -2px), calc(var(--shake-intensity, 1) * -2px)) rotate(calc(var(--shake-intensity, 1) * 0.5deg)); }
    90% { transform: translate(calc(var(--shake-intensity, 1) * 2px), calc(var(--shake-intensity, 1) * 4px)) rotate(0deg); }
    100% { transform: translate(calc(var(--shake-intensity, 1) * 2px), calc(var(--shake-intensity, 1) * -2px)) rotate(calc(var(--shake-intensity, 1) * -0.5deg)); }
}

#jumpscare-image.red-tint {
    filter: sepia(1) saturate(20) hue-rotate(-50deg) brightness(0.7) contrast(3) !important;
}

@keyframes screenGlitch {
    0% { filter: none; transform: translate(0); }
    20% { filter: hue-rotate(90deg) contrast(2); transform: translate(-5px, 2px); }
    40% { filter: invert(1) brightness(2); transform: translate(5px, -2px); }
    60% { filter: sepia(1) saturate(5); transform: translate(-2px, 5px); }
    80% { filter: blur(2px) contrast(3); transform: translate(2px, -5px); }
    100% { filter: none; transform: translate(0); }
}

@keyframes screenGlitchRed {
    0% { filter: none; background-color: transparent; }
    25% { filter: drop-shadow(0 0 10px red) contrast(4); background-color: rgba(255, 0, 0, 0.4); }
    50% { filter: invert(0.2) sepia(1) saturate(10) hue-rotate(-50deg); background-color: rgba(150, 0, 0, 0.6); }
    75% { filter: brightness(0.5) contrast(5); background-color: rgba(255, 50, 50, 0.3); }
    100% { filter: none; background-color: transparent; }
}

canvas {
    display: block;
}

#welcome-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(224, 247, 250, 0.9);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

#welcome-modal {
    background: white;
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0,0,0,0.15);
    border: 8px solid #2196f3;
    max-width: 90%;
}

#welcome-modal h1 {
    color: #2196f3;
    margin-bottom: 10px;
    font-size: 32px;
}

#welcome-modal p {
    color: #666;
    font-size: 18px;
    margin-bottom: 25px;
}

.welcome-icons {
    font-size: 40px;
    margin-bottom: 30px;
    display: flex;
    justify-content: center;
    gap: 10px;
}

#start-btn {
    padding: 15px 40px;
    background: #4caf50;
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    box-shadow: 0 8px 0 #388e3c;
}

#start-btn:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 #388e3c;
}

#mode-magnet.active {
    background: #fdd835;
    color: #333;
}

#mode-zero-void.active {
    background: #000;
    color: #fff;
}

/* Tab Navigation Styles */
.nav-row {
    display: flex;
    width: 100%;
    pointer-events: auto;
    background: #fff;
    border-bottom: 2px solid #ccc;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.nav-row::-webkit-scrollbar {
    display: none;
}

.nav-tab {
    flex: 0 0 auto;
    min-width: 70px;
    padding: 8px 10px;
    border: none;
    background: #f0f0f0;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    border-right: 1px solid #ddd;
    font-size: 13px;
    color: #666;
    transition: all 0.2s;
}

.nav-tab:last-child {
    border-right: none;
}

.nav-tab.active {
    background: #2196f3;
    color: white;
}

.category-section {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: center;
}

.category-section.active {
    display: flex;
}

.credits-line {
    font-size: 12px;
    color: #e91e63;
    font-weight: bold;
    margin: 5px 0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.manual-container {
    width: 90%;
    max-width: 600px;
    background: white;
    padding: 20px;
    border-radius: 20px;
    pointer-events: auto;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin-top: 10px;
}

#manual-search {
    width: 100%;
    padding: 12px;
    border: 2px solid #2196f3;
    border-radius: 10px;
    font-size: 18px;
    margin-bottom: 20px;
    box-sizing: border-box;
    font-family: inherit;
}

.manual-card {
    text-align: left;
    color: #333;
}

.manual-card h2 {
    margin-top: 0;
    color: #2196f3;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
}

.manual-card p {
    margin: 8px 0;
    font-size: 14px;
    line-height: 1.4;
}

.manual-card strong {
    color: #555;
    width: 100px;
    display: inline-block;
}

/* Enhanced Manual UI */
.manual-container {
    width: 95%;
    max-width: 800px;
    background: white;
    padding: 20px;
    border-radius: 25px;
    pointer-events: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.manual-header {
    width: 100%;
}

#manual-layout {
    display: grid;
    grid-template-columns: 1fr 200px;
    gap: 20px;
    animation: fadeIn 0.3s ease;
}

#manual-layout.hidden {
    display: none;
}

.manual-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: left;
}

.info-group {
    background: #f8f9fa;
    padding: 10px 15px;
    border-radius: 12px;
    border-left: 4px solid #2196f3;
}

.info-group label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    font-weight: bold;
    color: #999;
    margin-bottom: 4px;
}

.info-group p {
    margin: 0;
    font-size: 16px;
    color: #333;
    font-weight: 600;
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 5px;
}

.tag {
    background: #e3f2fd;
    color: #1976d2;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: bold;
}

.manual-preview {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.preview-card {
    background: #f0f4f8;
    padding: 10px;
    border-radius: 20px;
    border: 3px dashed #cbd5e0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

#manual-canvas {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
}

#manual-number-label {
    margin-top: 10px;
    font-weight: bold;
    color: #2d3748;
    font-size: 18px;
    letter-spacing: 1px;
}

#manual-empty-state {
    padding: 40px 20px;
    text-align: center;
    color: #a0aec0;
}

#manual-empty-state.hidden {
    display: none;
}

/* Calculator Styles */
.calculator-container {
    width: 95%;
    max-width: 500px;
    background: #2c3e50;
    padding: 15px;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: auto;
    margin-top: 5px;
}

.calc-display {
    background: #ecf0f1;
    border-radius: 10px;
    padding: 10px;
}

#calc-input {
    width: 100%;
    border: none;
    background: transparent;
    font-family: 'Courier New', Courier, monospace;
    font-size: 24px;
    text-align: right;
    color: #2c3e50;
    outline: none;
}

.calc-keypad {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.calc-row-specials, .calc-row-functions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(45px, 1fr));
    gap: 6px;
}

.calc-main-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.calc-btn {
    height: 44px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: filter 0.1s, transform 0.05s;
    font-family: inherit;
    display: flex;
    justify-content: center;
    align-items: center;
}

.calc-btn:active { transform: scale(0.95); }

.calc-btn.num { background: #34495e; color: white; }
.calc-btn.op { background: #f39c12; color: white; }
.calc-btn.constant { background: #9b59b6; color: white; }
.calc-btn.sci { background: #16a085; color: white; }
.calc-btn.special { background: #e74c3c; color: white; }
.calc-btn.action { 
    background: #2ecc71; 
    color: white; 
    grid-column: span 3;
    font-size: 14px;
}

@media (max-width: 600px) {
    #manual-layout {
        grid-template-columns: 1fr;
    }
    .manual-preview {
        order: -1;
    }
}

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