/*
 * Arcade theme, on top of Bootstrap 5.3.
 *
 * "Arcade" identity: a lavender canvas, a sidebar drawn like a dotted play mat with a Stack tower at its bottom (on
 * phones, a top bar and a dark tab bar), electric violet as the action color, coral as the highlight. Headings use a
 * geometric sans (Sora), the text Plus Jakarta Sans like every niouts application.
 * Colors are tokens redefined for each theme (data-bs-theme on <html>, set by the "theme" Stimulus controller): the
 * dark theme is the arcade room with the lights off.
 */

:root,
[data-bs-theme="light"] {
    --ar-canvas: #f5f3fb;
    --ar-surface: #fff;
    --ar-surface-2: #eeeaf7;
    --ar-ink: #1d1640;
    --ar-primary: #5b3df5;
    --ar-primary-strong: #4426d6;
    --ar-primary-soft: #e9e4ff;
    --ar-on-primary: #fff;
    --ar-accent: #f0435f;
    --ar-accent-strong: #c42744;
    --ar-accent-soft: #ffe1e6;
    --ar-success: #15803d;
    --ar-success-soft: #dcf5e3;
    --ar-danger: #b42318;
    --ar-danger-soft: #fde4e1;
    --ar-gold: #b7791f;
    --ar-gold-soft: #fdf0d5;
    --ar-plan: #f0edf9;
    --ar-plan-line: rgba(91, 61, 245, 0.12);
    --ar-plan-fg: #1d1640;
    --ar-plan-muted: rgba(29, 22, 64, 0.66);
    --ar-plan-hover: rgba(29, 22, 64, 0.06);
    --ar-plan-active-bg: #fff;
    --ar-block-1: #5b3df5;
    --ar-block-2: #8a6cff;
    --ar-block-3: #f0435f;
    --ar-block-4: #ffb547;
    --ar-street: #1d1640;
    --ar-shadow: 0 1px 2px rgba(29, 22, 64, 0.05), 0 10px 28px -14px rgba(29, 22, 64, 0.22);

    --bs-body-bg: var(--ar-surface);
    --bs-body-color: #352d5c;
    --bs-emphasis-color: #1d1640;
    --bs-secondary-color: #6c6888;
    --bs-secondary-bg: #e2ddf0;
    --bs-tertiary-bg: #faf9fd;
    --bs-border-color: #e6e1f2;
    --bs-primary: #5b3df5;
    --bs-primary-rgb: 91, 61, 245;
    --bs-primary-text-emphasis: #4426d6;
    --bs-primary-bg-subtle: #e9e4ff;
    --bs-primary-border-subtle: #bcb0fb;
    --bs-link-color: #5b3df5;
    --bs-link-color-rgb: 91, 61, 245;
    --bs-link-hover-color: #c42744;
    --bs-link-hover-color-rgb: 196, 39, 68;
    --bs-focus-ring-color: rgba(91, 61, 245, 0.25);
}

