/* ============================================================================
   World Builder Agent - Premium Minimal Design
   Inspired by Linear, Vercel, and Figma aesthetics
   Supports light/dark mode with system preference detection
   ============================================================================ */

/* ============================================================================
   Design Tokens - Light Mode (Default)
   ============================================================================ */

:root {
    /* Clean, minimal light palette with refined accents */
    --bg-canvas: #fafafa;
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #ebebeb;
    --bg-elevated: #ffffff;

    /* Text hierarchy */
    --text-primary: #0a0a0a;
    --text-secondary: #525252;
    --text-tertiary: #a3a3a3;

    /* Accent colors - consistent across themes */
    --accent-primary: #0a0a0a;
    --accent-blue: #2563eb;
    --accent-violet: #7c3aed;
    --accent-emerald: #059669;
    --accent-amber: #d97706;
    --accent-rose: #e11d48;

    /* Borders */
    --border-subtle: #e5e5e5;
    --border-default: #d4d4d4;
    --border-strong: #a3a3a3;

    /* Canvas-specific colors (used by JS) */
    --canvas-grid: #e5e5e5;
    --canvas-hover: rgba(37, 99, 235, 0.15);
    --canvas-empty: #fafafa;
    --canvas-text: #0a0a0a;
    --canvas-text-inverse: #ffffff;
    --canvas-user-tile: rgba(37, 99, 235, 0.12);
    --canvas-auto-tile: rgba(5, 150, 105, 0.12);
    --canvas-undo-tile: rgba(217, 119, 6, 0.15);
    --canvas-skeleton: #e8e8e8;
    --canvas-skeleton-dim: #f0f0f0;
    --canvas-label-bg: rgba(10, 10, 10, 0.85);

    /* Subtle overlays - adapt to theme */
    --overlay-subtle: rgba(0, 0, 0, 0.02);
    --overlay-light: rgba(0, 0, 0, 0.04);
    --overlay-medium: rgba(0, 0, 0, 0.06);

    /* Spacing scale (8px base) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;

    /* Border radius - base values for squircle generation */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-2xl: 28px;
    --radius-full: 9999px;

    /* Squircle smoothing factor (0-1, where 1 = maximum iOS-style smoothing) */
    --corner-smoothing: 1;

    /* Premium multi-layer shadows - Light mode */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.03);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.06), 0 4px 6px rgba(0,0,0,0.03);
    --shadow-xl: 0 20px 25px rgba(0,0,0,0.08), 0 10px 10px rgba(0,0,0,0.02);

    /* Focus ring */
    --ring-offset: 2px;
    --ring-width: 2px;
    --ring-color: var(--accent-blue);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

    /* Animation timing - smooth, natural motion */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    --duration-fast: 180ms;
    --duration-normal: 280ms;
    --duration-slow: 400ms;

    /* Color scheme indicator */
    color-scheme: light dark;
}

/* ============================================================================
   Design Tokens - Dark Mode
   ============================================================================ */

@media (prefers-color-scheme: dark) {
    :root {
        /* Premium dark palette */
        --bg-canvas: #0a0a0a;
        --bg-primary: #141414;
        --bg-secondary: #1a1a1a;
        --bg-tertiary: #262626;
        --bg-elevated: #1a1a1a;

        /* Text hierarchy - inverted */
        --text-primary: #fafafa;
        --text-secondary: #a3a3a3;
        --text-tertiary: #737373;

        /* Accent colors - slightly brighter for dark mode */
        --accent-primary: #fafafa;
        --accent-blue: #3b82f6;
        --accent-violet: #8b5cf6;
        --accent-emerald: #10b981;
        --accent-amber: #f59e0b;
        --accent-rose: #f43f5e;

        /* Borders - darker */
        --border-subtle: #262626;
        --border-default: #404040;
        --border-strong: #525252;

        /* Canvas-specific colors (used by JS) */
        --canvas-grid: #262626;
        --canvas-hover: rgba(59, 130, 246, 0.25);
        --canvas-empty: #0a0a0a;
        --canvas-text: #fafafa;
        --canvas-text-inverse: #0a0a0a;
        --canvas-user-tile: rgba(59, 130, 246, 0.2);
        --canvas-auto-tile: rgba(16, 185, 129, 0.2);
        --canvas-undo-tile: rgba(245, 158, 11, 0.25);
        --canvas-skeleton: #262626;
        --canvas-skeleton-dim: #1a1a1a;
        --canvas-label-bg: rgba(0, 0, 0, 0.85);

        /* Subtle overlays - white for dark theme */
        --overlay-subtle: rgba(255, 255, 255, 0.03);
        --overlay-light: rgba(255, 255, 255, 0.05);
        --overlay-medium: rgba(255, 255, 255, 0.08);

        /* Premium multi-layer shadows - Dark mode (more pronounced) */
        --shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
        --shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
        --shadow-md: 0 4px 6px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.15);
        --shadow-lg: 0 10px 15px rgba(0,0,0,0.3), 0 4px 6px rgba(0,0,0,0.15);
        --shadow-xl: 0 20px 25px rgba(0,0,0,0.4), 0 10px 10px rgba(0,0,0,0.1);
    }
}

/* ============================================================================
   Squircle (iOS-style Superellipse Corners)
   True continuous curvature using SVG masks

   The superellipse (Lamé curve): |x/a|^n + |y/b|^n = 1
   iOS uses n ≈ 4-5 for that signature smooth corner blend
   We approximate this with cubic bezier curves in SVG paths
   ============================================================================ */

/*
 * Squircle SVG masks - these create TRUE superellipse corners
 * The magic number 0.552284749831 is the bezier control point offset
 * for approximating a circle, but we use ~0.8 for squircle effect
 */

