:root {
    --bg-color: #0b0c10;
    --panel-bg: rgba(10, 20, 40, 0.7);
    --border-color: rgba(66, 135, 245, 0.6);
    --glow-color: rgba(66, 135, 245, 0.8);
    --alert-color: #ff2a2a;
    --text-primary: #ffffff;
    --text-secondary: #8b9bb4;
    --gold: #ffd700;
    --gold-dark: #b8860b;

    --cell-size: clamp(45px, 11vmin, 80px);
    --grid-gap: 5px;
    --grid-padding: 0px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Background */
#space-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background-image: url('bg.png');
    background-repeat: no-repeat;
    background-position: center calc(50% + 60px);
    /* Move down slightly */
    background-size: 130%;
    /* Enlarge to fit the circular window */
    /* Adding a slight blue tint to match the image mood */
    box-shadow: inset 0 0 100px rgba(0, 50, 150, 0.3);
}

/* Layout */
#app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    position: relative;
    padding: 10px 0;
}

/* Top Layer: Title and Hero */
#top-layer {
    position: relative;
    height: 150px;
    display: flex;
    justify-content: center;
    z-index: 20;
}

#game-title {
    text-align: center;
    background: radial-gradient(ellipse at center, rgba(10, 20, 50, 0.9) 0%, rgba(10, 20, 50, 0) 70%);
    padding: 10px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
}

.title-sub {
    font-size: 24px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 0 10px #00aaff;
    letter-spacing: 2px;
}

.title-main {
    font-size: 54px;
    font-weight: 900;
    background: linear-gradient(to bottom, #fff7c0, #f8b500);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0px 4px 2px rgba(0, 0, 0, 0.8));
    letter-spacing: 4px;
    margin: -5px 0;
}

.title-banner {
    background: linear-gradient(90deg, transparent, rgba(50, 100, 200, 0.8), transparent);
    padding: 4px 30px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 2px;
    border: 1px solid rgba(100, 150, 255, 0.5);
    box-shadow: 0 0 10px rgba(0, 100, 255, 0.5);
}

#hero-character {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 250px;
    height: 250px;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: floatHero 4s ease-in-out infinite;
    z-index: 30;
}

.hero-image {
    width: 100%;
    height: 100%;
    background: url('hero.png') center center / contain no-repeat;
    /* Removed border-radius and box-shadow to remove the circular frame restriction */
}

@keyframes floatHero {

    0%,
    100% {
        transform: translateY(0) rotate(5deg);
    }

    50% {
        transform: translateY(-15px) rotate(-5deg);
    }
}

/* Hero reacts on win — excited bounce + glow */
#hero-character.hero-react {
    animation: heroReact 0.6s ease-out;
}

@keyframes heroReact {
    0% {
        transform: scale(1) rotate(0deg);
        filter: brightness(1);
    }

    30% {
        transform: scale(1.25) rotate(-10deg);
        filter: brightness(1.4) drop-shadow(0 0 15px #00aaff);
    }

    60% {
        transform: scale(1.15) rotate(8deg);
        filter: brightness(1.2) drop-shadow(0 0 10px #ffd700);
    }

    100% {
        transform: scale(1) rotate(5deg);
        filter: brightness(1);
    }
}

/* Hero shakes on panic (board rotation) */
#hero-character.panic {
    animation: panicShake 0.4s infinite;
}

@keyframes panicShake {
    0% {
        transform: translate(2px, 2px) rotate(0deg);
    }

    25% {
        transform: translate(-2px, -2px) rotate(-5deg);
    }

    50% {
        transform: translate(0px, 4px) rotate(5deg);
    }

    75% {
        transform: translate(-2px, 0px) rotate(-2deg);
    }

    100% {
        transform: translate(2px, -2px) rotate(2deg);
    }
}

/* Center Panel (Grid inside Circular Frame) */
#center-panel {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    margin-top: -100px;
    /* pull up significantly to fit the background window */
}