[data-bs-theme="dark"] {
    --ar-canvas: #0f0c1d;
    --ar-surface: #17132b;
    --ar-surface-2: #221c3d;
    --ar-ink: #f1eefe;
    --ar-primary: #a594ff;
    --ar-primary-strong: #c7bcff;
    --ar-primary-soft: #2a2260;
    --ar-on-primary: #140f2e;
    --ar-accent: #ff8496;
    --ar-accent-strong: #ffa9b6;
    --ar-accent-soft: #4a1d2a;
    --ar-success: #5ad88c;
    --ar-success-soft: #173d2a;
    --ar-danger: #ff8a7a;
    --ar-danger-soft: #45231f;
    --ar-gold: #ffc861;
    --ar-gold-soft: #3f2f12;
    --ar-plan: #120e24;
    --ar-plan-line: rgba(165, 148, 255, 0.1);
    --ar-plan-fg: #f1eefe;
    --ar-plan-muted: rgba(241, 238, 254, 0.68);
    --ar-plan-hover: rgba(255, 255, 255, 0.07);
    --ar-plan-active-bg: rgba(255, 255, 255, 0.1);
    --ar-block-1: #4a33c9;
    --ar-block-2: #7b62f0;
    --ar-block-3: #e0566d;
    --ar-block-4: #e9a640;
    --ar-street: #09071a;
    --ar-shadow: none;

    --bs-body-color: #dcd8ec;
    --bs-emphasis-color: #fff;
    --bs-secondary-color: #a7a2c2;
    --bs-secondary-bg: #2b2450;
    --bs-tertiary-bg: #1b1633;
    --bs-border-color: #2a2448;
    --bs-primary: #a594ff;
    --bs-primary-rgb: 165, 148, 255;
    --bs-primary-text-emphasis: #d6cfff;
    --bs-primary-bg-subtle: #2a2260;
    --bs-primary-border-subtle: #4b3fa0;
    --bs-link-color: #c7bcff;
    --bs-link-color-rgb: 199, 188, 255;
    --bs-link-hover-color: #ffa9b6;
    --bs-link-hover-color-rgb: 255, 169, 182;
    --bs-focus-ring-color: rgba(165, 148, 255, 0.25);
}

:root {
    --ar-header-height: 4rem;
    --ar-tabbar-height: 3.75rem;
    --ar-sidebar-width: 16.5rem;
    --ar-font-display: "Sora Variable", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --bs-font-sans-serif: "Plus Jakarta Sans Variable", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --bs-body-font-size: 0.9375rem;
    --bs-border-radius: 0.85rem;
    --bs-border-radius-sm: 0.6rem;
    --bs-border-radius-lg: 1.25rem;
    --bs-border-radius-xl: 1.5rem;
}

body {
    background-color: var(--ar-canvas);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    color: var(--ar-ink);
    font-weight: 700;
    letter-spacing: -0.01em;
    text-wrap: balance;
}

.min-w-0 {
    min-width: 0;
}

.num {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* ---------- Bootstrap components bound to the theme colors ---------- */

.btn {
    --bs-btn-font-weight: 700;
    --bs-btn-padding-x: 1.15rem;
    --bs-btn-padding-y: 0.5rem;
    --bs-btn-border-radius: 999px;
    --bs-btn-font-size: 0.9rem;
    transition: background-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    --bs-btn-color: var(--ar-on-primary);
    --bs-btn-bg: var(--ar-primary);
    --bs-btn-border-color: transparent;
    --bs-btn-hover-color: var(--ar-on-primary);
    --bs-btn-hover-bg: var(--ar-primary-strong);
    --bs-btn-hover-border-color: transparent;
    --bs-btn-active-color: var(--ar-on-primary);
    --bs-btn-active-bg: var(--ar-primary-strong);
    --bs-btn-active-border-color: transparent;
    box-shadow: 0 6px 16px -6px rgba(var(--bs-primary-rgb), 0.55);
}

/* Secondary actions: a filled, quiet button. */
.btn-soft {
    --bs-btn-color: var(--ar-ink);
    --bs-btn-bg: var(--ar-surface-2);
    --bs-btn-border-color: transparent;
    --bs-btn-hover-color: var(--ar-ink);
    --bs-btn-hover-bg: var(--bs-secondary-bg);
    --bs-btn-hover-border-color: transparent;
    --bs-btn-active-color: var(--ar-ink);
    --bs-btn-active-bg: var(--bs-secondary-bg);
    --bs-btn-active-border-color: transparent;
}

.btn-icon {
    display: inline-grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
}

/* Fields: filled, the border only shows on focus. */
.form-control,
.form-select {
    min-height: 3rem;
    border: 1.5px solid transparent;
    border-radius: 0.85rem;
    background-color: var(--ar-surface-2);
    color: var(--bs-body-color);
    font-weight: 500;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--ar-primary);
    background-color: var(--ar-surface);
    box-shadow: 0 0 0 4px var(--bs-focus-ring-color);
}

