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

:root {
    /* High-contrast color palette for accessibility */
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #93c5fd;
    --secondary-color: #059669;
    --secondary-dark: #047857;
    --accent-color: #dc2626;
    --accent-light: #fca5a5;
    
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-accent: #f3f4f6;
    --border-color: #d1d5db;
    --border-light: #e5e7eb;
    
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --border-radius: 8px;
    --border-radius-sm: 4px;
    --border-radius-lg: 12px;
    
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

body {
    font-family: var(--font-family);
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    scroll-behavior: smooth;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    line-height: 1.2;
    margin-bottom: 0.5em;
    font-weight: 700;
    color: var(--text-primary);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; }

p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header & Navigation */
header {
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    max-width: 1200px;
    margin: 0 auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

nav h1 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin: 0;
}

/* Hamburger Menu Styles */
.hamburger-menu {
    display: none;
    flex-direction: column;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius-sm);
    transition: background-color 0.2s ease;
    position: relative;
    z-index: 101;
}

.hamburger-menu:hover {
    background-color: rgba(37, 99, 235, 0.1);
}

.hamburger-line {
    width: 24px;
    height: 3px;
    background-color: var(--primary-color);
    margin: 2px 0;
    transition: all 0.3s ease;
    border-radius: 2px;
}

/* Hamburger Animation States */
.hamburger-menu.active .hamburger-line:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.hamburger-menu.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

.hamburger-menu.active .hamburger-line:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

.nav-links {
    display: flex;
    gap: 2rem;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.nav-links a:hover,
.nav-links a:focus {
    color: var(--primary-color);
    outline: none;
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 4rem 0;
    text-align: center;
}

.hero h1 {
    color: white;
    font-size: 3rem;
    margin-bottom: 1rem;
}

.hero-tagline {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    color: var(--primary-light);
}

.value-props {
    list-style: none;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 2rem;
    margin-bottom: 2rem;
}

.value-props li {
    color: var(--primary-light);
    font-weight: 500;
}

/* Sections */
section {
    padding: 4rem 0;
}

section:nth-child(even) {
    background-color: var(--bg-secondary);
}

/* Calculator Section */
.calculator-section {
    background-color: var(--bg-primary);
}

.calculator-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    margin-top: 2rem;
}

.calculator-form {
    background-color: var(--bg-secondary);
    padding: 2rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
}

/* Form Styles */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background-color: var(--bg-primary);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group input:invalid {
    border-color: var(--error-color);
}

/* Roommates Section */
.roommates-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-light);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.roommate-entry {
    background-color: var(--bg-primary);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-light);
    margin-bottom: 1rem;
    position: relative;
}

.roommate-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.roommate-number {
    font-weight: 600;
    color: var(--primary-color);
}

.remove-roommate {
    background: none;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.25rem;
    border-radius: var(--border-radius-sm);
    transition: background-color 0.2s ease;
}

.remove-roommate:hover {
    background-color: var(--accent-light);
}

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

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-example {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

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

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: var(--bg-primary);
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

.btn-secondary:hover,
.btn-secondary:focus {
    background-color: var(--primary-color);
    color: white;
}

.btn-example {
    background-color: var(--secondary-color);
    color: white;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
}

.btn-example:hover {
    background-color: var(--secondary-dark);
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

/* Results Container */
.results-container {
    background-color: var(--bg-primary);
    padding: 2rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    border-left: 4px solid var(--success-color);
}

.results-summary {
    margin-bottom: 2rem;
    padding: 1rem;
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
}

.results-chart {
    margin: 2rem 0;
    text-align: center;
}

.results-breakdown {
    margin: 2rem 0;
}

.breakdown-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.breakdown-table th,
.breakdown-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.breakdown-table th {
    background-color: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-primary);
}

.breakdown-table td {
    color: var(--text-secondary);
}

.breakdown-table .amount {
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.results-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

/* Chart Styles */
.chart-container {
    position: relative;
    height: 300px;
    margin: 2rem auto;
}

.pie-chart {
    width: 300px;
    height: 300px;
    margin: 0 auto;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 2px;
}

/* Instructions Section */
.instruction-list {
    list-style: none;
    counter-reset: step-counter;
}

.instruction-list li {
    counter-increment: step-counter;
    margin-bottom: 2rem;
    padding-left: 3rem;
    position: relative;
}

.instruction-list li::before {
    content: counter(step-counter);
    position: absolute;
    left: 0;
    top: 0;
    background-color: var(--primary-color);
    color: white;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Examples Section */
.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.example-card {
    background-color: var(--bg-primary);
    padding: 2rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
}

.example-card h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.example-card ul {
    list-style: none;
    margin: 1rem 0;
}

.example-card li {
    padding: 0.25rem 0;
    color: var(--text-secondary);
}

.example-card li:before {
    content: "• ";
    color: var(--primary-color);
    font-weight: 600;
}

/* Math Section */
.math-explanation {
    background-color: var(--bg-primary);
    padding: 2rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    margin-top: 2rem;
}

.math-explanation h3 {
    color: var(--primary-color);
    margin-top: 2rem;
    margin-bottom: 1rem;
}

.math-explanation h3:first-child {
    margin-top: 0;
}

.math-explanation p {
    font-family: var(--font-mono);
    background-color: var(--bg-secondary);
    padding: 1rem;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary-color);
    margin: 1rem 0;
}

.transparency-note {
    background-color: var(--bg-accent);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--success-color);
    margin-top: 2rem;
}

.transparency-note p {
    margin: 0;
    color: var(--text-primary);
    background: none;
    padding: 0;
    border: none;
    font-family: var(--font-family);
}

/* Tips Section */
.tips-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.tip-card {
    background-color: var(--bg-primary);
    padding: 2rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    text-align: center;
}

.tip-card h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

/* FAQ Section */
.faq-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.faq-item {
    background-color: var(--bg-primary);
    padding: 2rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
}

.faq-item h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.125rem;
}

