/* ============================================
   Premium Browser UI - Performance Optimized
   Enhanced: i18n support, Premium visuals, DPI-aware
   ============================================ */

/* DPI-aware font rendering */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
}

:root {
    /* Colors — Dark theme (default) */
    --bg-primary: #0f0f12;
    --bg-secondary: #1a1a1f;
    --bg-tertiary: #242429;
    --bg-elevated: #2a2a30;
    --bg-hover: rgba(255, 255, 255, 0.06);
    --accent-primary: #ff6b35;
    --accent-secondary: #ff8c5a;
    --accent-glow: rgba(255, 107, 53, 0.3);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-tertiary: rgba(255, 255, 255, 0.5);
    --border-subtle: rgba(255, 255, 255, 0.08);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);

    /* Premium: Gradient backgrounds */
    --gradient-accent: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    --gradient-surface: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    --gradient-glass: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0.02) 100%);

    /* Layout - Responsive using clamp() */
    --toolbar-height: clamp(44px, 5vw, 52px);
    --tab-height: clamp(38px, 4vw, 46px);
    --mobile-toolbar: clamp(52px, 8vh, 68px);
    --border-radius-sm: clamp(6px, 1vw, 10px);
    --border-radius-md: clamp(10px, 1.5vw, 14px);
    --border-radius-lg: clamp(14px, 2vw, 20px);

    /* Fluid layout tokens — single source of truth for spacing & sizing.
       All values use clamp(min, fluid, max) so they scale continuously
       between mobile and 4K without breakpoint jumps. */
    --space-1:  clamp(2px, 0.25vw, 4px);
    --space-2:  clamp(4px, 0.5vw, 8px);
    --space-3:  clamp(6px, 0.75vw, 12px);
    --space-4:  clamp(8px, 1vw, 16px);
    --space-5:  clamp(12px, 1.5vw, 20px);
    --space-6:  clamp(16px, 2vw, 28px);
    --space-8:  clamp(24px, 3vw, 44px);
    --space-10: clamp(32px, 4vw, 60px);

    /* Toolbar tokens — drive .nav-bar internal grid rhythm */
    --toolbar-edge:   clamp(12px, 1.4vw, 24px);   /* toolbar left/right padding */
    --toolbar-gap:    clamp(8px, 1vw, 14px);
    --control-size:   clamp(36px, 4vw, 44px);

    /* Tile / row grid tokens */
    --tile-min:       clamp(140px, 18vw, 220px);  /* shortcut card min width */
    --tile-gap:       clamp(12px, 1.4vw, 24px);   /* used in shortcut/recent grids */

    /* Container width ceiling — content never exceeds this on massive screens */
    --page-max-width: 1400px;

    /* Container query sizing threshold — single breakpoint-free scale */
    --cq-sm: 380px;
    --cq-md: 560px;
    --cq-lg: 860px;
    
    /* Typography - Responsive */
    --font-size-xs: clamp(10px, 1.2vw, 12px);
    --font-size-sm: clamp(12px, 1.4vw, 14px);
    --font-size-base: clamp(14px, 1.6vw, 16px);
    --font-size-lg: clamp(16px, 2vw, 18px);
    
    /* Transitions */
    --transition-fast: 100ms ease;
    --transition-base: 150ms ease;
    --transition-slow: 250ms ease;

    /* Monospace stack — consistent code/URL rendering across platforms.
       SF Mono for macOS, Cascadia for Win11, DejaVu/Ubuntu Mono for Linux. */
    --font-mono: "SF Mono", "Cascadia Code", "DejaVu Sans Mono", "Ubuntu Mono", "Consolas", monospace;
}

[data-theme="light"] {
    /* Colors — Light theme override */
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #ebebed;
    --bg-elevated: #fafafa;
    --bg-hover: rgba(0, 0, 0, 0.05);
    --accent-primary: #ff6b35;
    --accent-secondary: #ff8c5a;
    --accent-glow: rgba(255, 107, 53, 0.25);
    --text-primary: #1d1d1f;
    --text-secondary: rgba(0, 0, 0, 0.6);
    --text-tertiary: rgba(0, 0, 0, 0.4);
    --border-subtle: rgba(0, 0, 0, 0.08);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    /* Safe area padding for notched devices */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* PWA standalone mode */
    overscroll-behavior: none;
}

/* Fullscreen PWA */
@media (display-mode: standalone) {
    body {
        background: var(--bg-primary);
    }
}

/* Fullscreen (F11) — immersive browser chrome.
   When the browser enters fullscreen via the Fullscreen module, it
   adds .is-fullscreen to body. We hide the URL/nav bar so the page
   gets the full viewport. The tab bar has its own auto-hide logic
   (see .tab-bar.auto-hidden above). The sidebar is force-closed so
   it can't overlay the content either. The transition matches the
   tab-bar's transition so chrome disappears together. */
body.is-fullscreen .nav-bar {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    transition: transform var(--transition-slow), opacity var(--transition-slow);
}
body.is-fullscreen .sidebar {
    flex-basis: 0;
    width: 0;
    border-right-color: transparent;
    transition: width 0.25s ease, flex-basis 0.25s ease,
                border-right-color 0.25s ease;
}

/* Glass surface — premium panel base for floating menus and drawers.
   Applies the dark elevated background, hairline border, and drop
   shadow that the menu / library / wallet / context-menu panels share.
   The .sidebar class opts out (see rule near the sidebar block) so the
   drawer can keep its own visuals. */
.glass-panel {
    contain: layout style paint;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-md);
}

/* ============================================
   Tab Bar - Premium Design
/* ============================================
   Find Bar (Ctrl+F) - Premium Design
   ============================================ */
.find-bar {
    display: flex;
    align-items: center;
    gap: clamp(4px, 0.6vw, 8px);
    height: 36px;
    padding: 0 clamp(8px, 1vw, 14px);
    background: var(--bg-secondary, rgba(20, 20, 28, 0.92));
    border-top: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    contain: layout;
    animation: findBarSlideIn 160ms ease;
}
.find-bar[hidden] { display: none; }
@keyframes findBarSlideIn {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.find-bar input {
    flex: 1 1 auto;
    min-width: 0;
    height: 26px;
    padding: 0 10px;
    background: var(--bg-tertiary, rgba(255, 255, 255, 0.06));
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    border-radius: 8px;
    color: var(--text-primary, #fff);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition-base), background var(--transition-base);
}
.find-bar input:focus {
    border-color: var(--accent, #5b8def);
    background: rgba(91, 141, 239, 0.08);
}
.find-count {
    flex: 0 0 auto;
    font-size: 11px;
    color: var(--text-secondary, rgba(255, 255, 255, 0.55));
    min-width: 56px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.find-count.no-match { color: #ff6b6b; }
.find-prev, .find-next, .find-close {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-secondary, rgba(255, 255, 255, 0.7));
    cursor: pointer;
    font-size: 10px;
    transition: background var(--transition-base), color var(--transition-base);
}
.find-prev:hover, .find-next:hover, .find-close:hover {
    background: var(--bg-tertiary, rgba(255, 255, 255, 0.08));
    color: var(--text-primary, #fff);
}
.find-close svg { width: 14px; height: 14px; }
.find-bar mark.find-current {
    background: rgba(91, 141, 239, 0.45);
    color: inherit;
    padding: 0;
    border-radius: 2px;
}
.find-bar mark.find-other {
    background: rgba(255, 213, 79, 0.32);
    color: inherit;
    padding: 0;
    border-radius: 2px;
}

/* ============================================
   Tab Bar - Premium Design
   ============================================ */
.tab-bar {
    display: flex;
    align-items: center;
    height: var(--tab-height);
    background: var(--bg-secondary);
    padding: 0 clamp(4px, 0.8vw, 8px);
    gap: clamp(2px, 0.4vw, 4px);
    contain: layout;
    position: relative;
    transition: transform var(--transition-slow), opacity var(--transition-slow);
}

.tab-bar.auto-hidden {
    transform: translateY(calc(-100% - 4px));
    opacity: 0;
    pointer-events: none;
    position: absolute;
}

/* Bottom border for depth */
.tab-bar::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--border-subtle);
}

.tab-strip {
    display: flex;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    gap: clamp(2px, 0.4vw, 4px);
    scrollbar-width: thin;
    scrollbar-color: var(--border-subtle) transparent;
    position: relative;
    contain: content;
}

/* Horizontal scroll shadows — fade edges when content overflows */
.tab-strip::before,
.tab-strip::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40px;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms;
}
.tab-strip::before {
    left: 0;
    background: linear-gradient(to right, var(--bg-secondary), transparent);
}
.tab-strip::after {
    right: 0;
    background: linear-gradient(to left, var(--bg-secondary), transparent);
}
/* Show left shadow when scrolled right (has overflow on left) */
.tab-strip.scrolled-left::before { opacity: 1; }
/* Show right shadow when there's overflow on right */
.tab-strip.scrolled-right::after { opacity: 1; }

.tab-strip::-webkit-scrollbar {
    height: 4px;
}
.tab-strip::-webkit-scrollbar-track {
    background: transparent;
}
.tab-strip::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 2px;
}

.tab {
    display: flex;
    align-items: center;
    gap: clamp(6px, 1vw, 10px);
    height: clamp(30px, 3.5vw, 38px);
    padding: 0 clamp(8px, 1.2vw, 14px);
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition:
        background var(--transition-base),
        transform var(--transition-fast),
        box-shadow var(--transition-base),
        opacity 180ms ease,
        max-width 200ms ease,
        padding 200ms ease,
        margin 200ms ease;
    min-width: clamp(100px, 15vw, 180px);
    max-width: clamp(140px, 20vw, 220px);
    position: relative;
    contain: layout style;
}

/* Tab close animation: shrink + fade before DOM removal */
.tab.closing {
    opacity: 0;
    transform: scaleX(0.7);
    max-width: 0;
    padding-left: 0;
    padding-right: 0;
    margin: 0;
    pointer-events: none;
    overflow: hidden;
}

.tab:hover {
    background: var(--bg-elevated);
    box-shadow: var(--shadow-sm);
}

.tab.active {
    background: var(--bg-primary);
    box-shadow: var(--shadow-md);
}

.tab.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--gradient-accent);
    border-radius: var(--border-radius-sm) var(--border-radius-sm) 0 0;
}

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

