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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

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

header {
    text-align: center;
    margin-bottom: 40px;
    position: relative;
}

h1 {
    color: white;
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.subtitle {
    color: rgba(255,255,255,0.9);
    font-size: 1.2em;
}

.language-selector {
    position: absolute;
    top: 0;
    right: 0;
}

.language-selector select {
    padding: 8px 12px;
    border-radius: 8px;
    border: none;
    background: rgba(255,255,255,0.95);
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

main {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.calculator-section {
    display: grid;
    gap: 30px;
}

.input-area {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
}

#formulaInput {
    width: 100%;
    min-height: 100px;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 18px;
    font-family: 'Courier New', monospace;
    resize: vertical;
    transition: border-color 0.3s;
}

#formulaInput:focus {
    outline: none;
    border-color: #4285f4;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.primary-btn, .secondary-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.primary-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102,126,234,0.4);
}

.secondary-btn {
    background: #f1f3f5;
    color: #495057;
}

.secondary-btn:hover {
    background: #e9ecef;
}

.variables-section, .functions-panel {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
}

h3 {
    color: #343a40;
    margin-bottom: 15px;
    font-size: 1.3em;
}

.variables-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.variable-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: white;
    border-radius: 8px;
}

.var-name {
    font-weight: 600;
    color: #495057;
    min-width: 60px;
}

.var-value {
    flex: 1;
    padding: 8px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 14px;
}

.delete-btn {
    padding: 6px 12px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.delete-btn:hover {
    background: #c82333;
}

.add-btn {
    padding: 10px 16px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.add-btn:hover {
    background: #218838;
}

.function-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
}

.func-btn {
    padding: 10px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.func-btn:hover {
    background: #4285f4;
    color: white;
    border-color: #4285f4;
}

.result-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
}

.result-display {
    min-height: 60px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    font-size: 24px;
    font-weight: 600;
    display: flex;
    align-items: center;
}

.result-display .success {
    color: #28a745;
}

.result-display .error {
    color: #dc3545;
    font-size: 16px;
}

.graph-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
    display: none;
}

#graphCanvas {
    width: 100%;
    height: 400px;
    background: white;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.graph-controls {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.graph-controls label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #495057;
}

.graph-controls input {
    width: 80px;
    padding: 8px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
}

.history-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 12px;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.history-item:hover {
    background: #e9ecef;
}

.history-formula {
    font-family: 'Courier New', monospace;
    color: #495057;
    margin-bottom: 5px;
}

.history-result {
    color: #28a745;
    font-weight: 600;
}

.examples-section {
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 12px;
}

.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.example-btn {
    padding: 12px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    font-size: 14px;
}

.example-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

footer {
    text-align: center;
    margin-top: 40px;
    color: rgba(255,255,255,0.9);
    font-size: 14px;
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    h1 {
        font-size: 2em;
    }
    
    .subtitle {
        font-size: 1em;
    }
    
    .language-selector {
        position: static;
        margin-top: 20px;
    }
    
    main {
        padding: 20px;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .primary-btn, .secondary-btn {
        width: 100%;
    }
    
    .function-buttons {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    }
    
    .graph-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .graph-controls label {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .examples-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    h1 {
        font-size: 1.5em;
    }
    
    main {
        padding: 15px;
        border-radius: 15px;
    }
    
    #formulaInput {
        font-size: 16px;
        min-height: 80px;
    }
    
    .result-display {
        font-size: 20px;
    }
}

/* スクロールバーのスタイリング */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* アニメーション */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.calculator-section > * {
    animation: fadeIn 0.5s ease-out;
}