:root {
    --bg: #0f0f0f;
    --surface: #1a1a2e;
    --surface-hover: #22223a;
    --border: #2a2a3e;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #6c63ff;
    --accent-hover: #5a52d5;
    --danger: #ef5350;
    --danger-hover: #e53935;
    --warning: #f5a623;
    --success: #4caf50;
    --success-hover: #43a047;
    --radius: 12px;

    /* Typography scale — 6 steps */
    --fs-xs:   0.75rem;   /* badges, tiny labels, timestamps        */
    --fs-sm:   0.875rem;  /* secondary text, captions, metadata     */
    --fs-base: 1rem;      /* body text, buttons (browser default)   */
    --fs-lg:   1.2rem;    /* card titles, section sub-headers       */
    --fs-xl:   1.5rem;    /* section headers, modal titles          */
    --fs-2xl:  2rem;      /* page h1, display numbers               */

    /* Spacing scale — 4px base grid */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    min-width: 44px;
    min-height: 44px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

#app-screen {
    max-width: 720px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    min-height: 100vh;
}
@media (max-width: 720px) {
    #app-screen { border-left: none; border-right: none; }
}

.hidden { display: none !important; }

.auth-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 16px;
}
.auth-container h1 { font-size: 2.5rem; }
.auth-container p { color: var(--text-muted); margin-bottom: 12px; }

header {
    padding: 0 32px;
    min-height: 72px;
    display: flex;
    align-items: center;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.header-icon {
    font-size: var(--fs-2xl);
    display: none;
}

.header-title {
    font-size: var(--fs-xl);
    display: none;
    padding: 16px 0 20px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

#telegram-login {
    display: flex;
    align-items: center;
}

#telegram-login iframe {
    display: block;
    vertical-align: middle;
}

.header-top::before {
    content: "🃏 SimpleJack";
    font-size: var(--fs-xl);
    font-weight: 600;
}

@media (max-width: 600px) and (orientation: portrait) {
    .header-top::before {
        content: none;
    }
    .header-icon {
        display: block;
    }
    .header-title {
        display: block;
    }
}

.user-info {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    transition: background 0.15s;
}

.user-info:hover {
    background: var(--surface-hover);
}

.user-avatar {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    font-size: var(--fs-base);
    color: var(--text-muted);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    min-width: 120px;
    z-index: 100;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.user-dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: var(--fs-base);
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.user-dropdown-item:hover {
    background: var(--surface-hover);
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: var(--fs-base);
    transition: all 0.2s;
}
.btn-logout:hover { border-color: var(--text-muted); color: var(--text); }

.tabs {
    display: flex;
    gap: 8px;
    padding: 20px 32px 0;
    flex-wrap: wrap;
    border-top: 1px solid var(--border);
}
.tab {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: var(--fs-base);
    transition: all 0.2s;
}
.tab:hover { border-color: var(--accent); color: var(--text); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding: 24px 32px;
}

.app-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.app-card:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    transform: translateY(-2px);
}
.app-card .icon { font-size: 2.5rem; }
.app-card .name { font-size: var(--fs-lg); font-weight: 600; }
.app-card .description { color: var(--text-muted); font-size: var(--fs-base); line-height: 1.4; }
.app-card .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.app-card .tag {
    background: rgba(108, 99, 255, 0.15);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: var(--fs-xs);
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
