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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #ffffff;
    --surface: #f8fafc;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --highlight: #fef3c7;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

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-primary);
    line-height: 1.6;
}

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

header {
    text-align: center;
    margin-bottom: 3rem;
    background: var(--background);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    position: relative;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

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

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

.language-selector select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--background);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s;
}

.language-selector select:hover {
    border-color: var(--primary-color);
}

main {
    background: var(--background);
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.input-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    .input-section {
        grid-template-columns: 1fr;
    }
}

.pattern-input-container,
.test-input-container {
    display: flex;
    flex-direction: column;
}

label {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem;
    transition: all 0.3s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.delimiter {
    color: var(--text-muted);
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0 0.5rem;
}

#regexPattern {
    flex: 1;
    border: none;
    background: transparent;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    color: var(--text-primary);
    outline: none;
}

#regexFlags {
    width: 60px;
    border: none;
    background: transparent;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    color: var(--text-primary);
    outline: none;
    text-align: center;
}

.pattern-error {
    color: var(--error-color);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    min-height: 1.2rem;
}

textarea {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    font-family: 'Courier New', monospace;
    font-size: 0.95rem;
    resize: vertical;
    transition: all 0.3s;
    background: var(--surface);
}

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

.results-section {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
}

.tab-button {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}

.tab-button:hover {
    color: var(--text-primary);
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.match-stats {
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

#matchCount {
    color: var(--primary-color);
    font-size: 1.1rem;
}

.match-results {
    max-height: 400px;
    overflow-y: auto;
}

.match-item {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.match-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.match-number {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.match-text {
    font-family: 'Courier New', monospace;
    background: var(--surface);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    color: var(--success-color);
}

.match-position {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-left: auto;
}

.match-groups {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.group-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.group-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
}

.group-value {
    font-family: 'Courier New', monospace;
    background: var(--surface);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    color: var(--primary-color);
}

.highlighted-text {
    font-family: 'Courier New', monospace;
    background: var(--background);
    padding: 1rem;
    border-radius: 0.5rem;
    margin-top: 1rem;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.8;
}

.highlighted-text mark {
    background: var(--highlight);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-weight: 600;
}

.no-matches {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
    font-style: italic;
}

.pattern-explanation {
    background: var(--background);
    padding: 1rem;
    border-radius: 0.5rem;
}

.explanation-list {
    font-family: 'Courier New', monospace;
    line-height: 2;
}

.pattern-part {
    background: var(--surface);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    color: var(--primary-color);
    font-weight: 600;
}

.pattern-library {
    max-height: 500px;
    overflow-y: auto;
}

.library-search {
    margin-bottom: 1rem;
}

.library-search input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.95rem;
    transition: all 0.3s;
}

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

.pattern-list {
    display: grid;
    gap: 1rem;
}

.pattern-item {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s;
}

.pattern-item:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
}

.pattern-info {
    flex: 1;
}

.pattern-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.pattern-description {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.pattern-code {
    font-family: 'Courier New', monospace;
    background: var(--surface);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    color: var(--primary-color);
    font-size: 0.85rem;
    display: inline-block;
}

.use-pattern-btn {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

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

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

.tool-button {
    padding: 0.75rem 1.5rem;
    background: var(--background);
    color: var(--text-primary);
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.tool-button:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

footer {
    text-align: center;
    margin-top: 3rem;
    color: white;
    padding: 1rem;
}

.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--success-color);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

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

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

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

/* レスポンシブデザイン */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .tools-section {
        flex-direction: column;
    }
    
    .tool-button {
        width: 100%;
    }
    
    .language-selector {
        position: static;
        margin-top: 1rem;
    }
}