.circular-frame {
    position: relative;
    width: calc(5 * var(--cell-size) + 4 * var(--grid-gap) + 90px);
    height: calc(5 * var(--cell-size) + 4 * var(--grid-gap) + 90px);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Deepened frosted glass effect */
    background: rgba(5, 20, 51, 0.5);
    /* darker background tint */
    backdrop-filter: blur(8px);
    /* stronger blur */
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7), inset 0 0 50px rgba(0, 100, 255, 0.4);
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.outer-ring {
    display: none;
    /* Hidden because the background image already has a window frame */
}

.inner-ring {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    border: 4px solid #4da6ff;
    box-shadow: 0 0 20px #00aaff, inset 0 0 20px #00aaff;
    z-index: 2;
    pointer-events: none;
}

.circular-frame.alert .inner-ring {
    border-color: #ff2a2a;
    box-shadow: 0 0 30px #ff0000, inset 0 0 30px #ff0000;
    animation: flashAlert 0.5s infinite alternate;
}

@keyframes flashAlert {
    from {
        opacity: 0.6;
    }

    to {
        opacity: 1;
    }
}

.grid-wrapper {
    position: relative;
    width: calc(5 * var(--cell-size) + 4 * var(--grid-gap));
    height: calc(5 * var(--cell-size) + 4 * var(--grid-gap));
    z-index: 5;
    /* Clip the grid slightly to fit the circular illusion better, though 5x5 fits nicely in a circle */
}

#grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Draw grid lines behind symbols */
#grid::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        linear-gradient(rgba(0, 100, 255, 0.2) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 100, 255, 0.2) 1px, transparent 1px);
    background-size: calc(var(--cell-size) + var(--grid-gap)) calc(var(--cell-size) + var(--grid-gap));
    background-position: -1px -1px;
    z-index: 0;
    pointer-events: none;
}

.symbol-cell {
    position: absolute;
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: calc(var(--cell-size) * 0.6);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s, scale 0.3s;
    z-index: 2;
    text-align: center;
}

.symbol-cell.large {
    width: calc(var(--cell-size) * 2 + var(--grid-gap));
    height: calc(var(--cell-size) * 2 + var(--grid-gap));
    font-size: calc(var(--cell-size) * 1.3);
    z-index: 3;
}

.symbol-text {
    font-weight: 900;
    font-family: 'Outfit', sans-serif;
    -webkit-text-stroke: 1px #ffd700;
    filter: drop-shadow(0 4px 2px rgba(0, 0, 0, 0.8));
    display: inline-block;
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
}

