/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Custom properties for viewport height */
:root {
    --vh: 1vh; /* Fallback */
    --real-viewport-height: 100vh; /* Fallback */
}

/* Add smooth scrolling for the entire page */
html {
    scroll-behavior: smooth;
    /* Prevent iOS Safari from zooming on inputs */
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: #000000;
    color: #ffffff;
    line-height: 1.6;
    height: 100vh;
    /* Use -webkit-fill-available for iOS Safari */
    height: -webkit-fill-available;
    /* Use custom property for accurate height */
    height: var(--real-viewport-height);
    overflow: hidden; /* Prevent body scrolling */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
    /* Add safe area support for iOS devices with notch */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.container {
    height: 100vh;
    height: -webkit-fill-available;
    height: var(--real-viewport-height);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Ensure container respects safe areas */
    position: relative;
}

/* Header styles */
header {
    padding: 10px 20px;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    /* Ensure header is always visible on iOS */
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: #000000;
}

header h1 {
    font-size: 2.5rem;
    color: #ffffff;
    margin-bottom: 10px;
    text-align: center;
}

nav {
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-link,
.change-api-key-btn,
.symbol-selector {
    color: #ffffff;
    text-decoration: none;
    padding: 6px 14px;
    border: 1px solid #666;
    border-radius: 4px;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    font-size: 0.85rem;
    background-color: transparent;
    cursor: pointer;
    font-family: inherit;
    line-height: 1;
    /* Ensure consistent height for all buttons */
    height: 36px;
    /* Normalize appearance across browsers */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.symbol-selector {
    min-width: 80px;
    /* Additional styling for select element */
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='6'%3E%3Cpath d='M0 0l6 6 6-6' fill='%23ffffff'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 12px 6px;
    padding-right: 28px; /* Make room for arrow */
}

.symbol-selector option {
    background-color: #111111;
    color: #ffffff;
}

.nav-link:hover,
.change-api-key-btn:hover,
.symbol-selector:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: #ffffff;
    transform: scale(1.05);
}

.symbol-selector:focus {
    outline: none;
    border-color: #ffffff;
}

.symbol-selector:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.symbol-selector:disabled:hover {
    transform: none;
    background-color: transparent;
    border-color: #666;
}

/* Main content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* Important for Firefox */
}

/* Content wrapper */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Main layout - side by side */
.main-layout {
    display: flex;
    height: 100%;
    gap: 20px;
    padding: 20px;
    overflow: hidden;
    flex: 1;
}

/* Events section - Left side (30%) */
.events-section {
    width: 30%;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for overflow to work */
}

/* Chart section - Right side (70%) */
.chart-section {
    width: 70%;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for overflow to work */
}

/* Loading styles */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid #ffffff;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading p {
    color: #ffffff;
    font-size: 1.2rem;
    margin-bottom: 5px;
}

.loading-detail {
    color: #888888;
    font-size: 0.9rem;
    margin-top: 5px;
}

/* Chart container */
.chart-container {
    background: #000000;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 20px;
    flex: 1;
    position: relative;
    min-height: 0;
    overflow: hidden;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.9);
    /* Prevent text selection and context menus */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.chart-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(1px 1px at 20% 30%, white, transparent),
        radial-gradient(1px 1px at 60% 70%, white, transparent),
        radial-gradient(0.5px 0.5px at 50% 50%, white, transparent),
        radial-gradient(0.5px 0.5px at 80% 20%, white, transparent),
        radial-gradient(0.5px 0.5px at 10% 80%, white, transparent),
        radial-gradient(1px 1px at 95% 40%, white, transparent),
        radial-gradient(0.5px 0.5px at 40% 90%, white, transparent);
    background-size: 200% 200%;
    background-position: 50% 50%;
    animation: twinkle 15s ease-in-out infinite;
    opacity: 0.4;
    pointer-events: none;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 0.1; transform: scale(1.1); }
}

.chart-container canvas {
    max-width: 100%;
    max-height: 100%;
    position: relative;
    z-index: 1;
    /* Prevent text selection on canvas */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    /* Prevent default touch behaviors */
    touch-action: none;
}

