/* Pro Toolbox - Modern, Clean Design */

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

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #64748b;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #475569;
}

/* Light Mode Theme */
body.light-mode {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --background: #f1f5f9;
    --surface: #ffffff;
    --surface-light: #e2e8f0;
    --text: #0f172a;
    --text-secondary: #475569;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --border: #cbd5e1;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

#app {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
}

/* Screens */
.screen {
    display: none !important;
    min-height: 100vh;
    padding: 20px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--background);
}

.screen.active {
    display: block !important;
    animation: slideIn 0.3s ease;
    position: relative;
}

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

/* Header */
.app-header {
    text-align: center;
    padding: 20px 15px;
    background: linear-gradient(135deg, var(--surface), var(--surface-light));
    border-radius: 0 0 16px 16px;
    margin-bottom: 15px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.app-header h1 {
    font-size: 32px;
    margin-bottom: 5px;
    font-weight: 800;
    letter-spacing: 1.5px;
    background: linear-gradient(135deg, var(--primary), #60a5fa, var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 2px 20px rgba(59, 130, 246, 0.3);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.device-note {
    background: rgba(245, 158, 11, 0.15);
    border: 2px solid rgba(245, 158, 11, 0.3);
    border-radius: 12px;
    padding: 15px 20px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-top: 20px;
}

.device-note strong {
    color: var(--warning);
}

/* Tool Grid */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 0 15px;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

.tool-card {
    background: linear-gradient(135deg, var(--surface), var(--surface-light));
    border-radius: 12px;
    padding: 14px 4px;
    box-sizing: border-box;
    min-width: 0;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid rgba(59, 130, 246, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    position: relative;
}

.tool-card:hover {
    background: linear-gradient(135deg, var(--surface-light), #334155);
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 12px 35px rgba(59, 130, 246, 0.3);
    border-color: var(--primary);
}

.tool-card:active {
    transform: translateY(0);
}

.tool-icon {
    font-size: 40px;
    margin-bottom: 8px;
    display: block;
}

.tool-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
    word-wrap: break-word;
    overflow-wrap: break-word;
    padding: 0 1px;
}

.tool-card .favorite-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    transition: all 0.2s;
    z-index: 10;
}

.tool-card .favorite-btn:hover,
.tool-card .favorite-btn.active {
    opacity: 1;
    background: rgba(243, 156, 18, 0.9);
    transform: scale(1.1);
}

.tool-card:hover .favorite-btn {
    opacity: 0.8;
}

/* Pro Badge */
.pro-badge {
    position: absolute;
    top: 5px;
    left: 5px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: white;
    font-size: 9px;
    font-weight: 700;
    padding: 3px 6px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.4);
    letter-spacing: 0.5px;
}

/* Tool Screen Common Styles */
.tool-screen {
    display: flex;
    flex-direction: column;
}

.tool-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding: 20px;
    background: var(--surface);
    border-radius: 16px;
}

