/* The camera games: kid-friendly, TV-optimized styles */

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

body {
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Arial Rounded MT Bold', sans-serif;
    overflow: hidden;
    background: linear-gradient(180deg, #87CEEB 0%, #98D8C8 100%);
    min-height: 100vh;
}

/* Screens */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.hidden {
    display: none !important;
}

/* Start Screen */
#start-screen {
    display: flex;
    overflow-y: auto;
    background: linear-gradient(180deg, #87CEEB 0%, #98D8C8 50%, #90EE90 100%);
}

.start-content {
    text-align: center;
    /* Auto margins center it, and still let a short screen scroll to the top */
    margin: auto;
    padding: 64px 20px 32px;
}

.start-content h1 {
    font-size: clamp(3rem, 14vw, 5rem);
    color: #FF6B6B;
    text-shadow: 4px 4px 0 #FFE66D, 8px 8px 0 #4ECDC4;
    margin-bottom: 20px;
    animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.game-icon {
    font-size: clamp(4rem, 20vw, 8rem);
    margin: 30px 0;
}

.game-icon.spin {
    animation: spin 3s linear infinite;
}

.game-icon.float {
    animation: float 2s ease-in-out infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes float {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-12px) scale(1.08); }
}

.instructions {
    font-size: clamp(1.3rem, 5.5vw, 2rem);
    color: #2C3E50;
    margin: 0 auto 40px;
    max-width: 600px;
}

.big-button {
    font-family: inherit;
    font-size: clamp(1.6rem, 7vw, 2.5rem);
    padding: 0.6em 1.5em;
    white-space: nowrap;
    background: linear-gradient(180deg, #FF6B6B 0%, #EE5A5A 100%);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 8px 0 #CC4444, 0 12px 20px rgba(0,0,0,0.2);
    transition: all 0.1s ease;
}

.big-button:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 0 #CC4444, 0 16px 24px rgba(0,0,0,0.2);
}

.big-button:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 #CC4444, 0 8px 16px rgba(0,0,0,0.2);
}

.big-button:disabled {
    cursor: wait;
    opacity: 0.8;
    transform: none;
}

.phone-tip {
    display: none;
    font-size: 1.2rem;
    color: #2C3E50;
    margin: 30px auto 0;
    max-width: 600px;
}

/* Touch screens are usually phones and tablets */
@media (pointer: coarse) {
    .phone-tip {
        display: block;
    }
}

.camera-note {
    font-size: 1.2rem;
    color: #444;
    margin: 30px auto 0;
    max-width: 600px;
}

#start-error {
    font-size: 1.4rem;
    color: #fff;
    background: #C0392B;
    border-radius: 16px;
    padding: 12px 24px;
    margin: 24px auto 0;
    max-width: 600px;
}

/* Link back to the project page */
.back-link {
    position: fixed;
    top: 15px;
    left: 15px;
    font-size: 1.1rem;
    color: #2C3E50;
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 20px;
    background: rgba(255,255,255,0.5);
}

.back-link:hover {
    background: rgba(255,255,255,0.9);
}

a.control-button {
    display: inline-block;
    text-decoration: none;
}

/* Game Screen */
#game-screen {
    background: linear-gradient(180deg, #87CEEB 0%, #B0E0E6 40%, #90EE90 100%);
}

#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Hidden, but not display: none, so every browser keeps decoding frames */
#webcam {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Camera Preview */
#camera-preview {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 240px;
    border: 4px solid white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    z-index: 100;
}

#preview-canvas {
    display: block;
    width: 100%;
    transform: scaleX(-1);
}

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

/* Status Container */
#status-container {
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

#status-text {
    font-size: 3rem;
    color: white;
    text-shadow: 3px 3px 0 #333, -1px -1px 0 #333;
    padding: 15px 40px;
    background: rgba(0,0,0,0.3);
    border-radius: 30px;
    min-width: 300px;
}

#status-detail {
    font-size: 4rem;
    margin-top: 10px;
    text-shadow: 2px 2px 0 #333;
}

/* RPM Meter */
#meter-container {
    position: absolute;
    top: 50%;
    right: 40px;
    transform: translateY(-50%);
    text-align: center;
}

#meter-label {
    font-size: 2rem;
    color: white;
    text-shadow: 2px 2px 0 #333;
    margin-bottom: 10px;
}

#meter-bar {
    width: 60px;
    height: 400px;
    background: rgba(255,255,255,0.3);
    border: 4px solid white;
    border-radius: 30px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 4px 10px rgba(0,0,0,0.2);
}

#meter-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(180deg, #FF6B6B 0%, #FFE66D 50%, #4ECDC4 100%);
    border-radius: 0 0 26px 26px;
    transition: height 0.1s ease-out;
}

#meter-value {
    font-size: 2.5rem;
    color: white;
    text-shadow: 2px 2px 0 #333;
    margin-top: 15px;
}

/* Guidance Message */
#guidance-message {
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2.5rem;
    color: #FFE66D;
    text-shadow: 3px 3px 0 #333;
    padding: 20px 40px;
    background: rgba(0,0,0,0.5);
    border-radius: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#guidance-message.visible {
    opacity: 1;
}

/* Controls */
#controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 15px;
    pointer-events: auto;
}