.chart-container h2 {
    color: #ffffff;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.8rem;
}

#sentimentChart {
    background-color: transparent;
    border-radius: 5px;
}

/* Chart navigation buttons */
.chart-nav-btn {
    position: absolute;
    bottom: 20px;
    left: 0;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-left: none;
    color: #cccccc;
    width: auto;
    min-width: 60px;
    height: 36px;
    padding: 0 8px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.3s ease;
    z-index: 10;
    border-radius: 0 4px 4px 0;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

/* Constellation animation */
@keyframes constellationGlow {
    0% {
        opacity: 0.15;
        filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.2));
    }
    50% {
        opacity: 0.5;
        filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.6));
    }
    100% {
        opacity: 0.15;
        filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.2));
    }
}

/* Enhanced star glow animation */
@keyframes starPulse {
    0% {
        transform: scale(1);
        filter: drop-shadow(0 0 5px currentColor);
    }
    50% {
        transform: scale(1.2);
        filter: drop-shadow(0 0 15px currentColor);
    }
    100% {
        transform: scale(1);
        filter: drop-shadow(0 0 5px currentColor);
    }
}

.chart-nav-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
    border-left: none;
    color: #ffffff;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

.chart-nav-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

.chart-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    box-shadow: none;
}

.chart-nav-btn:disabled:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
    border-left: none;
    color: #cccccc;
    box-shadow: none;
}

.chart-nav-left {
    /* No additional styles needed - positioned by parent */
}

.click-counter {
    font-size: 12px;
    font-weight: bold;
    background-color: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 4px;
}

/* Chunk loading indicator */
.chunk-loading {
    position: absolute;
    top: 10px;
    left: 10px;
    background-color: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    padding: 8px 15px;
    border-radius: 4px;
    font-size: 0.85rem;
    display: none;
    z-index: 100;
    flex-direction: column;
    gap: 4px;
}

.chunk-loading.active {
    display: flex;
}

.chunk-loading-detail {
    color: #888888;
    font-size: 0.75rem;
}

/* Data summary */
.data-summary {
    background-color: #111111;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 30px;
}

.data-summary h3 {
    color: #ffffff;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.5rem;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: #000000;
    border: 1px solid #333;
    border-radius: 5px;
}

.summary-item .label {
    color: #cccccc;
    font-weight: bold;
}

.summary-item .value {
    color: #ffffff;
    font-weight: bold;
}

/* Events list */
.events-list {
    background: #000000;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8);
}

#eventsContainer {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 10px;
    min-height: 0; /* Important for scrolling */
}

/* Custom scrollbar for events container */
#eventsContainer::-webkit-scrollbar {
    width: 8px;
}

#eventsContainer::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

#eventsContainer::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

#eventsContainer::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.event-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
}

.event-item:last-child {
    margin-bottom: 0;
}

.event-item:hover {
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
}

.event-item.highlighted {
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.2);
}

.event-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.event-timestamp {
    color: #cccccc;
    font-size: 0.9rem;
}

.event-sentiment {
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
}

.event-sentiment.bullish {
    background-color: #004400;
    color: #00ff00;
}

.event-sentiment.bearish {
    background-color: #440000;
    color: #ff0000;
}

.event-sentiment.neutral {
    background-color: #333333;
    color: #ffffff;
}

.event-summary {
    color: #ffffff;
    line-height: 1.4;
}