:root {
    /*
     * =========================================================================
     * SQUIRCLE MASK SYSTEM
     * =========================================================================
     *
     * iOS-style superellipse corners using SVG masks.
     * The superellipse formula: |x/a|^n + |y/b|^n = 1, where n ≈ 4-5 for iOS
     *
     * KEY MATH INSIGHT:
     * -----------------
     * With preserveAspectRatio='none', corners stretch proportionally to the
     * element's dimensions. A corner defined as C% in a viewBox becomes:
     *   - X-radius = C% × element_width
     *   - Y-radius = C% × element_height
     *
     * This works perfectly for SQUARE elements (1:1 aspect ratio).
     * For variable-width elements, we must choose C% based on the EXPECTED
     * aspect ratio to avoid over-rounding narrow instances.
     *
     * FORMULA FOR CHOOSING CORNER %:
     * ------------------------------
     * target_corner_px = desired visual corner radius in pixels
     * expected_height = typical element height in pixels
     * corner_percent = (target_corner_px / expected_height) × 100
     *
     * Example: For 12px corners on a 44px tall element:
     *   corner_percent = (12 / 44) × 100 = 27%
     *
     * But we must also consider the narrowest expected width to avoid
     * corners that exceed available space:
     *   max_safe_percent = (min_width / 2) / expected_height × 100
     *
     * For a message that could be 60px wide × 44px tall:
     *   max_safe = (30 / 44) × 100 = 68% (corners can't exceed half width)
     *
     * =========================================================================
     */

    /* Squircle smoothing factor (0.55 = circular, 0.85+ = iOS squircle) */
    --sq-smooth: 0.85;

    /*
     * SQUARE SQUIRCLE MASKS (aspect ratio ≈ 1:1)
     * Use for: icons, square buttons, thumbnails, avatars
     * viewBox: 100×100
     */

    /* r = 12% - subtle rounding */
    --squircle-sm: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M 12,0 L 88,0 C 92,0 96,0.5 98,2 C 99.5,4 100,8 100,12 L 100,88 C 100,92 99.5,96 98,98 C 96,99.5 92,100 88,100 L 12,100 C 8,100 4,99.5 2,98 C 0.5,96 0,92 0,88 L 0,12 C 0,8 0.5,4 2,2 C 4,0.5 8,0 12,0 Z' fill='black'/%3E%3C/svg%3E");

    /* r = 16% - moderate rounding */
    --squircle-md: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M 16,0 L 84,0 C 89,0 94,1 97,3 C 99,6 100,11 100,16 L 100,84 C 100,89 99,94 97,97 C 94,99 89,100 84,100 L 16,100 C 11,100 6,99 3,97 C 1,94 0,89 0,84 L 0,16 C 0,11 1,6 3,3 C 6,1 11,0 16,0 Z' fill='black'/%3E%3C/svg%3E");

    /* r = 20% - pronounced rounding */
    --squircle-lg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M 20,0 L 80,0 C 86,0 92,1.5 96,4 C 98.5,8 100,14 100,20 L 100,80 C 100,86 98.5,92 96,96 C 92,98.5 86,100 80,100 L 20,100 C 14,100 8,98.5 4,96 C 1.5,92 0,86 0,80 L 0,20 C 0,14 1.5,8 4,4 C 8,1.5 14,0 20,0 Z' fill='black'/%3E%3C/svg%3E");

    /* r = 24% - very rounded */
    --squircle-xl: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M 24,0 L 76,0 C 83,0 90,2 94,6 C 98,10 100,17 100,24 L 100,76 C 100,83 98,90 94,94 C 90,98 83,100 76,100 L 24,100 C 17,100 10,98 6,94 C 2,90 0,83 0,76 L 0,24 C 0,17 2,10 6,6 C 10,2 17,0 24,0 Z' fill='black'/%3E%3C/svg%3E");

    /* r = 28% - modal-style heavy rounding */
    --squircle-2xl: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M 28,0 L 72,0 C 80,0 88,2.5 92,7 C 97.5,12 100,20 100,28 L 100,72 C 100,80 97.5,88 92,93 C 88,97.5 80,100 72,100 L 28,100 C 20,100 12,97.5 8,93 C 2.5,88 0,80 0,72 L 0,28 C 0,20 2.5,12 8,7 C 12,2.5 20,0 28,0 Z' fill='black'/%3E%3C/svg%3E");

    /*
     * WIDE ELEMENT MASKS (aspect ratio ≈ 3:1 to 8:1)
     * Use for: buttons, form inputs, dropdowns
     * Expected dimensions: ~120-300px wide × 36-44px tall
     * viewBox: 400×100 (4:1 ratio as baseline)
     *
     * COMPENSATION: For a 200×40 element mapped to 400×100 viewBox:
     *   X scale = 0.5, Y scale = 0.4, ratio = 1.25
     * We make Y corner values ~1.25× larger than X to compensate.
     */

    /* 6% X / 8% Y corner - for very wide inputs (text fields, search bars) */
    --squircle-wide-xs: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 100' preserveAspectRatio='none'><path d='M6 0h388c2.5 0 4 1.5 5 3.5s1 4.5 1 4.5v84c0 0 0 2.5-1 4.5s-2.5 3.5-5 3.5H6c-2.5 0-4-1.5-5-3.5S0 92 0 92V8c0 0 0-2.5 1-4.5S3.5 0 6 0z' fill='black'/></svg>");

    /* 10% X / 13% Y corner - for form inputs, selects */
    --squircle-wide-sm: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 100' preserveAspectRatio='none'><path d='M10 0h380c4 0 6.5 2 8 5s2 7 2 8v74c0 1 0 5-2 8s-4 5-8 5H10c-4 0-6.5-2-8-5s-2-7-2-8V13c0-1 0-5 2-8s4-5 8-5z' fill='black'/></svg>");

    /* 14% X / 18% Y corner - for buttons, pills */
    --squircle-wide-md: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 100' preserveAspectRatio='none'><path d='M14 0h372c5 0 8.5 2.5 10.5 6.5s3.5 9 3.5 11.5v64c0 2.5-1.5 7.5-3.5 11.5s-5.5 6.5-10.5 6.5H14c-5 0-8.5-2.5-10.5-6.5S0 84.5 0 82V18c0-2.5 1.5-7.5 3.5-11.5S9 0 14 0z' fill='black'/></svg>");

    /*
     * CHAT MESSAGE MASKS (aspect ratio varies: 1.5:1 to 7:1)
     * Use for: chat bubbles, notifications, toasts
     * Expected: 60-340px wide × 44-120px tall
     *
     * COMPENSATION FOR NON-UNIFORM SCALING:
     * -------------------------------------
     * When a 300×100 viewBox maps to a 180×44 element:
     *   X scale = 0.6, Y scale = 0.44, ratio = 1.36
     *
     * To make corners appear equally smooth in both directions,
     * we pre-compensate by making Y corner values ~1.4× larger than X values.
     * This way, after the Y dimension compresses more, both appear equal.
     *
     * Formula: Y_svg = X_svg × (typical_X_scale / typical_Y_scale)
     * For X=10, Y = 10 × 1.4 = 14 (in the path definition)
     */

    /* 10% X / 14% Y corner - subtle, safe for narrow messages */
    --squircle-msg-sm: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 100' preserveAspectRatio='none'><path d='M10 0h280c4 0 7 2 8.5 5s1.5 7 1.5 9v72c0 2 0 6-1.5 9s-4.5 5-8.5 5H10c-4 0-7-2-8.5-5S0 88 0 86V14c0-2 0-6 1.5-9S6 0 10 0z' fill='black'/></svg>");

    /* 12% X / 17% Y corner - balanced, default for messages */
    --squircle-msg-md: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 100' preserveAspectRatio='none'><path d='M12 0h276c5 0 8 2.5 10 6s2 8 2 11v66c0 3 0 7.5-2 11s-5 6-10 6H12c-5 0-8-2.5-10-6s-2-8-2-11V17c0-3 0-7.5 2-11s5-6 10-6z' fill='black'/></svg>");

    /* 15% X / 21% Y corner - rounder, for emphasis */
    --squircle-msg-lg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 100' preserveAspectRatio='none'><path d='M15 0h270c6 0 10 3 12.5 7.5s2.5 10 2.5 13.5v58c0 3.5 0 9-2.5 13.5S291 100 285 100H15c-6 0-10-3-12.5-7.5S0 82.5 0 79V21c0-3.5 0-9 2.5-13.5S9 0 15 0z' fill='black'/></svg>");

    /*
     * MODAL MASKS (aspect ratio ≈ 1.2:1 to 1.6:1)
     * Use for: dialogs, popovers, sheets
     * Expected: 400-900px wide × 300-700px tall
     * viewBox: 140×100 (1.4:1 baseline - closer to typical modal proportions)
     *
     * COMPENSATION (opposite of messages!):
     * Modals are often taller than baseline, so Y scales MORE than X.
     * To compensate, we make X corners larger: X = Y × 1.2
     *
     * Example: 600×500 modal (1.2:1) with 140×100 viewBox (1.4:1):
     *   X scale = 4.29, Y scale = 5.0, ratio = 0.86
     *   X compresses less, so we pre-enlarge X in SVG
     */

    /* 20% X / 16% Y corner - standard modal rounding */
    --squircle-modal-md: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 140 100' preserveAspectRatio='none'><path d='M20 0h100c7 0 12 2 15 5.5s5 8 5 10.5v68c0 2.5-2 7-5 10.5s-8 5.5-15 5.5H20c-7 0-12-2-15-5.5S0 86.5 0 84V16c0-2.5 2-7 5-10.5S13 0 20 0z' fill='black'/></svg>");

    /* 24% X / 20% Y corner - larger modal rounding (dialogs, confirms) */
    --squircle-modal-lg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 140 100' preserveAspectRatio='none'><path d='M24 0h92c8 0 14 2.5 17.5 7s5.5 10 5.5 13v60c0 3-2 8.5-5.5 13s-9.5 7-17.5 7H24c-8 0-14-2.5-17.5-7S0 83 0 80V20c0-3 2-8.5 5.5-13S16 0 24 0z' fill='black'/></svg>");

    /*
     * LEGACY PILL MASKS (deprecated - use wide-* or msg-* instead)
     * Kept for backwards compatibility
     */
    --squircle-pill-xs: var(--squircle-wide-xs);
    --squircle-pill-sm: var(--squircle-wide-sm);
    --squircle-pill-md: var(--squircle-wide-md);
    --squircle-pill-lg: var(--squircle-msg-lg);
}

/*
 * SQUIRCLE SAFETY VALVES
 * ----------------------
 * Fallback classes for edge cases where aspect ratio deviates significantly
 * from expected values, causing visible corner asymmetry.
 *
 * Use cases:
 * - .squircle-compact: Near-square elements (aspect ratio < 1.5:1)
 * - .squircle-fallback: Complete fallback to border-radius (any ratio)
 */

/* For near-square elements - uses symmetric square mask */
.squircle-compact {
    -webkit-mask-image: var(--squircle-md) !important;
    mask-image: var(--squircle-md) !important;
}

/* Complete fallback - removes mask, uses border-radius */
.squircle-fallback {
    -webkit-mask-image: none !important;
    mask-image: none !important;
    border-radius: var(--radius-lg) !important;
}