.tab-icon {
    width: clamp(14px, 1.6vw, 18px);
    height: clamp(14px, 1.6vw, 18px);
    border-radius: 50%;
    background: var(--bg-hover);
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(9px, 1.2vw, 12px);
    overflow: hidden;
}
.tab-icon:not([style*="background-image"])::after {
    content: '🌐';
    opacity: 0.4;
}

.tab-title {
    flex: 1;
    font-size: var(--font-size-xs);
    font-weight: 450;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    will-change: contents;
}

.tab.active .tab-title {
    color: var(--text-primary);
    font-weight: 500;
}

.tab-close {
    width: clamp(16px, 2vw, 22px);
    height: clamp(16px, 2vw, 22px);
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(12px, 1.4vw, 16px);
    opacity: 0;
    transition: 
        opacity var(--transition-fast),
        background var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast);
    flex-shrink: 0;
}

.tab:hover .tab-close,
.tab.active .tab-close {
    opacity: 1;
}

.tab-close:hover {
    background: rgba(255, 100, 100, 0.15);
    color: #ff6b6b;
    transform: scale(1.1);
}

.tab-audio {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 11px;
    padding: 0 1px;
    opacity: 0.7;
    flex-shrink: 0;
}
.tab.has-audio .tab-audio { display: flex; }
.tab-audio:hover { opacity: 1; }

.tab.has-audio .tab-mute { opacity: 0.3; }
.tab.has-audio.has-muted .tab-mute { opacity: 1; }

.tab-mute {
    display: flex;
    align-items: center;
    justify-content: center;
}
.tab-pin {
    display: none;
    width: clamp(12px, 1.4vw, 16px);
    height: clamp(12px, 1.4vw, 16px);
    color: var(--accent-primary);
    flex-shrink: 0;
    pointer-events: none;
}
.tab.pinned .tab-pin {
    display: block;
}
.tab.pinned {
    min-width: clamp(44px, 6vw, 70px);
    max-width: clamp(60px, 8vw, 90px);
    background: var(--bg-secondary);
}

.tab-group-badge {
    display: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-right: 4px;
}
.tab.has-group .tab-group-badge {
    display: block;
}

.tab.dragging {
    opacity: 0.4;
    transform: scale(0.95);
}

.tab.pinned .tab-icon {
    display: none;
}
.tab.pinned .tab-title {
    display: none;
}
.tab.pinned .tab-close {
    display: none;
}
.tab.pinned:hover {
    background: var(--bg-elevated);
}

/* ============================================
   Bookmarks Bar
   ============================================ */
.bookmarks-bar {
    display: flex;
    align-items: center;
    gap: clamp(2px, 0.4vw, 6px);
    padding: 0 clamp(4px, 0.8vw, 10px);
    height: clamp(26px, 3vw, 34px);
    background: var(--bg-tertiary, rgba(255,255,255,0.04));
    border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.06));
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    /* content = layout + style + paint. `overflow: hidden/auto` already
       clips children, so paint containment is a no-op visually but lets
       the browser skip painting children of off-screen bookmark pills. */
    contain: content;
    flex-shrink: 0;
}
.bookmarks-bar::-webkit-scrollbar { display: none; }
.bookmarks-bar:empty { display: none; }

/* ============================================
   Folder picker dialog (tree UI for promptForFolder)
   Modal scrim + centered tree dialog. Rows: caret / folder icon / name;
   nested levels indent via .bfp-children padding. bfp- prefix is unique
   in the tree (grep to verify before reusing).
   ============================================ */
.bfp-scrim {
    position: fixed;
    inset: 0;
    z-index: 2100;
    background: rgba(8, 8, 12, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.bfp-dialog {
    width: min(420px, 92vw);
    max-height: min(560px, 80vh);
    max-height: min(560px, 80dvh);
    display: flex;
    flex-direction: column;
    border-radius: var(--border-radius-lg, 12px);
    padding: 0;
    overflow: hidden;
}
.bfp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.08));
    flex-shrink: 0;
}
.bfp-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}
.bfp-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}
.bfp-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.bfp-tree {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
}
.bfp-node { min-width: 0; }
.bfp-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 13px;
    transition: background var(--transition-fast, 120ms ease);
    user-select: none;
}
.bfp-row:hover { background: var(--bg-hover); }
.bfp-row:focus { background: var(--bg-hover); outline: none; }
.bfp-row:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: -2px; }
.bfp-row.bfp-selected {
    background: var(--bg-tertiary, rgba(255,255,255,0.06));
    color: var(--accent-primary);
}
.bfp-caret {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    color: var(--text-tertiary);
    transition: transform var(--transition-fast, 120ms ease);
}
.bfp-caret[aria-expanded="true"] { transform: rotate(90deg); }
.bfp-caret-leaf { visibility: hidden; }
.bfp-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    color: var(--accent-primary);
}
.bfp-row.bfp-selected .bfp-icon { color: var(--accent-primary); }
.bfp-row-root .bfp-icon { color: var(--text-secondary); }
.bfp-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bfp-children { padding-left: 20px; }
.bfp-namerow {
    padding: 12px 16px 4px;
    flex-shrink: 0;
}
.bfp-nameinput {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color, rgba(255,255,255,0.12));
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
}
.bfp-nameinput:focus { outline: none; border-color: var(--accent-primary); }
.bfp-nameinput.bfp-shake { border-color: #e5484d; }
.bfp-newrow {
    padding: 10px 16px 4px;
    border-top: 1px solid var(--border-color, rgba(255,255,255,0.08));
    flex-shrink: 0;
}
.bfp-newinput {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color, rgba(255,255,255,0.12));
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
}
.bfp-newinput:focus { outline: none; border-color: var(--accent-primary); }
.bfp-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 16px 14px;
    flex-shrink: 0;
}
.bfp-btn {
    padding: 7px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color, rgba(255,255,255,0.12));
    background: var(--bg-tertiary, rgba(255,255,255,0.06));
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition-fast, 120ms ease);
}
.bfp-btn:hover { background: var(--bg-hover); }
.bfp-btn.bfp-ok {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}
.bfp-btn.bfp-ok:hover { filter: brightness(1.08); }
@media (max-width: 480px) {
    .bfp-dialog { width: 94vw; }
    .bfp-row { padding: 10px 12px; min-height: 40px; }
}


/* Folder pills on the bar. Same pill shape as .bar-item; the arrow marks
   it as opening a dropdown. bar-folder pills are <button> elements so the
   default link styling does not apply. */
.bar-folder {
    border: 1px solid var(--border-color, rgba(255,255,255,0.08));
    font-family: inherit;
}
.bar-folder[aria-expanded="true"] {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}
.bar-folder .bar-folder-arrow {
    width: 10px;
    height: 10px;
    margin-left: 2px;
    flex-shrink: 0;
    opacity: 0.7;
}

/* ============================================
   Bookmarks folder dropdown (multi-level)
   Shared level-0 panel (#bookmarks-dropdown, toggled under the bar) and
   per-level submenu panels (.bm-submenu, appended to body). Fixed
   positioning like #context-menu: .bookmarks-bar has `contain: content`
   which would clip children, so the panels must live outside it.
   ============================================ */