.event-footer {
    margin-top: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.event-type {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-block;
}

/* Event Type Legend */
.event-type-legend {
    background-color: #111111;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 15px;
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #000;
}

.legend-label {
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Chunk Summary Styles */
.chunk-summary {
    padding: 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chunk-summary-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 10px;
}

.summary-section {
    margin-bottom: 25px;
    animation: fadeIn 0.5s ease-in-out;
}

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

.summary-type {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.summary-text {
    color: #ffffff;
    line-height: 1.6;
    font-size: 0.95rem;
}

.summary-hint {
    text-align: center;
    color: #888888;
    font-size: 0.85rem;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-style: italic;
}

/* Progressive constellation animation styles */
@keyframes starGlow {
    0% {
        filter: brightness(1) drop-shadow(0 0 3px currentColor);
    }
    50% {
        filter: brightness(1.5) drop-shadow(0 0 10px currentColor);
    }
    100% {
        filter: brightness(1) drop-shadow(0 0 3px currentColor);
    }
}

/* Canvas glow effect during animation */
.chart-container.animating-constellation {
    animation: subtleGlow 2s ease-in-out;
}

@keyframes subtleGlow {
    0% {
        box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8);
    }
    50% {
        box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8), inset 0 0 50px rgba(255, 255, 255, 0.05);
    }
    100% {
        box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8), inset 0 0 60px rgba(255, 255, 255, 0.1);
    }
}

/* Custom scrollbar for summary content */
.chunk-summary-content::-webkit-scrollbar {
    width: 8px;
}

.chunk-summary-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.chunk-summary-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.chunk-summary-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Error styles */
.error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.error h3 {
    color: #ff0000;
    margin-bottom: 15px;
    font-size: 1.5rem;
}

.error p {
    color: #cccccc;
    margin-bottom: 20px;
}

.error-link {
    color: #00FFC8;
    text-decoration: none;
    border-bottom: 1px solid #00FFC8;
    transition: all 0.3s ease;
}

.error-link:hover {
    color: #ffffff;
    border-bottom-color: #ffffff;
}

.retry-button {
    background-color: #ffffff;
    color: #000000;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.3s ease;
}

.retry-button:hover {
    background-color: #cccccc;
    transform: scale(1.05);
}

/* Footer */
footer {
    padding: 15px 20px;
    border-top: 1px solid #333;
    flex-shrink: 0;
    background-color: #000000;
    /* Ensure footer is always at the bottom */
    margin-top: auto;
    /* Add safe area for bottom on iOS */
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
}

#footer {
    text-align: center;
    color: #cccccc;
    font-size: 12px;
}

/* API Key Modal */
.api-key-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.api-key-modal-content {
    background-color: #111111;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    max-height: 90vh;
    overflow-y: auto;
}

.api-key-modal-content h2 {
    color: #ffffff;
    margin-bottom: 20px;
    font-size: 1.8rem;
}

.api-key-modal-content h3 {
    color: #ffffff;
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.api-key-modal-content p {
    color: #cccccc;
    margin-bottom: 20px;
    line-height: 1.5;
}

/* View API Key Modal specific styles */
.api-key-view-modal {
    max-width: 600px;
}

.api-key-info {
    margin: 20px 0;
}

.api-key-display-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 15px 0;
    padding: 15px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    border: 1px solid #333;
}

.api-key-display {
    font-family: monospace;
    background-color: transparent;
    padding: 0;
    border-radius: 3px;
    font-size: 0.9rem;
    display: inline-block;
    word-break: break-all;
    color: #ffffff;
    flex: 1;
    text-align: left;
}

.copy-btn {
    background-color: #00FFC8;
    color: #000000;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.copy-btn:hover {
    background-color: #00ccaa;
    transform: scale(1.05);
}

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

/* API Key Sections */
.api-key-section {
    margin-bottom: 25px;
}

.api-key-divider {
    text-align: center;
    margin: 25px 0;
    position: relative;
}

.api-key-divider span {
    background-color: #111111;
    padding: 0 15px;
    color: #888888;
    position: relative;
    z-index: 1;
}

.api-key-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background-color: #333;
    z-index: 0;
}

/* Form Inputs */
#apiKeyInput,
.register-form input {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    background-color: #000000;
    border: 1px solid #333;
    border-radius: 5px;
    color: #ffffff;
    margin-bottom: 15px;
    font-family: inherit;
    box-sizing: border-box;
}

#apiKeyInput {
    font-family: monospace;
}

#apiKeyInput:focus,
.register-form input:focus {
    outline: none;
    border-color: #00FFC8;
    box-shadow: 0 0 0 2px rgba(0, 255, 200, 0.2);
}

