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

:root {
    --primary-color: #4a90e2;
    --primary-hover: #357abd;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-color: #2c3e50;
    --text-light: #7f8c8d;
    --border-color: #e1e8ed;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.16);
    --radius: 8px;
    --transition: all 0.3s ease;
}

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;
    color: var(--text-color);
    line-height: 1.6;
}

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

header {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 30px;
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 28px;
    font-weight: 700;
    color: var(--text-color);
}

.logo {
    width: 36px;
    height: 36px;
    color: var(--primary-color);
}

.language-selector {
    display: flex;
    gap: 8px;
}

.lang-btn {
    padding: 8px 16px;
    border: 2px solid var(--border-color);
    background: var(--card-bg);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    font-weight: 500;
}

.lang-btn:hover {
    border-color: var(--primary-color);
    background: #f0f7ff;
}

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

main {
    display: grid;
    gap: 24px;
}

.input-section, .output-section, .replacements-section, 
.options-section, .presets-section, .history-section, .stats-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

label {
    font-weight: 600;
    color: var(--text-color);
    font-size: 16px;
}

textarea {
    width: 100%;
    min-height: 150px;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 15px;
    resize: vertical;
    transition: var(--transition);
    font-family: 'Monaco', 'Courier New', monospace;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

textarea[readonly] {
    background-color: #f5f7fa;
}

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

.section-header h2 {
    font-size: 20px;
    color: var(--text-color);
}

#rulesContainer {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rule-item {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px;
    background: var(--bg-color);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.rule-search, .rule-replace {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    transition: var(--transition);
}

.rule-search:focus, .rule-replace:focus {
    outline: none;
    border-color: var(--primary-color);
}

.arrow {
    color: var(--text-light);
    font-weight: bold;
    font-size: 18px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

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

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

.btn-success:hover {
    background: #229954;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

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

.btn-danger:hover {
    background: #c0392b;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-large {
    padding: 14px 32px;
    font-size: 16px;
}

.options-section h3, .presets-section h3, .history-section h3 {
    margin-bottom: 16px;
    color: var(--text-color);
    font-size: 18px;
}

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

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius);
    transition: var(--transition);
}

.checkbox-label:hover {
    background: var(--bg-color);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.preset-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

#presetSelect {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    background: white;
}

.action-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    padding: 20px 0;
}

.output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

#historyList {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 12px;
    background: var(--bg-color);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.history-time {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.history-content {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.history-input, .history-output {
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    padding: 4px 8px;
    background: white;
    border-radius: 4px;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-count {
    font-size: 12px;
    color: var(--primary-color);
    font-weight: 600;
}

.stats-section {
    display: flex;
    justify-content: space-around;
    background: linear-gradient(135deg, var(--primary-color), #764ba2);
    color: white;
}

.stat {
    text-align: center;
}

.stat span:first-child {
    display: block;
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 8px;
}

.stat span:last-child {
    font-size: 32px;
    font-weight: 700;
}

footer {
    text-align: center;
    padding: 30px;
    color: white;
    font-size: 14px;
}

.notification {
    position: fixed;
    bottom: 30px;
    right: 30px;
    padding: 16px 24px;
    border-radius: var(--radius);
    font-weight: 500;
    transform: translateX(400px);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
}

.notification.show {
    transform: translateX(0);
}

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

.notification.error {
    background: var(--danger-color);
    color: white;
}

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

/* スクロールバー */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
    border-radius: var(--radius);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: var(--radius);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-hover);
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .container {
        padding: 12px;
    }
    
    header {
        flex-direction: column;
        gap: 16px;
    }
    
    .title {
        font-size: 24px;
    }
    
    .language-selector {
        width: 100%;
        justify-content: center;
    }
    
    .rule-item {
        flex-direction: column;
    }
    
    .arrow {
        transform: rotate(90deg);
    }
    
    .preset-controls {
        flex-direction: column;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .btn-large {
        width: 100%;
    }
    
    .history-content {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .stats-section {
        flex-direction: column;
        gap: 20px;
    }
}