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

body {
    font-family: 'Courier New', 'Segoe UI', monospace;
    background: radial-gradient(circle at 20% 30%, #0a0a1a, #03030f);
    min-height: 100vh;
    padding: 20px;
    color: #b8f2e2;
}

.game-container {
    max-width: 950px;
    margin: 0 auto;
    background: rgba(10, 20, 30, 0.75);
    backdrop-filter: blur(12px);
    border-radius: 28px;
    padding: 24px;
    box-shadow: 0 0 40px rgba(0, 255, 255, 0.2);
    border: 1px solid #00ffff66;
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #00ffcc;
}

h1 {
    font-size: 2rem;
    background: linear-gradient(135deg, #00ffcc, #ff66cc);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: 2px;
    text-shadow: 0 0 8px cyan;
}

.player-info {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    background: rgba(0, 30, 40, 0.7);
    padding: 12px 20px;
    border-radius: 40px;
    margin: 18px 0;
    font-size: 0.85rem;
    font-weight: bold;
    border: 1px solid cyan;
}

.player-info span {
    background: #00ffff10;
    padding: 5px 14px;
    border-radius: 30px;
    font-family: monospace;
}

.action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.reset-btn, .hint-btn, .lore-btn {
    background: #1a2a3a;
    color: cyan;
    border: 1px solid cyan;
    padding: 8px 18px;
    border-radius: 40px;
    cursor: pointer;
    font-weight: bold;
    transition: 0.2s;
    font-family: monospace;
}

.reset-btn:hover {
    background: #ff3366;
    color: white;
    border-color: white;
}

.hint-btn:hover {
    background: #ffaa33;
    color: black;
}

.game-view {
    min-height: 550px;
    padding: 15px;
}

.room-card {
    background: rgba(0, 0, 0, 0.65);
    border-radius: 24px;
    padding: 25px;
    margin-bottom: 25px;
    border-left: 6px solid #00ffcc;
    box-shadow: 0 4px 20px rgba(0,255,255,0.1);
}

.room-title {
    font-size: 1.9rem;
    margin-bottom: 12px;
    color: #ff66cc;
    font-weight: bold;
}

.room-description {
    line-height: 1.7;
    margin-bottom: 25px;
    font-size: 1rem;
}

.puzzle-area {
    background: #001e2a;
    padding: 22px;
    border-radius: 20px;
    margin: 20px 0;
    border: 1px solid #00ffaa;
}

.puzzle-question {
    font-weight: bold;
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: #ffcc88;
    font-family: monospace;
}

.puzzle-hint {
    font-size: 0.8rem;
    color: #aaa;
    margin-bottom: 12px;
    font-style: italic;
}

.puzzle-input {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin: 20px 0;
}

.puzzle-input input {
    flex: 2;
    padding: 14px;
    background: #031018;
    border: 2px solid #00ffcc;
    color: #00ffcc;
    border-radius: 16px;
    font-size: 1rem;
    font-family: monospace;
}

.puzzle-input button {
    background: #00ffcc;
    color: #000;
    border: none;
    padding: 14px 28px;
    border-radius: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
}

.puzzle-input button:hover {
    background: #ff66cc;
    transform: scale(1.02);
}

.code-display {
    background: #000000aa;
    padding: 18px;
    border-radius: 16px;
    margin: 18px 0;
    text-align: center;
    font-family: monospace;
    font-size: 1.2rem;
    letter-spacing: 2px;
    border: 1px dashed cyan;
}

.success-message {
    color: #88ffaa;
    font-weight: bold;
    margin-top: 12px;
}

.error-message {
    color: #ff8888;
    margin-top: 12px;
}

.unlock-area {
    margin-top: 30px;
    padding: 22px;
    background: #0a2a2aaa;
    border-radius: 20px;
    border: 1px solid cyan;
}

.unlock-input {
    display: flex;
    gap: 12px;
    margin-top: 15px;
}

.unlock-input input {
    flex: 1;
    padding: 12px;
    background: #00000099;
    border: 2px solid cyan;
    color: cyan;
    border-radius: 14px;
    font-family: monospace;
}

.unlock-input button {
    background: #2a6b6b;
    color: white;
    border: none;
    padding: 12px 28px;
    border-radius: 14px;
    cursor: pointer;
    font-weight: bold;
}

.room-list {
    display: grid;
    gap: 12px;
    margin-top: 30px;
}

.room-button {
    background: #0a1f2a;
    border: 1px solid #2affcc;
    color: #ccffff;
    padding: 14px;
    border-radius: 18px;
    cursor: pointer;
    transition: 0.2s;
    text-align: left;
    font-family: monospace;
}

.room-button:hover:not(:disabled) {
    background: #1a5f6f;
    transform: translateX(8px);
}

.room-button.locked {
    opacity: 0.4;
    cursor: not-allowed;
}

.room-button.unlocked {
    border-left: 8px solid #66ff66;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.85);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #07161f;
    margin: 8% auto;
    padding: 25px;
    border: 2px solid cyan;
    width: 80%;
    max-width: 600px;
    border-radius: 28px;
    color: #bbffdd;
    max-height: 70vh;
    overflow-y: auto;
}

.close {
    color: #ff66cc;
    float: right;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
}

footer {
    margin-top: 30px;
    padding-top: 18px;
    border-top: 1px solid cyan;
    font-size: 0.8rem;
    text-align: center;
}

.footer-links {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

@media (max-width: 700px) {
    .player-info {
        flex-direction: column;
        align-items: center;
    }
    .room-title {
        font-size: 1.5rem;
    }
}

/* Multiplayer Panel Styles */
.multiplayer-panel {
    margin-bottom: 20px;
}

.lobby-view {
    background: rgba(0, 30, 40, 0.8);
    border-radius: 20px;
    padding: 25px;
    text-align: center;
    border: 1px solid #00ffcc;
}

.lobby-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.primary-btn, .secondary-btn {
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 40px;
    cursor: pointer;
    transition: 0.2s;
    font-family: monospace;
}

.primary-btn {
    background: #00ffcc;
    color: #0a0a1a;
}

.primary-btn:hover {
    background: #ff66cc;
    transform: scale(1.02);
}

.secondary-btn {
    background: #1a2a3a;
    border: 1px solid #00ffcc;
    color: #00ffcc;
}

.secondary-btn:hover {
    background: #2a4a5a;
}

.room-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    background: rgba(0, 0, 0, 0.5);
    padding: 12px 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    border: 1px solid #ffcc88;
}

.small-btn {
    background: #2a4a5a;
    border: 1px solid #00ffcc;
    color: #00ffcc;
    padding: 5px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
}

.small-btn.danger {
    border-color: #ff6666;
    color: #ff8888;
}

.small-btn:hover {
    background: #3a6a7a;
}

#roomCodeInput {
    padding: 10px;
    font-size: 1.2rem;
    text-align: center;
    letter-spacing: 3px;
    background: #031018;
    border: 2px solid #00ffcc;
    color: #00ffcc;
    border-radius: 10px;
    font-family: monospace;
}

#joinSection {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Chat panel */
.chat-panel {
    margin-top: 20px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 15px;
    padding: 10px;
}

.chat-messages {
    height: 100px;
    overflow-y: auto;
    font-size: 0.8rem;
    padding: 5px;
}

.chat-input-area {
    display: flex;
    gap: 5px;
    margin-top: 5px;
}

.chat-input-area input {
    flex: 1;
    padding: 5px;
    background: #031018;
    border: 1px solid #00ffcc;
    color: white;
    border-radius: 8px;
}

.chat-input-area button {
    background: #00ffcc20;
    border: 1px solid #00ffcc;
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
}

/* Ending Cinematic Styles */
.ending-modal .modal-content {
    background: #000000;
    border: 2px solid #ffcc88;
    max-width: 700px;
    text-align: center;
}

.ending-text {
    font-family: 'Courier New', monospace;
    color: #ffeedd;
    font-size: 1.1rem;
    line-height: 1.8;
    text-align: center;
    padding: 20px;
    min-height: 400px;
    white-space: pre-line;
}

.ending-text .star {
    color: #ffcc88;
    font-size: 1.2rem;
}

.ending-text .whisper {
    color: #88aaff;
    font-style: italic;
}

.ending-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #ffcc8833;
}

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

