:root {
    --primary: #2c3e50;
    --secondary: #ff6b6b;
    --accent: #3d5a80;
    --light-bg: #f8f9fa;
    --teal: #4ecdc4;
    --border-color: #e0e0e0;
    --text-color: #000000;
    --text-light: #666;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Times New Roman', Times, serif;
    font-size: 1rem;
    line-height: 1.6;
    color: #000;
    background-color: var(--light-bg);
}

/* Main Container */
.container {
    max-width: 1400px;
    padding: 0 10px;
    margin: 0 auto;
}

/* Mobile Layout (default) */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 0 20px;
}

#converter-tool {
    background-color: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Ad Zones */
.ad-zone {
    background-color: #f0f0f0;
    border: 1px dashed var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-light);
}

#ad-left, #ad-right {
    display: none;
}

#ad-tablet {
    display: none;
    width: 300px;
    height: 250px;
    margin: 10px auto;
}

#ad-mobile {
    width: 320px;
    height: 100px;
    margin: 10px auto;
}

/* Related Tools */
#related-tools {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
    display: none;
}

#mobile-tablet-related-tools {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
    margin-top: 10px;
    display: none;
}

.tools-list {
    list-style: none;
}

.tools-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.tools-list li:last-child {
    border-bottom: none;
}

.tools-list a {
    color: #000;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tools-list a:hover {
    color: var(--teal);
}

/* Form Styles */
.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #000;
}

input, select, textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 1rem;
    color: #000;
}

#custom-precision-input {
    display: none;
    margin-top: 10px;
}

button {
    color: white;
    border: none;
    padding: 12px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    width: 100%;
    transition: background-color 0.3s;
    position: relative;
    font-weight: bold;
    font-size: 1rem;
}

#calculate-btn {
    background-color: var(--teal);
}

#calculate-btn:hover {
    background-color: #3db8af;
}

#reset-btn {
    background-color: var(--secondary);
}

#reset-btn:hover {
    background-color: #e55a5a;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.export-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.export-buttons button {
    flex: 1;
    min-width: 120px;
    padding: 8px 12px;
    font-size: 1rem;
    background-color: var(--accent);
}

.export-buttons button:hover {
    background-color: var(--primary);
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Output Section */
.output-section {
    margin-top: 30px;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
    display: none;
}

.rounded-result {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--secondary);
    margin-bottom: 15px;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
}

.calculation-steps {
    background-color: var(--light-bg);
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 15px;
    white-space: pre-line;
    word-wrap: break-word;
    overflow-wrap: break-word;
    color: #000;
}

.error-display {
    background-color: var(--light-bg);
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 15px;
    color: #000;
}

.error-display p {
    margin-bottom: 8px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.error-display p:last-child {
    margin-bottom: 0;
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    table-layout: fixed;
}

.summary-table th, .summary-table td {
    border: 1px solid var(--border-color);
    padding: 12px 8px;
    text-align: left;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    vertical-align: top;
    line-height: 1.4;
    color: #000;
}

.summary-table th {
    background-color: var(--light-bg);
    font-weight: bold;
    font-size: 1rem;
}

/* Chart Container */
.chart-container {
    margin-top: 20px;
    height: 250px;
    position: relative;
}

/* Typography */
h1 {
    font-size: 1.25rem;
    margin-bottom: 20px;
    color: #000;
    text-align: center;
}

h2 {
    font-size: 1.125rem;
    margin: 20px 0 15px;
    color: #ff6b6b;
}

h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: #000;
}

/* Large Number Display - Enhanced for very large numbers */
.large-number {
    display: block;
    width: 100%;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    font-family: 'Courier New', monospace;
    background-color: #f8f9fa;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #e9ecef;
    line-height: 1.4;
    font-size: 1rem;
    overflow-x: auto;
    max-height: 200px;
    overflow-y: auto;
    color: #000;
}

.result-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.result-line {
    display: block;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    color: #000;
}

/* Specific styles for output elements */
#result-value,
#original-value,
#rounded-value,
#absolute-error,
#error-value,
#steps-detail,
#relative-error {
    display: block;
    width: 100%;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.4;
    margin-bottom: 5px;
}

#result-value {
    font-size: 1.25rem;
    color: var(--secondary);
    font-weight: bold;
}

#original-value,
#rounded-value,
#absolute-error,
#error-value {
    font-family: 'Courier New', monospace;
    background-color: #f8f9fa;
    padding: 6px;
    border-radius: 3px;
    border: 1px solid #e9ecef;
    font-size: 1rem;
    color: #000;
}

#steps-detail {
    white-space: pre-line;
    font-family: 'Courier New', monospace;
    background-color: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #e9ecef;
    font-size: 1rem;
    line-height: 1.5;
    color: #000;
}

#relative-error {
    font-weight: bold;
    color: var(--secondary);
}