/* Squircle utility classes - apply true superellipse corners */
.squircle-sm {
    -webkit-mask-image: var(--squircle-sm);
    mask-image: var(--squircle-sm);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

.squircle-md {
    -webkit-mask-image: var(--squircle-md);
    mask-image: var(--squircle-md);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

.squircle-lg {
    -webkit-mask-image: var(--squircle-lg);
    mask-image: var(--squircle-lg);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

.squircle-xl {
    -webkit-mask-image: var(--squircle-xl);
    mask-image: var(--squircle-xl);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

.squircle-2xl {
    -webkit-mask-image: var(--squircle-2xl);
    mask-image: var(--squircle-2xl);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

/*
 * Squircle border technique:
 * Since mask-image clips CSS borders, we use a pseudo-element approach
 * for true squircle borders that follow the mask curve perfectly.
 *
 * Method: ::before pseudo-element extends beyond the main element by
 * the border width, has the same mask, and shows the border color.
 * The main element's background covers the center, revealing the border edge.
 */

/* Base squircle border setup - add to elements that need borders */
.squircle-border {
    position: relative;
    border: none !important;
}

.squircle-border::before {
    content: '';
    position: absolute;
    inset: -1px; /* Extend by border width */
    background: var(--border-default);
    -webkit-mask-image: inherit;
    mask-image: inherit;
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    z-index: -1;
    pointer-events: none;
}

.squircle-border-subtle::before {
    background: var(--border-subtle);
}

.squircle-border-strong::before {
    background: var(--border-strong);
}

/*
 * For elements that need shadow with squircle shape,
 * use filter: drop-shadow() which respects the mask
 */
.squircle-shadow {
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.07)) drop-shadow(0 2px 4px rgba(0,0,0,0.05));
}

.squircle-shadow-lg {
    filter: drop-shadow(0 10px 15px rgba(0,0,0,0.1)) drop-shadow(0 4px 6px rgba(0,0,0,0.05));
}

/*
 * Inset border utilities for dynamic squircles
 * Uses box-shadow which gets clipped by the mask, creating perfect squircle borders
 */
.squircle-inset-border {
    box-shadow: inset 0 0 0 1px var(--border-default);
}

.squircle-inset-border-subtle {
    box-shadow: inset 0 0 0 1px var(--border-subtle);
}

.squircle-inset-border-strong {
    box-shadow: inset 0 0 0 1px var(--border-strong);
}

/* Combined shadow + border utilities */
.squircle-inset-border-with-shadow {
    box-shadow:
        inset 0 0 0 1px var(--border-subtle),
        0 4px 6px rgba(0,0,0,0.07),
        0 2px 4px rgba(0,0,0,0.05);
}

.squircle-inset-border-with-shadow-lg {
    box-shadow:
        inset 0 0 0 1px var(--border-subtle),
        0 10px 15px rgba(0,0,0,0.1),
        0 4px 6px rgba(0,0,0,0.05);
}

/* ============================================================================
   Reset & Base Styles
   ============================================================================ */

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

html {
    height: 100%;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-canvas);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    height: 100%;
    position: relative;
}

/* Subtle gradient accent overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        125deg,
        rgba(254, 255, 0, 0.07) 0%,
        rgba(47, 254, 113, 0.05) 50%,
        rgba(255, 135, 249, 0.07) 100%
    );
    pointer-events: none;
    z-index: 0;
}

/* Reduce gradient intensity in dark mode */
@media (prefers-color-scheme: dark) {
    body::before {
        background: linear-gradient(
            135deg,
            rgba(254, 255, 0, 0.04) 0%,
            rgba(47, 254, 113, 0.03) 50%,
            rgba(255, 135, 249, 0.04) 100%
        );
    }
}

/* ============================================================================
   Animations - Smooth, natural motion
   ============================================================================ */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Message entry - slides in from side with fade */
@keyframes messageSlideInLeft {
    from {
        opacity: 0;
        transform: translateX(-16px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes messageSlideInRight {
    from {
        opacity: 0;
        transform: translateX(16px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Dropdown expand - smooth height reveal */
@keyframes expandDown {
    from {
        opacity: 0;
        transform: translateY(-8px) scaleY(0.95);
        transform-origin: top center;
    }
    to {
        opacity: 1;
        transform: translateY(0) scaleY(1);
        transform-origin: top center;
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Modal pop - slight bounce */
@keyframes modalPop {
    0% {
        opacity: 0;
        transform: scale(0.9);
    }
    70% {
        opacity: 1;
        transform: scale(1.02);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes pulseSoft {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

@keyframes dotPulse {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-3px); }
    40% { transform: translateX(3px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

@keyframes shimmer-text {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes dot-pulse {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.9); }
    30% { opacity: 1; transform: scale(1); }
}

/* ============================================================================
   App Layout
   ============================================================================ */

.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    animation: fadeIn var(--duration-normal) var(--ease-out);
    position: relative;
    z-index: 1;
}

.hidden {
    display: none !important;
}

/* ============================================================================
   Header
   ============================================================================ */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-5);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-subtle);
    min-height: 56px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.header-logo {
    color: var(--text-primary);
}

.header h1 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    gap: var(--space-3);
    align-items: center;
}

/* ============================================================================
   Buttons - True iOS-style superellipse corners via SVG mask
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: none;
    /* Wide element mask with moderate corners for buttons */
    -webkit-mask-image: var(--squircle-wide-md);
    mask-image: var(--squircle-wide-md);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    /* Fallback */
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    white-space: nowrap;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 var(--ring-offset) var(--bg-primary),
                0 0 0 calc(var(--ring-offset) + var(--ring-width)) var(--ring-color);
}

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

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

/* Primary Button - Uses accent color */
.btn-primary {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--text-secondary);
}

/* Ghost Button - Transparent with border on hover */
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Secondary Button */
.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--border-default);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
    box-shadow: inset 0 0 0 1px var(--border-strong);
}

/* Small Button */
.btn-small {
    padding: var(--space-1) var(--space-2);
    font-size: 0.75rem;
    background: var(--bg-secondary);
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--border-subtle);
    color: var(--text-secondary);
}

.btn-small:hover:not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    box-shadow: inset 0 0 0 1px var(--border-default);
}

/* Danger Button */
.btn-danger {
    background: var(--accent-rose);
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--accent-rose);
    color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
    background: #be123c;
    box-shadow: inset 0 0 0 1px #be123c;
}

/* Icon Button */
.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
}

.btn-danger-subtle {
    background: transparent;
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--border-default);
    color: var(--text-secondary);
}

.btn-danger-subtle:hover:not(:disabled) {
    background: var(--accent-rose);
    box-shadow: inset 0 0 0 1px var(--accent-rose);
    color: #ffffff;
}

.btn-danger-subtle:disabled {
    opacity: 0.3;
}

.btn-danger-subtle.confirm-delete {
    background: var(--accent-rose);
    box-shadow: inset 0 0 0 1px var(--accent-rose);
    color: #ffffff;
    animation: pulse 0.5s ease-in-out infinite alternate;
}

/* Copy Link Button Success State */
#copy-link-btn.success {
    background: var(--accent-emerald);
    box-shadow: inset 0 0 0 1px var(--accent-emerald);
    color: #ffffff;
}

#copy-link-btn.success:hover {
    background: var(--accent-emerald);
}

/* Button Group */
.btn-group {
    display: flex;
    gap: 0;
}

.btn-group .btn {
    border-radius: 0;
}

.btn-group .btn:first-child {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.btn-group .btn:last-child {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.btn-group .btn:not(:first-child) {
    margin-left: -1px;
}

/* ============================================================================
   Select / Dropdowns
   ============================================================================ */

.select-wrapper {
    position: relative;
    display: inline-flex;
}

.select-wrapper-full {
    width: 100%;
}

.session-select,
.settings-input[type="text"],
select.settings-input {
    appearance: none;
    position: relative;
    padding: var(--space-2) var(--space-4);
    padding-right: var(--space-6);
    background: var(--bg-primary);
    /* Wide element mask for dropdowns/selects */
    -webkit-mask-image: var(--squircle-wide-xs);
    mask-image: var(--squircle-wide-xs);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--border-default);
    /* Fallback */
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    min-width: 160px;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.session-select:hover,
select.settings-input:hover {
    box-shadow: inset 0 0 0 1px var(--border-strong);
}

.session-select:focus,
select.settings-input:focus {
    outline: none;
    box-shadow: inset 0 0 0 1.5px var(--accent-blue);
    /* Focus glow via filter since it respects the mask */
    filter: drop-shadow(0 0 0 3px rgba(37, 99, 235, 0.12));
}

.select-chevron {
    position: absolute;
    right: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-tertiary);
}

/* ============================================================================
   Main Content
   ============================================================================ */

.main-content {
    display: flex;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    /* Gap between panels */
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--bg-canvas);
}

/* ============================================================================
   Chat Panel
   ============================================================================ */

.chat-panel {
    display: flex;
    flex-direction: column;
    width: 400px;
    min-width: 250px;
    max-width: 600px;
    min-height: 0;
    background: var(--bg-primary);
    /* Gap and padding for concentric corners - padding must exceed squircle corner radius */
    gap: var(--space-2);
    padding: var(--space-3);
    /* No inset border - squircle mask would clip it */
}

/* Panel Resize Handle */
.panel-resize-handle {
    width: 12px;
    margin: 0 -6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: col-resize;
    z-index: 10;
    flex-shrink: 0;
}

.resize-handle-bar {
    width: 4px;
    height: 48px;
    background: var(--border-subtle);
    border-radius: var(--radius-full);
    transition: all var(--duration-fast) var(--ease-out);
}

.panel-resize-handle:hover .resize-handle-bar,
.panel-resize-handle.dragging .resize-handle-bar {
    background: var(--border-strong);
    height: 64px;
}

.panel-resize-handle.dragging {
    cursor: col-resize;
}

/* Prevent text selection while resizing */
body.panel-resizing {
    cursor: col-resize !important;
    user-select: none;
}

body.panel-resizing * {
    cursor: col-resize !important;
}

