:root {
    --bg-color: #450a0a;
    --app-bg: radial-gradient(circle at center, #991b1b 0%, #450a0a 100%);
    --text-color: #fff;
    --pipe-color: #fde68a; 
    --pipe-active-color: #ffbf00; 
    --cell-size: 44px;
    --cell-gap: 2px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Roboto', sans-serif;
    touch-action: pan-x pan-y; 
}

body {
    background-color: var(--bg-color);
    background-image: var(--app-bg);
    color: var(--text-color);
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app {
    width: 100%;
    max-width: 430px; 
    height: 100%;
    position: relative;
    background: transparent;
    overflow: hidden;
}

.screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
}

#screen-start {
    justify-content: center;
    align-items: center;
}

#screen-start h1 {
    font-size: 3.5rem;
    background: linear-gradient(135deg, #fef08a, #f59e0b);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.5));
}

.subtitle {
    color: #fcd34d;
    margin-bottom: 2rem;
    font-weight: bold;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
}

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

.primary-btn {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #450a0a;
    box-shadow: 0 4px 0 #b45309, 0 8px 10px rgba(0,0,0,0.4);
}

.danger-btn {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    box-shadow: 0 4px 0 #991b1b;
}

#top-bar, #bottom-bar {
    display: flex;
    justify-content: space-between;
    padding: 15px 20px;
    background: rgba(127, 29, 29, 0.85); 
    border-bottom: 2px solid #b91c1c;
    font-size: 1.1rem;
    font-weight: bold;
    z-index: 10;
}
#bottom-bar { border-bottom: none; border-top: 2px solid #b91c1c; }

.time { color: #fef08a; }

#game-area-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 5px;
    perspective: none; 
}

#game-area {
    display: grid;
    grid-template-columns: var(--cell-size) auto var(--cell-size);
    gap: var(--cell-gap);
    align-items: start;
    transform: none; 
}

.side-col {
    display: grid;
    grid-template-rows: repeat(10, var(--cell-size));
    gap: var(--cell-gap);
}

#grid-board {
    display: grid;
    grid-template-columns: repeat(6, var(--cell-size));
    grid-template-rows: repeat(10, var(--cell-size));
    gap: var(--cell-gap);
    background: #7f1d1d; 
    padding: var(--cell-gap);
    border-radius: 8px;
    box-shadow: inset 0 0 15px rgba(69, 10, 10, 0.8), 0 5px 15px rgba(0,0,0,0.6);
    border: 2px solid #b91c1c;
}

.cell-entity {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    user-select: none;
    border-radius: 8px;
}

.pipe-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: #991b1b; 
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s;
}

.pipe-inner {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    filter: drop-shadow(2px 4px 4px rgba(69, 10, 10, 0.8));
    pointer-events: none; 
}

.pipe-part {
    position: absolute;
}

.pipe-center {
    width: 14px; height: 14px;
    top: 15px; left: 15px;
    border-radius: 2px;
}

.pipe-arm-top, .pipe-arm-bottom, .pipe-arm-left, .pipe-arm-right, .pipe-center {
    background: linear-gradient(135deg, #fffbeb 0%, var(--pipe-color) 100%) !important;
}

.pipe-arm-top { width: 14px; height: 15px; top: 0; left: 15px; }
.pipe-arm-bottom { width: 14px; height: 15px; bottom: 0; left: 15px; }
.pipe-arm-left { width: 15px; height: 14px; top: 15px; left: 0; }
.pipe-arm-right { width: 15px; height: 14px; top: 15px; right: 0; }

.pipe-bridge-h { width: 100%; height: 14px; top: 15px; left: 0; position: absolute; background: linear-gradient(0deg, #f59e0b 0%, #fef3c7 50%, #f59e0b 100%) !important; border-radius: 2px; z-index: 2; }
.pipe-bridge-v { width: 14px; height: 100%; top: 0; left: 15px; position: absolute; background: linear-gradient(90deg, #d97706 0%, #f59e0b 50%, #d97706 100%) !important; box-shadow: -2px 0 4px rgba(69,10,10,0.6), 2px 0 4px rgba(69,10,10,0.6); border-radius: 2px; z-index: 1; }

.connected .pipe-arm-top, .connected .pipe-arm-bottom, .connected .pipe-arm-left, .connected .pipe-arm-right, .connected .pipe-center {
    background: var(--pipe-active-color) !important;
    box-shadow: 0 0 10px var(--pipe-active-color), inset 0 0 5px rgba(255,255,255,0.7) !important;
}

.lit-bridge {
    background: var(--bridge-color) !important;
    box-shadow: 0 0 10px var(--bridge-color), inset 0 0 5px rgba(255,255,255,0.7) !important;
}

.pipe-corner-tr {
    position: absolute;
    width: 29px; height: 29px;
    top: 0; left: 15px;
    background: transparent !important;
    border-bottom: 14px solid var(--pipe-color);
    border-left: 14px solid var(--pipe-color);
    border-bottom-left-radius: 20px;
    transition: border-color 0.3s;
    box-shadow: none !important;
    pointer-events: none;
}
.connected .pipe-corner-tr {
    border-color: var(--pipe-active-color) !important;
    filter: drop-shadow(0 0 6px var(--pipe-active-color));
}

.rocket-icon {
    filter: grayscale(1);
    transition: filter 0.3s, transform 0.3s;
}
.rocket-icon.lit {
    filter: grayscale(0);
    transform: translateY(-5px) scale(1.2);
}
.rocket-icon.special {
    filter: grayscale(0.5) brightness(1.5) drop-shadow(0 0 5px rgba(255, 255, 255, 0.8));
}

.modal {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(69, 10, 10, 0.85); 
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s;
}

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

.modal-content {
    background: #fffbeb;
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    width: 85%;
    border: 5px solid #f59e0b; 
    box-shadow: 0 10px 25px rgba(0,0,0,0.5), inset 0 0 15px rgba(245, 158, 11, 0.2);
}

.modal-content h2 {
    margin-bottom: 20px;
    color: #dc2626; 
    font-size: 2rem;
}

.details-text {
    margin-bottom: 25px;
    font-size: 1.05rem;
    line-height: 1.6;
    text-align: left;
    white-space: pre-wrap;
    color: #991b1b;
    font-weight: bold;
}

.particle {
    position: fixed;
    width: 8px; height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 0 15px currentColor, 0 0 30px currentColor; 
    mix-blend-mode: screen;
}

@media (max-width: 380px) {
    :root {
        --cell-size: 38px;
    }
    .pipe-center { width: 12px; height: 12px; top: 13px; left: 13px; }
    .pipe-arm-top, .pipe-arm-bottom { width: 12px; height: 13px; left: 13px; }
    .pipe-arm-left, .pipe-arm-right { width: 13px; height: 12px; top: 13px; }
    .pipe-corner-tr { width: 25px; height: 25px; left: 13px; border-width: 12px; border-bottom-left-radius: 17px; }
    .pipe-bridge-v { width: 12px; left: 13px; }
    .pipe-bridge-h { height: 12px; top: 13px; }
    .btn { padding: 10px 16px; font-size: 0.95rem; }
}
