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

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --success-color: #10b981;
    --error-color: #ef4444;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 2rem 1rem;
    color: var(--text-primary);
}

.container {
    max-width: 900px;
    margin: 0 auto;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.95;
}

.graph-section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 0.75rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
    animation: fadeIn 0.5s ease;
}

.graph-section canvas {
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
    background: #ffffff;
    /* Maintain 4:3 aspect ratio (800:600) */
    aspect-ratio: 4 / 3;
    object-fit: contain;
}

.calculator-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
}

.input-section {
    margin-bottom: 2rem;
}

.input-group {
    margin-bottom: 1.5rem;
}

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

.input-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    font-family: 'Courier New', monospace;
}

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

.help-text {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.speed-control {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.speed-control input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--border-color);
    outline: none;
    border-radius: 3px;
    cursor: pointer;
}

.speed-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.speed-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--primary-dark);
}

.speed-control input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.speed-control input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.2);
    background: var(--primary-dark);
}

.speed-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 0 0.25rem;
}

.calculate-btn {
    width: 100%;
    padding: 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.calculate-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.calculate-btn:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
    opacity: 0.7;
}

.results-section {
    border-top: 2px solid var(--border-color);
    padding-top: 2rem;
    animation: fadeIn 0.5s ease;
}

.results-section h2 {
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.result-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.summary-item {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary-color) 100%);
    padding: 1.25rem;
    border-radius: 12px;
    color: white;
    box-shadow: var(--shadow);
}

.summary-item .label {
    display: block;
    font-size: 0.85rem;
    opacity: 0.9;
    margin-bottom: 0.5rem;
}

.summary-item .value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
}

.table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

th, td {
    padding: 1rem;
    text-align: left;
    font-size: 0.95rem;
}

th {
    font-weight: 600;
}

tbody tr {
    border-bottom: 1px solid var(--border-color);
}

tbody tr:hover {
    background: #f1f5f9;
}

tbody tr:last-child {
    border-bottom: none;
}

/* Animation for table rows */
tbody tr.animate-row {
    opacity: 0;
    transform: translateX(-20px);
    transition: all 0.4s ease-out;
}

tbody tr.animate-row.visible {
    opacity: 1;
    transform: translateX(0);
}

/* Highlight effect for newly added row */
@keyframes highlightRow {
    0% {
        background: rgba(99, 102, 241, 0.3);
    }
    100% {
        background: transparent;
    }
}

tbody tr.animate-row.visible {
    animation: highlightRow 0.8s ease-out;
}

td {
    font-family: 'Courier New', monospace;
}

tbody tr.error-row {
    background-color: #fee2e2;
    color: var(--error-color);
    border-left: 4px solid var(--error-color);
}

tbody tr.error-row td {
    color: var(--error-color);
    font-weight: 500;
}

.error-message {
    background: #fee2e2;
    color: var(--error-color);
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid var(--error-color);
    margin-top: 1rem;
    animation: shake 0.5s ease;
}

.hidden {
    display: none;
}

.info-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow);
}

.info-section h3 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.info-section ul {
    list-style: none;
    margin-bottom: 2rem;
}

.info-section li {
    padding: 0.5rem 0;
    color: var(--text-secondary);
    line-height: 1.6;
}

.info-section li strong {
    color: var(--text-primary);
}

.collapsible-section {
    margin: 1.5rem 0;
}

.collapsible-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    text-align: left;
    transition: all 0.3s ease;
}

.collapsible-header:hover {
    opacity: 0.8;
}

.collapsible-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.toggle-icon {
    font-size: 0.8rem;
    color: var(--primary-color);
    transition: transform 0.3s ease;
    margin-left: 1rem;
    flex-shrink: 0;
}

.collapsible-header[aria-expanded="true"] .toggle-icon {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out, opacity 0.3s ease-out;
    opacity: 0;
}

.collapsible-content.expanded {
    max-height: 2000px;
    opacity: 1;
    transition: max-height 0.5s ease-in, opacity 0.4s ease-in;
}

