* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    color: #fdfdfd;
    background: radial-gradient(circle at center, #020b24 0%, #030920 55%, #01020c 100%);
    min-height: 100vh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    direction: rtl;
    text-align: right;
}

.game-wrapper {
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 2vw, 1.6rem);
    padding: clamp(1rem, 2.5vw, 1.75rem);
    max-width: 1100px;
    width: min(100%, 1100px);
    margin: 0 auto;
}

.top-bar,
.bottom-bar {
    text-align: center;
    background: rgba(8, 20, 54, 0.75);
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}

.top-bar h1 {
    margin: 0 0 0.3rem;
    font-size: 2rem;
    letter-spacing: 1px;
}

.objective {
    margin: 0;
    font-size: 0.95rem;
    color: #d1def9;
}

.bottom-bar {
    font-size: 0.85rem;
    color: #9ba8d2;
}

.game-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: clamp(1rem, 2vw, 1.5rem);
    align-items: start;
    justify-items: center;
}

canvas {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    aspect-ratio: 1 / 1;
    background: radial-gradient(circle at center, rgba(254, 245, 199, 0.25), rgba(8, 10, 30, 0.95) 60%);
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
}

.hud {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: rgba(4, 7, 22, 0.85);
    padding: 1.2rem;
    border-radius: 16px;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.35);
    max-width: 320px;
    width: 100%;
    justify-self: stretch;
    align-self: start;
}

.hud section {
    background: rgba(8, 18, 44, 0.75);
    padding: 1rem;
    border-radius: 12px;
}

.hud h2 {
    margin-top: 0;
    font-size: 1.2rem;
    color: #ffe7a1;
}

.hud p {
    margin: 0.4rem 0;
    line-height: 1.3;
}

.score-board span {
    font-size: 1.2rem;
    color: #9fe8ff;
}

.clue-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.controls {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

button {
    flex: 1 1 48%;
    background: linear-gradient(135deg, #345fff, #42c8ff);
    color: #0b1025;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(66, 200, 255, 0.35);
}

button:active {
    transform: translateY(1px);
    box-shadow: none;
}

.status-text {
    min-height: 1.4rem;
    font-size: 0.95rem;
    color: #ffe7a1;
}

.legend ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem 1rem;
    font-size: 0.95rem;
}

.legend-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-left: 0.5rem;
    vertical-align: middle;
}

.swatch-mercury { background: #9ea1a5; }
.swatch-venus   { background: #f5b567; }
.swatch-earth   { background: #4db5ff; }
.swatch-mars    { background: #ff6951; }
.swatch-jupiter { background: #d7a978; }
.swatch-saturn  { background: #f0d58b; }
.swatch-uranus  { background: #78d0ff; }
.swatch-neptune { background: #5374ff; }

@media (max-width: 1080px) {
    .game-area {
        grid-template-columns: 1fr;
        justify-items: stretch;
    }

    canvas {
        max-width: min(100%, 560px);
    }

    .hud {
        flex-direction: row;
        flex-wrap: wrap;
        max-width: none;
        align-self: stretch;
    }

    .hud section {
        flex: 1 1 220px;
    }
}

@media (max-width: 540px) {
    .top-bar h1 {
        font-size: 1.5rem;
    }

    .objective {
        font-size: 0.85rem;
    }

    .hud h2 {
        font-size: 1.05rem;
    }

    .legend ul {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    body {
        padding: 0;
    }

    .game-wrapper {
        padding: clamp(0.75rem, 4vw, 1rem);
    }

    .top-bar h1 {
        font-size: 1.7rem;
    }

    .objective {
        font-size: 0.9rem;
    }

    canvas {
        max-width: min(100%, 480px);
    }

    .hud {
        flex-direction: column;
        gap: 0.8rem;
        max-width: 100%;
    }

    .hud section {
        flex: 1 1 100%;
    }

    button {
        flex: 1 1 100%;
    }
}