.ending-line {
    animation: fadeInText 1s ease-out forwards;
    margin-bottom: 20px;
}

/* Room completion animation */
@keyframes fragmentReveal {
    0% { opacity: 0; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}

.code-display {
    animation: fragmentReveal 0.5s ease-out;
}

/* Additional styles for better UI */

/* Flowchart nodes - more button-like */
.flowchart-node {
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.flowchart-node:hover {
    transform: scale(1.1);
    border-width: 3px;
    box-shadow: 0 0 15px cyan;
}

.flowchart-node.unlocked {
    cursor: pointer;
    animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 5px #ffcc88; }
    50% { box-shadow: 0 0 15px #ffcc88; }
}

/* Code display with labels */
.code-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin: 5px 0;
    background: #00ffcc10;
    border-radius: 8px;
    border-left: 3px solid #00ffcc;
}

.code-room {
    font-size: 0.8rem;
    color: #ffcc88;
}

.code-value {
    font-family: monospace;
    font-weight: bold;
    letter-spacing: 1px;
}

/* Scroll to top button (optional) */
.scroll-top {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #00ffcc;
    color: black;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 100;
}

.scroll-top.visible {
    opacity: 0.7;
}

.scroll-top:hover {
    opacity: 1;
}

/* ============================================
   MOBILE-FRIENDLY FLOWCHART
   ============================================ */
.flowchart-section {
    margin-top: 30px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 20px;
    border: 1px solid #00ffcc33;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.flowchart-section h3 {
    margin-bottom: 15px;
    color: #ffcc88;
    text-align: center;
    font-size: 1rem;
}

.flowchart {
    position: relative;
    min-width: 900px;
    min-height: 850px;
    overflow: visible;
}

/* Make flowchart nodes slightly smaller on mobile */
@media (max-width: 700px) {
    .flowchart-section {
        padding: 10px;
    }
    
    .flowchart {
        min-width: 800px;
        transform: scale(0.9);
        transform-origin: top left;
    }
    
    .flowchart-node {
        width: 65px;
        height: 65px;
    }
    
    .node-icon {
        font-size: 1.2rem;
    }
    
    .node-name {
        font-size: 0.6rem;
    }
}

/* ============================================
   MOBILE-FRIENDLY MODAL (Lore & Ending)
   ============================================ */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(5px);
    overflow-y: auto;
}

.modal-content {
    background: #07161f;
    margin: 10% auto;
    padding: 20px;
    border: 2px solid cyan;
    width: 90%;
    max-width: 600px;
    border-radius: 20px;
    color: #bbffdd;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

/* Mobile modal adjustments */
@media (max-width: 700px) {
    .modal-content {
        margin: 5% auto;
        width: 95%;
        padding: 15px;
        max-height: 85vh;
    }
    
    .modal-content h2 {
        font-size: 1.3rem;
        margin-right: 30px;
    }
    
    .close {
        font-size: 28px;
        position: absolute;
        top: 10px;
        right: 15px;
    }
}

/* Ending modal specific */
.ending-modal .modal-content {
    background: #000000;
    border: 2px solid #ffcc88;
    max-width: 700px;
    text-align: center;
}

.ending-text {
    font-family: 'Courier New', monospace;
    color: #ffeedd;
    font-size: 1rem;
    line-height: 1.6;
    padding: 15px;
}

@media (max-width: 700px) {
    .ending-text {
        font-size: 0.85rem;
        line-height: 1.5;
        padding: 10px;
    }
    
    .ending-text .star {
        font-size: 1.5rem;
    }
    
    .ending-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .ending-buttons button {
        width: 100%;
        padding: 10px;
    }
}

/* ============================================
   SCROLLABLE LORE CONTENT
   ============================================ */
#loreContent {
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 5px;
}

#loreContent p {
    margin: 12px 0;
    padding: 10px;
    background: #00ffcc10;
    border-left: 3px solid #00ffcc;
    border-radius: 8px;
    font-size: 0.9rem;
    word-wrap: break-word;
}