.bookmarks-dropdown,
.bm-submenu {
    position: fixed;
    width: max-content;
    min-width: 180px;
    max-width: 320px;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
    border-radius: var(--border-radius-md);
    padding: 4px;
    display: none;
    z-index: 2000;
}

.bookmarks-dropdown.visible,
.bm-submenu {
    display: block;
}

.bookmarks-dropdown.visible {
    animation: menuFadeIn 100ms ease forwards;
}

/* Menu items: bookmarks open the URL, folder items open the next level.
   Shared styling with .context-item so the dropdown reads like the
   rest of the chrome's menus. */
.bm-menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 6px 10px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.3;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    gap: 10px;
    transition: background-color var(--transition-fast);
    font-family: inherit;
}
.bm-menu-item svg {
    flex: 0 0 14px;
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.bm-menu-item img.bm-menu-icon {
    flex: 0 0 14px;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    object-fit: cover;
}
.bm-menu-item .bm-menu-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bm-menu-item .bm-menu-arrow {
    flex: 0 0 10px;
    width: 10px;
    height: 10px;
    opacity: 0.7;
}
.bm-menu-item:hover,
.bm-menu-item:focus-visible {
    background: var(--bg-hover);
    outline: none;
}
.bm-menu-item:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}


.bar-item {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 clamp(6px, 1vw, 12px);
    height: clamp(20px, 2.5vw, 28px);
    border-radius: var(--border-radius-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color, rgba(255,255,255,0.08));
    color: var(--text-secondary);
    font-size: clamp(10px, 1.2vw, 13px);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    text-decoration: none;
}
.bar-item:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}
.bar-item svg {
    width: clamp(12px, 1.4vw, 16px);
    height: clamp(12px, 1.4vw, 16px);
    flex-shrink: 0;
}
.bar-item img.bar-item-icon {
    width: clamp(12px, 1.4vw, 16px);
    height: clamp(12px, 1.4vw, 16px);
    flex-shrink: 0;
    border-radius: 3px;
    object-fit: cover;
}

.tab-add,
.menu-btn {
    width: clamp(30px, 3.5vw, 38px);
    height: clamp(30px, 3.5vw, 38px);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 
        background var(--transition-fast),
        color var(--transition-base),
        transform var(--transition-fast);
}

.tab-add:hover,
.menu-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.tab-add:active,
.menu-btn:active {
    transform: scale(0.92);
}

.tab-add svg,
.menu-btn svg {
    width: clamp(16px, 1.8vw, 20px);
    height: clamp(16px, 1.8vw, 20px);
}

/* ============================================
   Navigation - Premium Design
   ============================================ */
.nav-bar {
    /* 3-column grid guarantees the right group touches the right edge
       at every viewport width — no more white space past the last icon. */
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    height: var(--toolbar-height);
    background: var(--gradient-surface);
    padding-inline: var(--toolbar-edge);
    column-gap: var(--toolbar-gap);
    contain: layout;
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
}

/* Subtle top highlight line */
.nav-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1) 50%, transparent);
}

.nav-group {
    display: flex;
    align-items: center;
    gap: clamp(1px, 0.3vw, 3px);
}

.nav-btn {
    width: var(--control-size);
    height: var(--control-size);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 
        background var(--transition-fast),
        color var(--transition-base),
        transform var(--transition-fast),
        box-shadow var(--transition-fast);
    position: relative;
}

/* Subtle press effect */
.nav-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--accent-primary);
    opacity: 0;
    transform: scale(0.8);
    transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.nav-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.nav-btn:active:not(:disabled) {
    transform: scale(0.92);
}

.nav-btn:active:not(:disabled)::after {
    opacity: 0.15;
    transform: scale(1);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Focus ring only on keyboard navigation (suppressed on mouse click) */
.nav-btn:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }

.nav-btn svg {
    width: clamp(18px, 2vw, 22px);
    height: clamp(18px, 2vw, 22px);
    stroke-width: 1.75;
    transition: stroke-width var(--transition-fast);
}

.nav-btn:hover:not(:disabled) svg {
    stroke-width: 2;
}

/* Reload button spinning animation */
@keyframes spin360 {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}
.nav-btn.reloading {
    position: relative;
}
.nav-btn.reloading svg {
    display: none;
}
.nav-btn.reloading::before {
    content: "";
    display: block;
    width: 20px;
    height: 20px;
    background: none;
    /* Firefox-style stop "X" — pure CSS cross */
    background-image: linear-gradient(currentColor, currentColor),
                      linear-gradient(currentColor, currentColor);
    background-size: 18px 2px, 2px 18px;
    background-position: center;
    background-repeat: no-repeat;
    transform: rotate(45deg);
    border-radius: 1px;
}

/* Premium: Icon-only variant has subtle bg on hover */
.nav-btn.icon-only:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.06);
}

#search-engine-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}
.se-btn-icon {
    width: 18px;
    height: 18px;
    background-image: var(--se-btn-icon, none);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    flex-shrink: 0;
}
.se-btn-arrow {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: 0.7;
}

/* ============================================
   URL Bar - Premium Design
   ============================================ */
.url-bar {
    /* Lives in the middle grid column (minmax(0, 1fr)) so it absorbs
       whatever horizontal space is available between the control groups. */
    flex: 1;
    min-width: 0;            /* allow it to shrink on cramped viewports */
    max-width: 100%;         /* never overflow its grid track */
    width: 100%;
    height: clamp(36px, 4vw, 44px);
    background: var(--gradient-surface);
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    padding: 0 clamp(8px, 1.5vw, 14px);
    gap: clamp(6px, 1vw, 10px);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.05);
    transition: 
        background var(--transition-base),
        border-color var(--transition-base),
        box-shadow var(--transition-base),
        transform var(--transition-fast);
    contain: layout style;
    position: relative;
    overflow: hidden;
}

/* Subtle glass overlay */
.url-bar::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-glass);
    pointer-events: none;
    opacity: 0.5;
    border-radius: inherit;
}

.url-bar:focus-within {
    background: var(--bg-elevated);
    border-color: var(--accent-primary);
    box-shadow: 
        var(--shadow-md),
        0 0 0 1px var(--accent-primary),
        var(--shadow-glow);
    transform: translateY(-0.5px);
}

.url-icon {
    font-size: clamp(14px, 1.6vw, 18px);
    flex-shrink: 0;
    opacity: 0.8;
    filter: saturate(0.9);
    transition: opacity var(--transition-fast), transform var(--transition-base),
                background-color var(--transition-fast);
    /* Firefox-style identity button: same vertical padding as the URL bar
       height, padded just enough so a click feels like a button without
       hijacking focus from the input. */
    appearance: none;
    border: none;
    background: transparent;
    padding: 0;
    margin: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    /* Stack the favicon (background) under the lock/glyph. */
    color: inherit;
}
.url-icon:hover {
    opacity: 1;
    background: var(--bg-hover);
}
.url-icon:active {
    transform: scale(0.92);
}
.url-icon[aria-expanded="true"] {
    background: var(--bg-active);
    opacity: 1;
}
.url-icon:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 1px;
}

.url-icon-glyph,
.url-icon-favicon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: inherit;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 16px 16px;
    pointer-events: none;
}
/* The favicon layer visually wins over the glyph when present — Firefox
   draws the small lock/warn overlay in the bottom-right of the favicon,
   not on top of it covering the whole image. We approximate by hiding the
   centered glyph while the favicon shows. */
.url-icon-favicon[style*="display: block"] ~ .url-icon-glyph,
.url-icon-favicon:not([style*="display: none"]) ~ .url-icon-glyph {
    opacity: 0;
}

.url-bar:focus-within .url-icon {
    opacity: 1;
    transform: scale(1.05);
}

.url-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-weight: 450;
    caret-color: var(--accent-primary);
    letter-spacing: -0.01em;
}

.url-input::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

.star-btn {
    width: clamp(26px, 3vw, 32px);
    height: clamp(26px, 3vw, 32px);
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: 
        color var(--transition-base),
        transform var(--transition-base),
        background var(--transition-fast);
    flex-shrink: 0;
    position: relative;
}

.star-btn:hover {
    color: var(--accent-primary);
    transform: scale(1.15);
    background: rgba(255, 107, 53, 0.1);
}

.star-btn.active {
    color: var(--accent-primary);
}

.star-btn.active::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: 0 0 12px var(--accent-glow);
    opacity: 0.6;
    animation: starPulse 2s ease-in-out infinite;
    will-change: transform, opacity;
}