.control-button {
    font-family: inherit;
    font-size: 1.2rem;
    padding: 12px 24px;
    background: rgba(255,255,255,0.9);
    color: #333;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

.control-button:hover {
    background: white;
    transform: scale(1.05);
}

.control-button:active {
    transform: scale(0.95);
}

/* Subtle fullscreen button */
#fullscreen-btn {
    position: fixed;
    top: 15px;
    right: 15px;
    font-size: 0.9rem;
    padding: 8px 14px;
    background: rgba(255,255,255,0.4);
    color: rgba(0,0,0,0.5);
    box-shadow: none;
    opacity: 0.6;
    transition: opacity 0.2s ease, background 0.2s ease;
}

#fullscreen-btn:hover {
    opacity: 1;
    background: rgba(255,255,255,0.8);
    color: #333;
    transform: none;
}

/* Responsive adjustments for TV */
@media (min-width: 1920px) {
    .start-content h1 {
        font-size: 7rem;
    }

    .instructions {
        font-size: 2.5rem;
    }

    .big-button {
        font-size: 3rem;
        padding: 30px 80px;
    }

    #status-text {
        font-size: 4rem;
    }

    #meter-bar {
        width: 80px;
        height: 500px;
    }

    #meter-value {
        font-size: 3rem;
    }

    #guidance-message {
        font-size: 3rem;
    }
}

/* Short screens: laptops and phones held sideways */
@media (max-height: 600px) {
    .start-content h1 {
        font-size: 3rem;
    }

    .game-icon {
        font-size: 4rem;
        margin: 15px 0;
    }

    .instructions {
        font-size: 1.5rem;
        margin-bottom: 20px;
    }

    .big-button {
        font-size: 1.8rem;
    }

    #meter-bar {
        height: 250px;
    }
}

/* Phones: everything smaller, so the game stays in view */
@media (max-width: 700px), (max-height: 500px) {
    .game-icon {
        margin: 10px 0;
    }

    .phone-tip,
    .camera-note,
    #start-error {
        font-size: 1rem;
        margin-top: 20px;
    }

    #status-container {
        top: 12px;
        width: max-content;
        max-width: calc(100% - 24px);
    }

    #status-text {
        font-size: 1.6rem;
        padding: 8px 20px;
        min-width: 0;
        border-radius: 20px;
    }

    #status-detail {
        font-size: 2rem;
        margin-top: 4px;
    }

    #meter-container {
        right: 12px;
    }

    #meter-label {
        font-size: 1rem;
        margin-bottom: 6px;
    }

    #meter-bar {
        width: 32px;
        height: min(250px, 35vh);
        border-width: 3px;
    }

    #meter-value {
        font-size: 1.3rem;
        margin-top: 6px;
    }

    #guidance-message {
        bottom: 70px;
        width: max-content;
        max-width: calc(100% - 24px);
        text-align: center;
        font-size: 1.4rem;
        padding: 10px 20px;
        border-radius: 16px;
    }

    #camera-preview {
        width: 110px;
        top: 50%;
        bottom: auto;
        left: 12px;
        transform: translateY(-50%);
        border-width: 3px;
        border-radius: 10px;
    }

    #controls {
        left: 12px;
        right: 12px;
        bottom: 12px;
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }

    .control-button {
        font-size: 0.95rem;
        padding: 8px 14px;
    }

    #fullscreen-btn {
        top: 12px;
        right: 12px;
        font-size: 0.8rem;
        padding: 6px 10px;
    }
}

/* Phones held upright: the buttons take two rows */
@media (max-width: 500px) {
    #guidance-message {
        bottom: 110px;
    }
}

/* Phones held sideways: fit the start screen without scrolling */
@media (max-height: 500px) {
    .start-content {
        padding-top: 48px;
        padding-bottom: 16px;
    }

    .start-content h1 {
        font-size: 2.5rem;
        margin-bottom: 8px;
    }

    .game-icon {
        display: none;
    }

    .instructions {
        font-size: 1.2rem;
        margin-bottom: 16px;
    }

    .big-button {
        font-size: 1.5rem;
    }

    .phone-tip,
    .camera-note,
    #start-error {
        font-size: 0.9rem;
        margin-top: 12px;
    }
}

/* Win screen, over the game */
#win-screen {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    pointer-events: none;
}

#win-screen .win-content {
    margin: auto;
    padding: 30px 40px;
    text-align: center;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 30px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    pointer-events: auto;
    animation: pop-in 0.4s cubic-bezier(0.2, 1.6, 0.4, 1);
}

#win-screen h2 {
    font-size: clamp(2.5rem, 10vw, 4.5rem);
    color: #FF6B6B;
    text-shadow: 3px 3px 0 #FFE66D, 6px 6px 0 #4ECDC4;
}

#win-screen p {
    font-size: clamp(1.2rem, 4.5vw, 1.8rem);
    color: #2C3E50;
    margin: 10px 0 24px;
}

@keyframes pop-in {
    from { transform: scale(0.3); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Keep the start screen still for people who ask for less motion */
@media (prefers-reduced-motion: reduce) {
    .start-content h1,
    .game-icon,
    #win-screen .win-content {
        animation: none;
    }
}