.symbol-text[data-val="9"],
.symbol-text[data-val="Q"] {
    background-image: linear-gradient(to bottom, #d946ef, #9333ea);
}

.symbol-text[data-val="10"] {
    background-image: linear-gradient(to bottom, #4ade80, #16a34a);
}

.symbol-text[data-val="J"] {
    background-image: linear-gradient(to bottom, #60a5fa, #2563eb);
}

.symbol-text[data-val="K"] {
    background-image: linear-gradient(to bottom, #f87171, #dc2626);
}

.symbol-text[data-val="A"] {
    background-image: linear-gradient(to bottom, #fde047, #ca8a04);
}

.symbol-hero {
    width: 80%;
    height: 80%;
    background: url('hero.png') center center / cover no-repeat;
    border-radius: 50%;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.8), inset 0 0 10px rgba(100, 200, 255, 0.5);
    position: relative;
}

.symbol-hero-badge {
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    font-size: calc(var(--cell-size) * 0.25);
    background: linear-gradient(to bottom, #fde047, #ca8a04);
    border-radius: 5px;
    padding: 0 5px;
    box-shadow: 0 2px 5px black;
    color: #fff;
    font-weight: 900;
    font-family: 'Outfit', sans-serif;
    -webkit-text-stroke: 1px #854d0e;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.symbol-cell.crushing {
    animation: crushShake 0.1s infinite;
}

@keyframes crushShake {
    0% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(2px);
    }

    100% {
        transform: translateY(0);
    }
}

.symbol-cell.winning {
    animation: winPop 0.4s ease-out;
    filter: drop-shadow(0 0 10px gold) drop-shadow(0 0 20px gold);
    z-index: 5;
}

@keyframes winPop {
    0% {
        scale: 1;
    }

    50% {
        scale: 1.2;
    }

    100% {
        scale: 1;
        opacity: 0;
    }
}

.symbol-cell.crushed {
    animation: crushedEffect 0.3s forwards;
}

@keyframes crushedEffect {
    0% {
        scale: 1;
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        scale: 0.2;
        opacity: 0;
        transform: translateY(20px);
        filter: grayscale(1);
    }
}

.symbol-cell.falling {
    animation: dropVibration 0.3s ease-in;
}

@keyframes dropVibration {
    0% {
        transform: translateY(-10px);
    }

    80% {
        transform: translateY(2px);
    }

    100% {
        transform: translateY(0);
    }
}

/* Bottom Console */
#bottom-console {
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    z-index: 20;
}

.console-panel {
    background: linear-gradient(180deg, #1e3a8a, #0f172a);
    border: 2px solid #3b82f6;
    border-radius: 40px;
    width: 90%;
    max-width: 600px;
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(59, 130, 246, 0.5);
    position: relative;
}

.console-panel::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 10%;
    right: 10%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #60a5fa, transparent);
}

.display-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 20px;
    padding: 5px 15px;
    border: 1px solid rgba(59, 130, 246, 0.3);
    min-width: 140px;
}

.display-box.right {
    flex-direction: row-reverse;
}

.display-box .icon {
    font-size: 24px;
    background: radial-gradient(circle, #fde047, #ca8a04);
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    border: 2px solid #fff;
    color: #000;
}

.display-box.right .icon {
    background: radial-gradient(circle, #93c5fd, #2563eb);
}

.display-box .info {
    display: flex;
    flex-direction: column;
}

.display-box .value {
    font-size: 18px;
    font-weight: 800;
    color: #fff;
}

.display-box .label {
    font-size: 10px;
    color: #94a3b8;
}

.spin-controls {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: -10px;
    display: flex;
    align-items: center;
    gap: 15px;
    background: #0f172a;
    padding: 10px 20px;
    border-radius: 50px;
    border: 2px solid #3b82f6;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.8);
}

.adj-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: none;
    background: linear-gradient(180deg, #3b82f6, #1d4ed8);
    color: #fff;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
}

.adj-btn:active {
    transform: translateY(2px);
}

.spin-btn-gold {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(180deg, #fef08a, #ca8a04);
    border: 4px solid #fff;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5), inset 0 0 10px rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.1s;
}

.spin-btn-gold:active:not(:disabled) {
    transform: scale(0.95);
}

.spin-btn-gold:disabled {
    filter: grayscale(1);
    cursor: not-allowed;
}

.spin-arrows {
    font-size: 40px;
    color: #451a03;
    font-weight: 900;
}

/* Overlays */
#message-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    z-index: 100;
    background: radial-gradient(circle, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 70%);
}

#message-overlay.hidden {
    opacity: 0;
}

#message-text {
    font-size: 80px;
    font-weight: 900;
    color: gold;
    text-shadow: 0 0 20px #ff8800, 0 0 40px #ff0000, 5px 5px 0px #000;
    transform: scale(0);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#message-overlay:not(.hidden) #message-text {
    transform: scale(1);
}

@media (max-width: 700px) {
    .console-panel {
        flex-direction: column;
        height: 120px;
        padding-top: 10px;
    }

    .display-box {
        width: 100%;
        justify-content: space-between;
    }

    .spin-controls {
        bottom: 10px;
    }

    .title-main {
        font-size: 40px;
    }
}