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

body {
    font-family: Arial, Helvetica, sans-serif;
    background-color: #fcfcfc;
    color: #111111;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    padding: 2rem;
    overflow: hidden;
    transition: background-color 0.5s ease;
}

body.time-up {
    background-color: #fca5a5;
}

/* Teacher Config Section with smooth transition for hiding */
.teacher-panel {
    position: absolute;
    top: 2rem;
    width: 100%;
    max-width: 860px;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: center;
    gap: 1.5rem;
    padding-bottom: 2rem;
    border-bottom: 3px solid #e5e5e5;
    z-index: 10;
    background-color: transparent;
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 1;
    transform: translateY(0);
}

/* Hides the control panel seamlessly */
.teacher-panel.hidden {
    opacity: 0;
    transform: translateY(-20px);
    pointer-events: none;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label,
.group-label {
    font-size: 0.9rem;
    font-weight: bold;
    color: #555555;
    text-transform: uppercase;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

input[type="number"] {
    width: 90px;
    padding: 0.6rem;
    font-size: 1.5rem;
    font-weight: bold;
    border: 3px solid #222222;
    border-radius: 0px;
    background-color: #ffffff;
    color: #000000;
    text-align: center;
}

input[type="number"]:focus {
    background-color: #fffde7;
    outline: none;
}

.unit-label {
    font-size: 1.2rem;
    font-weight: bold;
    color: #222222;
}

.start-btn {
    padding: 0.75rem 2rem;
    font-size: 1.3rem;
    font-weight: bold;
    text-transform: uppercase;
    background-color: #000000;
    color: #ffffff;
    border: 3px solid #000000;
    border-radius: 0px;
    cursor: pointer;
    height: 52px;
}

.start-btn:hover {
    background-color: #2563eb;
    border-color: #2563eb;
}

.start-btn:active {
    background-color: #1d4ed8;
}

/* Main timer display container setup */
.display-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.timer-display {
    font-size: 35vh;
    font-weight: bold;
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1;
    user-select: none;
}

.timer-display.running {
    color: #000000;
}

.timer-display.finished {
    color: #b91c1c;
    animation: classroomAlert 1s infinite ease-in-out;
}

@keyframes classroomAlert {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.12);
    }

    100% {
        transform: scale(1);
    }
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}


/* =====================================================
   MODE SWITCH
   ===================================================== */

.mode-switch {
    display: flex;
}

.mode-btn {
    height: 52px;
    padding: 0 1.2rem;
    font-size: 1.1rem;
    font-weight: bold;
    text-transform: uppercase;
    background-color: #ffffff;
    color: #222222;
    border: 3px solid #222222;
    border-radius: 0px;
    cursor: pointer;
}

/* Collapse the double border between adjacent buttons */
.mode-btn + .mode-btn {
    border-left: none;
}

.mode-btn:hover {
    background-color: #fffde7;
}

.mode-btn.active {
    background-color: #222222;
    color: #ffffff;
}

/* =====================================================
   BUBU MODE
   ===================================================== */

/* Keeps the timer above the wandering Bubu */
.display-container {
    position: relative;
    z-index: 1;
}

/* Small Bubu drifting around the screen while the time runs.
   Its position is driven from JavaScript through `transform`. */
.bubu-wanderer {
    position: fixed;
    top: 0;
    left: 0;
    width: 14vh;
    height: auto;
    z-index: 0;
    opacity: 0.9;
    pointer-events: none;
    user-select: none;
    display: none;
    will-change: transform;
}

.bubu-wanderer.visible {
    display: block;
}

/* Giant Bubu shown when the time is up */
.bubu-finale {
    position: fixed;
    inset: 0;
    z-index: 5;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2vh;
    pointer-events: none;
}

.bubu-finale.visible {
    display: flex;
}

/* The giant Bubu replaces the timer digits */
body.bubu-finale-active .display-container {
    visibility: hidden;
}

/* The wrapper pops in, the image inside keeps bouncing.
   Two elements are used so the animations don't fight over `transform`. */
.bubu-finale-pop {
    animation: bubuPopIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.bubu-finale-image {
    display: block;
    height: 62vh;
    width: auto;
    max-width: 90vw;
    object-fit: contain;
    animation: bubuBounce 1.2s infinite ease-in-out;
}

.speech-bubble {
    position: relative;
    padding: 1.5vh 4vh;
    font-size: 9vh;
    font-weight: bold;
    color: #b91c1c;
    background-color: #ffffff;
    border: 4px solid #222222;
    border-radius: 3vh;
    animation: bubuPopIn 0.6s 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* Bubble tail pointing down towards Bubu */
.speech-bubble::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -2.6vh;
    width: 4vh;
    height: 4vh;
    background-color: #ffffff;
    border-right: 4px solid #222222;
    border-bottom: 4px solid #222222;
    transform: translateX(-50%) rotate(45deg);
}

@keyframes bubuPopIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes bubuBounce {
    0%,
    100% {
        transform: translateY(0) rotate(-3deg);
    }

    50% {
        transform: translateY(-3vh) rotate(3deg);
    }
}