.dropdown-menu {
    --bs-dropdown-bg: var(--ar-surface);
    --bs-dropdown-border-color: var(--bs-border-color);
    --bs-dropdown-border-radius: 1.1rem;
    --bs-dropdown-padding-y: 0.4rem;
    --bs-dropdown-item-padding-y: 0.55rem;
    --bs-dropdown-link-color: var(--bs-body-color);
    --bs-dropdown-link-hover-bg: var(--ar-surface-2);
    --bs-dropdown-link-active-color: var(--ar-primary-strong);
    --bs-dropdown-link-active-bg: var(--ar-primary-soft);
    min-width: 15rem;
    padding-inline: 0.4rem;
    box-shadow: 0 18px 40px -12px rgba(29, 22, 64, 0.3);
}

.dropdown-item {
    border-radius: 0.7rem;
    font-weight: 600;
}

.dropdown-item i {
    width: 1.25rem;
    margin-right: 0.5rem;
    opacity: 0.75;
}

.offcanvas {
    --bs-offcanvas-bg: var(--ar-surface);
    --bs-offcanvas-border-color: var(--bs-border-color);
}

/* ---------- Application shell ---------- */

.app-body {
    min-height: 100dvh;
}

/* Desktop: the sidebar on the left, the page on the right. Phones: a top bar and a tab bar around the page. */
.app-shell {
    display: flex;
    min-height: 100dvh;
}

.app-shell-main {
    flex: 1;
    min-width: 0;
}

.app-main {
    padding-bottom: calc(var(--ar-tabbar-height) + env(safe-area-inset-bottom, 0px) + 2.5rem);
}

@media (min-width: 992px) {
    .app-main {
        padding-bottom: 4rem;
    }
}

.app-container {
    max-width: 80rem;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--ar-plan-fg);
    font-family: var(--ar-font-display);
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    text-decoration: none;
    line-height: 1;
}

.app-brand:hover {
    color: var(--ar-plan-fg);
}

.app-brand em {
    font-style: normal;
    color: var(--ar-accent);
}

.app-brand-mark {
    display: inline-grid;
    place-items: center;
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 0.7rem;
    background: var(--ar-primary);
    color: var(--ar-on-primary);
    font-size: 1.05rem;
    box-shadow: inset 0 -3px 0 var(--ar-accent);
}

/* ---------- Desktop sidebar: a dotted play mat, a Stack tower at its bottom ---------- */

.app-sidebar {
    position: sticky;
    top: 0;
    flex-direction: column;
    gap: 1.75rem;
    width: var(--ar-sidebar-width);
    height: 100dvh;
    flex: none;
    overflow: hidden;
    padding: 1.75rem 1rem 0;
    border-right: 1px solid var(--bs-border-color);
    background-color: var(--ar-plan);
    background-image: radial-gradient(var(--ar-plan-line) 1.5px, transparent 1.5px);
    background-size: 1.25rem 1.25rem;
    color: var(--ar-plan-fg);
}

.app-sidebar .app-brand {
    padding-inline: 0.5rem;
}

.app-side-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.app-side-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.45rem 0.85rem 0.45rem 0.45rem;
    border-radius: 0.95rem;
    color: var(--ar-plan-muted);
    font-weight: 700;
    font-size: 0.92rem;
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
}

.app-side-icon,
.app-user-icon {
    display: inline-grid;
    place-items: center;
    width: 2.2rem;
    height: 2.2rem;
    flex: none;
    border-radius: 0.7rem;
    background: var(--ar-plan-hover);
    font-size: 1rem;
    transition: background 0.2s, color 0.2s;
}

.app-side-link:hover {
    color: var(--ar-plan-fg);
    background: var(--ar-plan-hover);
}

.app-side-link.active {
    color: var(--ar-plan-fg);
    background: var(--ar-plan-active-bg);
    box-shadow: var(--ar-shadow);
}

