:root {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #2481cc;
    --tg-theme-button-color: #2481cc;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f1f1f1;
    --viewport-height: 100vh;
    
    --color-primary: #2c3e50;
    --color-secondary: #34495e;
    --color-success: #27ae60;
    --color-warning: #f39c12;
    --color-danger: #e74c3c;
    --color-info: #3498db;
    
    --border-radius: 8px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
    
    /* Light theme - additional variables */
    --bg-primary: rgba(255, 255, 255, 0.95);
    --bg-secondary: rgba(0, 0, 0, 0.05);
    --bg-tertiary: rgba(0, 0, 0, 0.03);
    --text-primary: var(--tg-theme-text-color);
    --text-secondary: var(--tg-theme-hint-color);
    --border-color: rgba(0, 0, 0, 0.1);
}

/* Dark theme */
[data-theme="dark"], .dark-theme {
    --tg-theme-bg-color: #17212b;
    --tg-theme-text-color: #ffffff;
    --tg-theme-hint-color: #708499;
    --tg-theme-link-color: #6ab7ff;
    --tg-theme-button-color: #5288c1;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #232e3c;
    
    --color-primary: #6ab7ff;
    --color-secondary: #5288c1;
    --color-success: #4daf6e;
    --color-warning: #ffa85c;
    --color-danger: #ff6b8a;
    --color-info: #6ab7ff;
    
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    
    /* Dark theme - additional variables */
    --bg-primary: rgba(35, 46, 60, 0.95);
    --bg-secondary: rgba(255, 255, 255, 0.08);
    --bg-tertiary: rgba(255, 255, 255, 0.04);
    --text-primary: var(--tg-theme-text-color);
    --text-secondary: var(--tg-theme-hint-color);
    --border-color: rgba(255, 255, 255, 0.12);
}

/* Base button styles for all platforms */
.action-button,
.location-button {
    /* Basic button properties */
    display: block;
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    
    /* Ensure visibility */
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    
    /* Mobile optimizations */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    
    /* Proper positioning */
    position: relative;
    z-index: 1;
    
    /* Background clipping */
    background-clip: padding-box;
    
    /* Minimum touch target */
    min-height: 44px;
    
    /* Desktop Telegram WebView fix */
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}

.action-button {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    margin-bottom: 8px;
}

.action-button:hover,
.action-button:focus {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    outline: none;
    opacity: 0.9;
}

.action-button:active {
    transform: translateY(0) scale(0.98);
    transition: transform 0.1s ease;
    opacity: 0.8;
}

.action-button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.location-button {
    border: 2px solid var(--tg-theme-button-color);
    background: transparent;
    color: var(--tg-theme-button-color);
    margin-bottom: 6px;
}

.location-button:hover,
.location-button:focus {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    outline: none;
    opacity: 0.9;
}

.location-button:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
    opacity: 0.8;
}

.location-button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
}

#game-container {
    max-width: 420px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: visible;
}

#character-status {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

#time-display {
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 12px;
    color: var(--color-primary);
}

.need-container {
    margin-bottom: 8px;
}

.need-label {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.need-bar {
    width: 100%;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.need-fill {
    height: 100%;
    border-radius: 4px;
    transition: var(--transition);
    position: relative;
}

.need-good {
    background: linear-gradient(90deg, #27ae60, #2ecc71);
}

.need-medium {
    background: linear-gradient(90deg, #f39c12, #f1c40f);
}

.need-low {
    background: linear-gradient(90deg, #e67e22, #f39c12);
}

.need-critical {
    background: linear-gradient(90deg, #e74c3c, #c0392b);
    animation: pulse 1s infinite;
}

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

#location-display {
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

#location-name {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-primary);
}

#location-description {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.4;
}

#inventory-display {
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

#inventory-display h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--color-primary);
}

#inventory-items {
    display: grid;
    gap: 8px;
}

.inventory-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 14px;
    border: 1px solid var(--border-color);
}

.item-name {
    font-weight: 500;
    flex: 1;
    color: var(--text-primary);
}

.item-amount {
    margin: 0 8px;
    color: var(--color-info);
    font-weight: 600;
}

.item-weight {
    font-size: 12px;
    color: var(--text-secondary);
}

.empty-inventory {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    padding: 20px;
}

#actions-menu {
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: var(--shadow);
    flex: 1;
    border: 1px solid var(--border-color);
    overflow-y: auto;
    max-height: 50vh;
}

#actions-menu h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--color-primary);
}

#actions-list {
    display: grid;
    gap: 8px;
    overflow-y: auto;
    max-height: calc(50vh - 60px);
}

.action-time,
.action-energy {
    font-size: 12px;
    opacity: 0.8;
}

.no-actions {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    padding: 20px;
}

#navigation {
    margin-top: auto;
}

#navigation h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-primary);
}

#location-buttons {
    display: grid;
    gap: 6px;
}

.location-condition {
    font-size: 12px;
    opacity: 0.7;
}

#message-display {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-primary);
    color: white;
    padding: 12px 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    z-index: 1000;
    max-width: calc(100vw - 40px);
    text-align: center;
    font-weight: 500;
    display: none;
}

.message-info {
    background: var(--color-info);
}

.message-success {
    background: var(--color-success);
}

.message-warning {
    background: var(--color-warning);
}

.message-error {
    background: var(--color-danger);
}

.error-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--color-danger);
    color: white;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    z-index: 3000;
    text-align: center;
    font-weight: 500;
}

@media (max-width: 480px) {
    #game-container {
        padding: 12px;
        gap: 12px;
    }
    
    #character-status,
    #location-display,
    #inventory-display,
    #actions-menu {
        padding: 12px;
    }
    
    .action-button {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .location-button {
        padding: 8px 10px;
        font-size: 13px;
    }
}

@media (max-height: 600px) {
    #game-container {
        gap: 8px;
    }
    
    #character-status,
    #location-display,
    #inventory-display,
    #actions-menu {
        padding: 10px;
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-in;
}

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

/* Desktop Telegram specific fixes */
.telegram-desktop {
    height: auto;
    min-height: calc(var(--vh, 1vh) * 100);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.telegram-desktop body {
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100vh;
}

.telegram-desktop .action-button,
.telegram-desktop .location-button {
    /* Force hardware acceleration */
    transform: translateZ(0);
    backface-visibility: hidden;
    will-change: transform;
    
    /* Ensure clickability */
    position: relative;
    z-index: 10;
}

.telegram-desktop .action-button::before,
.telegram-desktop .location-button::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    z-index: -1;
}

/* Fix for desktop hover states */
@media (hover: hover) and (pointer: fine) {
    .action-button:hover,
    .location-button:hover {
        filter: brightness(1.1);
    }
    
    .action-button:active,
    .location-button:active {
        filter: brightness(0.9);
    }
}

/* Ensure buttons work in all WebView contexts */
button {
    -webkit-app-region: no-drag;
    app-region: no-drag;
}

/* Pointer events support */
@supports (pointer-events: auto) {
    .action-button,
    .location-button {
        pointer-events: auto !important;
    }
    
    .action-button[disabled],
    .location-button[disabled] {
        pointer-events: none !important;
    }
}

/* Additional desktop fixes */
.telegram-desktop button {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

/* Ensure proper stacking context */
#actions-menu,
#navigation {
    position: relative;
    z-index: 100;
}

#actions-list,
#location-buttons {
    position: relative;
    z-index: 101;
}

/* Force GPU acceleration for smoother interactions */
.action-button,
.location-button {
    -webkit-transform: translate3d(0, 0, 0);
    -moz-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}