.back-btn {
    background: var(--surface-light);
    border: none;
    color: var(--text);
    font-size: 24px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.back-btn:hover {
    background: var(--primary);
}

.tool-title {
    flex: 1;
    text-align: center;
    font-size: 24px;
    font-weight: 700;
}

.tool-content {
    flex: 1;
    background: var(--surface);
    border-radius: 20px;
    padding: 30px;
    padding-bottom: 90px; /* Extra space for sticky ad at bottom */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Common UI Elements */
.display-large {
    font-size: 72px;
    font-weight: 700;
    color: var(--primary);
    margin: 20px 0;
    font-variant-numeric: tabular-nums;
}

.display-medium {
    font-size: 48px;
    font-weight: 600;
    margin: 15px 0;
}

.label {
    color: var(--text-secondary);
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

.btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 16px 32px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

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

.btn-secondary {
    background: var(--surface-light);
    box-shadow: none;
}

.input-group {
    width: 100%;
    margin: 20px 0;
}

.input-group label {
    display: block;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-size: 14px;
}

.input-group input,
.input-group select {
    width: 100%;
    background: var(--background);
    border: 2px solid var(--border);
    color: var(--text);
    padding: 14px 18px;
    border-radius: 10px;
    font-size: 18px;
    transition: all 0.2s;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Permission Prompt */
.permission-prompt {
    text-align: center;
    padding: 40px;
}

.permission-prompt p {
    color: var(--text-secondary);
    margin: 20px 0;
    line-height: 1.6;
}

/* Mobile Responsive */
@media (max-width: 600px) {
    .tool-grid {
        gap: 15px;
        padding: 0 5px;
    }
    
    .tool-card {
        padding: 25px 15px;
    }
    
    .tool-icon {
        font-size: 52px;
    }
    
    .tool-name {
        font-size: 16px;
    }
    
    .display-large {
        font-size: 56px;
    }
}

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

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Settings Panel Styles */
.settings-section {
    margin-bottom: 30px;
}

.settings-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.settings-item {
    background: var(--surface);
    padding: 16px 18px;
    border-radius: 12px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.settings-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

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

.settings-select {
    background: var(--surface-light);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    min-width: 150px;
}

.settings-select option {
    background: var(--surface);
    color: var(--text);
}

.settings-button {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    transition: all 0.2s;
}

.settings-button:active {
    transform: scale(0.98);
}

/* Toggle Switch */
.settings-toggle {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

.settings-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--surface-light);
    transition: 0.3s;
    border-radius: 28px;
    border: 2px solid var(--border);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 2px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.settings-toggle input:checked + .toggle-slider {
    background-color: var(--primary);
    border-color: var(--primary);
}

.settings-toggle input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    color: var(--text);
    padding: 14px 24px;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
    z-index: 10000;
    font-size: 14px;
    font-weight: 600;
    animation: toastSlideUp 0.3s ease-out;
    border: 1px solid var(--border);
}

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

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

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

@keyframes toastSlideUp {
    from {
        bottom: 60px;
        opacity: 0;
    }
    to {
        bottom: 80px;
        opacity: 1;
    }
}

/* Hardware acceleration */
.tool-card, .btn, .screen {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* ========== SMART HYBRID LAYOUT - COMPACT MOBILE UI ========== */
/* Make everything smaller to fit on mobile screens */

.tool-content {
    padding: 0 10px 10px 10px;
}

/* Full-screen tools (only Star Map and Mirror now) */
#star-map-screen .tool-content,
#mirror-screen .tool-content {
    max-height: 100vh;
    overflow: hidden;
    padding: 0;
}

/* Compact spacing for all tools */
.tool-content > div {
    margin-bottom: 8px !important; /* Much smaller gaps */
}

.tool-content h2, .tool-content h3 {
    font-size: 14px !important; /* Smaller headings */
    margin-bottom: 6px !important;
    padding: 0 !important;
}

.tool-content p, .tool-content .device-note {
    font-size: 11px !important; /* Smaller text */
    line-height: 1.4 !important;
    margin-bottom: 6px !important;
}

/* Compact buttons - MUCH smaller */
.tool-content button, .tool-content .btn {
    padding: 8px 12px !important; /* Much smaller */
    font-size: 12px !important;
    margin: 4px 0 !important;
}

/* Compact info boxes - MUCH smaller */
.tool-content .info-box,
.tool-content [style*="background: rgba"],
.tool-content [style*="padding: 20px"],
.tool-content [style*="padding: 15px"],
.tool-content [style*="padding: 18px"],
.tool-content [style*="padding: 30px"] {
    padding: 8px !important; /* Much smaller padding */
    font-size: 11px !important;
    line-height: 1.4 !important;
    margin-bottom: 6px !important;
}

/* Compact display boxes */
.tool-content .display-box,
.tool-content .display-value,
.tool-content [class*="display"] {
    padding: 10px !important; /* Much smaller */
    font-size: 18px !important; /* Smaller display values */
}

/* Compact labels */
.tool-content .label,
.tool-content label {
    font-size: 11px !important;
    margin-bottom: 4px !important;
}

/* Scrollable sections */
.scrollable-section {
    max-height: 200px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Collapsible Advanced Panel */
.advanced-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.advanced-panel.open {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

/* Compact sliders */
.tool-content input[type="range"] {
    height: 4px !important; /* Much thinner sliders */
    margin: 4px 0 !important; /* Less spacing */
}

/* Compact grid layouts */
.tool-content [style*="display: grid"] {
    gap: 6px !important; /* Smaller gap */
}

/* Compact input fields */
.tool-content input[type="text"],
.tool-content input[type="number"],
.tool-content select {
    padding: 8px !important;
    font-size: 12px !important;
    margin: 4px 0 !important;
}

/* Smaller border radius for tighter look */
.tool-content [style*="border-radius: 20px"],
.tool-content [style*="border-radius: 16px"],
.tool-content [style*="border-radius: 14px"] {
    border-radius: 10px !important;
}

.tool-content [style*="border-radius: 12px"] {
    border-radius: 8px !important;
}

/* Back button always visible - MUST be above everything */
.back-button {
    position: sticky;
    top: 0;
    z-index: 9999 !important; /* Above all tool content */
    background: var(--background);
    padding: 10px 0;
    margin: 0 0 5px 0;
}

/* For fullscreen tools, make back button fixed */
#mirror-screen .back-button,
#star-map-screen .back-button {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999 !important;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    padding: 10px 15px;
    margin: 0;
}

/* Star Map should still be fullscreen */
#star-map-canvas {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 1;
}

#star-map-screen .controls {
    position: fixed;
    z-index: 10;
    pointer-events: auto;
}

/* Hide scrollbar on iOS */
.tool-content::-webkit-scrollbar,
.scrollable-section::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}