@import url('https://fonts.googleapis.com/css2?family=Exo:wght@400;700;900&display=swap');

:root {
    --space-bg-top: #1a0d33;
    --space-bg-bottom: #0f061f;
    --neon-cyan: #00e5ff;
    --neon-cyan-soft: rgba(0, 229, 255, 0.5);
    --modal-bg: #1f0d40;
    --modal-card-bg: #291a46;
    --slot-fill: #151030;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Exo', sans-serif;
    background: linear-gradient(180deg, var(--space-bg-top) 0%, var(--space-bg-bottom) 100%);
    color: #e2e8f0;
    overflow: hidden;
    touch-action: none;
    user-select: none;
}

#game-wrapper {
    position: relative;
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse 120% 100% at 50% 50%, #251840 0%, var(--space-bg-top) 40%, var(--space-bg-bottom) 100%);
}

/* Sparse starfield */
#game-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background-image:
        radial-gradient(1px 1px at 15% 20%, rgba(255,255,255,0.8) 0%, transparent 100%),
        radial-gradient(1px 1px at 85% 25%, rgba(255,255,255,0.7) 0%, transparent 100%),
        radial-gradient(1px 1px at 50% 50%, rgba(255,255,255,0.5) 0%, transparent 100%),
        radial-gradient(1.5px 1.5px at 70% 70%, rgba(255,255,255,0.6) 0%, transparent 100%),
        radial-gradient(1px 1px at 25% 80%, rgba(255,255,255,0.45) 0%, transparent 100%),
        radial-gradient(1px 1px at 90% 55%, rgba(255,255,255,0.5) 0%, transparent 100%),
        radial-gradient(1px 1px at 40% 15%, rgba(255,255,255,0.55) 0%, transparent 100%);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    opacity: 0.7;
}

/* Hexagonal pattern background – original density */
#hex-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='104' viewBox='0 0 60 104' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 0l25.98 15v30L30 60 4.02 45V15z' stroke-width='1' stroke='%23334155' fill='none' opacity='0.2'/%3E%3Cpath d='M30 52l25.98 15v30L30 112 4.02 97V67z' stroke-width='1' stroke='%23334155' fill='none' opacity='0.2'/%3E%3C/svg%3E");
    z-index: 2;
    pointer-events: none;
}

#game-wrapper canvas {
    width: 100%;
    height: 100%;
    z-index: 10;
    filter: drop-shadow(0 0 20px rgba(0, 229, 255, 0.08));
    cursor: pointer;
}

.ui-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0;
    margin: 0;
    z-index: 20;
}

.header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    min-height: 72px;
    margin: 0;
    padding: 12px;
    box-sizing: border-box;
    pointer-events: auto;
}
.header__score {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.header__score .label {
    font-size: 0.8rem;
    letter-spacing: 0.18em;
}

.header__score .value {
    font-size: 2.6rem;
    font-weight: 900;
}

.header-btn {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: var(--modal-card-bg);
    color: #e2e8f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    transition: transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(0, 229, 255, 0.2);
}
.header-btn:hover {
    transform: scale(1.04);
    box-shadow: 0 0 16px var(--neon-cyan-soft);
}
.header-btn:active { transform: scale(0.96); }
.header-btn--home { color: var(--neon-cyan); }
.header-btn--sound.is-muted {
    color: rgba(148, 163, 184, 0.9);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.8);
    border-color: rgba(148, 163, 184, 0.35);
}

.header__score.stats-box {
    text-align: center;
}

.label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(226, 232, 240, 0.7);
}
.value {
    font-size: 2rem;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}

/* Next Tile Hex */
.next-container {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 16px;
    pointer-events: auto;
}
.next-container__label { margin-bottom: 0.5rem; }