/* Settings Panel */
.settings-panel {
    background: var(--bg-secondary);
    /* Concentric radius - smaller than parent panel's squircle */
    border-radius: var(--radius-xl);
    box-shadow: inset 0 0 0 1px var(--border-subtle);
    /* Padding so toggle hover doesn't touch edges */
    padding: var(--space-2);
    overflow: visible;
}

.settings-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: transparent;
    border: none;
    /* Rounded corners for hover state */
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    text-align: left;
    transition: background-color var(--duration-fast) var(--ease-out),
                color var(--duration-fast) var(--ease-out);
}

.settings-toggle:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.settings-icon {
    color: var(--text-tertiary);
}

.settings-toggle-text {
    flex: 1;
}

.settings-expand {
    color: var(--text-tertiary);
    transition: transform var(--duration-fast) var(--ease-out);
}

.settings-panel.expanded .settings-expand {
    transform: rotate(180deg);
}

.settings-content {
    /* Extra padding for squircle corners */
    padding: var(--space-3) var(--space-4) var(--space-4);
    animation: expandDown var(--duration-normal) var(--ease-out);
    transform-origin: top center;
}

.settings-content.collapsed {
    display: none;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.settings-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.settings-field label {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.settings-field label .optional {
    font-weight: 400;
    color: var(--text-tertiary);
    text-transform: none;
    letter-spacing: normal;
}

.settings-input {
    padding: var(--space-2) var(--space-3);
    background: var(--bg-secondary);
    /* Wide element mask for form inputs */
    -webkit-mask-image: var(--squircle-wide-xs);
    mask-image: var(--squircle-wide-xs);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--border-subtle);
    /* Fallback */
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    resize: vertical;
    transition: all var(--duration-fast) var(--ease-out);
}

.settings-input:hover {
    box-shadow: inset 0 0 0 1px var(--border-default);
}

.settings-input:focus {
    outline: none;
    background: var(--bg-primary);
    box-shadow: inset 0 0 0 1.5px var(--accent-blue);
    /* Focus glow via filter since it respects the mask */
    filter: drop-shadow(0 0 0 3px rgba(37, 99, 235, 0.12));
}

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

.settings-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.settings-custom-input {
    margin-top: var(--space-2);
}

.settings-hint {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.settings-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding-top: var(--space-2);
}

.settings-status {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.settings-status.success {
    color: var(--accent-emerald);
}

.settings-status.error {
    color: var(--accent-rose);
}

/* Preset field */
.preset-field {
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: var(--space-4);
}

.preset-row {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.preset-select {
    flex: 1;
}

.preset-modified {
    font-size: 0.6875rem;
    color: var(--accent-amber);
    font-weight: 500;
    margin-top: var(--space-1);
}

/* Chat Messages */
.chat-messages-wrapper {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-secondary);
    /* Concentric radius - smaller than parent panel's squircle */
    border-radius: var(--radius-xl);
    box-shadow: inset 0 0 0 1px var(--border-subtle);
}

.chat-messages {
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

/* Messages - Chat bubbles with smooth corners */
.message {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-xl);
    max-width: 90%;
    word-wrap: break-word;
}

.message-user {
    background: var(--accent-blue);
    color: #ffffff;
    align-self: flex-end;
    margin-left: auto;
    animation: messageSlideInRight var(--duration-normal) var(--ease-out);
}

.message-assistant {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    align-self: flex-start;
    /* Subtle inset border */
    box-shadow: inset 0 0 0 1px var(--border-default);
    animation: messageSlideInLeft var(--duration-normal) var(--ease-out);
}

.message-thinking {
    background: transparent;
    color: var(--text-tertiary);
    font-style: italic;
    align-self: flex-start;
    padding: var(--space-2) var(--space-4);
    /* No mask for simple thinking text */
    -webkit-mask-image: none;
    mask-image: none;
}

.message-error {
    background: rgba(225, 29, 72, 0.08);
    /* Use inset shadow for border since mask clips actual borders */
    box-shadow: inset 0 0 0 1px rgba(225, 29, 72, 0.3);
    color: var(--accent-rose);
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    animation: messageSlideInLeft var(--duration-normal) var(--ease-out), shake 0.4s var(--ease-out) 0.15s;
}

.error-retry-btn {
    background: var(--accent-rose);
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    flex-shrink: 0;
}

.error-retry-btn:hover {
    background: #be123c;
    transform: translateY(-1px);
}

.error-retry-btn:active {
    transform: translateY(0);
}

.system-message {
    background: rgba(37, 99, 235, 0.06);
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.2);
    color: var(--text-secondary);
    align-self: center;
    font-size: 0.8125rem;
    padding: var(--space-2) var(--space-3);
    /* Use message mask with subtle corners */
    -webkit-mask-image: var(--squircle-msg-sm);
    mask-image: var(--squircle-msg-sm);
    animation: fadeIn var(--duration-normal) var(--ease-out);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    /* Fallback */
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    max-width: 80%;
}

.system-message .system-icon {
    font-size: 1rem;
}

.message pre {
    background: var(--bg-tertiary);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    margin-top: var(--space-2);
    white-space: pre-wrap;
}

.message code {
    background: var(--bg-tertiary);
    padding: 0.1em 0.35em;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.85em;
}

.message h3, .message h4 {
    margin: 0.4em 0 0.2em;
    font-weight: 600;
}

.message h3 { font-size: 1em; }
.message h4 { font-size: 0.9em; }

.message ul, .message ol {
    margin: 0.3em 0;
    padding-left: 1.4em;
}

.message li {
    margin: 0.15em 0;
}

.message del {
    opacity: 0.6;
}

.welcome-msg {
    line-height: 1.7;
}

.welcome-msg strong {
    color: var(--accent-blue);
}

.welcome-msg em {
    color: var(--text-secondary);
}

.welcome-msg.compact {
    padding: var(--space-2) var(--space-3);
    font-size: 0.8125rem;
}

/* Onboarding welcome message */
.welcome-msg.onboarding {
    padding: var(--space-4);
}

.onboarding-header {
    font-size: 1rem;
    margin-bottom: var(--space-3);
    color: var(--text-primary);
}

.onboarding-steps {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.onboarding-step {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    font-size: 0.8125rem;
    line-height: 1.5;
}

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-blue);
    color: white;
    font-size: 0.6875rem;
    font-weight: 600;
    flex-shrink: 0;
}

.step-text {
    color: var(--text-secondary);
}

.step-text strong {
    color: var(--text-primary);
}

.onboarding-tip {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    border-top: 1px solid var(--border-subtle);
    padding-top: var(--space-2);
    margin-top: var(--space-2);
}

/* Gentle pulse animation for ready state */
.pulse-gentle {
    animation: pulseGentle 2s ease-in-out infinite;
}

@keyframes pulseGentle {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Thinking Indicator */
.thinking-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.thinking-indicator {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-secondary);
    /* Wide element mask for consistent corners */
    -webkit-mask-image: var(--squircle-wide-sm);
    mask-image: var(--squircle-wide-sm);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--border-subtle);
    /* Fallback */
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

/* When thinking-indicator has expanded activity, adjust corners */
.thinking-wrapper:has(.activity-container:not(.collapsed)) .thinking-indicator {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    -webkit-mask-image: none;
    mask-image: none;
}

.thinking-indicator:hover {
    background: var(--bg-tertiary);
}

.thinking-indicator.complete {
    background: transparent;
    box-shadow: none;
    padding: var(--space-2) var(--space-4);
}

.thinking-indicator.complete .thinking-status {
    color: var(--text-tertiary);
}

.thinking-indicator.complete .thinking-expand {
    display: none;
}

.thinking-status {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    background: linear-gradient(
        90deg,
        var(--text-tertiary) 0%,
        var(--text-primary) 50%,
        var(--text-tertiary) 100%
    );
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer-text 2s ease-in-out infinite;
}

.thinking-indicator.complete .thinking-status {
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
    -webkit-text-fill-color: var(--text-tertiary);
    animation: none;
}

.thinking-indicator.complete.error .thinking-status {
    -webkit-text-fill-color: var(--accent-rose);
}

.thinking-dots {
    display: inline-flex;
    gap: 1px;
}

.thinking-dots span {
    animation: dot-pulse 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

.thinking-expand {
    color: var(--text-tertiary);
    font-size: 0.625rem;
    transition: transform var(--duration-fast) var(--ease-out);
}

.thinking-elapsed {
    color: var(--text-tertiary);
    font-size: 0.6875rem;
    font-weight: 500;
    padding: 2px 6px;
    background: rgba(37, 99, 235, 0.1);
    border-radius: 4px;
    margin-left: auto;
    margin-right: var(--space-2);
}

/* Activity Stream - nested inside thinking wrapper */
.thinking-wrapper .activity-container {
    /* Remove mask since this is nested and connected to thinking-indicator */
    -webkit-mask-image: none;
    mask-image: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    margin-top: -4px;
    box-shadow: none;
    /* Use inset shadow for top border */
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    animation: expandDown var(--duration-normal) var(--ease-out);
    transform-origin: top center;
}

.thinking-wrapper .activity-container.collapsed {
    display: none;
}

.thinking-wrapper .activity-container .activity-content-wrapper {
    padding-top: var(--space-2);
}

.activity-container {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    /* Wide element mask for consistent corners */
    -webkit-mask-image: var(--squircle-wide-sm);
    mask-image: var(--squircle-wide-sm);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--border-subtle);
    /* Fallback */
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-2);
    overflow: visible; /* Allow hover effects */
    font-size: 0.8125rem;
}