/* Mobile-first responsive design */
@media (max-width: 767px) {
    .container {
        padding: 0 8px;
    }
    
    #converter-tool {
        padding: 15px;
    }
    
    .output-section {
        margin-top: 20px;
        padding-top: 15px;
    }
    
    .rounded-result {
        font-size: 1.5rem;
    }
    
    .calculation-steps,
    .error-display {
        padding: 12px;
    }
    
    .summary-table {
        display: block;
        overflow-x: auto;
        font-size: 1rem;
    }
    
    .summary-table th, 
    .summary-table td {
        padding: 8px 6px;
        min-width: 100px;
        font-size: 0.875rem;
    }
    
    .chart-container {
        height: 200px;
    }
    
    #mobile-tablet-related-tools {
        display: block;
    }
    
    .export-buttons {
        flex-direction: column;
    }
    
    .export-buttons button {
        width: 100%;
        font-size: 0.875rem;
    }
    
    /* Ensure very large numbers are readable on mobile */
    #result-value,
    #original-value,
    #rounded-value,
    #absolute-error,
    #error-value {
        font-size: 1rem;
        padding: 4px;
    }
    
    #steps-detail {
        font-size: 1rem;
        padding: 8px;
    }
    
    h1 {
        font-size: 1.25rem;
    }
    
    h2 {
        font-size: 1.125rem;
    }
    
    h3 {
        font-size: 1rem;
    }
}

/* Tablet Layout */
@media (min-width: 768px) and (max-width: 1024px) {
    .container {
        padding: 0 15px;
    }
    
    #converter-tool {
        padding: 25px;
    }
    
    .summary-table th, 
    .summary-table td {
        padding: 10px 8px;
        max-width: 180px;
    }
    
    #ad-tablet {
        display: flex;
    }

    #ad-mobile {
        display: none;
    }

    #mobile-tablet-related-tools {
        display: block;
    }
    
    .button-group {
        flex-direction: row;
    }
    
    .button-group button {
        width: auto;
        flex: 1;
    }
    
    h2 {
        font-size: 1.25rem;
    }
    
    h3 {
        font-size: 1.125rem;
    }
}

/* Desktop Layout */
@media (min-width: 1025px) {
    .container {
        display: grid;
        grid-template-columns: 300px 1fr 300px;
        gap: 20px;
        padding: 0 15px;
    }

    .main-content {
        grid-column: 2;
    }

    .sidebar {
        position: sticky;
        top: 20px;
        height: fit-content;
    }

    #ad-left, #ad-right {
        display: flex;
    }

    #ad-left {
        width: 300px;
        height: 250px;
        margin-bottom: 20px;
    }

    #ad-right {
        width: 300px;
        height: 600px;
    }

    #ad-tablet, #ad-mobile {
        display: none;
    }

    #related-tools {
        display: block;
    }

    #mobile-tablet-related-tools {
        display: none;
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.375rem;
    }

    h3 {
        font-size: 1.25rem;
    }
    
    .button-group {
        flex-direction: row;
    }
    
    .button-group button {
        width: auto;
        flex: 1;
    }

    .summary-table th, 
    .summary-table td {
        max-width: 200px;
        padding: 12px 10px;
    }
    
    /* Desktop specific large number handling */
    #result-value {
        font-size: 1.25rem;
    }
    
    #original-value,
    #rounded-value,
    #absolute-error,
    #error-value {
        font-size: 1rem;
    }
}

/* Extra large screens */
@media (min-width: 1400px) {
    .container {
        max-width: 1600px;
    }
    
    .summary-table th, 
    .summary-table td {
        max-width: 250px;
    }
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus styles for accessibility */
button:focus, input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Breadcrumb styles */
.breadcrumb {
    padding: 0px 10px;
    color: #000;
    margin-bottom: 5px;
    font-size: 1rem;
}

.breadcrumb a {
    color: #000;
    text-decoration: none;
    transition: color 0.3s;
}

.breadcrumb a:hover {
    color: var(--secondary);
    text-decoration: underline;
}

/* Print styles */
@media print {
    .ad-zone,
    .export-buttons,
    .button-group,
    #related-tools,
    #mobile-tablet-related-tools {
        display: none !important;
    }
    
    .output-section {
        display: block !important;
        border-top: none;
        margin-top: 0;
        padding-top: 0;
    }
    
    .large-number {
        background-color: white;
        border: 1px solid #000;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --text-light: #000000;
        --light-bg: #ffffff;
    }
    
    .calculation-steps,
    .error-display {
        border: 2px solid #000000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation: none;
        border: 3px solid #fff;
    }
    
    button {
        transition: none;
    }
}

.mobile-table {
    overflow-x: auto;
    margin: 20px 0;
    border: 1px solid #eee;
    border-radius: 8px;
}

.mobile-table table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
}

.mobile-table th, .mobile-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #eee;
    color: #000;
    font-size: 1rem;
}

.mobile-table th {
    background-color: #4ecdc4;
    font-weight: bold;
}

.mobile-table tr:nth-child(even) {
    background-color: #fafafa;
}