.search-engine-select-wrapper {
    position: relative;
    display: none;
    align-items: center;
    flex-shrink: 0;
    width: clamp(26px, 3vw, 32px);
    height: clamp(26px, 3vw, 32px);
}

.search-engine-select-wrapper.visible {
    display: inline-flex;
}

.search-engine-select {
    width: 100%;
    height: 100%;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: clamp(11px, 1.2vw, 13px);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    padding: 0 4px;
    outline: none;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.search-engine-select:focus {
    border-color: var(--accent-primary);
}

.search-engine-select:hover {
    border-color: var(--accent-primary);
}

@keyframes starPulse {
    0%, 100% { opacity: 0.4; transform: scale(0.95); }
    50% { opacity: 0.8; transform: scale(1.1); }
}

.star-btn.active svg {
    fill: var(--accent-primary);
}

.star-btn svg {
    width: clamp(16px, 1.8vw, 20px);
    height: clamp(16px, 1.8vw, 20px);
    transition: fill var(--transition-base), transform var(--transition-base);
}

.suggestion-icon {
    width: 16px;
    height: 16px;
    margin-right: 12px;
    border-radius: 4px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    /* Favicon image sizing */
    overflow: hidden;
}

.suggestion-favicon {
    width: 16px;
    height: 16px;
    object-fit: contain;
    border-radius: 2px;
}

.suggestion-icon.suggestion-bookmark {
    background: rgba(255, 107, 53, 0.15);
    color: var(--accent-primary);
}

.suggestion-icon.suggestion-history {
    background: var(--bg-hover);
}

.suggestion-icon.suggestion-search {
    background: rgba(66, 133, 244, 0.15);
    color: #4285f4;
}

.suggestion-group-header {
    padding: 8px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-top: 1px solid var(--border-subtle);
}

.suggestion-group-header:first-child {
    border-top: none;
    padding-top: 4px;
}

.suggestion-text {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.suggestion-title {
    font-size: 13px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.suggestion-url {
    font-size: 12px;
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   Menu Panel - Hardware Accelerated
   Sizes track viewport plus orientation: tight in landscape, generous
   in portrait (always ≥44px hit targets so thumb use stays accessible).

   Width formula clamps a fluid vw term so the dropdown grows on big
   monitors, shrinks on phones, and never trips the readability floor.
   ============================================ */
.menu-panel {
    /* Panel drops from BELOW the nav-bar (the hamburger lives at the end
       of the nav-bar's right group). Anchoring under the toolbar row keeps
       the hamburger clickable while the menu is open. */
    position: fixed;
    top: calc(var(--tab-height) + var(--toolbar-height));
    right: var(--toolbar-edge);
    width: clamp(220px, 22vw, 320px);
    max-height: calc(100vh - var(--tab-height) - var(--toolbar-height) - var(--space-4));
    border-radius: var(--border-radius-md);
    display: none;
    z-index: 1000;
    overflow: hidden auto;
}

.menu-panel.visible {
    display: block;
    animation: menuFadeIn 150ms ease forwards;
}

/* Hand the panel a slightly larger footprint whenever the viewport is
   narrower than 768px OR locked to portrait — both cases flip the menu
   into thumb-friendly territory without needing JS. */
@media (max-width: 768px),
       (orientation: portrait) and (max-width: 1024px) {
    .menu-panel {
        /* Pull in from the right edge only as much as vw warrants; on
           a phone it's essentially full-width with the toolbar tap area
           still visible on the left. */
        right: var(--toolbar-edge);
        left: auto;
        width: clamp(240px, 60vw, 340px);
        max-height: calc(100vh - var(--tab-height) - var(--toolbar-height) - var(--space-5));
        border-radius: var(--border-radius-lg);
    }
    .menu-item {
        padding: 12px 14px;
        /* Enforce a Material/iOS friendly hit area in thumb mode. */
        min-height: 44px;
    }
    .menu-item,
    .menu-item .shortcut,
    .menu-icon {
        font-size: 15px;
    }
    .menu-icon { width: 20px; height: 20px; }
}

/* Very narrow screens — tablet-portrait and below. Use a near-full-width
   drop-down anchored to the right edge so it doesn't fight the URL bar. */
@media (max-width: 480px),
       (orientation: portrait) and (max-width: 640px) {
    .menu-panel {
        width: min(88vw, 360px);
    }
    .menu-item {
        padding: 14px 16px;
        font-size: 16px;
        min-height: 48px;
    }
    .menu-icon { width: 22px; height: 22px; }
    .menu-divider { margin: 10px 14px; }
}

/* Landscape mobile (long but short-window) — keep landscape density but
   use the smaller terrain to stack the menu above the URL bar instead
   of beside it. */
@media (max-height: 480px) and (orientation: landscape) {
    .menu-panel {
        width: clamp(220px, 30vw, 280px);
        /* Grow downward into the available viewport. */
        max-height: calc(100vh - var(--tab-height) - var(--space-3));
    }
}

@keyframes menuFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-4px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.menu-content {
    padding: 8px;
}

.menu-section {
    padding: 4px;
}

.menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 450;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
    gap: 12px;
}

.menu-item:hover {
    background: var(--bg-hover);
}

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

.menu-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.menu-item .shortcut {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-tertiary);
}

.menu-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 8px 12px;
}

/* ============================================
   Page Info Panel (Ctrl+I)
   Anchored to the identity button (#url-icon): left edge aligns with the
   icon's left, top sits just below the nav-bar. JS sets --pi-anchor-l and
   --pi-anchor-t from the rect of #url-icon at open() time so the popover
   follows the icon regardless of window size.
   ============================================ */
.page-info-panel {
    position: fixed;
    top: var(--pi-anchor-t, 52px);
    left: var(--pi-anchor-l, 60px);
    width: min(340px, calc(100vw - var(--pi-anchor-l, 60px) - 12px));
    z-index: 1000;
    padding: 0;
}
.page-info-panel[hidden] { display: none; }

/* ============================================
   Search Engine Panel (Ctrl+Shift+S)
   Anchored to #search-engine-btn
   ============================================ */
.search-engine-panel {
    position: fixed;
    top: var(--pi-anchor-t, 52px);
    left: var(--pi-anchor-l, 60px);
    width: min(150px, calc(100vw - var(--sep-anchor-l, 60px) - 12px));
    z-index: 1000;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.search-engine-panel[hidden] { display: none; }

/* Compact header override — the panel is only 150px wide; the shared
   .settings-header (16px/20px padding, 32px close) is sized for the
   full-page settings panel and forces the title to wrap 3 lines. */
.search-engine-panel .settings-header {
    padding: 8px 10px 8px 12px;
    gap: 6px;
}
.search-engine-panel .settings-header h3 {
    font-size: 13px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1 1 auto;
}
.search-engine-panel .settings-close {
    width: 22px;
    height: 22px;
    font-size: 16px;
    flex-shrink: 0;
}

.sep-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 13px;
}
.sep-row:last-child { border-bottom: none; }
.sep-row:hover,
.sep-row.kb-active { background: var(--bg-hover); }

.sep-icon {
    width: 18px;
    height: 18px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    flex-shrink: 0;
}
.sep-name {
    flex: 1;
    font-weight: 500;
    color: var(--text-primary);
}
.sep-url {
    font-size: 11px;
    color: var(--text-secondary);
}

.page-info-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: var(--font-size-sm);
    font-weight: 600;
}
.page-info-header .icon-btn {
    margin-left: auto;
}
.page-info-content {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.pi-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.pi-label {
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.pi-value {
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    word-break: break-all;
}
.pi-value.url { color: var(--accent-primary); font-family: var(--font-mono); font-size: 12px; }
.pi-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}
.pi-badge.secure { background: rgba(16,185,129,0.15); color: #10b981; }
.pi-badge.insecure { background: rgba(239,68,68,0.15); color: #ef4444; }
.pi-badge.info { background: var(--bg-secondary); color: var(--text-secondary); }

/* ============================================
   Suggestions URL Panel
   ============================================ */
.suggestions-url-panel {
    position: fixed;
    top: var(--sup-anchor-t, 52px);
    left: var(--sup-anchor-l, 60px);
    width: var(--sup-width, min(480px, calc(100vw - var(--sup-anchor-l, 60px) - 12px)));
    z-index: 1000;
    background: var(--bg-elevated);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
    max-height: min(60vh, 480px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}
.suggestions-url-panel[hidden] { display: none; }

.suggestions-url-content {
    padding: 6px 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.suggestions-url-item {
    display: flex;
    align-items: center;
    padding: 9px 14px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}
.suggestions-url-item:hover,
.suggestions-url-item.kb-active {
    background: var(--bg-hover);
    border-radius: 8px;
    margin: 0 4px;
    padding-left: 10px;
}
.suggestions-url-item.kb-active {
    outline: 2px solid var(--accent-primary);
    outline-offset: -1px;
}

.suggestions-url-icon {
    width: 16px;
    height: 16px;
    margin-right: 12px;
    border-radius: 4px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}
.suggestions-url-icon img {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    object-fit: contain;
}
.suggestions-url-icon.bookmark { background: rgba(255, 107, 53, 0.15); color: var(--accent-primary); }
.suggestions-url-icon.history  { background: var(--bg-hover); }
.suggestions-url-icon.search  { background: rgba(96, 165, 250, 0.15); color: #60a5fa; }
.suggestions-url-icon.topsite { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }

.suggestions-url-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.suggestions-url-title {
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}
.suggestions-url-url {
    font-size: 11px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.suggestions-url-group-header {
    padding: 10px 18px 4px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 2px;
}

/* Trailing "all search engines" row. Hosts a horizontal strip of small
   engine buttons so users can dispatch a one-shot search with any
   registered engine without leaving the panel. The label and the
   engine strip live on the same line so the row stays a single row
   of vertical space (~28px) instead of stacking title + engines into
   a tall two-line block. */
.suggestions-url-engines-row {
    /* Keep the trailing row compact — it's a one-line horizontal strip,
       not a full nav-row. */
    padding-top: 6px;
    padding-bottom: 6px;
}
.suggestions-url-engines-row .suggestions-url-text {
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    column-gap: 8px;
    row-gap: 4px;
    min-width: 0;
}
.suggestions-url-engines-row .suggestions-url-title {
    /* Keep the label on one line - if the panel is too narrow we shrink
       the engine buttons instead of wrapping this text. */
    white-space: nowrap;
    flex-shrink: 0;
}
.suggestions-url-engines {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 4px;
    margin-top: 2px;
    min-width: 0;
}
.suggestions-url-engine {
    appearance: none;
    border: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    border-radius: 6px;
    width: 22px;
    height: 22px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background-color var(--transition-fast),
                transform var(--transition-fast),
                border-color var(--transition-fast);
}
.suggestions-url-engine:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
}
.suggestions-url-engine:active {
    transform: scale(0.92);
}
.suggestions-url-engine:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 1px;
}
.suggestions-url-engine img {
    width: 14px;
    height: 14px;
    object-fit: contain;
    border-radius: 3px;
    pointer-events: none;
}

/* ============================================
   Command Palette (Ctrl+Shift+P)
   ============================================ */
.cmd-palette {
    position: fixed;
    top: 52px;
    left: 50%;
    transform: translateX(-50%);
    width: min(520px, 92vw);
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    z-index: 1100;
    padding: 0;
    overflow: hidden;
}
.cmd-palette[hidden] { display: none; }

.cmd-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
}
#cmd-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: var(--font-size-md);
    color: var(--text-primary);
}
#cmd-input::placeholder { color: var(--text-tertiary); }

.cmd-results {
    overflow-y: auto;
    padding: 4px;
}

.cmd-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    transition: background var(--transition-base);
}
.cmd-item:hover, .cmd-item.highlighted {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.cmd-item:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}
.cmd-item .cmd-label { flex: 1; }
.cmd-item .cmd-shortcut {
    font-size: 11px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

/* ============================================
   Wallet Panel
   ============================================ */
.wallet-panel {
    position: fixed;
    top: 52px;
    right: 60px;
    width: 340px;
    display: none;
    flex-direction: column;
    z-index: 1000;
    padding: 0;
}

.wallet-panel.visible {
    display: flex;
    animation: menuFadeIn 150ms ease forwards;
}

.wallet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.wallet-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.wallet-content {
    padding: 24px 20px;
}

.wallet-state {
    text-align: center;
}

.wallet-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.wallet-state p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.wallet-connect-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, #f6851b, #e8a953);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.wallet-connect-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(246, 133, 27, 0.4);
}

.wallet-connect-btn svg {
    width: 20px;
    height: 20px;
}

.wallet-hint {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 12px;
}

.wallet-info {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

.wallet-address {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.wallet-avatar {
    font-size: 32px;
}

.wallet-ens {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.wallet-address-text {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.wallet-balance {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.wallet-network {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13px;
}

.network-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
}

.wallet-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.wallet-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background-color var(--transition-base);
}

.wallet-action-btn:hover {
    background: var(--bg-tertiary);
}

.wallet-action-btn svg {
    width: 16px;
    height: 16px;
}

.wallet-disconnect-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: background-color var(--transition-base), color var(--transition-base);
}

.wallet-disconnect-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
    color: #ef4444;
}

/* ============================================
   Reading Mode
   ============================================ */
.reading-mode {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.reading-mode[hidden] { display: none; }

.reading-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    height: 48px;
    flex-shrink: 0;
}
.reading-title {
    flex: 1;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reading-content {
    flex: 1;
    overflow-y: auto;
    padding: clamp(24px, 5vw, 60px) clamp(16px, 5vw, 80px);
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
    font-size: clamp(16px, 2vw, 20px);
    line-height: 1.75;
    color: var(--text-primary);
}
.reading-content h1,
.reading-content h2,
.reading-content h3 {
    margin: 1.5em 0 0.5em;
    color: var(--text-primary);
    line-height: 1.3;
}
.reading-content h1 { font-size: 1.8em; }
.reading-content h2 { font-size: 1.4em; }
.reading-content h3 { font-size: 1.2em; }
.reading-content p { margin: 1em 0; }
.reading-content img { max-width: 100%; height: auto; border-radius: 8px; margin: 1em 0; }
.reading-content a { color: var(--accent-primary); }
.reading-content blockquote {
    border-left: 3px solid var(--accent-primary);
    margin: 1em 0;
    padding: 0.5em 1em;
    background: var(--bg-secondary);
    border-radius: 0 6px 6px 0;
    font-style: italic;
    color: var(--text-secondary);
}
.reading-content pre,
.reading-content code {
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 0.85em;
    overflow-x: auto;
}
.reading-content code { padding: 2px 6px; }
.reading-content pre { padding: 16px; }
.reading-content pre code { padding: 0; background: none; }
.reading-content ul,
.reading-content ol { padding-left: 1.5em; margin: 1em 0; }
.reading-content li { margin: 0.3em 0; }
.reading-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: 0.9em;
}
.reading-content th,
.reading-content td {
    border: 1px solid var(--border-subtle);
    padding: 8px 12px;
    text-align: left;
}
.reading-content th { background: var(--bg-secondary); }
.reading-mode .reading-close svg { stroke: var(--text-secondary); }
.reading-mode .reading-close:hover svg { stroke: var(--text-primary); }

/* ============================================
   Sidebar - 默认隐藏，仅 .visible 时展开
   ============================================ */
.sidebar {
    position: relative;
    flex: 0 0 0px;
    width: 0;
    overflow: hidden;
    background: var(--bg-elevated);
    border-left: 0px;
    border-right: 0px;
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease, flex-basis 0.25s ease;
    will-change: width, flex-basis; /* 提前告知浏览器 */
}

.sidebar.visible {
    flex: 0 0 var(--sidebar-width, 300px);
    width: var(--sidebar-width, 300px);
    border-right: 1px solid var(--border-subtle);  /* ← 展开时才画边框 */
    overflow: visible;
}

/* 拖动时临时移除过渡，实现即时响应 */
.sidebar.resizing {
    transition: none !important;
    will-change: width;
}

/* ============================================
   Sidebar Resizer - 贴近右边缘
   ============================================ */
.sidebar-resizer {
    position: absolute;
    top: 0;
    right: -4px;
    width: 8px;
    height: 100%;
    cursor: ew-resize;
    background: transparent;
    z-index: 10;
    transition: background 0.15s ease;
}

.sidebar-resizer:hover,
.sidebar-resizer.dragging {
    background: var(--accent-primary);
}

.sidebar-resizer.visible {
    display: block;
}

/* ============================================
   Content Area (包装 Sidebar 和 WebAppGroup)
   ============================================ */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    position: relative;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.sidebar-header .icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-fast), color var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.sidebar-header .icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-header .icon-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

/* Sidebar toolbar (view tabs: bookmarks/history/downloads) */
.sidebar-toolbar {
    display: flex;
    padding: 8px 12px;
    gap: 4px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.sidebar-tab svg {
    width: 16px;
    height: 16px;
}

.sidebar-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-tab.active {
    background: rgba(255, 107, 53, 0.15);
    color: var(--accent-primary);
}

/* Search bar inside the sidebar */
.sidebar-search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-search-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-tertiary);
}

#sidebar-search-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    background: var(--bg-input, rgba(0,0,0,0.1));
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

#sidebar-search-input::placeholder {
    color: var(--text-tertiary);
}