@media (max-width: 700px) {
    #loreContent p {
        font-size: 0.8rem;
        padding: 8px;
    }
}

/* ============================================
   CODE ENTRIES - Prevent overflow
   ============================================ */
.code-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    margin: 5px 0;
    background: #00ffcc10;
    border-radius: 8px;
    border-left: 3px solid #00ffcc;
}

.code-room {
    font-size: 0.8rem;
    color: #ffcc88;
    word-break: keep-all;
}

.code-value {
    font-family: monospace;
    font-weight: bold;
    letter-spacing: 1px;
    word-break: break-all;
}

@media (max-width: 700px) {
    .code-entry {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ============================================
   ROOM CARDS - Mobile padding
   ============================================ */
@media (max-width: 700px) {
    .room-card {
        padding: 15px;
    }
    
    .room-title {
        font-size: 1.2rem;
    }
    
    .room-description {
        font-size: 0.9rem;
        line-height: 1.5;
    }
    
    .puzzle-area {
        padding: 12px;
    }
    
    .puzzle-question {
        font-size: 0.9rem;
    }
    
    .puzzle-input input {
        font-size: 0.9rem;
        padding: 10px;
    }
    
    .puzzle-input button {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
}

/* ============================================
   FADE IN/OUT ANIMATION (for popups)
   ============================================ */
@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -60%); }
    15% { opacity: 1; transform: translate(-50%, -50%); }
    85% { opacity: 1; transform: translate(-50%, -50%); }
    100% { opacity: 0; visibility: hidden; }
}