/* Submit Buttons */
.api-key-submit-btn {
    background-color: #00FFC8;
    color: #000000;
    border: none;
    padding: 10px 30px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.3s ease;
    width: 100%;
}

.api-key-submit-btn:hover {
    background-color: #00ccaa;
    transform: scale(1.02);
}

.api-key-submit-btn:disabled {
    background-color: #666666;
    cursor: not-allowed;
    transform: none;
}

/* Registration Form */
.register-form {
    margin: 0;
}

/* Registration Results */
.register-error {
    background-color: rgba(255, 0, 0, 0.1);
    border: 1px solid #ff0000;
    color: #ff6666;
    padding: 10px;
    border-radius: 5px;
    margin-top: 15px;
}

.register-success {
    background-color: rgba(0, 255, 200, 0.1);
    border: 1px solid #00FFC8;
    color: #00FFC8;
    padding: 15px;
    border-radius: 5px;
    margin-top: 15px;
}

.register-success p {
    margin: 5px 0;
    color: #00FFC8;
}

.register-info {
    font-size: 0.9rem;
    color: #cccccc !important;
    margin-top: 10px !important;
}

.topup-link {
    color: #00FFC8;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.3s ease;
}

.topup-link:hover {
    border-bottom-color: #00FFC8;
}

/* API key display for registration success */
.register-success .api-key-display {
    font-family: monospace;
    background-color: rgba(0, 0, 0, 0.5);
    padding: 5px 10px;
    border-radius: 3px;
    font-size: 0.9rem;
    display: inline-block;
    margin-top: 5px;
    word-break: break-all;
    color: #ffffff;
}

.api-key-modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 15px;
}

.api-key-modal-buttons button {
    background-color: #00FFC8;
    color: #000000;
    border: none;
    padding: 10px 30px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.3s ease;
}

.api-key-modal-buttons button:hover {
    background-color: #00ccaa;
    transform: scale(1.05);
}

.api-key-link {
    color: #ffffff;
    text-decoration: none;
    padding: 10px 20px;
    border: 1px solid #ffffff;
    border-radius: 5px;
    transition: all 0.3s ease;
    display: inline-block;
}

.api-key-link:hover {
    background-color: #ffffff;
    color: #000000;
}

.api-key-note {
    color: #888888;
    font-size: 0.9rem;
    margin-top: 15px;
}