#sidebar-search-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.12);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 4px;
    contain: content;
}

/* Sidebar items (bookmarks, history, downloads) */
.sidebar-item {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
    gap: 10px;
    min-height: 40px;
}

.sidebar-item:hover {
    background: var(--bg-hover);
}

.sidebar-item-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--accent-primary);
}

.sidebar-item-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
}

.sidebar-item-title {
    flex: 1;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.sidebar-item-time {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Sidebar item actions (edit, delete buttons) */
.sidebar-item-action {
    opacity: 0;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity var(--transition-base), background-color var(--transition-fast), color var(--transition-fast);
}

.sidebar-item:hover .sidebar-item-action {
    opacity: 1;
}

.sidebar-item-action:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-item-action[data-action="delete"]:hover,
.sidebar-item-action[data-action="delete-history"]:hover {
    color: var(--danger, #ef4444);
}

/* Downloads specific layout */
.sidebar-item-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.sidebar-item-meta {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-folder-header {
    display: flex;
    align-items: center;
    padding: 10px 14px 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0;
    margin-top: 6px;
}

.sidebar-folder-header:first-child {
    margin-top: 0;
}

/* Bookmarks tree menu (sidebar): collapsible folder branches. The
   toggle row flips aria-expanded (JS is the source of truth); children
   nest via inline padding-left per level, set at render time. */
.sidebar-tree-node { min-width: 0; }

.sidebar-tree-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-md, 8px);
    cursor: pointer;
    transition: background var(--transition-base);
    user-select: none;
}

.sidebar-tree-toggle:hover,
.sidebar-tree-toggle:focus,
.sidebar-tree-toggle.kb-active { background: var(--bg-hover); }

.sidebar-tree-toggle:focus { outline: none; }
.sidebar-tree-toggle:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: -2px; }

.sidebar-tree-caret {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    color: var(--text-tertiary);
    transition: transform var(--transition-base);
}

.sidebar-tree-toggle[aria-expanded="true"] .sidebar-tree-caret { transform: rotate(90deg); }

.sidebar-tree-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--accent-primary);
}