.app-side-link.active .app-side-icon {
    background: var(--ar-accent);
    color: #fff;
}

/* The settings, standing on the tower at the bottom of the sidebar. */
.app-side-account {
    position: relative;
    z-index: 1;
    margin-top: auto;
    margin-bottom: 1rem;
}

.app-user-button {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.35rem 0.85rem 0.35rem 0.35rem;
    border: 0;
    border-radius: 0.95rem;
    background: rgba(255, 255, 255, 0.9);
    color: #1d1640;
    font-weight: 700;
    font-size: 0.85rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 8px 20px -12px rgba(0, 0, 0, 0.5);
}

.app-user-button .app-user-icon {
    background: var(--ar-primary-soft);
    color: #4426d6;
}

.app-user-button:hover,
.app-user-button[aria-expanded="true"] {
    background: #fff;
}

.app-side-tower {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 7rem;
}

.app-tower-1 { fill: var(--ar-block-1); }
.app-tower-2 { fill: var(--ar-block-2); }
.app-tower-3 { fill: var(--ar-block-3); }
.app-tower-4 { fill: var(--ar-block-4); }

/* ---------- Phones: a top bar ---------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 1030;
    padding-top: env(safe-area-inset-top, 0px);
    border-bottom: 1px solid var(--bs-border-color);
    background: color-mix(in srgb, var(--ar-canvas) 88%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.app-header-inner {
    display: flex;
    align-items: center;
    height: var(--ar-header-height);
}

/* ---------- Phones: a dark tab bar at the bottom of the screen ---------- */

.app-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    display: flex;
    justify-content: space-around;
    height: calc(var(--ar-tabbar-height) + env(safe-area-inset-bottom, 0px));
    padding: 0 0.5rem env(safe-area-inset-bottom, 0px);
    background: var(--ar-street);
    box-shadow: inset 0 3px 0 var(--ar-accent);
}

.app-tab {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-width: 0;
    padding: 0.4rem 0.25rem;
    border: 0;
    background: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.68rem;
    font-weight: 700;
    text-decoration: none;
}

.app-tab i {
    font-size: 1.3rem;
    line-height: 1;
}

.app-tab span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-tab:hover,
.app-tab.active {
    color: #fff;
}

/* The active tab: a lit bar above its icon. */
.app-tab.active::before {
    content: "";
    width: 1.5rem;
    height: 0.2rem;
    margin-bottom: 0.15rem;
    border-radius: 0 0 0.2rem 0.2rem;
    background: var(--ar-accent);
    box-shadow: 0 0 10px 1px var(--ar-accent);
}

/* Bottom sheets (offcanvas) */
.app-sheet.offcanvas-bottom {
    height: auto;
    max-height: 85vh;
    border: 0;
    border-radius: 1.75rem 1.75rem 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.app-sheet .offcanvas-header {
    padding-top: 1.5rem;
    padding-bottom: 0.5rem;
}

.app-sheet .offcanvas-header::before {
    content: "";
    position: absolute;
    top: 0.6rem;
    left: 50%;
    width: 2.75rem;
    height: 0.3rem;
    margin-left: -1.375rem;
    border-radius: 1rem;
    background: var(--bs-border-color);
}

.app-sheet-link {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.7rem 0.5rem;
    border-radius: 1rem;
    color: var(--bs-body-color);
    font-weight: 700;
    text-decoration: none;
}

.app-sheet-link > i {
    display: inline-grid;
    place-items: center;
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 0.8rem;
    background: var(--ar-surface-2);
    font-size: 1.1rem;
}

.app-sheet-link:hover {
    background: var(--ar-surface-2);
    color: var(--ar-ink);
}

/* Theme switcher, and any other segmented control */
.app-theme-switch,
.app-segmented {
    display: flex;
    gap: 0.2rem;
    padding: 0.25rem;
    border-radius: 999px;
    background: var(--ar-surface-2);
}

.app-theme-switch .btn,
.app-segmented .btn {
    flex: 1;
    --bs-btn-padding-y: 0.35rem;
    --bs-btn-padding-x: 0.5rem;
    --bs-btn-font-size: 0.78rem;
    --bs-btn-color: var(--bs-secondary-color);
    --bs-btn-hover-color: var(--ar-ink);
    --bs-btn-active-color: var(--ar-ink);
    --bs-btn-active-bg: var(--ar-surface);
    border: 0;
}

.app-theme-switch .btn.active,
.app-segmented .btn.active {
    background: var(--ar-surface);
    color: var(--ar-ink);
    box-shadow: 0 1px 4px rgba(29, 22, 64, 0.15);
}

/* ---------- Page structure ---------- */

.app-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    margin: 0.5rem 0 1.75rem;
}

