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

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    width: 240px;
    height: 292px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overscroll-behavior: none;
}

.container {
    text-align: center;
    padding: 5px;
    max-width: 235px;
}

.logo {
    font-size: 64px;
    margin-bottom: 5px;
    opacity: 0;
    animation: fadeInUp 1s ease 0.2s forwards;
}

h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 3px;
    opacity: 0;
    animation: fadeInUp 1s ease 0.4s forwards;
}

.subtitle {
    font-size: 14px;
    font-weight: 400;
    opacity: 0.9;
    margin-bottom: 5px;
    opacity: 0;
    animation: fadeInUp 1s ease 0.6s forwards;
}

.status {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 4px 8px;
    font-size: 12px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    opacity: 0;
    animation: fadeInUp 1s ease 0.8s forwards;
}

.status.active {
    background: rgba(0, 255, 136, 0.2);
    border-color: rgba(0, 255, 136, 0.5);
    color: #00ff88;
}

.controls {
    position: absolute;
    bottom: 4px;
    left: 2px;
    right: 2px;
    width: calc(100% - 4px);
    font-size: 10px;
    opacity: 0.6;
    text-align: center;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
}

/* Tab System */
.tab-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.tab-nav {
    display: flex;
    height: 40px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0 0 10px 10px;
    padding: 2px;
    justify-content: space-between;
}

.tab-button {
    flex: 1;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 16px;
    font-weight: 600;
    border-radius: 6px;
    transition: background-color 0.2s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 2px;
    position: relative;
    transform: translate3d(0, 0, 0);
    /* Removed will-change to reduce memory overhead */
}

.tab-button.active {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    backdrop-filter: blur(10px);
}

.tab-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.tab-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transform: translate3d(0, 0, 0);
    transition: opacity 0.2s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 3px 15px 3px;
    pointer-events: none;
    /* ✅ FIXED: Prevent inactive panels from blocking clicks */
}

.tab-panel.active {
    opacity: 1;
    pointer-events: auto;
    /* ✅ FIXED: Allow clicks on active panel */
}

/* Widget Styles */
.widget {
    width: 100%;
    margin-bottom: 3px;
    text-align: center;
}

.widget label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.8;
}

/* Slider Styles */
.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 5px 8px;
    width: 100%;
}

.slider-track {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    position: relative;
}

.slider-thumb {
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: -5px;
    left: 0;
    /* Transform is set dynamically via JS for GPU acceleration */
    transform: translateX(calc(50 * 2.04px - 50%)); /* Initial position at 50% */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    transition: transform 0.2s ease; /* Only transition transform for better performance */
}

#scroll-value {
    font-size: 18px;
    font-weight: 600;
    min-width: 38px;
    text-align: center;
}

/* Touch Display */
.touch-display {
    width: calc(100% - 16px);
    height: 70px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin: 5px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Canvas-based touch indicator (GPU-accelerated) */
#touch-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 204px;
    height: 60px;
}

/* Legacy touch-indicator styles - no longer used (rendered on canvas) */

.touch-coords {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    z-index: 10; /* Above canvas */
    opacity: 0.8;
    font-weight: 600;
    pointer-events: none;
}

/* Button Status */
.button-status {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 5px 8px;
}

.btn-indicator {
    flex: 1;
    height: 22px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-indicator.active {
    background: rgba(0, 255, 136, 0.2);
    border-color: rgba(0, 255, 136, 0.5);
    color: #00ff88;
    transform: scale(1.05);
    box-shadow: 0 0 12px rgba(0, 255, 136, 0.3);
}

/* Hardware Demo Container */
.hardware-demo {
    width: 100%;
    max-width: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* Sensor Styles */
.leveler-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    gap: 10px;
}

.leveler-section,
.shake-section,
.readings-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.section-label {
    font-size: 9px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Canvas-based sensor visualization (GPU-accelerated) */
#sensor-canvas {
    width: 85px;
    height: 85px;
    display: block;
    /* Leveler circle rendered via GPU-accelerated canvas */
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
}

#arrow-canvas {
    width: 60px;
    height: 60px;
    display: block;
    /* Motion arrow rendered via GPU-accelerated canvas */
}

