:root {
    --bg-color: #111520;
    --accent-gold: #ffdf00;
    --accent-blue: #00e5ff;
    --text-color: #ffffff;
    --panel-bg: rgba(0, 0, 0, 0.6);
}

html, body {
    background-color: var(--bg-color);
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none; /* Prevents pull-to-refresh and scroll */
    font-family: 'Montserrat', sans-serif;
    color: var(--text-color);
    position: fixed; /* Extra lock for iOS */
}

#game-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    touch-action: none;
    z-index: 1;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* User Interface */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.detailed-scoreboard {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border-radius: 0 0 15px 15px;
    padding: 10px 5px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.score-header {
    display: flex;
    align-items: stretch;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.score-header.ai {
    background: rgba(244, 63, 94, 0.1);
    border-color: rgba(244, 63, 94, 0.3);
}

.player-name {
    width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--accent-blue);
    background: rgba(0, 0, 0, 0.4);
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    text-shadow: 0 0 5px rgba(0, 229, 255, 0.5);
}

.score-header.ai .player-name {
    color: #f43f5e;
    text-shadow: 0 0 5px rgba(244, 63, 94, 0.5);
}

.frames-container {
    display: flex;
    flex: 1;
}

.frame-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 0; /* allows squishing */
}

.frame-number {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 0;
}

.frame-top {
    display: flex;
    height: 40%;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.2);
}

.frame-top>div {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: bold;
}

.frame-top>div:first-child {
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}

/* For 10th frame having 3 boxes */
.frame-box:nth-child(10) .frame-top>div {
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}
.frame-box:nth-child(10) .frame-top>div:last-child {
    border-right: none;
}

.frame-bottom {
    height: 60%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 800;
}

.total-score {
    width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 900;
    color: var(--accent-gold);
    background: rgba(0, 0, 0, 0.4);
    text-shadow: 0 0 10px rgba(255, 223, 0, 0.5);
}

.active-frame {
    background: rgba(0, 229, 255, 0.2) !important;
}

.pin-status-wrapper {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px 15px 50% 50%; /* Triangle-ish shield */
    padding: 15px 25px 25px 25px;
    backdrop-filter: blur(5px);
    pointer-events: none;
    transition: opacity 0.3s;
}

.pin-triangle {
    display: grid;
    grid-template-columns: repeat(7, 12px); /* 4 rows needing offset handling */
    grid-template-rows: repeat(4, 18px);
    gap: 4px;
    justify-content: center;
}

.pin-icon {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid white;
    background: white;
    color: black;
    font-size: 9px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: Arial, sans-serif;
    transition: all 0.2s;
}

.pin-icon.knocked {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.3);
}

/* Explicit Grid placement for the 10 pins */
#pin-icon-7 { grid-row: 1; grid-column: 1; }
#pin-icon-8 { grid-row: 1; grid-column: 3; }
#pin-icon-9 { grid-row: 1; grid-column: 5; }
#pin-icon-10 { grid-row: 1; grid-column: 7; }

#pin-icon-4 { grid-row: 2; grid-column: 2; }
#pin-icon-5 { grid-row: 2; grid-column: 4; }
#pin-icon-6 { grid-row: 2; grid-column: 6; }

#pin-icon-2 { grid-row: 3; grid-column: 3; }
#pin-icon-3 { grid-row: 3; grid-column: 5; }

#pin-icon-1 { grid-row: 4; grid-column: 4; }


/* Status Notifications (Strike, Spare, etc) */
.status-msg {
    position: absolute;
    top: 40vh;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    font-weight: 900;
    background: linear-gradient(to bottom, #ffdf00, #ff8c00);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 15px rgba(255, 223, 0, 0.6));
    text-transform: uppercase;
    animation: popIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    white-space: nowrap;
}

@keyframes popIn {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.turn-indicator {
    position: absolute;
    top: 150px; /* Moved down to accommodate larger scoreboard */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 229, 255, 0.2);
    border: 1px solid #00e5ff;
    color: #00e5ff;
    padding: 8px 25px;
    border-radius: 30px;
    font-size: 1.4rem;
    font-weight: 800;
    text-shadow: 0 0 10px rgba(0, 229, 255, 0.8);
    transition: all 0.3s;
    letter-spacing: 1px;
}

.turn-indicator.ai {
    background: rgba(244, 63, 94, 0.2);
    border-color: #f43f5e;
    color: #f43f5e;
    text-shadow: 0 0 10px rgba(244, 63, 94, 0.8);
}

/* Full Screen Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    text-align: center;
    backdrop-filter: blur(10px);
    transition: opacity 0.3s;
}

.overlay-box {
    background: linear-gradient(135deg, rgba(29, 78, 216, 0.8), rgba(17, 24, 39, 0.9));
    padding: 30px 40px;
    border-radius: 20px;
    border: 1px solid rgba(0, 229, 255, 0.3);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), 0 0 20px rgba(0, 229, 255, 0.2);
    max-width: 90%;
    width: 450px;
}

.overlay-icon {
    font-size: 4rem;
    margin-bottom: 10px;
}

.overlay-title {
    font-size: 2.5rem;
    margin: 0 0 10px;
    background: linear-gradient(to bottom, #00e5ff, #0088cc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    line-height: 1.1;
}

.overlay-sub {
    font-size: 1.1rem;
    margin-bottom: 20px;
    color: #e0e0e0;
}

.instructions {
    text-align: left;
    background: rgba(0, 0, 0, 0.4);
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 25px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.instructions p {
    margin: 8px 0;
}

.pmg-btn {
    display: inline-block;
    padding: 15px 35px;
    font-size: 1.2rem;
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    color: white;
    background: linear-gradient(135deg, #00e5ff, #0088cc);
    border: none;
    border-radius: 30px;
    cursor: pointer;
    text-transform: uppercase;
    box-shadow: 0 5px 15px rgba(0, 229, 255, 0.4);
    transition: all 0.2s ease;
    pointer-events: auto;
}

.pmg-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(0, 229, 255, 0.4);
}

.pmg-btn-outline {
    display: inline-block;
    padding: 12px 30px;
    font-family: 'Montserrat', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s ease;
    pointer-events: auto;
}

.pmg-btn-outline:active {
    background: rgba(255,255,255,0.1);
}

.back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    color: white;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.1rem;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 15px;
    border-radius: 20px;
    z-index: 50;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
}

.hidden {
    display: none !important;
    opacity: 0;
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    .pin-status-wrapper {
        bottom: 10px;
        left: 10px;
        padding: 5px 15px 15px 15px;
        transform: scale(0.8);
        transform-origin: bottom left;
    }
}