.app-page-header h1 {
    margin: 0;
    font-family: var(--ar-font-display);
    font-size: clamp(1.75rem, 6vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.app-page-header .app-subtitle {
    margin: 0.45rem 0 0;
    color: var(--bs-secondary-color);
}

.app-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.4rem;
    color: var(--ar-accent);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.app-section-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 2.25rem 0 0.9rem;
    font-family: var(--ar-font-display);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.app-section-title::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--bs-border-color);
}

/* ---------- Cards, lists, pills ---------- */

.app-card {
    --bs-card-bg: var(--ar-surface);
    --bs-card-border-width: 1px;
    --bs-card-border-color: var(--bs-border-color);
    --bs-card-cap-bg: transparent;
    --bs-card-border-radius: 1.25rem;
    --bs-card-inner-border-radius: calc(1.25rem - 1px);
    box-shadow: var(--ar-shadow);
    overflow: hidden;
}

.app-label {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
}

.app-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
    vertical-align: middle;
}

.app-pill-primary { background: var(--ar-primary-soft); color: var(--ar-primary-strong); }
.app-pill-accent { background: var(--ar-accent-soft); color: var(--ar-accent-strong); }
.app-pill-success { background: var(--ar-success-soft); color: var(--ar-success); }
.app-pill-danger { background: var(--ar-danger-soft); color: var(--ar-danger); }
.app-pill-muted { background: var(--ar-surface-2); color: var(--bs-secondary-color); }

.app-feature {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 1.25rem;
}

.app-feature-icon {
    display: inline-grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    flex: none;
    margin-bottom: 0.35rem;
    border-radius: 0.85rem;
    background: var(--ar-primary-soft);
    color: var(--ar-primary);
    font-size: 1.25rem;
}

.app-feature h3 {
    margin: 0;
    font-size: 1rem;
}

.app-feature p {
    margin: 0 0 0.75rem;
    color: var(--bs-secondary-color);
    font-size: 0.875rem;
}

