:root {
    --ui-bg: rgba(2, 10, 24, .90);
    --ui-border: rgba(80, 190, 240, .22);
    --ui-text: #e0f4ff;
    --ui-pale: #8dc8e8;
    --ui-accent: #5bc8f5;
    --ui-danger: #ef476f;
    --ok: #3fe08f;
    --transition: all .3s cubic-bezier(.4, 0, .2, 1);
    --font: 'Fredoka', 'Nunito', 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
}

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

html,
body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    font-family: var(--font);
    background: radial-gradient(ellipse at 50% 35%, #0b2442 0%, #04122a 55%, #020a18 100%);
    color: var(--ui-text);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: 52px;
    background: var(--ui-bg);
    border-bottom: 1px solid var(--ui-border);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
}

.hud-left,
.hud-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 80px;
}

.hud-right {
    justify-content: flex-end;
}

.hud-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.score-label {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--ui-pale);
    letter-spacing: .6px;
}

.score-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--ui-accent);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.icon-btn {
    background: rgba(91, 200, 245, .12);
    border: 1px solid var(--ui-border);
    color: var(--ui-text);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
    text-decoration: none;
}

.icon-btn:hover {
    background: rgba(91, 200, 245, .25);
}

.icon-btn svg {
    pointer-events: none;
}

#stage {
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 36px;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
}

#tiles {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: 640px;
}

.tile {
    width: clamp(38px, 11vw, 64px);
    height: clamp(50px, 14vw, 80px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(22px, 7vw, 38px);
    font-weight: 700;
    color: var(--ui-text);
    border-radius: 12px;
    border: 1px solid var(--ui-border);
    background: linear-gradient(160deg, #16507f, #0a2a4d);
    box-shadow: 0 6px 14px rgba(0, 0, 0, .4);
    cursor: grab;
    touch-action: none;
    transition: transform .15s, background .2s, border-color .2s;
}

.tile.sel {
    border-color: var(--ui-accent);
    background: linear-gradient(160deg, #1f7ab8, #0d3a66);
    transform: translateY(-6px);
}

.tile.over {
    border-color: #ffd84d;
    background: linear-gradient(160deg, #6b5a14, #3a3008);
}

.tile.drag {
    transition: none;
    z-index: 10;
    cursor: grabbing;
    opacity: .92;
    box-shadow: 0 14px 28px rgba(0, 0, 0, .55);
}

.tile.win {
    border-color: var(--ok);
    background: linear-gradient(160deg, #1b8a55, #0b4a2d);
    cursor: default;
}

.ctrl {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.ctrl .btn-sky {
    width: auto;
    min-height: 46px;
    padding: 10px 20px;
    font-size: 16px;
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(1, 6, 18, .87);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.overlay.open {
    display: flex;
}

.modal {
    position: relative;
    background: linear-gradient(160deg, #0a1f3a, #030f22);
    border: 1px solid var(--ui-border);
    border-radius: 22px;
    padding: 30px 26px;
    max-width: 380px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .7);
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    color: var(--ui-pale);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: var(--transition);
}

.modal-close:hover {
    background: rgba(255, 255, 255, .1);
}

.modal h2 {
    font-size: 22px;
    color: var(--ui-accent);
    margin-bottom: 18px;
}

.modal h3 {
    font-size: 15px;
    color: var(--ui-accent);
    margin: 14px 0 6px;
}

.modal section {
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    padding-bottom: 12px;
    margin-bottom: 4px;
}

.modal ul {
    padding-left: 18px;
}

.modal li {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 4px;
    color: var(--ui-pale);
}

.modal li strong {
    color: var(--ui-text);
}

.pause-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}

#pauseOverlay .modal h2 {
    text-align: center;
    margin: 10px 0 28px;
    letter-spacing: 1px;
}

.start-modal {
    text-align: center;
}

.start-title {
    font-size: 30px !important;
    letter-spacing: 1px;
    margin-bottom: 12px !important;
}

.start-text {
    font-size: 15px;
    line-height: 1.6;
    color: var(--ui-pale);
    margin-bottom: 10px;
}

.start-text strong {
    color: var(--ui-text);
}

.start-keys {
    font-size: 12px;
    color: var(--ui-pale);
    opacity: .7;
    margin-bottom: 22px;
}

.gameover-emoji {
    font-size: 56px;
    text-align: center;
    margin-bottom: 4px;
}

.gameover-title {
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 10px;
}

.gameover-title.ok {
    color: var(--ok);
}

.gameover-title.bad {
    color: var(--ui-danger);
}

.end-word {
    text-align: center;
    font-size: 30px;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 8px;
    overflow-wrap: anywhere;
}

.go-msg {
    text-align: center;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ui-pale);
    margin: 0 0 18px;
}

.btn-sky {
    display: block;
    width: 100%;
    padding: 14px;
    border-radius: 14px;
    border: none;
    font-family: var(--font);
    font-size: 17px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, #0077b6, #023e8a);
    box-shadow: 0 6px 18px rgba(0, 119, 182, .4);
    transition: var(--transition);
}

.btn-sky:hover {
    filter: brightness(1.12);
    transform: translateY(-2px);
}

.btn-sky:active {
    transform: translateY(0);
}

.btn-sky.secondary {
    background: rgba(255, 255, 255, .07);
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, .12);
}

.btn-sky.secondary:hover {
    background: rgba(255, 255, 255, .14);
}

.modal::-webkit-scrollbar {
    width: 5px;
}

.modal::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, .2);
    border-radius: 3px;
}

.modal::-webkit-scrollbar-thumb {
    background: var(--ui-accent);
}

@media (prefers-reduced-motion: reduce) {
    .tile {
        transition: none;
    }
}

.btn-sky.danger {
    color: #ffb3c4;
    border-color: rgba(239, 71, 111, .35);
}

.btn-sky.danger:hover {
    background: rgba(239, 71, 111, .16);
}