.activity-container.status-success {
    box-shadow: inset 0 0 0 1px rgba(5, 150, 105, 0.35);
}

.activity-container.status-error {
    box-shadow: inset 0 0 0 1px rgba(225, 29, 72, 0.35);
}

.activity-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--overlay-subtle);
    cursor: pointer;
    user-select: none;
}

.activity-header:hover {
    background: var(--overlay-light);
}

.activity-toggle {
    font-size: 0.5rem;
    color: var(--text-tertiary);
    width: 10px;
}

.activity-title {
    flex: 1;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.activity-status-icon {
    display: flex;
    align-items: center;
    font-size: 0.875rem;
}

.activity-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-2) var(--space-3);
    padding-left: calc(var(--space-3) + 18px);
    background: var(--overlay-subtle);
}

.activity-container.collapsed .activity-content-wrapper {
    display: none;
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: 4px 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.activity-item .activity-icon,
.activity-item .activity-spinner {
    flex-shrink: 0;
}

.activity-item .step-content {
    flex: 1;
    color: var(--text-secondary);
}

.activity-item.status-complete .step-content {
    color: var(--text-primary);
}

.activity-summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    margin-top: var(--space-1);
    border-top: 1px solid var(--border-subtle);
    font-size: 0.75rem;
}

.activity-summary .summary-text {
    color: var(--accent-emerald);
    font-weight: 500;
}

.activity-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-default);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.activity-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    font-size: 12px;
    flex-shrink: 0;
}

.activity-icon.success {
    color: var(--accent-emerald);
}

.activity-icon.error {
    color: var(--accent-rose);
}

.activity-content {
    flex: 1;
}

/* Activity Reasoning */
.activity-reasoning {
    background: rgba(124, 58, 237, 0.05);
    border-radius: var(--radius-sm);
    padding: var(--space-2);
    margin: var(--space-1) 0;
}

.activity-reasoning .activity-icon.reasoning {
    font-size: 12px;
    align-self: flex-start;
    margin-top: 2px;
}

.reasoning-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reasoning-label {
    font-size: 0.625rem;
    color: var(--accent-violet);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.reasoning-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
    line-height: 1.4;
}

.reasoning-text.truncated {
    display: inline;
}

.expand-btn {
    background: none;
    border: none;
    color: var(--accent-blue);
    font-size: 0.6875rem;
    cursor: pointer;
    padding: 0;
    margin-left: var(--space-1);
}

.expand-btn:hover {
    text-decoration: underline;
}

/* Activity Steps */
.activity-step {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: var(--space-1) 0;
    border-bottom: 1px solid var(--border-subtle);
}

.activity-step:last-child {
    border-bottom: none;
}

.activity-step .step-main {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
}

.activity-step .step-spinner {
    width: 12px;
    height: 12px;
    border-width: 1.5px;
    flex-shrink: 0;
}

.activity-step .step-message {
    font-size: 0.75rem;
    color: var(--text-primary);
    font-weight: 500;
}

.activity-step.status-running .step-message {
    color: var(--text-secondary);
}

.step-reason {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    padding-left: calc(12px + var(--space-2));
    line-height: 1.4;
    font-style: italic;
}

/* Tool Context */
.tool-context {
    background: var(--overlay-subtle);
    border-radius: var(--radius-sm);
    padding: var(--space-2);
    margin: var(--space-1) 0;
    font-size: 0.75rem;
}

.context-row {
    display: flex;
    gap: var(--space-2);
    padding: 2px 0;
}

.context-label {
    color: var(--text-tertiary);
    min-width: 80px;
}

.context-value {
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.context-value.placement-first_tile {
    color: var(--accent-amber);
}

.context-value.placement-adjacent {
    color: var(--accent-emerald);
}

.context-value.placement-isolated {
    color: var(--accent-blue);
}

.tool-summary {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    padding-top: var(--space-1);
    display: none;
}

.tool-summary.has-summary {
    display: block;
    color: var(--accent-emerald);
    font-style: italic;
}

.tool-steps {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-left: var(--space-3);
}

/* Activity Response */
.activity-response {
    margin-top: var(--space-2);
    padding: var(--space-3);
    background: var(--overlay-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    line-height: 1.6;
    border-top: 1px solid var(--border-subtle);
}

.activity-response pre {
    background: var(--bg-tertiary);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    margin-top: var(--space-2);
    white-space: pre-wrap;
}

.activity-response code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.85em;
}

.activity-container.has-response {
    border-left: 2px solid var(--accent-emerald);
}

.activity-container.has-response .activity-header {
    background: rgba(5, 150, 105, 0.05);
}

/* Selection Info */
.selection-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    background: rgba(37, 99, 235, 0.06);
    border-top: 1px solid rgba(37, 99, 235, 0.15);
    color: var(--accent-blue);
    font-size: 0.8125rem;
}

.selection-info button {
    margin-left: auto;
}

/* Chat Input */
.chat-input-container {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--bg-secondary);
    /* Concentric radius - smaller than parent panel's squircle */
    border-radius: var(--radius-xl);
    box-shadow: inset 0 0 0 1px var(--border-subtle);
}

.chat-input {
    flex: 1;
    padding: var(--space-3);
    background: var(--bg-secondary);
    /* Wide element mask for text inputs */
    -webkit-mask-image: var(--squircle-wide-sm);
    mask-image: var(--squircle-wide-sm);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--border-subtle);
    /* Fallback */
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    resize: none;
    transition: all var(--duration-fast) var(--ease-out);
}

.chat-input:hover {
    box-shadow: inset 0 0 0 1px var(--border-default);
}

.chat-input:focus {
    outline: none;
    background: var(--bg-primary);
    box-shadow: inset 0 0 0 1.5px var(--accent-blue);
    /* Focus glow via filter since it respects the mask */
    filter: drop-shadow(0 0 0 3px rgba(37, 99, 235, 0.12));
}

.chat-input:disabled {
    opacity: 0.5;
}

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

.send-btn {
    align-self: flex-end;
    width: 40px;
    height: 40px;
    padding: 0;
    /* True squircle via SVG mask */
    -webkit-mask-image: var(--squircle-md);
    mask-image: var(--squircle-md);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    /* Fallback */
    border-radius: var(--radius-lg);
}

/* ============================================================================
   Canvas Panel
   ============================================================================ */

.canvas-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
    /* Gap and padding for concentric corners - padding must exceed squircle corner radius */
    gap: var(--space-2);
    padding: var(--space-3);
    /* No inset border - squircle mask would clip it */
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) var(--space-4);
    background: var(--bg-secondary);
    /* Concentric radius - smaller than parent panel's squircle */
    border-radius: var(--radius-xl);
    box-shadow: inset 0 0 0 1px var(--border-subtle);
}

.canvas-header h2 {
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.canvas-controls {
    display: flex;
    gap: var(--space-3);
    align-items: center;
}

/* Toggle Switch */
.toggle-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    position: relative;
    width: 32px;
    height: 18px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    transition: all var(--duration-fast) var(--ease-out);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: var(--text-tertiary);
    border-radius: 50%;
    transition: all var(--duration-fast) var(--ease-out);
}

.toggle-label input:checked + .toggle-switch {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.toggle-label input:checked + .toggle-switch::after {
    transform: translateX(14px);
    background: var(--bg-primary);
}

.toggle-text {
    color: var(--text-secondary);
    transition: color var(--duration-fast) var(--ease-out);
}

.toggle-label:hover .toggle-text {
    color: var(--text-primary);
}

/* Canvas Container with Dot Grid */
.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: var(--bg-canvas);
    background-image: radial-gradient(circle, var(--border-subtle) 1px, transparent 1px);
    background-size: 24px 24px;
    /* Concentric radius - smaller than parent panel's squircle */
    border-radius: var(--radius-xl);
    box-shadow: inset 0 0 0 1px var(--border-subtle);
}

.canvas-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
}

.canvas-container canvas:active {
    cursor: grabbing;
}

/* Canvas Empty State */
.canvas-empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-secondary);
    animation: fadeIn var(--duration-slow) var(--ease-out);
}

.empty-icon {
    color: var(--text-tertiary);
    margin-bottom: var(--space-4);
}

.empty-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-hint {
    font-size: 0.8125rem;
    color: var(--text-tertiary);
}

/* Canvas Footer */
.canvas-footer {
    display: flex;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    background: var(--bg-secondary);
    /* Concentric radius - smaller than parent panel's squircle */
    border-radius: var(--radius-xl);
    box-shadow: inset 0 0 0 1px var(--border-subtle);
}

.coords-display {
    font-family: var(--font-mono);
}