.app-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.app-list > li {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.app-list > li:last-child {
    border-bottom: 0;
}

.app-list .app-feature-icon {
    margin: 0;
}

/* ---------- Home: the game cards ---------- */

.app-game-card {
    transition: transform 0.2s, box-shadow 0.2s;
}

.app-game-card:hover {
    transform: translateY(-2px);
}

.app-game-cover {
    display: grid;
    place-items: end center;
    height: 9.5rem;
    padding: 1rem 1rem 0;
    overflow: hidden;
    background: linear-gradient(160deg, var(--ar-primary-soft), var(--ar-accent-soft));
}

.app-game-cover svg {
    width: min(100%, 20rem);
    height: 100%;
}

.app-cover-block {
    fill: hsl(var(--block-hue) 70% 62%);
}

.app-cover-moving {
    animation: app-cover-slide 2.4s ease-in-out infinite alternate;
}

@keyframes app-cover-slide {
    from { transform: translateX(-70px); }
    to { transform: translateX(30px); }
}

.app-game-cover-2048 {
    place-items: center;
    padding: 1rem;
}

.app-cover-grid {
    display: grid;
    grid-template-columns: repeat(8, 2.1rem);
    grid-template-rows: repeat(2, 2.1rem);
    gap: 0.3rem;
    transform: rotate(-6deg);
}

.app-cover-grid .app-tile {
    position: static;
    width: auto;
    height: auto;
    font-size: 0.7rem;
    border-radius: 0.45rem;
}

.app-cover-grid .app-tile:not([class*="app-tile-"]) {
    background: rgba(255, 255, 255, 0.4);
}

.app-podium {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.app-podium li {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    font-weight: 600;
}

.app-medal {
    display: inline-grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    flex: none;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 800;
    background: var(--ar-surface-2);
    color: var(--ar-ink);
}

.app-medal-1 { background: #ffd166; color: #5c3d00; }
.app-medal-2 { background: #d9dde8; color: #2f3446; }
.app-medal-3 { background: #f2b38a; color: #5a2a0c; }

/* ---------- Leaderboard ---------- */

.app-leaderboard {
    --bs-table-bg: transparent;
}

.app-leaderboard > :not(caption) > * > * {
    padding: 0.8rem 1rem;
    vertical-align: middle;
}

.app-leaderboard thead th {
    color: var(--bs-secondary-color);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.app-leaderboard tr.is-you > * {
    background: var(--ar-accent-soft);
}

.app-segmented a.btn {
    flex: 0 1 auto;
}

/* ---------- Game screen: the whole screen, a bar on top ---------- */

.app-game-body {
    overflow: hidden;
    overscroll-behavior: none;
}

.app-game {
    display: flex;
    flex-direction: column;
    height: 100dvh;
}

.app-game-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 1rem 0.6rem;
    border-bottom: 1px solid var(--bs-border-color);
    background: var(--ar-canvas);
}

.app-game-title {
    margin: 0;
    font-family: var(--ar-font-display);
    font-size: 1.3rem;
}

.app-game-scores {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

.app-game-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 4.25rem;
    padding: 0.25rem 0.75rem;
    border-radius: 0.8rem;
    background: var(--ar-surface-2);
    line-height: 1.15;
}

.app-game-score .app-label {
    font-size: 0.6rem;
}

.app-game-score output {
    font-size: 1.15rem;
    color: var(--ar-ink);
}

.app-game-main {
    position: relative;
    flex: 1;
    min-height: 0;
}

.app-game-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: color-mix(in srgb, var(--ar-canvas) 45%, transparent);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.app-game-overlay[hidden] {
    display: none;
}

.app-game-dialog {
    width: min(100%, 25rem);
    padding: 1.5rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 1.5rem;
    background: var(--ar-surface);
    box-shadow: 0 24px 60px -20px rgba(29, 22, 64, 0.45);
    text-align: center;
    animation: app-dialog-in 0.25s ease-out;
}

@keyframes app-dialog-in {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
}

.app-final-score {
    font-family: var(--ar-font-display);
    font-size: 3.25rem;
    line-height: 1;
    color: var(--ar-primary);
}

.app-score-message {
    margin-top: 1rem;
    padding: 0.6rem 0.8rem;
    border-radius: 0.8rem;
    background: var(--ar-success-soft);
    color: var(--ar-success);
    font-weight: 700;
}

.app-score-message.is-error {
    background: var(--ar-danger-soft);
    color: var(--ar-danger);
}

.app-game-hint {
    color: var(--bs-secondary-color);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
}

/* ---------- Stack ---------- */

.app-stack-stage {
    position: absolute;
    inset: 0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}

.app-stack-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.app-stack-stage .app-game-hint {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    margin: 0;
    pointer-events: none;
    color: #fff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

/* ---------- 2048 ---------- */

.app-2048-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    height: 100%;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
}

.app-2048-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: min(100%, 30rem, calc(100dvh - 13rem));
    min-height: 2.25rem;
}

.app-2048-toolbar .btn {
    margin-left: auto;
}

.app-2048-board {
    --gap: clamp(0.4rem, 2.2vw, 0.75rem);
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--gap);
    width: min(100%, 30rem, calc(100dvh - 13rem));
    aspect-ratio: 1;
    padding: var(--gap);
    border-radius: 1.25rem;
    background: var(--ar-surface-2);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    outline: none;
}

.app-2048-board:focus-visible {
    box-shadow: 0 0 0 4px var(--bs-focus-ring-color);
}

.app-2048-board .app-game-overlay {
    border-radius: inherit;
}

.app-2048-cell {
    border-radius: 0.7rem;
    background: color-mix(in srgb, var(--ar-ink) 7%, transparent);
}

.app-2048-tiles {
    position: absolute;
    inset: var(--gap);
}

.app-tile {
    position: absolute;
    top: 0;
    left: 0;
    display: grid;
    place-items: center;
    width: calc((100% - 3 * var(--gap)) / 4);
    height: calc((100% - 3 * var(--gap)) / 4);
    border-radius: 0.7rem;
    background: var(--tile-bg, #eee4da);
    color: var(--tile-fg, #5b4b3a);
    font-family: var(--ar-font-display);
    font-size: clamp(1.1rem, 7vw, 2.1rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    transform: translate(calc(var(--x) * (100% + var(--gap))), calc(var(--y) * (100% + var(--gap))));
    transition: transform 0.11s ease-in-out;
}

.app-tile-long { font-size: clamp(0.9rem, 5.5vw, 1.65rem); }

.app-tile-2 { --tile-bg: #ece8fb; --tile-fg: #3b2f7a; }
.app-tile-4 { --tile-bg: #ddd5fb; --tile-fg: #3b2f7a; }
.app-tile-8 { --tile-bg: #b9a8ff; --tile-fg: #fff; }
.app-tile-16 { --tile-bg: #9a83ff; --tile-fg: #fff; }
.app-tile-32 { --tile-bg: #7b5cff; --tile-fg: #fff; }
.app-tile-64 { --tile-bg: #5b3df5; --tile-fg: #fff; }
.app-tile-128 { --tile-bg: #ff9fb0; --tile-fg: #fff; }
.app-tile-256 { --tile-bg: #ff7a92; --tile-fg: #fff; }
.app-tile-512 { --tile-bg: #f0435f; --tile-fg: #fff; }
.app-tile-1024 { --tile-bg: #ffb547; --tile-fg: #fff; }
.app-tile-2048 { --tile-bg: #ff9f1c; --tile-fg: #fff; box-shadow: 0 0 22px 2px rgba(255, 159, 28, 0.55); }
.app-tile-super { --tile-bg: #1d1640; --tile-fg: #ffd166; }

[data-bs-theme="dark"] .app-tile-2 { --tile-bg: #2f2858; --tile-fg: #e4defd; }
[data-bs-theme="dark"] .app-tile-4 { --tile-bg: #3d3473; --tile-fg: #e4defd; }
[data-bs-theme="dark"] .app-tile-super { --tile-bg: #fff; --tile-fg: #5b3df5; }

.app-tile-new {
    animation: app-tile-appear 0.18s ease-out 0.05s backwards;
}

.app-tile-merged {
    animation: app-tile-pop 0.18s ease-out;
    z-index: 1;
}

@keyframes app-tile-appear {
    from { opacity: 0; scale: 0.3; }
}

@keyframes app-tile-pop {
    50% { scale: 1.15; }
}

.app-2048-toast {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 4;
    margin: 0;
    padding: 0.75rem 1.25rem;
    border-radius: 999px;
    background: var(--ar-ink);
    color: var(--ar-canvas);
    font-weight: 800;
    text-align: center;
    transform: translate(-50%, -50%);
    animation: app-dialog-in 0.25s ease-out;
    pointer-events: none;
}
