/* ── Reset & Box Model ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-tap-highlight-color: transparent; }
body {
    height: 100%;
    font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
    background: radial-gradient(ellipse at center, #1a2a4a 0%, #0a0f1e 100%);
    color: #f0f4ff;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── CSS Custom Properties ─────────────────────────────────────────────── */
:root {
    --bg-deep:    #0a0f1e;
    --bg-mid:     #1a2a4a;
    --surface:    rgba(255, 255, 255, 0.07);
    --surface-hi: rgba(255, 255, 255, 0.13);
    --border:     rgba(255, 255, 255, 0.12);
    --border-hi:  rgba(255, 255, 255, 0.25);
    --text:       #f0f4ff;
    --text-dim:   rgba(240, 244, 255, 0.55);
    --text-muted: rgba(240, 244, 255, 0.32);
    --accent-1:   #FF9800;
    --accent-2:   #F44336;
    --success:    #4CAF50;
    --warning:    #FFEB3B;

    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius:    12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow:    0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

    /* Piece colours (used in game CSS and JS) */
    --piece-I: #00BCD4;
    --piece-L: #FF9800;
    --piece-O: #FFEB3B;
    --piece-T: #9C27B0;
    --piece-S: #4CAF50;
    --piece-Z: #F44336;

    /* Safe-area insets (notched phones) */
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left:   env(safe-area-inset-left, 0px);
    --safe-right:  env(safe-area-inset-right, 0px);
}

/* ── Common elements ───────────────────────────────────────────────────── */
button { font-family: inherit; cursor: pointer; }
input  { font-family: inherit; }
a { color: var(--accent-1); text-decoration: none; }

:focus-visible {
    outline: 2px solid var(--accent-1);
    outline-offset: 2px;
}

/* ── Webkit scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 2px; }

/* ── App root ──────────────────────────────────────────────────────────── */
#app {
    min-height: 100dvh;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Screen base ───────────────────────────────────────────────────────── */
.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.screen-enter {
    animation: fadeSlideIn 0.18s ease-out both;
}

/* ── Animations ────────────────────────────────────────────────────────── */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60%  { transform: translateX(-5px); }
    40%, 80%  { transform: translateX(5px); }
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(8px) translateX(-50%); }
    to   { opacity: 1; transform: translateY(0)   translateX(-50%); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateY(0)    translateX(-50%); }
    to   { opacity: 0; transform: translateY(8px)  translateX(-50%); }
}

/* ── Spinner ───────────────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
    vertical-align: middle;
    flex-shrink: 0;
}
.spinner-sm { width: 14px; height: 14px; border-width: 2px; }

/* ── Shake utility ─────────────────────────────────────────────────────── */
.shake { animation: shake 0.4s ease-in-out; }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: calc(16px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(22, 32, 58, 0.97);
    border: 1px solid var(--border-hi);
    border-radius: var(--radius);
    padding: 10px 20px;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    white-space: nowrap;
    max-width: 90vw;
    text-align: center;
    pointer-events: none;
    animation: toastIn 0.22s ease-out both;
}
.toast.error   { border-color: rgba(244, 67,  54, 0.6); color: #ff8a80; }
.toast.success { border-color: rgba(76,  175, 80, 0.6); color: #a5d6a7; }
.toast.fade-out { animation: toastOut 0.28s ease-in both; }

/* ── Loading / generic loading screen ─────────────────────────────────── */
.loading-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-dim);
    font-size: 0.9rem;
}