/* ============================================================================
   Workflow Panel
   ============================================================================ */

.workflow-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-secondary);
    /* Concentric radius - smaller than parent panel's squircle */
    border-radius: var(--radius-xl);
    box-shadow: inset 0 0 0 1px var(--border-subtle);
    gap: var(--space-4);
}

.workflow-stage {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: 0.8125rem;
}

.stage-dots {
    display: flex;
    align-items: center;
    gap: 0;
}

.stage-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border-default);
    transition: all var(--duration-fast) var(--ease-out);
}

.stage-dot.active {
    background: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.15);
}

.stage-dot.completed {
    background: var(--accent-emerald);
}

.stage-line {
    width: 16px;
    height: 2px;
    background: var(--border-default);
}

.stage-text {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.workflow-actions {
    display: flex;
    gap: var(--space-2);
}

/* Stage Colors */
.stage-initialized { color: var(--text-tertiary); }
.stage-placing_locations { color: var(--accent-blue); }
.stage-layout_confirmed { color: var(--accent-amber); }
.stage-filled { color: var(--accent-emerald); }
.stage-depth_estimation { color: var(--accent-violet); }
.stage-splat_generation { color: var(--accent-violet); }
.stage-completed { color: var(--accent-emerald); }

/* ============================================================================
   Status Bar
   ============================================================================ */

.status-bar {
    display: flex;
    gap: var(--space-6);
    padding: var(--space-2) var(--space-5);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-subtle);
    font-size: 0.6875rem;
}

.status-section {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border-default);
    transition: background var(--duration-fast) var(--ease-out);
}

.status-label {
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.status-value {
    color: var(--text-primary);
    font-weight: 500;
}

.status-value.connected {
    color: var(--accent-emerald);
}

.status-value.connected + .status-dot,
.status-section:has(.status-value.connected) .status-dot {
    background: var(--accent-emerald);
}

.status-value.disconnected {
    color: var(--accent-rose);
}

.status-section:has(.status-value.disconnected) .status-dot {
    background: var(--accent-rose);
}

.status-value.connecting {
    color: var(--accent-amber);
}

.status-section:has(.status-value.connecting) .status-dot {
    background: var(--accent-amber);
    animation: pulse 1s ease-in-out infinite;
}

.status-value.reconnecting {
    color: var(--accent-amber);
    font-size: 0.75rem;
}

.status-section:has(.status-value.reconnecting) .status-dot {
    background: var(--accent-amber);
    animation: pulse 0.8s ease-in-out infinite;
}

/* Auto-save indicator */
.autosave-section {
    margin-left: auto;  /* Push to right side */
    cursor: pointer;
}

.autosave-indicator {
    font-size: 0.6875rem;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 4px;
    transition: all var(--duration-fast) var(--ease-out);
}

.autosave-indicator:hover {
    opacity: 0.8;
}

.autosave-idle {
    color: var(--text-tertiary);
    background: transparent;
}

.autosave-saved {
    color: var(--accent-emerald);
    background: rgba(5, 150, 105, 0.1);
}

.autosave-dirty {
    color: var(--accent-amber);
    background: rgba(217, 119, 6, 0.1);
}

.autosave-saving {
    color: var(--accent-blue);
    background: rgba(37, 99, 235, 0.1);
    animation: pulse 1s ease-in-out infinite;
}

.autosave-disabled {
    color: var(--text-tertiary);
    background: rgba(128, 128, 128, 0.1);
    text-decoration: line-through;
}

.autosave-retrying {
    color: var(--accent-amber);
    background: rgba(217, 119, 6, 0.15);
    animation: pulse 0.8s ease-in-out infinite;
}

.autosave-warning {
    color: var(--accent-red, #ef4444);
    background: rgba(239, 68, 68, 0.15);
    font-weight: 600;
}

.autosave-cloud-warning {
    color: var(--accent-amber);
    background: rgba(217, 119, 6, 0.15);
    border: 1px dashed var(--accent-amber);
}

/* System message in chat */
.system-message {
    background: rgba(217, 119, 6, 0.1);
    border-left: 3px solid var(--accent-amber);
    padding: var(--space-3) var(--space-4);
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.system-message .system-icon {
    margin-right: var(--space-2);
}

/* Toast notifications */
#toast-container {
    position: fixed;
    bottom: var(--space-6);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    transition: opacity var(--duration-normal) var(--ease-out),
                transform var(--duration-normal) var(--ease-spring);
    pointer-events: auto;
}

.toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.toast-success {
    background: var(--accent-emerald);
    color: white;
}

.toast-info {
    background: var(--accent-blue);
    color: white;
}

.toast-warning {
    background: var(--accent-amber);
    color: white;
}

.toast-icon {
    font-size: 1rem;
}

.toast-text {
    white-space: nowrap;
}

/* Recovery banner */
.recovery-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, var(--accent-blue), #4f46e5);
    color: white;
    padding: var(--space-4);
    z-index: 10000;
    animation: slideDown var(--duration-slow) var(--ease-out);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.recovery-banner-fade {
    animation: slideUp 0.5s ease-out forwards;
}

@keyframes slideUp {
    to {
        transform: translateY(-100%);
        opacity: 0;
    }
}

.recovery-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.recovery-icon {
    font-size: 1.5rem;
}

.recovery-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.recovery-text strong {
    font-weight: 600;
}

.recovery-text span {
    font-size: 0.875rem;
    opacity: 0.9;
}

.recovery-actions {
    display: flex;
    gap: var(--space-2);
}

.recovery-actions .btn {
    padding: var(--space-2) var(--space-4);
    font-size: 0.875rem;
}

.recovery-actions .btn-primary {
    background: white;
    color: var(--accent-blue);
}

.recovery-actions .btn-primary:hover {
    background: rgba(255, 255, 255, 0.9);
}

.recovery-actions .btn-secondary {
    background: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.recovery-actions .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
}

@media (max-width: 768px) {
    .recovery-content {
        flex-wrap: wrap;
    }

    .recovery-text {
        flex-basis: calc(100% - 50px);
    }

    .recovery-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ============================================================================
   Modals
   ============================================================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn var(--duration-normal) var(--ease-out);
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    pointer-events: none;
}

.modal-content {
    position: relative;
    background: var(--bg-primary);
    /* Fallback - JS applies dynamic squircle mask */
    border-radius: var(--radius-2xl);
    /* Generous padding to prevent content clipping at squircle corners */
    padding: var(--space-6);
    max-width: 600px;
    max-height: 80vh;
    overflow: auto;
    /* No inset border - squircle mask would clip it at corners */
    /* Outer shadow via filter (respects mask shape) */
    filter: drop-shadow(0 20px 25px rgba(0,0,0,0.15)) drop-shadow(0 10px 10px rgba(0,0,0,0.08));
    animation: modalPop var(--duration-slow) var(--ease-out);
}

.modal-close {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    transition: all var(--duration-fast) var(--ease-out);
}

.modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-content h3 {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: var(--space-4);
    padding-right: var(--space-6);
}

/* Tile Details Modal - wider, use medium corners */
.modal-tile-details {
    max-width: 800px;
    width: 90vw;
    -webkit-mask-image: var(--squircle-modal-md);
    mask-image: var(--squircle-modal-md);
}

.tile-modal-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-5);
    margin-top: var(--space-3);
}

#tile-modal-image {
    width: 100%;
    /* Squircle for images */
    -webkit-mask-image: var(--squircle-xl);
    mask-image: var(--squircle-xl);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    /* Fallback */
    border-radius: var(--radius-xl);
    background: var(--bg-secondary);
}

.tile-details {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.tile-detail-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.tile-detail-row .detail-label {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.tile-detail-row .detail-value {
    font-size: 0.875rem;
    color: var(--text-primary);
}

.tile-detail-row .detail-value.mono {
    font-family: var(--font-mono);
}

.tile-prompt-row {
    flex: 1;
}

.prompt-text {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    background: var(--bg-secondary);
    padding: var(--space-3);
    /* Wide element mask for code/text boxes */
    -webkit-mask-image: var(--squircle-wide-sm);
    mask-image: var(--squircle-wide-sm);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--border-subtle);
    /* Fallback */
    border-radius: var(--radius-lg);
    max-height: 150px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.4;
    color: var(--text-primary);
}

.tile-modal-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-subtle);
}

.tile-modal-actions .btn {
    flex: 1;
}

/* Confirmation Modal */
.modal-confirm {
    max-width: 420px;
    text-align: center;
}

.modal-confirm h3 {
    padding-right: 0;
}

.confirm-description {
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
    line-height: 1.5;
}

.confirm-description strong {
    color: var(--accent-blue);
}

.fill-settings-preview {
    background: var(--bg-secondary);
    /* Wide element mask for preview boxes */
    -webkit-mask-image: var(--squircle-wide-sm);
    mask-image: var(--squircle-wide-sm);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px var(--border-subtle);
    /* Fallback */
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    text-align: left;
}