.sidebar-tree-name {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-transform: none;
    letter-spacing: 0;
}

.sidebar-tree-count {
    margin-left: auto;
    font-size: 11px;
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 999px;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Indented hierarchy: constant 18px per nesting level (same contract as
   the library tree's .tree-children) — nesting accumulates naturally,
   so deeper subfolders indent further. */
.sidebar-tree-children { padding-left: 18px; }

.bookmark-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
    gap: 12px;
}

.bookmark-item:hover {
    background: var(--bg-hover);
}

.bookmark-icon {
    font-size: 18px;
}

.bookmark-item span:last-child {
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   Context Menu
   Fluid width to match viewport state and orientation; on touch devices
   we lock hit targets to ≥44px so the context menu reads cleanly even
   when triggered by long-press.
   ============================================ */
.context-menu {
    position: fixed;
    /* Width follows the longest item in the menu but stays within sane
       bounds. The previous `clamp(180px, 22vw, 240px)` clipped English
       labels like "Open image in new tab" at viewports below ~860px
       (menu dropped to 180px and 134px of text didn't fit in the 126px
       label slot). max-content grows the menu to fit the longest
       item; min-width keeps it usable when items are short; max-width
       caps it so a single very long label can't push the menu past
       the viewport edge (the JS-side showContextMenu also clamps
       rect.right to viewport - 8px). */
    width: max-content;
    min-width: 200px;
    max-width: 360px;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
    border-radius: var(--border-radius-md);
    padding: 4px;
    display: none;
    z-index: 2000;
}

.context-menu.visible {
    display: block;
    animation: menuFadeIn 100ms ease forwards;
}

/* Thumb-friendly overrides on phone / portrait. */
@media (max-width: 768px),
       (orientation: portrait) and (max-width: 1024px) {
    .context-menu {
        /* On small screens the menu is constrained by viewport width
           rather than by content width. Use a generous clamp that
           matches the chrome (60vw) but stays under the viewport. */
        width: clamp(220px, 60vw, 320px);
        min-width: 0;
        max-width: none;
        border-radius: var(--border-radius-lg);
    }
    .context-item {
        padding: 10px 12px;
        min-height: 40px;
        font-size: 14px;
    }
    .context-item .context-icon { width: 16px; height: 16px; }
}

@media (max-width: 480px),
       (orientation: portrait) and (max-width: 640px) {
    .context-menu {
        width: min(80vw, 320px);
        min-width: 0;
        max-width: none;
    }
    .context-item {
        padding: 12px 14px;
        min-height: 44px;
        font-size: 15px;
    }
}

.context-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 6px 10px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.3;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    gap: 10px;
    transition: background-color var(--transition-fast);
}

.context-item .context-icon {
    flex: 0 0 14px;
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.context-item .context-icon svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.context-item .context-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.context-item:hover {
    background: var(--bg-hover);
}

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

.context-item.disabled,
.context-item[disabled] {
    color: var(--text-disabled, #888);
    cursor: not-allowed;
    opacity: 0.5;
}

.context-item.disabled:hover,
.context-item[disabled]:hover {
    background: transparent;
}

.context-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 4px 6px;
}

/* ============================================
   Content Area - Browser Container & WebAppGroup
   ============================================ */
.browser-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    contain: layout style;
}

my-webappgroup {
    flex: 1;
    display: block;
    position: relative;
    background: #fff;
    min-width: 0;
    contain: strict;
}

my-webappgroup iframe,
my-webappgroup webappview,
my-webappgroup webview {
    position: absolute;
    inset: 0;
    border: 0;
}

/* Loading placeholder shown over the webappgroup while a new tab is
   fetching/rendering its first document. Lives inside the custom element
   so positioning and stacking are scoped per-instance. */
my-webappgroup .webappgroup-loading-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 14px;
    background: var(--bg-primary, #0f0f12);
    z-index: 1;
    color: var(--text-secondary, #888);
    font-size: 14px;
}
my-webappgroup .webappgroup-loading-overlay[style*="flex"] {
    display: flex !important;
}
my-webappgroup .webappgroup-loading-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid var(--border-subtle, #333);
    border-top-color: var(--accent-primary, #4a9eff);
    animation: webappgroup-spin 0.9s linear infinite;
}
@keyframes webappgroup-spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Mobile Navigation - Premium Design
   ============================================ */
.mobile-nav {
    display: none;
    height: clamp(44px, 6vw, 54px);
    padding: 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
}

.mobile-url-bar {
    flex: 1;
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 clamp(8px, 1.5vw, 12px);
    gap: clamp(4px, 1vw, 8px);
}

.mobile-nav-btn {
    width: clamp(32px, 8vw, 40px);
    height: clamp(32px, 8vw, 40px);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius-sm);
    transition: 
        background var(--transition-fast),
        color var(--transition-base),
        transform var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.mobile-nav-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.08);
}

.mobile-nav-btn:disabled {
    opacity: 0.35;
}

.mobile-nav-btn svg {
    width: clamp(18px, 5vw, 24px);
    height: clamp(18px, 5vw, 24px);
}

.mobile-url-container {
    flex: 1;
    height: clamp(32px, 8vw, 40px);
    background: var(--gradient-surface);
    border-radius: calc(var(--border-radius-md) * 1.5);
    display: flex;
    align-items: center;
    padding: 0 clamp(10px, 2vw, 16px);
    gap: clamp(6px, 1vw, 10px);
    border: 1px solid var(--border-subtle);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
    transition: 
        border-color var(--transition-base),
        box-shadow var(--transition-base);
}

.mobile-url-container:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 
        inset 0 1px 2px rgba(0,0,0,0.2),
        0 0 0 1px var(--accent-primary),
        var(--shadow-glow);
}

.mobile-url-icon {
    font-size: clamp(12px, 3vw, 16px);
}

.mobile-url-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    caret-color: var(--accent-primary);
}

.mobile-url-input::placeholder {
    color: var(--text-tertiary);
}

.mobile-star-btn {
    width: clamp(32px, 8vw, 40px);
    height: clamp(32px, 8vw, 40px);
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius-sm);
    transition: 
        color var(--transition-base),
        transform var(--transition-base);
    -webkit-tap-highlight-color: transparent;
}

.mobile-star-btn:active {
    transform: scale(0.9);
}

.mobile-star-btn:hover {
    color: var(--accent-primary);
}

.mobile-star-btn.active {
    color: var(--accent-primary);
}

.mobile-star-btn.active svg {
    fill: var(--accent-primary);
}