/* Legacy DOM-based styles - no longer used (replaced by canvas) */
/* .leveler-circle, .leveler-crosshair, .leveler-bubble now rendered on canvas */

.sensor-readings {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 60px;
}

.reading-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
}

.reading-label {
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
}

.reading-value {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: #00ff88;
}

/* Shake Detector Styles */
.shake-detector {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.shake-indicator {
    width: 52px;
    height: 52px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    margin-bottom: 2px;
}

.shake-indicator.active {
    background: rgba(255, 107, 107, 0.3);
    border-color: rgba(255, 107, 107, 0.8);
    transform: scale(1.15);
    box-shadow: 0 0 12px rgba(255, 107, 107, 0.6);
    animation: shake-pulse 0.5s ease;
}

.shake-icon {
    font-size: 28px;
    transition: transform 0.3s ease;
}

.shake-indicator.active .shake-icon {
    transform: rotate(15deg);
}

.shake-count {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.1);
    padding: 3px 8px 2px 8px;
    border-radius: 4px;
    min-width: 32px;
    text-align: center;
    font-family: 'Courier New', monospace;
}

@keyframes shake-pulse {
    0%, 100% {
        transform: scale(1.15);
    }
    50% {
        transform: scale(1.25);
    }
}

/* Motion Grid Styles */
.motion-grid {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 35px 35px;
    gap: 3px;
}

.motion-cell {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* Tilt Angles Cell */
.tilt-angles {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 2px 4px;
}

.tilt-label {
    font-size: 8px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
}

.tilt-value {
    font-size: 13px;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    color: #00ff88;
}

/* Motion Arrow Cell */
.motion-arrow-cell {
    background: rgba(255, 255, 255, 0.05);
    grid-row: span 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Legacy motion-arrow styles - no longer used (rendered on canvas) */
/* .motion-arrow now rendered on sensor-canvas */

/* Orientation Cell */
.orientation-cell {
    padding: 3px;
}

.orientation-label {
    font-size: 13px;
    font-weight: 600;
    color: #00ff88;
    font-family: 'Courier New', monospace;
}

/* Storage Styles - Unified & Compact */
.widget-compact {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    padding: 4px;
    margin-bottom: 3px;
}

.widget-compact label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 9px;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.9;
}

.item-count {
    font-size: 8px;
    color: white;
    font-family: 'Courier New', monospace;
    font-weight: 400;
}

/* Storage Type Selector */
.storage-type-selector {
    display: flex;
    gap: 6px;
    margin-bottom: 4px;
    width: 100%;
}

.storage-type-option {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    padding: 4px 8px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.75;
    display: flex;
    align-items: center;
    justify-content: center;
}

.storage-type-option:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.3);
    opacity: 1;
}

.storage-type-option.active {
    background: rgba(0, 255, 136, 0.2);
    border-color: rgba(0, 255, 136, 0.6);
    opacity: 1;
}

.storage-input-compact {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 3px 5px;
    border-radius: 3px;
    font-size: 10px;
    font-family: 'Courier New', monospace;
    margin-bottom: 2px;
    transition: all 0.2s ease;
}

.storage-input-compact:focus {
    outline: none;
    border-color: rgba(0, 255, 136, 0.5);
    background: rgba(0, 0, 0, 0.4);
}

.storage-input-compact::placeholder {
    color: rgba(255, 255, 255, 0.3);
    font-size: 9px;
}

.storage-input-compact:last-child {
    margin-bottom: 0;
}

.storage-btn-row {
    display: flex;
    gap: 2px;
    margin-bottom: 2px;
    width: 100%;
}

.storage-btn-unified,
.message-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 3px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    height: 17px;
}

.storage-btn-unified:hover,
.message-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(0, 255, 136, 0.5);
}