.fill-settings-note {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    margin-bottom: var(--space-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.fill-setting-row {
    display: flex;
    justify-content: space-between;
    padding: var(--space-1) 0;
    font-size: 0.8125rem;
}

.fill-setting-label {
    color: var(--text-secondary);
}

.fill-setting-value {
    color: var(--text-primary);
    font-weight: 500;
    max-width: 200px;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.confirm-warning {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: rgba(217, 119, 6, 0.08);
    /* Wide element mask for warning boxes */
    -webkit-mask-image: var(--squircle-wide-sm);
    mask-image: var(--squircle-wide-sm);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    border: none;
    /* Border via inset shadow since mask clips borders */
    box-shadow: inset 0 0 0 1px rgba(217, 119, 6, 0.25);
    /* Fallback */
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-5);
    text-align: left;
    font-size: 0.8125rem;
    color: var(--accent-amber);
}

.confirm-warning .warning-icon {
    flex-shrink: 0;
    margin-top: 2px;
}

.confirm-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
}

.confirm-actions .btn {
    min-width: 100px;
}

/* Preset Dialog */
.preset-name-input-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: var(--space-4) 0;
    text-align: left;
}

.preset-name-input-row label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Output Modal - wider, use medium corners */
.modal-large {
    max-width: 900px;
    width: 90vw;
    -webkit-mask-image: var(--squircle-modal-md);
    mask-image: var(--squircle-modal-md);
}

.output-tabs {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-4);
}

.tab-btn {
    padding: var(--space-2) var(--space-4);
    background: transparent;
    border: none;
    /* iOS-style smooth corners */
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all var(--duration-fast) var(--ease-out);
}

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

.tab-btn.active {
    background: var(--accent-primary);
    color: #ffffff;
    box-shadow: inset 0 0 0 1px var(--accent-primary);
}

.output-image-container {
    position: relative;
    min-height: 300px;
    background: var(--bg-secondary);
    /* Squircle for image containers */
    -webkit-mask-image: var(--squircle-xl);
    mask-image: var(--squircle-xl);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    /* Fallback */
    border-radius: var(--radius-xl);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#output-image {
    max-width: 100%;
    max-height: 60vh;
    border-radius: var(--radius-md);
}

.output-loading {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    color: var(--text-secondary);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border-default);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.output-actions {
    display: flex;
    justify-content: center;
    gap: var(--space-3);
    margin-top: var(--space-4);
}

/* Gaussian Splat 3D Viewer */
.splat-container {
    position: relative;
    width: 100%;
    height: 500px;
    background: #0a0a0a;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.splat-container canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.splat-controls-overlay {
    position: absolute;
    bottom: var(--space-3);
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
}

.splat-hint {
    font-size: var(--text-xs);
    color: rgba(255, 255, 255, 0.5);
    background: rgba(0, 0, 0, 0.5);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
}

/* ============================================================================
   Library Modal
   ============================================================================ */

.library-modal-content {
    max-width: 900px;
    width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    /* Wider modal, use medium corners */
    -webkit-mask-image: var(--squircle-modal-md);
    mask-image: var(--squircle-modal-md);
}

.library-header {
    margin-bottom: var(--space-4);
}

.library-header h3 {
    margin-bottom: var(--space-3);
}

.library-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border-subtle);
}

.library-count {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
    overflow-y: auto;
    flex: 1;
    padding: var(--space-3) 0;
}

.library-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--duration-fast) var(--ease-out);
    cursor: pointer;
}

.library-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-default);
    box-shadow: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

.library-thumbnail {
    width: 100%;
    height: 140px;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.library-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.library-no-thumbnail {
    color: var(--text-tertiary);
    font-size: 0.75rem;
    text-align: center;
}

.library-badge {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    font-size: 0.625rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.library-badge-auto {
    background: rgba(100, 100, 100, 0.8);
    color: var(--text-inverse);
}

.library-badge-checkpoint {
    background: rgba(37, 99, 235, 0.9);
    color: white;
}

.library-info {
    padding: var(--space-3) var(--space-4);
}

.library-name {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: var(--space-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.library-style {
    font-size: 0.6875rem;
    color: var(--accent-blue);
    margin-bottom: var(--space-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.library-meta {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.library-meta-item {
    display: flex;
    align-items: center;
    gap: 2px;
}

.library-date {
    font-size: 0.625rem;
    color: var(--text-tertiary);
    margin-top: var(--space-2);
}

.library-actions {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}

.library-restore-btn {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    background: var(--accent-primary);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 500;
    transition: background var(--duration-fast) var(--ease-out);
}

.library-restore-btn:hover {
    background: #262626;
}

.library-delete-btn {
    padding: var(--space-2) var(--space-3);
    background: transparent;
    border: none;
    /* Border via inset shadow for consistency */
    box-shadow: inset 0 0 0 1px var(--border-default);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    transition: all var(--duration-fast) var(--ease-out);
}

.library-delete-btn:hover {
    background: var(--accent-rose);
    box-shadow: inset 0 0 0 1px var(--accent-rose);
    color: #ffffff;
}

.library-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-7) var(--space-5);
    text-align: center;
    min-height: 200px;
    color: var(--text-secondary);
    gap: var(--space-3);
}

.library-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-7) var(--space-5);
    text-align: center;
    min-height: 200px;
}

.library-empty-icon {
    color: var(--text-tertiary);
    margin-bottom: var(--space-4);
}

.library-empty-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.library-empty-hint {
    font-size: 0.8125rem;
    color: var(--text-tertiary);
}

/* Library Card Action Buttons */
.library-copy-btn,
.library-share-btn {
    padding: var(--space-2);
    background: transparent;
    border: none;
    box-shadow: inset 0 0 0 1px var(--border-default);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.75rem;
    transition: all var(--duration-fast) var(--ease-out);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
}

.library-copy-btn:hover {
    background: var(--accent-blue);
    box-shadow: inset 0 0 0 1px var(--accent-blue);
    color: #ffffff;
}

.library-share-btn:hover {
    background: var(--accent-emerald);
    box-shadow: inset 0 0 0 1px var(--accent-emerald);
    color: #ffffff;
}

/* Visibility Badges */
.library-badge-public {
    background: rgba(5, 150, 105, 0.9);
    color: white;
}

.library-badge-private {
    background: rgba(100, 100, 100, 0.8);
    color: var(--text-inverse);
}

.library-badge-unlisted {
    background: rgba(37, 99, 235, 0.9);
    color: white;
}

/* Visibility Options (Radio buttons) */
.visibility-options {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: var(--space-4) 0;
    text-align: left;
}

.visibility-option {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    border: 1px solid transparent;
}

.visibility-option:hover {
    background: var(--bg-tertiary);
}

.visibility-option:has(input:checked) {
    background: rgba(37, 99, 235, 0.08);
    border-color: var(--accent-blue);
}

.visibility-option input[type="radio"] {
    display: none;
}

.visibility-radio {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-default);
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 2px;
    position: relative;
    transition: all var(--duration-fast) var(--ease-out);
}

.visibility-option:has(input:checked) .visibility-radio {
    border-color: var(--accent-blue);
}

.visibility-option:has(input:checked) .visibility-radio::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: var(--accent-blue);
    border-radius: 50%;
}

.visibility-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.visibility-title {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.visibility-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Share Link Container */
.share-link-container {
    display: flex;
    gap: var(--space-2);
    margin: var(--space-4) 0;
}

.share-link-input {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-primary);
    outline: none;
}

.share-link-input:focus {
    border-color: var(--accent-blue);
}

.share-copy-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    white-space: nowrap;
}

/* ============================================================================
   Scrollbar Styling
   ============================================================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* ============================================================================
   Responsive
   ============================================================================ */

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .chat-panel {
        width: 100% !important;
        max-width: none;
        height: 50%;
    }

    .panel-resize-handle {
        display: none;
    }

    .canvas-panel {
        height: 50%;
    }

    .header {
        flex-direction: column;
        gap: var(--space-3);
        padding: var(--space-3);
    }

    .header-brand {
        width: 100%;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .tile-modal-body {
        grid-template-columns: 1fr;
    }

    .library-modal-content {
        max-height: 90vh;
    }

    .library-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }

    .library-thumbnail {
        height: 100px;
    }

    .library-toolbar {
        flex-direction: column;
        gap: var(--space-3);
        align-items: flex-start;
    }

    .workflow-panel {
        flex-direction: column;
        gap: var(--space-3);
    }

    .workflow-actions {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }
}

/* ============================================================================
   Focus Styles (Accessibility)
   ============================================================================ */

:focus-visible {
    outline: none;
    box-shadow: 0 0 0 var(--ring-offset) var(--bg-primary),
                0 0 0 calc(var(--ring-offset) + var(--ring-width)) var(--ring-color);
}

/* Remove focus outline on mouse click but keep for keyboard */
:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

/* ============================================================================
   Utility Classes
   ============================================================================ */

.mono {
    font-family: var(--font-mono);
}

/* ============================================================================
   Gallery Modal (Public Worlds)
   ============================================================================ */

.gallery-modal-content {
    max-width: 1000px;
    width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    -webkit-mask-image: var(--squircle-modal-md);
    mask-image: var(--squircle-modal-md);
}

