/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header Styles */
header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 2rem 0;
    text-align: center;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5rem;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.subtitle {
    font-size: 1.2rem;
    color: #7f8c8d;
    font-weight: 300;
}

/* Ad Banner Styles - Optimized for CLS */
.ad-banner-top,
.ad-banner-bottom {
    background: #f8f9fa;
    padding: 10px 0;
    text-align: center;
    border: 1px solid #e9ecef;
    /* Reserve space to prevent layout shift */
    min-height: 110px;
    contain: layout style;
}

.ad-banner-top {
    border-bottom: none;
}

.ad-banner-bottom {
    border-top: none;
    margin-top: 2rem;
}

.ad-placeholder {
    background: #e9ecef;
    color: #6c757d;
    padding: 20px;
    border-radius: 4px;
    font-size: 14px;
    align-items: center;
    justify-content: center;
    /* Fixed dimensions to prevent CLS */
    width: 100%;
    max-width: 728px;
    height: 90px;
    margin: 0 auto;
    /* Improve rendering performance */
    will-change: auto;
    transform: translateZ(0);
    /* Hide ad placeholders until real ads are inserted */
    display: none;
}

/* Main Layout */
main {
    padding: 2rem 0;
}

.calculator-wrapper {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 3rem;
    max-width: 800px;
    margin: 0 auto 3rem auto;
}

/* Sidebar Ads - Optimized for CLS */
.sidebar-left,
.sidebar-right {
    /* Hide sidebars when ads are not active */
    display: none;
    flex-direction: column;
    /* Fixed width to prevent layout shift */
    width: 200px;
    flex-shrink: 0;
}

.ad-sidebar {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    position: sticky;
    top: 20px;
    /* Fixed dimensions for CLS optimization */
    width: 180px;
    min-height: 620px;
    contain: layout style;
}

.ad-sidebar .ad-placeholder {
    width: 160px;
    height: 600px;
    /* Remove min-width/min-height to use fixed dimensions */
    flex-shrink: 0;
    /* Hide sidebar ad placeholders */
    display: none;
}

