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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --error-color: #ef4444;
    --background: #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 -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
}

.logo-container {
    margin-bottom: 15px;
}

.logo {
    width: 80px;
    height: 80px;
    border-radius: 16px;
}

header h1 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Cards */
.converter-card,
.history-card,
.reference-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    background: var(--background);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 24px;
}

.mode-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow);
}

.mode-btn:hover:not(.active) {
    background: var(--border-color);
}

/* Input Section */
.input-section {
    margin-bottom: 20px;
}

.input-section label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

#inputValue {
    width: 100%;
    padding: 14px 44px 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 1.125rem;
    font-weight: 500;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#inputValue:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

#inputValue.error {
    border-color: var(--error-color);
}

.clear-btn {
    position: absolute;
    right: 12px;
    width: 28px;
    height: 28px;
    border: none;
    background: var(--border-color);
    border-radius: 50%;
    font-size: 1.25rem;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.clear-btn:hover {
    background: var(--secondary-color);
    color: white;
}

.error-message {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-top: 8px;
    min-height: 20px;
}

/* Convert Button */
.convert-btn {
    width: 100%;
    padding: 14px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.convert-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

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

/* Result Section */
.result-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.result-section label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.result-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--background);
    padding: 16px;
    border-radius: 12px;
}

#resultValue {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.copy-btn {
    padding: 8px;
    border: none;
    background: var(--card-bg);
    border-radius: 8px;
    color: var(--secondary-color);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

/* History Card */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.history-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.clear-history-btn {
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--error-color);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.clear-history-btn:hover {
    background: #fef2f2;
}

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

.empty-history {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
    font-size: 0.875rem;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 8px;
    animation: slideIn 0.3s ease;
}

.history-item:last-child {
    margin-bottom: 0;
}

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

.history-item .conversion {
    font-weight: 500;
}

.history-item .arrow {
    color: var(--primary-color);
    margin: 0 8px;
}

.history-item .time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.history-item .copy-history-btn {
    padding: 4px 8px;
    border: none;
    background: var(--card-bg);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--secondary-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item .copy-history-btn:hover {
    background: var(--primary-color);
    color: white;
}

/* Reference Card */
.reference-card h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.reference-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    gap: 12px;
}

.reference-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    background: var(--background);
    border-radius: 8px;
    text-align: center;
}

.reference-item .roman {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

.reference-item .arabic {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Footer */
footer {
    text-align: center;
    padding: 24px 0;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

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

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

/* Mobile Responsive */
@media (max-width: 480px) {
    .container {
        padding: 16px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .converter-card,
    .history-card,
    .reference-card {
        padding: 20px;
    }

    .mode-btn {
        padding: 10px 12px;
        font-size: 0.875rem;
    }

    #inputValue {
        font-size: 1rem;
        padding: 12px 40px 12px 14px;
    }

    #resultValue {
        font-size: 1.25rem;
    }

    .reference-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Scrollbar styling */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: var(--background);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}