.hex-preview {
    width: 70px;
    height: 80px;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: 900;
    transition: transform 0.2s;
    background: var(--hex-bg, #334155);
    color: var(--hex-text, #fff);
    box-shadow: var(--hex-glow, 0 0 20px rgba(51,65,85,0.4));
    border: 1px solid rgba(255,255,255,0.12);
}
.hex-preview--tier-0 { --hex-bg: #ef4444; --hex-text: #fff; --hex-glow: 0 0 18px rgba(239,68,68,0.5); }
.hex-preview--tier-1 { --hex-bg: #3b82f6; --hex-text: #fff; --hex-glow: 0 0 18px rgba(59,130,246,0.5); }
.hex-preview--tier-2 { --hex-bg: #22c55e; --hex-text: #fff; --hex-glow: 0 0 18px rgba(34,197,94,0.5); }
.hex-preview--tier-3 { --hex-bg: #eab308; --hex-text: #fff; --hex-glow: 0 0 18px rgba(234,179,8,0.5); }
.hex-preview--tier-4 { --hex-bg: #a855f7; --hex-text: #fff; --hex-glow: 0 0 18px rgba(168,85,247,0.5); }
.hex-preview--tier-5 { --hex-bg: #ec4899; --hex-text: #fff; --hex-glow: 0 0 18px rgba(236,72,153,0.5); }
.hex-preview--tier-6 { --hex-bg: #f97316; --hex-text: #fff; --hex-glow: 0 0 18px rgba(249,115,22,0.5); }
.hex-preview--tier-7 { --hex-bg: #06b6d4; --hex-text: #fff; --hex-glow: 0 0 18px rgba(6,182,212,0.5); }
.hex-preview--tier-8 { --hex-bg: #84cc16; --hex-text: #fff; --hex-glow: 0 0 18px rgba(132,204,22,0.5); }
.hex-preview--tier-9 { --hex-bg: #f43f5e; --hex-text: #fff; --hex-glow: 0 0 18px rgba(244,63,94,0.5); }
.hex-preview--tier-10 { --hex-bg: #8b5cf6; --hex-text: #fff; --hex-glow: 0 0 18px rgba(139,92,246,0.5); }
.hex-preview--tier-11 { --hex-bg: #e11d48; --hex-text: #fff; --hex-glow: 0 0 18px rgba(225,29,72,0.5); }
.hex-preview--tier-12 { --hex-bg: #fff; --hex-text: #1a0d33; --hex-glow: 0 0 18px rgba(255,255,255,0.5); }
.hex-preview:active { transform: scale(0.9); }

/* Modals – sleek, thin cyan outline */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 6, 31, 0.88);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.modal.active { opacity: 1; pointer-events: auto; }

.modal-card {
    background: var(--modal-card-bg);
    border: 1px solid var(--neon-cyan);
    padding: 2.25rem 1.5rem;
    border-radius: 20px;
    text-align: center;
    max-width: 300px;
    width: 82%;
    box-shadow:
        0 0 0 1px rgba(0, 229, 255, 0.15),
        0 0 24px rgba(0, 229, 255, 0.2),
        0 24px 48px -12px rgba(0, 0, 0, 0.5);
}
.modal-card__logo {
    display: block;
    max-width: 200px;
    height: auto;
    margin: 0 auto 1.5rem;
    object-fit: contain;
    filter: drop-shadow(0 0 16px var(--neon-cyan-soft));
}
.modal-card__title {
    font-size: 1.75rem;
    font-weight: 900;
    margin-bottom: 0.5rem;
    letter-spacing: 0.02em;
}
.modal-card__title--start {
    color: #fff;
    text-shadow: 0 0 20px var(--neon-cyan), 0 0 40px var(--neon-cyan-soft);
}
.modal-card__title--gameover {
    color: #f43f5e;
    text-shadow: 0 0 16px rgba(244, 63, 94, 0.5);
}
.modal-card__subtitle {
    color: rgba(226, 232, 240, 0.9);
    margin-bottom: 1.5rem;
    font-size: 1rem;
    line-height: 1.5;
}
.modal-card__subtitle--small { margin-bottom: 1.5rem; font-size: 0.9375rem; }
.modal-card__highlight {
    color: var(--neon-cyan);
    font-weight: 700;
}
.mode-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 0 auto 18px;
    max-width: 340px;
}
.mode-btn {
    appearance: none;
    border: 1px solid rgba(0, 229, 255, 0.22);
    background: rgba(21, 16, 48, 0.55);
    color: rgba(226, 232, 240, 0.9);
    border-radius: 12px;
    padding: 10px 10px 9px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s, background 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 56px;
}
.mode-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(0, 229, 255, 0.5);
    box-shadow: 0 0 16px rgba(0, 229, 255, 0.15);
}
.mode-btn.is-active {
    background: rgba(0, 229, 255, 0.12);
    border-color: rgba(0, 229, 255, 0.9);
    box-shadow: 0 0 18px rgba(0, 229, 255, 0.25);
}
.mode-btn__title {
    font-weight: 900;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
}
.mode-btn__meta {
    font-size: 0.75rem;
    color: rgba(226, 232, 240, 0.75);
    letter-spacing: 0.06em;
}
.modal-card__score {
    font-size: 2rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 1.75rem;
}

/* Solid cyan button, white text – high contrast */
.btn-neon {
    background: var(--neon-cyan);
    color: #fff;
    font-family: 'Exo', sans-serif;
    font-size: 1.125rem;
    font-weight: 900;
    padding: 14px 40px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    letter-spacing: 0.06em;
    transition: transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 0 20px var(--neon-cyan-soft), 0 4px 12px rgba(0, 0, 0, 0.25);
}
.btn-neon:hover {
    transform: scale(1.02);
    box-shadow: 0 0 28px rgba(0, 229, 255, 0.6), 0 4px 16px rgba(0, 0, 0, 0.3);
}
.btn-neon:active { transform: scale(0.98); }

/* Responsive sizing – keep proportions (no stretching) */
@media (max-width: 480px) {
    .header { padding: 10px; min-height: 64px; }
    .header-btn { width: 42px; height: 42px; font-size: 1.1rem; }
    .value { font-size: 1.75rem; }
    .next-container { padding-bottom: 12px; }
    .hex-preview { width: 60px; height: 68px; font-size: 1.25rem; }
    .modal-card { padding: 1.9rem 1.25rem; max-width: 320px; width: 88%; }
    .modal-card__logo { max-width: 180px; }
    .mode-picker { gap: 8px; margin-bottom: 14px; }
    .mode-btn { min-height: 52px; padding: 9px 8px; }
}

@media (max-width: 640px) {
    .modal-card { max-width: 360px; }
}

@media (min-width: 641px) and (max-width: 768px) {
    .header { padding: 14px; }
    .modal-card { max-width: 360px; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .header { padding: 16px; }
    .modal-card { max-width: 380px; }
}

@media (min-width: 1025px) {
    .modal-card { max-width: 400px; }
}

/* Landscape mobile: reduce vertical UI footprint */
@media (max-width: 932px) and (orientation: landscape) {
    .header { min-height: 56px; padding: 10px 12px; }
    .next-container { padding-bottom: 10px; }
    .hex-preview { width: 56px; height: 64px; font-size: 1.15rem; }
    .modal-card { padding: 1.75rem 1.5rem; }
    .mode-btn { min-height: 48px; }
}