/* Calculator Section */
.calculator-section {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 2rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.calculator-card h2 {
    color: #2c3e50;
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 1.8rem;
}

/* Conversion Tabs */
.conversion-tabs {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
    border-bottom: 2px solid #ecf0f1;
}

.tab-btn {
    background: none;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: #7f8c8d;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

.tab-btn.active {
    color: #3498db;
    border-bottom-color: #3498db;
}

.tab-btn:hover {
    color: #2980b9;
    background: rgba(52, 152, 219, 0.05);
}

/* Input Styles */
.input-group {
    margin-bottom: 2rem;
}

.fraction-input,
.decimal-input {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1.5rem;
}

.fraction-input label,
.decimal-input label {
    font-weight: 600;
    color: #34495e;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.fraction-input input,
.decimal-input input {
    width: 200px;
    padding: 12px 16px;
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    font-size: 1.2rem;
    text-align: center;
    transition: all 0.3s ease;
    margin-bottom: 1rem;
}

.fraction-input input:focus,
.decimal-input input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.fraction-line {
    width: 220px;
    height: 3px;
    background: #34495e;
    margin: 0.5rem 0;
    border-radius: 2px;
}

.decimal-input {
    padding: 2rem 0;
}

.decimal-input input {
    width: 250px;
    font-size: 1.5rem;
}

/* Button Styles */
.convert-button-wrapper {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.convert-btn,
.clear-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 140px;
}

.convert-btn {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
}

.convert-btn:hover {
    background: linear-gradient(135deg, #2980b9, #1f5f8b);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

.clear-btn {
    background: linear-gradient(135deg, #95a5a6, #7f8c8d);
    color: white;
}

.clear-btn:hover {
    background: linear-gradient(135deg, #7f8c8d, #6c7b7d);
    transform: translateY(-2px);
}

/* Result Display */
.result-section {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1.5rem;
    margin: 2rem 0;
    display: none;
}

.result-section.show {
    display: block;
    animation: fadeInUp 0.5s ease;
}

.result-section h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    text-align: center;
}

.result-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.fraction-display,
.decimal-display {
    font-size: 2rem;
    font-weight: 700;
    color: #2c3e50;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.equals {
    font-size: 2rem;
    font-weight: 700;
    color: #e74c3c;
}

/* Steps Section */
.steps-section {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    border-left: 4px solid #3498db;
}

.steps-section h4 {
    color: #2c3e50;
    margin-bottom: 0.5rem;
}

.steps-content {
    color: #7f8c8d;
    line-height: 1.8;
}

/* Quick Conversions */
.quick-conversions {
    margin: 2rem 0;
    text-align: center;
}

.quick-conversions h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
}

.quick-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.quick-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, #e8f4f8, #d4edda);
    border: 2px solid #3498db;
    border-radius: 20px;
    color: #2c3e50;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.quick-btn:hover {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    transform: translateY(-2px);
}

/* Content Middle Ad */
.ad-content-middle {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    margin: 2rem 0;
}

.ad-content-middle .ad-placeholder {
    min-width: 100%;
    min-height: 250px;
}

/* History Section */
.history-section {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    padding: 1.5rem;
    margin-top: 2rem;
}

.history-section h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    text-align: center;
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid #3498db;
}

.history-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.conversion-type {
    font-size: 0.8rem;
    color: #7f8c8d;
    font-style: italic;
    margin-left: 0.5rem;
}

.no-history {
    text-align: center;
    color: #7f8c8d;
    font-style: italic;
    padding: 2rem;
}

.clear-history-btn {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 1rem;
    transition: all 0.3s ease;
}

.clear-history-btn:hover {
    background: linear-gradient(135deg, #c0392b, #a93226);
}

/* Educational Content */
.educational-content {
    margin-top: 3rem;
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

.content-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.content-card h2 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.content-card h3 {
    color: #34495e;
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}

.content-card p,
.content-card li {
    color: #7f8c8d;
    margin-bottom: 0.5rem;
    line-height: 1.7;
}

.content-card ol,
.content-card ul {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

/* Conversion Table */
.conversion-table {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.table-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 3px solid #3498db;
}

.fraction {
    font-weight: 600;
    color: #2c3e50;
}

.decimal {
    font-weight: 600;
    color: #e74c3c;
    font-family: 'Courier New', monospace;
}

/* FAQ Styles */
.faq-item {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #ecf0f1;
}

.faq-item:last-child {
    border-bottom: none;
}

/* Footer */
footer {
    background: rgba(44, 62, 80, 0.95);
    color: white;
    text-align: center;
    padding: 2rem 0;
    margin-top: 3rem;
}

.footer-links {
    margin-top: 1rem;
}

.footer-links a {
    color: #bdc3c7;
    text-decoration: none;
    margin: 0 1rem;
    transition: color 0.3s ease;
}

.footer-links a:hover {
    color: #3498db;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Design */
@media (max-width: 1024px) {
    .calculator-wrapper {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .sidebar-left,
    .sidebar-right {
        display: none;
    }
    
    .ad-placeholder {
        min-width: 100%;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .calculator-section {
        padding: 1.5rem;
    }
    
    .fraction-input input {
        width: 150px;
    }
    
    .fraction-line {
        width: 170px;
    }
    
    .result-display {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .fraction-display,
    .decimal-display {
        font-size: 1.5rem;
    }
    
    .content-grid {
        grid-template-columns: 1fr;
    }
    
    .convert-button-wrapper {
        flex-direction: column;
        align-items: center;
    }
    
    .convert-btn,
    .clear-btn {
        width: 100%;
        max-width: 200px;
    }
}

@media (max-width: 480px) {
    header {
        padding: 1.5rem 0;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    .calculator-section {
        padding: 1rem;
    }
    
    .fraction-input input {
        width: 120px;
        font-size: 1rem;
    }
    
    .fraction-line {
        width: 140px;
    }
    
    .quick-buttons {
        gap: 0.3rem;
    }
    
    .quick-btn {
        padding: 6px 12px;
        font-size: 0.9rem;
    }
}

/* Print Styles */
@media print {
    .ad-banner-top,
    .ad-banner-bottom,
    .ad-sidebar,
    .ad-content-middle {
        display: none !important;
    }
    
    body {
        background: white;
    }
    
    .calculator-section,
    .content-card {
        background: white;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .calculator-section {
        background: white;
        border: 2px solid #000;
    }
    
    .convert-btn {
        background: #000;
        border: 2px solid #000;
    }
    
    .quick-btn {
        border: 2px solid #000;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Internal Links Styles */
.internal-links {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1.5rem;
    margin-top: 2rem;
    border-left: 4px solid #3498db;
}

.internal-links h4 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.internal-links ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.internal-links li {
    margin-bottom: 0.5rem;
}

.internal-links a {
    color: #3498db;
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 0;
    display: inline-block;
    transition: all 0.3s ease;
    border-bottom: 1px solid transparent;
}

.internal-links a:hover {
    color: #2980b9;
    border-bottom-color: #2980b9;
    transform: translateX(5px);
}

.internal-links a:focus {
    outline: 2px solid #3498db;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Focus Styles for Accessibility */
.convert-btn:focus,
.clear-btn:focus,
.quick-btn:focus,
.clear-history-btn:focus {
    outline: 3px solid #3498db;
    outline-offset: 2px;
}

input:focus {
    outline: 3px solid #3498db;
    outline-offset: 2px;
}

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

/* Highlight target sections when linked to */
:target {
    animation: highlight 2s ease-in-out;
}

@keyframes highlight {
    0% {
        background-color: rgba(52, 152, 219, 0.1);
    }
    100% {
        background-color: transparent;
    }
}