/* Responsive design */
@media (max-width: 768px) {
    /* Container adjustments */
    .container {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
        height: -webkit-fill-available; /* iOS Safari specific */
        min-height: -webkit-fill-available;
    }
    
    /* Body adjustments for mobile */
    body {
        /* Reset safe area padding on mobile for better space usage */
        padding: 0;
        /* Apply safe areas only where needed */
        padding-top: env(safe-area-inset-top);
    }
    
    /* Header adjustments */
    header {
        padding: 10px 15px;
        position: sticky;
        top: 0;
        background-color: rgba(0, 0, 0, 0.95);
        backdrop-filter: blur(10px);
        z-index: 100;
        /* Add safe area for top */
        padding-top: calc(10px + env(safe-area-inset-top));
    }
    
    /* Main content adjustment */
    main {
        /* Calculate height accounting for safe areas */
        height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
    
    /* Main layout changes */
    .main-layout {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
        /* Use available height minus header and footer */
        height: auto;
        flex: 1;
        min-height: 0;
    }
    
    /* Events section on mobile */
    .events-section,
    .chart-section {
        width: 100%;
    }
    
    .events-section {
        height: 40%;
        min-height: 250px;
        order: 2; /* Show events below chart on mobile */
    }
    
    .chart-section {
        height: 60%;
        min-height: 300px;
        order: 1; /* Show chart above events on mobile */
    }
    
    /* Events list adjustments */
    .events-list {
        padding: 15px;
    }
    
    .event-item {
        padding: 12px;
        margin-bottom: 8px;
    }
    
    .event-header {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .event-timestamp {
        font-size: 0.8rem;
    }
    
    .event-summary {
        font-size: 0.9rem;
        line-height: 1.5;
    }
    
    .event-footer {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    /* Chart container adjustments */
    .chart-container {
        padding: 10px; /* Reduced padding since no legend */
        padding-bottom: 60px; /* Space for navigation button */
    }
    
    /* Hide the starfield background on mobile to improve performance */
    .chart-container::before {
        display: none;
    }
    
    /* Chart navigation button adjustments */
    .chart-nav-btn {
        bottom: 10px;
        height: 42px;
        min-width: 50px;
        font-size: 16px;
        padding: 0 8px;
        gap: 2px;
    }
    
    .click-counter {
        font-size: 11px;
        padding: 2px 4px;
        margin-left: 2px;
    }
    
    /* Chunk loading indicator */
    .chunk-loading {
        font-size: 0.8rem;
        padding: 6px 12px;
    }
    
    /* API Key Modal on mobile */
    .api-key-modal-content {
        padding: 20px;
        width: 95%;
        max-width: 100%;
        max-height: 85vh;
    }
    
    .api-key-view-modal {
        max-width: 100%;
    }
    
    .api-key-display-container {
        flex-direction: column;
        gap: 8px;
        padding: 12px;
    }
    
    .api-key-display {
        font-size: 0.8rem;
        text-align: center;
        padding: 8px 0;
    }
    
    .copy-btn {
        width: 100%;
        padding: 10px;
    }
    
    .api-key-section {
        margin-bottom: 20px;
    }
    
    .api-key-divider {
        margin: 20px 0;
    }
    
    #apiKeyInput,
    .register-form input {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 10px;
    }
    
    .api-key-submit-btn {
        padding: 12px 20px;
        font-size: 0.95rem;
    }
    
    .register-error,
    .register-success {
        font-size: 0.9rem;
        padding: 8px;
    }
    
    .api-key-modal-buttons {
        flex-direction: column;
        width: 100%;
    }
    
    .api-key-modal-buttons button,
    .api-key-link {
        width: 100%;
        text-align: center;
    }
    
    /* Navigation adjustments */
    nav {
        flex-direction: row;
        flex-wrap: nowrap; /* Prevent wrapping to keep all buttons in one row */
        justify-content: space-between;
        gap: 5px; /* Slightly larger gap for better spacing */
        overflow-x: auto; /* Allow horizontal scroll if needed */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        align-items: stretch; /* Make all items same height */
    }
    
    .nav-link,
    .change-api-key-btn,
    .symbol-selector {
        font-size: 0.75rem; /* Slightly larger font */
        padding: 6px 8px; /* More comfortable padding */
        margin: 0;
        height: 34px; /* Slightly taller for better touch targets */
        min-height: 34px;
        flex: 1 1 auto; /* Allow buttons to grow and fill space */
        white-space: nowrap; /* Prevent text wrapping */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Specific sizing for each button type */
    .nav-link {
        flex: 0 0 auto; /* Don't grow, just fit content */
        min-width: 65px;
    }
    
    .symbol-selector {
        flex: 0 0 auto; /* Don't grow, just fit content */
        min-width: 65px;
        max-width: 75px;
        background-size: 10px 5px; /* Slightly larger arrow */
        padding-right: 20px; /* Adjust for arrow */
        font-size: 0.75rem;
    }
    
    .view-api-key-btn {
        flex: 1 1 auto; /* Grow to fill space */
        min-width: 0; /* Allow shrinking if needed */
    }
    
    .change-api-key-btn:not(.view-api-key-btn) {
        flex: 1 1 auto; /* Grow to fill space */
        min-width: 0; /* Allow shrinking if needed */
    }
    
    /* Footer adjustments */
    footer {
        padding: 12px 15px;
        position: sticky;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.95);
        backdrop-filter: blur(10px);
    }
    
    #footer {
        font-size: 11px;
    }
    
    /* Loading screen adjustments */
    .loading p {
        font-size: 1.1rem;
    }
    
    .loading-detail {
        font-size: 0.85rem;
    }
    
    /* Error screen adjustments */
    .error h3 {
        font-size: 1.3rem;
    }
    
    .error p {
        font-size: 0.9rem;
        padding: 0 20px;
    }
    
    /* Chunk summary on mobile */
    .chunk-summary {
        padding: 15px;
    }
    
    .summary-section {
        margin-bottom: 20px;
    }
    
    .summary-type {
        font-size: 0.75rem;
        padding: 4px 10px;
    }
    
    .summary-text {
        font-size: 0.9rem;
        line-height: 1.5;
    }
}

/* Small mobile screens */
@media (max-width: 480px) {
    /* Even more compact layout */
    header {
        padding: 8px 10px;
    }
    
    .main-layout {
        padding: 8px;
        gap: 8px;
    }
    
    .events-section {
        height: 35%;
        min-height: 200px;
    }
    
    .chart-section {
        height: 65%;
        min-height: 250px;
    }
    
    .events-list,
    .chart-container {
        padding: 10px;
    }
    
    .event-item {
        padding: 10px;
        margin-bottom: 6px;
    }
    
    .event-timestamp {
        font-size: 0.75rem;
    }
    
    .event-summary {
        font-size: 0.85rem;
    }
    
    .event-sentiment,
    .event-type {
        font-size: 0.7rem;
        padding: 3px 6px;
    }
    
    nav {
        gap: 3px; /* Smaller gap for very small screens */
    }
    
    .nav-link,
    .change-api-key-btn,
    .symbol-selector {
        font-size: 0.7rem; /* Slightly smaller for very small screens */
        padding: 5px 6px; /* Slightly less padding */
        min-height: 32px; /* Slightly smaller height */
        height: 32px;
        line-height: normal; /* Reset line-height to allow flexbox to center properly */
    }
    
    /* More specific sizing for very small screens */
    .nav-link {
        min-width: 55px; /* Smaller minimum */
    }
    
    .symbol-selector {
        min-width: 55px; /* Smaller minimum width */
        max-width: 65px; /* Smaller max width */
        background-size: 8px 4px; /* Smaller arrow */
        padding-right: 18px; /* Adjust for smaller arrow */
        font-size: 0.7rem; /* Ensure font size is applied */
    }
    
    footer {
        padding: 10px;
    }
    
    #footer {
        font-size: 10px;
    }
    
    /* Even more compact chart navigation button */
    .chart-nav-btn {
        height: 38px;
        min-width: 45px;
        font-size: 14px;
        padding: 0 6px;
        gap: 2px; /* Maintain compact gap */
    }
    
    .click-counter {
        font-size: 10px;
        padding: 1px 3px;
    }
}

/* Landscape orientation for mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .main-layout {
        flex-direction: row;
    }
    
    .events-section {
        width: 40%;
        height: 100%;
        min-height: auto;
    }
    
    .chart-section {
        width: 60%;
        height: 100%;
        min-height: auto;
    }
    
    header {
        padding: 6px 15px;
    }
    
    footer {
        padding: 8px 15px;
    }
    
    .main-layout {
        height: calc(100vh - 100px);
        /* iOS Safari fix */
        height: calc(100dvh - 100px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
}

/* Touch device enhancements */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    .nav-link,
    .change-api-key-btn,
    .symbol-selector,
    .chart-nav-btn,
    .retry-button {
        min-height: 44px;
    }
    
    /* Override mobile button heights for better touch targets on touch devices */
    @media (max-width: 768px) {
        .nav-link,
        .change-api-key-btn,
        .symbol-selector {
            height: 40px; /* Larger height for touch devices */
            min-height: 40px;
        }
    }
    
    @media (max-width: 480px) {
        .nav-link,
        .change-api-key-btn,
        .symbol-selector {
            height: 38px; /* Still maintain good touch target on small screens */
            min-height: 38px;
        }
    }
    
    /* Remove hover effects on touch devices */
    .event-item:hover {
        border-color: rgba(255, 255, 255, 0.1);
        background: rgba(255, 255, 255, 0.02);
        box-shadow: none;
    }
    
    /* Make event items more touch-friendly */
    .event-item {
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
        /* Add active state for touch feedback */
        transition: all 0.2s ease;
    }
    
    .event-item:active {
        background: rgba(255, 255, 255, 0.1);
        transform: scale(0.98);
    }
    
    /* Keep highlighted state visible on touch devices */
    .event-item.highlighted {
        border-color: rgba(255, 255, 255, 0.6) !important;
        background: rgba(255, 255, 255, 0.12) !important;
        box-shadow: 0 0 30px rgba(255, 255, 255, 0.3) !important;
    }
    
    /* Improve scrolling performance */
    #eventsContainer {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* Add active states for better feedback */
    .nav-link:active,
    .change-api-key-btn:active,
    .chart-nav-btn:active {
        background-color: rgba(255, 255, 255, 0.2);
    }
    
    /* Chart canvas touch feedback - updated */
    .chart-container canvas {
        /* Allow only pinch zoom, no other touch actions */
        touch-action: pinch-zoom;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
        /* Extra prevention of text selection */
        -webkit-user-select: none !important;
        -webkit-touch-callout: none !important;
    }
    
    /* Long press visual indicator */
    .chart-container::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 80px;
        height: 80px;
        border-radius: 50%;
        background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 70%);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    
    .chart-container.touch-holding::after {
        opacity: 1;
        animation: touchRipple 0.5s ease-out;
    }
    
    @keyframes touchRipple {
        from {
            width: 40px;
            height: 40px;
            opacity: 0.8;
        }
        to {
            width: 80px;
            height: 80px;
            opacity: 1;
        }
    }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Sharper borders and shadows */
    .events-list,
    .chart-container,
    .event-item {
        border-width: 0.5px;
    }
}