/* Privacy Section */
.privacy-content {
    background-color: var(--bg-primary);
    padding: 2rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    margin-top: 2rem;
}

.privacy-content h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* CTA Section */
.cta-section {
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--secondary-dark) 100%);
    color: white;
    text-align: center;
}

.cta-section h2 {
    color: white;
    margin-bottom: 1rem;
}

.cta-section p {
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 2rem;
}

.cta-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Footer */
footer {
    background-color: var(--text-primary);
    color: white;
    padding: 2rem 0;
    text-align: center;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 1rem;
}

.footer-links a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer-links a:hover {
    color: white;
}

/* Loading and Error States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-message {
    background-color: var(--error-color);
    color: white;
    padding: 1rem;
    border-radius: var(--border-radius);
    margin: 1rem 0;
    text-align: center;
}

.success-message {
    background-color: var(--success-color);
    color: white;
    padding: 1rem;
    border-radius: var(--border-radius);
    margin: 1rem 0;
    text-align: center;
}

/* 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 indicators */
button:focus,
input:focus,
select:focus,
a:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --text-secondary: #000000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Responsive Design */
@media (max-width: 1024px) {
    /* Tablet Styles */
    .hamburger-menu {
        display: flex;
    }
    
    .nav-links {
        position: fixed;
        top: 0;
        right: -100%;
        height: 100vh;
        width: 300px;
        background-color: var(--bg-primary);
        box-shadow: var(--shadow-lg);
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2rem;
        transition: right 0.3s ease;
        z-index: 100;
        border-left: 1px solid var(--border-light);
    }
    
    .nav-links.active {
        right: 0;
    }
    
    .nav-links a {
        font-size: 1.125rem;
        padding: 1rem;
        border-radius: var(--border-radius);
        transition: all 0.2s ease;
        width: 80%;
        text-align: center;
    }
    
    .nav-links a:hover,
    .nav-links a:focus {
        background-color: var(--bg-secondary);
        color: var(--primary-color);
    }
    
    /* Overlay for mobile menu */
    .nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: 99;
    }
    
    .nav-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 0.5rem;
    }
    
    .nav-container {
        position: relative;
    }
    
    .nav-links {
        width: 280px;
        gap: 1.5rem;
    }
    
    .nav-links a {
        font-size: 1rem;
    }
    
    .hero h1 {
        font-size: 2rem;
    }
    
    .hero-tagline {
        font-size: 1rem;
    }
    
    .value-props {
        flex-direction: column;
        gap: 1rem;
    }
    
    .calculator-container {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .results-actions {
        flex-direction: column;
    }
    
    .cta-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .cta-buttons .btn-primary,
    .cta-buttons .btn-secondary {
        width: 100%;
        max-width: 300px;
    }
    
    .footer-links {
        flex-direction: column;
        gap: 1rem;
    }
    
    .examples-grid {
        grid-template-columns: 1fr;
    }
    
    .tips-grid {
        grid-template-columns: 1fr;
    }
    
    .faq-grid {
        grid-template-columns: 1fr;
    }
    
    section {
        padding: 2rem 0;
    }
    
    h1 { font-size: 2rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
}

@media (max-width: 480px) {
    .calculator-form,
    .results-container {
        padding: 1rem;
    }
    
    .roommate-fields {
        grid-template-columns: 1fr;
    }
    
    .instruction-list li {
        padding-left: 2.5rem;
    }
    
    .instruction-list li::before {
        width: 1.5rem;
        height: 1.5rem;
        font-size: 0.8rem;
    }
}

/* Print Styles */
@media print {
    .nav-container,
    .cta-section,
    footer,
    .btn-primary,
    .btn-secondary,
    .btn-example {
        display: none;
    }
    
    .calculator-container {
        grid-template-columns: 1fr;
    }
    
    .results-container {
        box-shadow: none;
        border: 1px solid var(--border-color);
    }
    
    body {
        font-size: 12pt;
        line-height: 1.4;
    }
    
    h1, h2, h3 {
        page-break-after: avoid;
    }
    
    .results-breakdown {
        page-break-inside: avoid;
    }
}