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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg);
    min-height: 100vh;      /* fallback for browsers without dvh support */
    min-height: 100dvh;     /* tracks the *actual* visible viewport as mobile
                                browser chrome (URL bar) shows/hides, instead
                                of the largest-possible-viewport value 100vh
                                uses — avoids a second height jump right
                                around the moment the shell reveals */
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    padding-top: 56px;
    padding-bottom: var(--bottom-nav-height);
}

/* Allow text selection/editing inside form fields and contenteditable.
   Required because body carries user-select:none (including the
   -webkit- prefix), which iOS Safari inherits into inputs and textareas,
   breaking cursor placement and copy-paste in those elements. */
input,
textarea,
[contenteditable] {
    user-select: text;
    -webkit-user-select: text;
}

/* ── Startup Splash ── */
#app-loading-splash {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    background: var(--bg);
}

#app-loading-splash .splash-logo {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--gold);
    text-shadow: 0 0 30px rgba(226, 176, 74, 0.25);
}

#app-loading-splash .splash-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(226, 176, 74, 0.18);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: splashSpin 0.8s linear infinite;
}

@keyframes splashSpin {
    to { transform: rotate(360deg); }
}

/* #app-shell must not introduce its own box in body's flex layout —
   body centers a single flow child (originally .app-container directly).
   display:contents removes app-shell's box from the render tree while
   keeping header/.app-container/nav as body's real flex participants,
   exactly matching the pre-splash DOM shape. .hidden's `!important`
   still wins to fully remove it from layout while loading. */
#app-shell {
    display: contents;
}

/* ── Sticky Header ── */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: var(--z-modal);
    background: rgba(15, 23, 36, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 520px;
    margin: 0 auto;
}

.app-title {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: var(--gold);
    text-transform: uppercase;
    text-shadow: 0 0 30px rgba(226, 176, 74, 0.25);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.settings-icon-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.1rem;
    transition: var(--transition);
    flex-shrink: 0;
}

.settings-icon-btn:hover {
    border-color: var(--gold);
    color: var(--gold);
}

/* ── App Container ── */
.app-container {
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4) var(--space-2);
    margin-bottom: var(--space-2);
}

/* ── Bottom Navigation ── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15, 23, 36, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: var(--bottom-nav-height);
    z-index: var(--z-sticky);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.03em;
    cursor: pointer;
    padding: var(--space-2) var(--space-1);
    border-radius: var(--radius-sm);
    margin: var(--space-1);
    transition: var(--transition);
}

.bottom-nav-btn .nav-icon {
    font-size: 1.2rem;
}

.bottom-nav-btn.active {
    color: var(--gold);
    background: var(--surface2);
}

.bottom-nav-btn:hover:not(.active) {
    color: var(--text);
}

/* ── Panels ── */
.panel {
    display: none;
    flex-direction: column;
    gap: var(--space-4);
}

.panel.active {
    display: flex;
}

/* ── Tab Row ── */
.tab-row {
    display: flex;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
}

.tab-btn {
    flex: 1;
    padding: var(--space-4);
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    background: var(--surface);
    color: var(--text-muted);
    font-weight: 700;
    font-size: var(--text-lg);
    cursor: pointer;
    text-align: center;
    transition: var(--transition);
}

.tab-btn.active {
    background: rgba(226, 176, 74, 0.08);
    color: var(--gold);
    border-color: var(--gold);
}

/* ── Generic Card ── */
.card {
    padding: var(--space-6);
    border-radius: var(--radius-lg);
    background: rgba(18, 26, 40, 0.95);
    border: 1px solid var(--border);
    backdrop-filter: blur(20px);
}

.section-title {
    font-size: var(--text-xl);
    color: var(--gold);
    font-weight: 700;
    margin-bottom: var(--space-2);
}

.section-heading {
    font-size: var(--text-2xl);
    font-weight: 800;
    color: var(--text-bright);
    margin: var(--space-1) 0 var(--space-1);
}

/* ── Category Header ── */
.category-header {
    font-weight: 800;
    font-size: var(--text-base);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: var(--space-2) var(--space-2);
    margin: var(--space-3) 0 var(--space-1);
    border-left: 4px solid var(--gold);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* ── Empty States ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: var(--space-8) var(--space-6);
    gap: var(--space-2);
}

.empty-state-icon {
    font-size: 2.8rem;
    filter: grayscale(0.3) opacity(0.7);
}

.empty-state-title {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text-bright);
}

.empty-state-desc {
    font-size: var(--text-base);
    color: var(--text-muted);
    line-height: 1.55;
    max-width: 280px;
}

.empty-state-desc strong {
    color: var(--gold);
    font-weight: 600;
}

/* ── Sticky / Collapsible Hero Card ── */
.header-hero-mini {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
    margin: 0 var(--space-2);
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity var(--transition), transform var(--transition);
}

#app-header.hero-collapsed .header-hero-mini {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#header-hero-level {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--gold);
    white-space: nowrap;
    flex-shrink: 0;
}

.header-xp-bar-outer {
    flex: 1;
    height: 6px;
    background: var(--xp-bar-bg);
    border-radius: var(--radius-xs);
    overflow: hidden;
    border: 1px solid var(--border);
}

.header-xp-bar-fill {
    height: 100%;
    border-radius: var(--radius-xs);
    background: linear-gradient(90deg, #d4942b, #f0c860);
    transition: width var(--progress-duration) var(--progress-easing);
}

/* ── Global Hidden ── */
.hidden {
    display: none !important;
}

/* ── Responsive ── */
@media (max-width: 480px) {
    #app-header {
        max-width: 100%;
    }

    .app-container {
        padding: var(--space-3) var(--space-3) var(--space-2);
    }

    .hero-card {
        padding: var(--space-6);
    }
}