.mobile-star-btn svg {
    width: clamp(16px, 4vw, 20px);
    height: clamp(16px, 4vw, 20px);
}

/* ============================================
   Mobile Bottom Bar - Premium Design
   ============================================ */
.mobile-bottom-bar {
    display: none;
    height: var(--mobile-toolbar);
    background: var(--gradient-surface);
    border-top: 1px solid var(--border-subtle);
    padding-bottom: env(safe-area-inset-bottom, 0);
    position: relative;
}

/* Subtle top highlight */
.mobile-bottom-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08) 50%, transparent);
}

.mobile-toolbar-btn {
    flex: 1;
    height: 100%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(2px, 0.5vh, 4px);
    transition: color var(--transition-base);
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.mobile-toolbar-btn:active {
    color: var(--accent-primary);
}

.mobile-toolbar-btn:active::after {
    content: '';
    position: absolute;
    inset: 20% 40%;
    background: var(--accent-primary);
    border-radius: 50%;
    opacity: 0.15;
    transform: scale(1.5);
}

.mobile-toolbar-btn svg {
    width: clamp(20px, 5vw, 26px);
    height: clamp(20px, 5vw, 26px);
}

.mobile-toolbar-btn span {
    font-size: clamp(9px, 2.2vw, 11px);
    font-weight: 500;
}

/* ============================================
   Mobile Tab Switcher
   ============================================ */
.tab-switcher {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 2000;
    display: none;
    flex-direction: column;
    contain: layout style;
}

.tab-switcher.visible {
    display: flex;
}

.tab-switcher-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 17px;
    font-weight: 600;
}

.done-btn {
    padding: 8px 20px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--transition-base), transform var(--transition-fast);
}

.done-btn:hover {
    background: var(--accent-secondary);
}

.done-btn:active {
    transform: scale(0.96);
}

.tab-grid {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    align-content: start;
    contain: content;
}

.tab-card {
    background: var(--bg-secondary);
    border-radius: 14px;
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
    aspect-ratio: 16/11;
    display: flex;
    flex-direction: column;
    position: relative;
    contain: layout style;
}

.tab-card:active {
    transform: scale(0.98);
}

.tab-card.active {
    box-shadow: 0 0 0 3px var(--accent-primary);
}

.tab-card-preview {
    flex: 1;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
}

.tab-card-info {
    padding: 10px 12px;
    background: var(--bg-secondary);
}

.tab-card-title {
    font-size: 12px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab-card-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.new-tab-btn {
    margin: 16px 20px;
    padding: 16px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: background-color var(--transition-base), transform var(--transition-fast);
}

.new-tab-btn:active {
    background: var(--accent-secondary);
    transform: scale(0.98);
}

.new-tab-btn svg {
    width: 20px;
    height: 20px;
}

/* ============================================
   Scrollbar - Thin & Subtle
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ============================================
   Responsive - Mobile-first composition
   ============================================ */

/* Mobile breakpoint: collapse desktop nav into mobile tab bar */
@media (max-width: 768px) {
    .desktop-nav { display: none !important; }
    .mobile-nav { display: flex; }
    .mobile-bottom-bar { display: flex; }
    .desktop-only { display: none !important; }

    .tab-bar {
        height: clamp(44px, 8vw, 52px);
        padding: 0 clamp(4px, 1vw, 8px);
    }

    .tab {
        min-width: clamp(80px, 25vw, 140px);
        max-width: clamp(120px, 35vw, 180px);
        height: clamp(34px, 7vw, 42px);
        padding: 0 clamp(6px, 2vw, 12px);
    }

    .tab-title {
        font-size: clamp(11px, 2.5vw, 13px);
    }

    .tab-icon {
        width: clamp(12px, 3vw, 16px);
        height: clamp(12px, 3vw, 16px);
    }

    .tab-close {
        width: clamp(14px, 4vw, 20px);
        height: clamp(14px, 4vw, 20px);
        font-size: clamp(10px, 3vw, 14px);
    }

    /* 移动端侧边栏全宽 */
    .sidebar.visible {
        flex: 0 0 100%;
        width: 100%;
    }

    .sidebar-toolbar {
        padding: 6px 8px;
        gap: 2px;
    }

    .sidebar-tab {
        padding: 8px 6px;
        font-size: 12px;
        gap: 4px;
    }

    .sidebar-tab svg {
        width: 14px;
        height: 14px;
    }

    .sidebar-search-bar {
        padding: 6px 8px;
    }

    .sidebar-search-icon {
        width: 14px;
        height: 14px;
    }

    #sidebar-search-input {
        padding: 6px 10px;
        font-size: 12px;
    }

    .menu-panel {
        left: clamp(4px, 2vw, 12px);
        right: clamp(4px, 2vw, 12px);
        width: auto;
        /* Below tab-bar + mobile nav row (the desktop-nav — and its
           hamburger — is hidden on mobile; the menu opens from the
           mobile-menu-tb-btn in the bottom bar). */
        top: clamp(52px, 10vw, 62px);
    }

    .context-menu {
        left: 50% !important;
        transform: translateX(-50%) !important;
        bottom: calc(var(--mobile-toolbar) + 8px);
        top: auto !important;
    }
}

/* High DPI (Retina) enhancements */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .nav-btn svg,
    .tab-add svg,
    .menu-btn svg,
    .mobile-nav-btn svg,
    .mobile-toolbar-btn svg {
        shape-rendering: geometricPrecision;
    }

    .url-bar,
    .mobile-url-container {
        border-width: 0.5px;
    }
}

/* Low DPI fallback */
@media (max-resolution: 96dpi) {
    .tab, .nav-btn, .url-bar {
        border-radius: 8px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .nav-btn,
    .tab-close,
    .tab-add,
    .menu-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .mobile-toolbar-btn {
        min-height: 60px;
    }
}

/* Desktop: switch which nav is visible. The 3-column grid handles every
   width from the moment we cross into this breakpoint. */
@media (min-width: 769px) {
    .desktop-nav { display: grid; }
    .mobile-nav { display: none !important; }
    .mobile-bottom-bar { display: none !important; }
    .desktop-only { display: flex; }
}

/* ============================================
   Toast
   Bottom-center transient feedback cards. Several may appear stacked if
   invoked in rapid succession. Auto-dismiss timer is per-toast.
   ============================================ */
.toast-container {
    position: fixed;
    left: 50%;
    bottom: clamp(16px, 3vh, 32px);
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
    z-index: 2500;
}

.toast {
    pointer-events: auto;
    background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-tertiary) 100%);
    color: var(--text-primary);
    font-size: 13.5px;
    line-height: 1.4;
    padding: 10px 16px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-lg);
    max-width: min(560px, 92vw);
    text-align: center;
    animation: toastSlideUp 180ms cubic-bezier(.22,1,.36,1) forwards;
    white-space: pre-wrap;
}

.toast.leaving {
    animation: toastFadeOut 180ms ease forwards;
}

.toast.success {
    border-color: rgba(76, 200, 128, 0.5);
    box-shadow: var(--shadow-lg), 0 0 18px rgba(76, 200, 128, 0.25);
}
.toast.error {
    border-color: rgba(255, 95, 95, 0.5);
    box-shadow: var(--shadow-lg), 0 0 18px rgba(255, 95, 95, 0.25);
}
.toast.info {
    border-color: var(--border-subtle);
}

@keyframes toastSlideUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastFadeOut {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(8px); }
}

/* ============================================================
   Virtual Mouse (TV/Box devices)
   ============================================================
   The cursor itself is a 28×28 dot rendered as a radial gradient.
   The needle/edge is a triangular wedge built from clip-path so it
   inherits color from --accent-primary and doesn't rely on an SVG.
   The .vm-ring is a halo that pulses when the user dwells long
   enough over a target, signalling "press OK to click".
   ============================================================ */
.virtual-mouse {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin-left: -16px;
    margin-top: -16px;
    z-index: 99999;
    pointer-events: none;
    transition: top 100ms cubic-bezier(.22,1,.36,1),
                left 100ms cubic-bezier(.22,1,.36,1);
    will-change: top, left;
    /* host is a stacking context so its children inherit the position */
}
.virtual-mouse[hidden] { display: none; }

.vm-cursor {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 35% 30%, #fff 0 18%, transparent 19%),
        conic-gradient(from 220deg at 22% 22%,
            var(--accent-primary) 0 8deg, transparent 8deg 32deg,
            transparent 32deg 360deg);
    /* Render the cursor as a PwaOS-orange ring with a white dot */
    border-radius: 50%;
    box-shadow:
        0 0 0 2px rgba(255,255,255,0.85),
        0 4px 14px rgba(0,0,0,0.4);
    /* The white-center dot is faked by masking the background. We use a
       radial gradient with a transparent ring instead. */
}