.gallery-header {
    margin-bottom: var(--space-4);
}

.gallery-header h3 {
    margin-bottom: var(--space-3);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: var(--space-4);
    overflow-y: auto;
    flex: 1;
    padding: var(--space-3) 0;
}

.gallery-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--duration-fast) var(--ease-out);
    cursor: pointer;
}

.gallery-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-default);
    box-shadow: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

.gallery-thumbnail {
    width: 100%;
    height: 160px;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.gallery-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-no-thumbnail {
    color: var(--text-tertiary);
    font-size: 0.75rem;
    text-align: center;
}

.gallery-info {
    padding: var(--space-3) var(--space-4);
}

.gallery-name {
    font-weight: 600;
    font-size: 0.9375rem;
    margin-bottom: var(--space-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.gallery-style {
    font-size: 0.75rem;
    color: var(--accent-blue);
    margin-bottom: var(--space-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.gallery-meta {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    display: flex;
    gap: var(--space-2);
    align-items: center;
    flex-wrap: wrap;
}

.gallery-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-7) var(--space-5);
    text-align: center;
    min-height: 200px;
    color: var(--text-secondary);
    gap: var(--space-3);
}

.gallery-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-7) var(--space-5);
    text-align: center;
    min-height: 200px;
}

.gallery-empty-icon {
    color: var(--text-tertiary);
    margin-bottom: var(--space-4);
}

.gallery-empty-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.gallery-empty-hint {
    font-size: 0.8125rem;
    color: var(--text-tertiary);
}

.gallery-load-more {
    display: flex;
    justify-content: center;
    padding: var(--space-4) 0;
}

/* Gallery Tabs */
.gallery-tabs {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.gallery-tab {
    padding: var(--space-2) var(--space-4);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

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

.gallery-tab.active {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.gallery-tab.hidden {
    display: none;
}

/* Gallery Visibility Controls */
.gallery-visibility {
    margin-top: var(--space-2);
}

.gallery-visibility-select {
    font-size: 0.6875rem;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    width: 100%;
}

.gallery-visibility-select.visibility-public {
    border-color: var(--accent-green);
    color: var(--accent-green);
}

.gallery-visibility-select.visibility-private {
    border-color: var(--text-tertiary);
    color: var(--text-tertiary);
}

.gallery-visibility-select.visibility-unlisted {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

/* Gallery Search and Sort Controls */
.gallery-controls {
    display: flex;
    gap: var(--space-3);
    padding: 0 var(--space-4);
    margin-bottom: var(--space-3);
}

.gallery-search {
    flex: 1;
}

.gallery-search input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.gallery-search input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.gallery-search input::placeholder {
    color: var(--text-tertiary);
}

.gallery-sort select {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

.gallery-sort select:focus {
    outline: none;
    border-color: var(--accent-blue);
}

/* Gallery Creator Attribution */
.gallery-creator {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    margin-top: var(--space-1);
}

.gallery-creator a {
    color: var(--accent-blue);
    text-decoration: none;
}

.gallery-creator a:hover {
    text-decoration: underline;
}

/* Gallery Description */
.gallery-description {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    margin-top: var(--space-1);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Gallery Fork Button */
.gallery-fork-btn {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    padding: var(--space-1) var(--space-2);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.6875rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.gallery-card:hover .gallery-fork-btn {
    opacity: 1;
}

.gallery-fork-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

/* Gallery Thumbnail - ensure relative positioning for fork button */
.gallery-thumbnail {
    position: relative;
}

/* User Profile Modal */
.user-profile-modal .modal-content {
    max-width: 800px;
    max-height: 80vh;
}

.user-profile-body {
    padding: var(--space-4);
    overflow-y: auto;
    max-height: 60vh;
}

/* ============================================================================
   Authentication UI
   ============================================================================ */

.auth-user-info {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.auth-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.auth-user-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-small {
    padding: var(--space-1) var(--space-2);
    font-size: 0.75rem;
}

.header-divider {
    width: 1px;
    height: 24px;
    background: var(--border-default);
    margin: 0 var(--space-2);
}

/* Auth Modal */
.auth-modal-content {
    max-width: 400px;
    width: 90vw;
    padding: var(--space-6);
}

.auth-modal-content h3 {
    margin-bottom: var(--space-5);
    text-align: center;
}

.auth-field {
    margin-bottom: var(--space-4);
}

.auth-field label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: var(--space-2);
    color: var(--text-primary);
}

.auth-field input {
    width: 100%;
    padding: var(--space-3);
    font-size: 0.9375rem;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color var(--duration-fast) var(--ease-out);
}

.auth-field input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.auth-field input::placeholder {
    color: var(--text-tertiary);
}

.auth-error {
    padding: var(--space-3);
    margin-bottom: var(--space-4);
    background: var(--accent-red-bg, rgba(239, 68, 68, 0.1));
    color: var(--accent-red, #ef4444);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.auth-submit {
    width: 100%;
    padding: var(--space-3);
    font-size: 1rem;
}

.auth-switch {
    margin-top: var(--space-5);
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--accent-blue);
    text-decoration: none;
    font-weight: 500;
    margin-left: var(--space-1);
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* ============================================================================
   Debug Panel - Agent Activity Log
   ============================================================================ */

.world-name-section .status-value.clickable {
    cursor: pointer;
    transition: color var(--duration-fast) var(--ease-out);
}

.world-name-section .status-value.clickable:hover {
    color: var(--accent-blue);
    text-decoration: underline;
}

.debug-toggle-section {
    margin-left: auto;
}

.debug-toggle-btn {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.debug-toggle-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-default);
    background: var(--bg-secondary);
}

.debug-toggle-btn.active {
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    background: rgba(37, 99, 235, 0.08);
}

.debug-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 420px;
    max-width: 90vw;
    background: var(--bg-primary);
    border-left: 1px solid var(--border-default);
    box-shadow: var(--shadow-xl);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform var(--duration-normal) var(--ease-out);
}

.debug-panel.hidden {
    transform: translateX(100%);
    pointer-events: none;
}

.debug-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}

.debug-panel-header h3 {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.debug-panel-actions {
    display: flex;
    gap: var(--space-2);
}

.debug-panel-filters {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}

.debug-filter {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.debug-filter input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent-blue);
}

.debug-log {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.5;
}

.debug-empty {
    color: var(--text-tertiary);
    text-align: center;
    padding: var(--space-6);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
}

.debug-entry {
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    border-left: 3px solid var(--border-default);
}

.debug-entry.type-tool_start {
    border-left-color: var(--accent-blue);
}

.debug-entry.type-tool_end.success {
    border-left-color: var(--accent-emerald);
}

.debug-entry.type-tool_end.error {
    border-left-color: var(--accent-rose);
}

.debug-entry.type-reasoning {
    border-left-color: var(--accent-violet);
}

.debug-entry.type-step {
    border-left-color: var(--accent-amber);
}

.debug-entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-1);
}

.debug-entry-type {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.625rem;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.debug-entry-time {
    font-size: 0.625rem;
    color: var(--text-tertiary);
}

.debug-entry-content {
    color: var(--text-primary);
    word-break: break-word;
}

.debug-entry-tool {
    color: var(--accent-blue);
    font-weight: 500;
}

.debug-entry-details {
    margin-top: var(--space-2);
    padding: var(--space-2);
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    max-height: 200px;
    overflow-y: auto;
}

.debug-entry-details pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.6875rem;
    color: var(--text-secondary);
}

.debug-entry-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    margin-top: var(--space-1);
    padding: var(--space-1) var(--space-2);
    font-size: 0.625rem;
    color: var(--text-tertiary);
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.debug-entry-toggle:hover {
    color: var(--text-secondary);
    border-color: var(--border-default);
}

.debug-entry-status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    font-size: 0.625rem;
    font-weight: 500;
}

.debug-entry-status.success {
    background: rgba(5, 150, 105, 0.1);
    color: var(--accent-emerald);
}

.debug-entry-status.error {
    background: rgba(225, 29, 72, 0.1);
    color: var(--accent-rose);
}

/* Scrollbar styling for debug log */
.debug-log::-webkit-scrollbar {
    width: 6px;
}

.debug-log::-webkit-scrollbar-track {
    background: transparent;
}

.debug-log::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

.debug-log::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* ============================================================================
   Multi-Tab Warning Banner
   ============================================================================ */

.multi-tab-warning {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    background: linear-gradient(135deg, var(--accent-amber), #f59e0b);
    color: #000;
    padding: var(--space-3) var(--space-4);
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: var(--shadow-lg);
    animation: slideDown 0.3s var(--ease-out);
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.multi-tab-warning-content {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    max-width: 800px;
    width: 100%;
}

.multi-tab-warning-content svg {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
}

.multi-tab-warning-content span {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
}

.multi-tab-warning-content button {
    flex-shrink: 0;
    padding: var(--space-2) var(--space-3);
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    color: #000;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.multi-tab-warning-content button:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* Adjust main content when warning is shown */
body:has(.multi-tab-warning) .header {
    margin-top: 52px;
}
