/* Reset, page frame and shell (top bar, navigation, menu, status line). */

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

html {
    -webkit-text-size-adjust: 100%;
    scrollbar-gutter: stable;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.4;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p, dl, dd, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
svg { display: block; }
[hidden] { display: none !important; }

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

html.no-scroll { overflow: hidden; }

/* ---------- Page frame ---------- */

.topbar,
.page {
    width: 100%;
    max-width: 1120px;
    margin-inline: auto;
    padding-inline: var(--gutter);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.page {
    padding-bottom: calc(var(--tabbar-h) + 44px + env(safe-area-inset-bottom));
}

.page > * + * { margin-top: 20px; }
.page > .sr-only + * { margin-top: 0; }

/* ---------- Top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 14px;
    padding-bottom: 12px;
}

.wordmark {
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-right: auto;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---------- Navigation: bottom tab bar on phones, pills on wide screens ---------- */

.nav {
    position: fixed;
    z-index: 40;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    height: var(--tabbar-h);
    display: flex;
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.9);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    box-shadow: var(--shadow-float);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ink-3);
    border-radius: 22px;
    transition: color 0.15s;
}

.nav-item .icon { width: 21px; height: 21px; }
.nav-item[aria-current="page"] { color: var(--accent); }

@media (min-width: 760px) {
    :root { --gutter: 28px; }

    .page { padding-bottom: 72px; }
    .page > * + * { margin-top: 28px; }
    .page > .sr-only + * { margin-top: 0; }

    .topbar { padding-top: 20px; padding-bottom: 20px; gap: 12px; }
    .wordmark { margin-right: 20px; }

    .nav {
        position: static;
        height: auto;
        margin-right: auto;
        gap: 2px;
        padding: 4px;
        border-radius: var(--r-pill);
        background: rgba(255, 255, 255, 0.55);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        box-shadow: none;
    }

    .nav-item {
        flex: none;
        flex-direction: row;
        gap: 7px;
        padding: 8px 16px;
        font-size: 14px;
        color: var(--ink-2);
        border-radius: var(--r-pill);
    }

    .nav-item .icon { width: 17px; height: 17px; }
    .nav-item:hover { color: var(--ink); }

    .nav-item[aria-current="page"] {
        background: var(--surface);
        color: var(--ink);
        box-shadow: 0 1px 2px rgba(28, 36, 32, 0.08);
    }
}

/* ---------- Menu ---------- */

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }

.menu-panel {
    position: absolute;
    z-index: 50;
    top: calc(100% + 8px);
    right: 0;
    min-width: 232px;
    padding: 8px;
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--shadow-float);
    animation: pop 0.16s var(--ease);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 11px 12px;
    border-radius: 13px;
    font-size: 15px;
    font-weight: 500;
    text-align: left;
}

.menu-item:hover { background: var(--surface-2); }
.menu-item .icon { width: 18px; height: 18px; color: var(--ink-2); }

.menu-sep {
    height: 1px;
    margin: 6px 12px;
    background: var(--line);
}

.menu-lang {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    font-size: 15px;
    font-weight: 500;
}

.menu-lang .icon { width: 18px; height: 18px; color: var(--ink-2); }
.menu-lang .seg { margin-left: auto; }

/* ---------- Status line: floats over the page so it never shifts the layout ---------- */

.status {
    position: fixed;
    z-index: 70;
    bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-inline: var(--gutter);
    pointer-events: none;
}

.status:empty { display: none; }

@media (min-width: 760px) {
    .status { top: 78px; bottom: auto; }
}

.status-msg {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: min(100%, 520px);
    padding: 10px 16px;
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--shadow-float);
    color: var(--ink);
    font-size: 13.5px;
    font-weight: 500;
    overflow-wrap: anywhere;
    cursor: pointer;
    pointer-events: auto;
    animation: pop 0.2s var(--ease);
    transition: opacity 0.4s;
}

.status-msg::before {
    content: "";
    flex: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}

.status-msg[data-tone="error"] { background: var(--down-soft); color: var(--down-ink); }
.status-msg[data-tone="error"]::before { background: currentColor; }
.status-msg.is-leaving { opacity: 0; }

/* ---------- Motion ---------- */

@keyframes pop {
    from { opacity: 0; transform: translateY(-4px) scale(0.98); }
}

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

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-delay: 0s !important;
        transition-duration: 0.01ms !important;
    }
}