@keyframes fadeInText {
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.ending-line {
    animation: fadeInText 0.8s ease-out forwards;
    opacity: 0;
    margin-bottom: 15px;
}

.ending-line:nth-child(1) { animation-delay: 0s; }
.ending-line:nth-child(2) { animation-delay: 0.5s; }
.ending-line:nth-child(3) { animation-delay: 1s; }
.ending-line:nth-child(4) { animation-delay: 1.5s; }
.ending-line:nth-child(5) { animation-delay: 2s; }
.ending-line:nth-child(6) { animation-delay: 2.5s; }
.ending-line:nth-child(7) { animation-delay: 3s; }
.ending-line:nth-child(8) { animation-delay: 3.5s; }
.ending-line:nth-child(9) { animation-delay: 4s; }
.ending-line:nth-child(10) { animation-delay: 4.5s; }
.ending-line:nth-child(11) { animation-delay: 5s; }
.ending-line:nth-child(12) { animation-delay: 5.5s; }
.ending-line:nth-child(13) { animation-delay: 6s; }
.ending-line:nth-child(14) { animation-delay: 6.5s; }
.ending-line:nth-child(15) { animation-delay: 7s; }

.star {
    color: #ffcc88;
    font-size: 2rem;
    margin: 20px 0;
    animation: pulse 2s infinite;
}

.whisper {
    color: #88aaff;
    font-style: italic;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -60%); }
    15% { opacity: 1; transform: translate(-50%, -50%); }
    85% { opacity: 1; transform: translate(-50%, -50%); }
    100% { opacity: 0; visibility: hidden; }
}