.vm-cursor::after {
    /* Replace the orange radial with a clean design using two
       layered shapes. */
    display: none;
}

.vm-ring {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--accent-primary);
    opacity: 0;
    transform: scale(0.85);
    transition: opacity var(--transition-slow), transform var(--transition-slow);
    pointer-events: none;
}
.virtual-mouse.dwelling .vm-ring {
    opacity: 0.85;
    transform: scale(1.05);
}

.virtual-mouse.dragging .vm-cursor {
    box-shadow:
        0 0 0 2px rgba(255,255,255,0.95),
        0 0 12px 2px var(--accent-primary),
        0 6px 18px rgba(0,0,0,0.55);
}
.virtual-mouse.dragging .vm-label {
    transform: translate(-50%, 6px) scale(1);
    opacity: 1;
}

.vm-label {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translate(-50%, 0) scale(0.6);
    transform-origin: top center;
    background: var(--bg-elevated);
    color: var(--text-primary);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    margin-top: 8px;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
    transition: opacity var(--transition-base), transform var(--transition-base);
}
.virtual-mouse:not(.dragging) .vm-label { opacity: 0; }

/* ============================================================
   Settings Panel
   ============================================================ */
.settings-panel {
    position: fixed;
    top: clamp(56px, 8vh, 76px);
    right: clamp(12px, 2vw, 24px);
    width: clamp(320px, 32vw, 420px);
    max-height: calc(100vh - 120px);
    background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 950;
    animation: panelFadeIn 180ms cubic-bezier(.22,1,.36,1) forwards;
    overflow: hidden;
}
.settings-panel[hidden] { display: none; }

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}
.settings-header h3 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.2px;
}
.settings-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-base), color var(--transition-base);
}
.settings-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px 16px;
}

.settings-section {
    padding: 8px 0 4px;
}
.settings-section-title {
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-tertiary);
    padding: 12px 8px 6px;
}
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color var(--transition-base);
}
.settings-row:hover { background: var(--bg-hover); }
.settings-row-info { flex: 1; min-width: 0; }
.settings-row-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.settings-row-desc {
    font-size: 12px;
    color: var(--text-tertiary);
    line-height: 1.45;
}

/* Toggle switch */
.settings-toggle {
    position: relative;
    width: 40px;
    height: 22px;
    border-radius: 999px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    flex-shrink: 0;
    transition: background-color var(--transition-base);
    cursor: pointer;
    padding: 0;
}
.settings-toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: transform 150ms cubic-bezier(.22,1,.36,1),
                background-color 150ms ease;
}
.settings-toggle.on { background: var(--accent-primary); border-color: transparent; }
.settings-toggle.on::after {
    transform: translateX(18px);
    background: #fff;
}

/* Select (theme picker uses a 3-up pill group) */
.settings-pills {
    display: inline-flex;
    background: var(--bg-tertiary);
    border-radius: 999px;
    padding: 2px;
    gap: 2px;
    flex-shrink: 0;
}
.settings-pill {
    padding: 5px 12px;
    border-radius: 999px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--transition-base), color var(--transition-base);
    white-space: nowrap;
}
.settings-pill:hover { color: var(--text-primary); }
.settings-pill.active {
    background: var(--accent-primary);
    color: #fff;
}

/* Buttons row (e.g. clear-history / re-run tour) */
.settings-button {
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color var(--transition-base), border-color var(--transition-base);
}
.settings-button:hover {
    background: var(--bg-hover);
    border-color: rgba(255,255,255,0.18);
}
.settings-button.danger { color: #ff7a7a; border-color: rgba(255,122,122,0.3); }
.settings-button.danger:hover {
    background: rgba(255,122,122,0.1);
    border-color: rgba(255,122,122,0.55);
}

/* Dropdown for language picker */
.settings-select {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    min-width: 140px;
    flex-shrink: 0;
}
.settings-select:hover { border-color: rgba(255,255,255,0.18); }
.settings-select:focus { outline: none; border-color: var(--accent-primary); }

.settings-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    color: var(--text-tertiary);
    text-align: center;
    flex-shrink: 0;
}
.settings-footer small { font-size: 11px; letter-spacing: 0.2px; }

@keyframes panelFadeIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   First-run Onboarding
   ============================================================
   The overlay uses a transparent backdrop so the user can still see
   the chrome and learn by example. The card is centered. Steps
   animate with a soft cross-fade; the previous/next buttons move
   the dialog along an implicit journey.
   ============================================================ */
.first-run-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.first-run-overlay[hidden] { display: none; }

.first-run-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 8, 12, 0.55);
    backdrop-filter: blur(8px);
    /* Don't block the user from interacting with the chrome while they
       read the first-run card. The backdrop has pointer-events: none so
       the settings/library still respond. */
    pointer-events: none;
    animation: firstRunFadeIn 220ms ease forwards;
}

.first-run-card {
    position: relative;
    width: min(440px, 92vw);
    background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg), 0 0 60px rgba(255, 107, 53, 0.15);
    padding: 24px;
    pointer-events: auto;
    animation: firstRunCardIn 280ms cubic-bezier(.22,1,.36,1) forwards;
}

.first-run-progress {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    font-size: 11px;
    color: var(--text-tertiary);
    letter-spacing: 1px;
    text-transform: uppercase;
}
.first-run-step-indicator {
    font-weight: 700;
    color: var(--accent-primary);
}
.first-run-skip {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background-color var(--transition-base), color var(--transition-base);
}
.first-run-skip:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.first-run-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.4px;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.first-run-body {
    font-size: 15px;
    line-height: 1.55;
    color: var(--text-secondary);
    margin-bottom: 18px;
}

.first-run-visual {
    width: 84px;
    height: 84px;
    margin: 6px auto 22px;
    background: rgba(255, 107, 53, 0.12);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    border: 1px solid rgba(255, 107, 53, 0.3);
}
.first-run-glyph {
    line-height: 1;
}

.first-run-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.first-run-prev,
.first-run-next {
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--transition-base), transform var(--transition-base);
}
.first-run-prev {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}
.first-run-prev:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.first-run-prev:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.first-run-next {
    background: var(--accent-primary);
    color: #fff;
    box-shadow: 0 4px 16px rgba(255, 107, 53, 0.3);
    margin-left: auto;
}
.first-run-next:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 22px rgba(255, 107, 53, 0.4);
}
.first-run-next:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

@keyframes firstRunFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes firstRunCardIn {
    from { opacity: 0; transform: translateY(10px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Compact first-run card on narrow viewports */
@media (max-width: 480px) {
    .first-run-card { padding: 20px; }
    .first-run-title { font-size: 18px; }
    .first-run-body { font-size: 14px; }
}

/* TV-specific tweak: enlarge virtual mouse hit feedback because the
   cursor is the only way a TV user can read state, so dwell noises
   need a slightly bigger glow.
   ============================================================ */
@media (pointer: coarse) and (hover: none) {
    .virtual-mouse .vm-cursor { box-shadow: 0 0 0 2px #fff, 0 0 12px 2px var(--accent-primary), 0 4px 14px rgba(0,0,0,0.4); }
    .virtual-mouse.dwelling .vm-cursor { transform: scale(1.15); }
}

/* ============================================
   Performance: prefers-reduced-motion
   Respect OS-level animation preference for
   accessibility + battery savings.
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================
   Performance: backdrop-filter fallback
   When the browser doesn't support backdrop-filter,
   use a more opaque background so glass surfaces
   are still readable without the blur.
   ============================================ */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .find-bar { background: var(--bg-secondary); }
    .first-run-backdrop { background: rgba(8, 8, 12, 0.85); }
    .tab-card-close { background: rgba(0, 0, 0, 0.9); }
}


/* ============================================
   Zoom cluster (Chrome/Edge-style) — right end of the URL bar.
   Hidden at 100% like modern browsers: appears only when the tab
   is zoomed (Ctrl+= / Ctrl+- / Ctrl+wheel). Percent pill = click
   to reset to 100%. Hidden on mobile (mobile-nav has its own bar).
   ============================================ */
.zoom-cluster {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    padding: 1px;
    gap: 1px;
    box-shadow: var(--shadow-sm);
}
.zoom-cluster[hidden] { display: none; }
.zoom-pill {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-weight: 550;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    height: 24px;
    min-width: 24px;
    padding: 0 6px;
    border-radius: 999px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.zoom-pill:hover { background: var(--bg-hover); }
.zoom-pill:active { transform: scale(0.92); }
.zoom-pill:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 1px;
}
.zoom-pct { min-width: 40px; }
@media (max-width: 767px) {
    .zoom-cluster { display: none; }
}