.input-format {
    margin: 1.5rem 0;
    padding-top: 1rem;
}

.input-format h4 {
    color: var(--text-primary);
    font-size: 1rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.input-format h4:first-child {
    margin-top: 0;
}

.input-format ul {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.input-format li {
    margin-bottom: 0.5rem;
    line-height: 1.8;
}

.input-format code {
    background: var(--bg-color);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: var(--primary-color);
    font-weight: 600;
}

.formula {
    background: var(--bg-color);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
    font-size: 1.1rem;
    color: var(--text-primary);
    font-family: 'Georgia', serif;
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

@keyframes pulseValue {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
        color: #fff;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
    }
    100% {
        transform: scale(1);
    }
}

.summary-item .value.animate-value {
    animation: pulseValue 0.6s ease-out;
}

@media (max-width: 768px) {
    body {
        padding: 0.75rem 0.5rem;
    }

    header {
        margin-bottom: 1rem;
    }

    header h1 {
        font-size: 1.75rem;
        margin-bottom: 0.25rem;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    .graph-section {
        padding: 0.4rem;
        margin-bottom: 1rem;
        border-radius: 12px;
    }

    .graph-section canvas {
        border-radius: 6px;
    }

    .calculator-card {
        padding: 1rem;
        margin-bottom: 1rem;
        border-radius: 12px;
    }

    .input-section {
        margin-bottom: 1.25rem;
    }

    .input-group {
        margin-bottom: 1rem;
    }

    .input-group label {
        font-size: 0.9rem;
        margin-bottom: 0.4rem;
    }

    .input-group input {
        padding: 0.6rem 0.75rem;
        font-size: 0.95rem;
    }

    .input-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .result-summary {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        margin-bottom: 1.25rem;
    }

    .summary-item {
        padding: 1rem;
    }

    .summary-item .label {
        font-size: 0.8rem;
        margin-bottom: 0.4rem;
    }

    .summary-item .value {
        font-size: 1.25rem;
    }

    .results-section {
        padding-top: 1.25rem;
    }

    .results-section h2 {
        margin-bottom: 1rem;
        font-size: 1.25rem;
    }

    .info-section {
        padding: 1rem;
        border-radius: 12px;
    }

    .info-section h3 {
        font-size: 1.1rem;
        margin-bottom: 0.75rem;
    }

    .input-format {
        margin: 1rem 0;
        padding-top: 0.75rem;
    }

    .input-format h4 {
        font-size: 0.9rem;
        margin-top: 1rem;
        margin-bottom: 0.4rem;
    }

    .input-format code {
        font-size: 0.8em;
        padding: 0.15rem 0.3rem;
    }

    .input-format ul {
        padding-left: 1rem;
        margin-bottom: 0.75rem;
    }

    .input-format li {
        margin-bottom: 0.4rem;
    }

    .collapsible-section {
        margin: 1rem 0;
    }

    .collapsible-header h3 {
        font-size: 1rem;
    }

    .toggle-icon {
        font-size: 0.7rem;
        margin-left: 0.5rem;
    }

    .calculate-btn {
        padding: 0.85rem;
        font-size: 1rem;
    }

    th, td {
        padding: 0.6rem 0.4rem;
        font-size: 0.8rem;
    }

    .error-message {
        padding: 0.75rem;
        margin-top: 0.75rem;
    }
}

/* Extra small screens (phones in portrait) */
@media (max-width: 480px) {
    body {
        padding: 0.5rem 0.25rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.85rem;
    }

    .graph-section {
        padding: 0.3rem;
        margin-bottom: 0.75rem;
    }

    .calculator-card {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .input-group {
        margin-bottom: 0.75rem;
    }

    .input-group input {
        padding: 0.5rem 0.6rem;
        font-size: 0.9rem;
    }

    .summary-item {
        padding: 0.75rem;
    }

    .summary-item .value {
        font-size: 1.1rem;
    }

    th, td {
        padding: 0.5rem 0.3rem;
        font-size: 0.75rem;
    }
}