/* iOS specific fixes */
.ios-device .container {
    height: calc(var(--vh, 1vh) * 100);
    min-height: calc(var(--vh, 1vh) * 100);
}

/* iOS specific button fixes */
.ios-device .nav-link,
.ios-device .change-api-key-btn,
.ios-device .symbol-selector {
    /* Force consistent appearance on iOS */
    -webkit-appearance: none;
    -webkit-border-radius: 4px;
    /* Ensure consistent rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Fix iOS tap highlight */
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
}

/* Ensure select element looks consistent on iOS */
.ios-device .symbol-selector {
    /* Remove iOS default styling */
    background-color: transparent;
    /* Ensure the custom arrow is visible */
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='6'%3E%3Cpath d='M0 0l6 6 6-6' fill='%23ffffff'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

/* iOS mobile specific */
@media (max-width: 768px) {
    .ios-device .nav-link,
    .ios-device .change-api-key-btn,
    .ios-device .symbol-selector {
        /* Ensure consistent height on iOS mobile */
        height: 34px !important;
        min-height: 34px !important;
        max-height: 34px !important;
        /* Ensure text is vertically centered */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* For touch devices, increase to 40px */
    @media (hover: none) and (pointer: coarse) {
        .ios-device .nav-link,
        .ios-device .change-api-key-btn,
        .ios-device .symbol-selector {
            height: 40px !important;
            min-height: 40px !important;
            max-height: 40px !important;
        }
    }
    
    .ios-device .symbol-selector {
        /* Adjust text position for select */
        text-align: left;
        justify-content: flex-start;
    }
}

.ios-device body {
    height: calc(var(--vh, 1vh) * 100);
    position: fixed;
    width: 100%;
}

.ios-device main {
    height: auto;
    flex: 1;
}

.ios-device .main-layout {
    height: 100%;
}

/* iOS landscape specific */
@media (max-width: 768px) and (orientation: landscape) {
    .ios-device .container {
        height: calc(var(--vh, 1vh) * 100);
    }
    
    .ios-device .main-layout {
        height: calc(100% - 60px); /* Reduced height for smaller header/footer in landscape */
    }
}

/* Prevent overscroll bounce on iOS */
.ios-device body {
    position: fixed;
    overflow: hidden;
    width: 100%;
}

.ios-device .container {
    -webkit-overflow-scrolling: touch;
} 