.storage-btn-unified:active,
.message-btn:active {
    background: rgba(0, 255, 136, 0.2);
    transform: scale(0.98);
}

.storage-output {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
    padding: 4px 5px;
    font-size: 10px;
    font-family: 'Courier New', monospace;
    color: #00ff88;
    border: 1px solid rgba(255, 255, 255, 0.15);
    flex: 1;
    width: 100%;
    word-break: break-all;
    white-space: pre-wrap;
    overflow-y: auto;
    line-height: 1.3;
    scroll-behavior: smooth;
}

.storage-output.error {
    color: #ff6b6b;
    border-color: rgba(255, 107, 107, 0.3);
}

.usage-fill {
    width: 100%;
    background: linear-gradient(180deg, #00ff88, #00cc66);
    height: 0%;
    position: absolute;
    bottom: 0;
    transition: height 0.3s ease;
    border-radius: 10px;
}

/* LLM Styles */
.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ff4444;
    transition: background-color 0.3s ease;
    flex-shrink: 0;
}

.status-indicator.connected {
    background: #00ff88;
    box-shadow: 0 0 6px rgba(0, 255, 136, 0.6);
}

.message-controls {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.response-display {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
    padding: 4px 5px;
    font-size: 10px;
    color: #00ff88;
    border: 1px solid rgba(255, 255, 255, 0.15);
    flex: 1;
    width: 100%;
    overflow-y: auto;
    word-wrap: break-word;
    font-family: 'Courier New', monospace;
    line-height: 1.3;
    margin-top: 5px;
    margin-bottom: 3px;
    max-height: 120px;
    scroll-behavior: smooth;
}

/* Toggle switches for LLM options */
.llm-toggles {
    display: flex;
    gap: 8px;
    margin-bottom: 5px;
    justify-content: space-between;
    width: 100%;
}

.toggle-option {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 8px;
    opacity: 0.9;
    flex: 1;
    justify-content: center;
}

.toggle-checkbox {
    appearance: none;
    width: 28px;
    height: 14px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 7px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-checkbox:checked {
    background: rgba(0, 255, 136, 0.3);
    border-color: rgba(0, 255, 136, 0.5);
}

.toggle-checkbox::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: white;
    top: 1px;
    left: 1px;
    transition: all 0.2s ease;
}

.toggle-checkbox:checked::after {
    left: 15px;
    background: #00ff88;
}

.toggle-label {
    font-size: 8px;
    font-weight: 600;
    white-space: nowrap;
}

.pulse {
    animation: pulse 2s infinite;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: float 6s infinite ease-in-out;
}

.particle:nth-child(1) {
    top: 20%;
    left: 10%;
    animation-delay: 0s;
}

.particle:nth-child(2) {
    top: 60%;
    left: 85%;
    animation-delay: 2s;
}

.particle:nth-child(3) {
    top: 80%;
    left: 15%;
    animation-delay: 4s;
}

.particle:nth-child(4) {
    top: 30%;
    left: 80%;
    animation-delay: 1s;
}

.particle:nth-child(5) {
    top: 70%;
    left: 70%;
    animation-delay: 3s;
}

/* Enhanced animations */
.particle.interactive {
    animation-duration: 3s;
    background: linear-gradient(45deg, rgba(0, 255, 136, 0.8), rgba(102, 126, 234, 0.6));
}

.tab-button:hover:not(.active) {
    background: rgba(255, 255, 255, 0.15);
}

/* Overview Tab Specific Styles */
.overview-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 5px;
    padding-bottom: 20px;
    /* Reduced space for controls overlap */
}

.overview-content .logo {
    margin-bottom: 5px;
}

.overview-content h1 {
    margin-bottom: 3px;
}

.overview-content .subtitle {
    margin-bottom: 5px;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0px) rotate(0deg);
        opacity: 0.6;
    }

    50% {
        transform: translateY(-20px) rotate(180deg);
        opacity: 1;
    }
}
