:root {
    --bg-body: #fafafa;
    --bg-surface: #ffffff;
    --text-main: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-color: #e0e0e0;
    --input-bg: #ffffff;
    --accent-color: #1a1a1a;
    --accent-text: #ffffff;
    --hover-bg: #f5f5f5;
    --shadow-color: rgba(0,0,0,0.08);
    --card-bg: #ffffff;
    --art-grad-1: #f0f0f0;
    --art-grad-2: #e0e0e0;
}

.dark-mode {
    --bg-body: #121212;
    --bg-surface: #1e1e1e;
    --text-main: #e0e0e0;
    --text-secondary: #aaaaaa;
    --text-muted: #777777;
    --border-color: #333333;
    --input-bg: #252525;
    --accent-color: #ffffff;
    --accent-text: #000000;
    --hover-bg: #2a2a2a;
    --shadow-color: rgba(0,0,0,0.4);
    --card-bg: #1e1e1e;
    --art-grad-1: #2a2a2a;
    --art-grad-2: #333333;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    padding: 0 0 80px 0;
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 20px;
}

.top-nav {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    width: 100%;
    position: sticky;
    top: 0;
    z-index: 500;
}

.nav-content {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    height: 60px;
    padding: 0 20px;
    gap: 30px;
    overflow-x: auto;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
    text-decoration: none;
    margin-right: 10px;
    letter-spacing: -0.5px;
}

.nav-links {
    display: flex;
    gap: 20px;
    height: 100%;
    align-items: center;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    transition: color 0.2s ease;
    white-space: nowrap;
    height: 100%;
    display: flex;
    align-items: center;
    border-bottom: 2px solid transparent;
}

.nav-link:hover {
    color: var(--text-main);
}

.nav-link.active {
    color: var(--text-main);
    border-bottom-color: var(--accent-color);
}

header {
    text-align: left;
    margin-bottom: 40px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content h1 {
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: -0.5px;
    margin-bottom: 10px;
    color: var(--text-main);
}

.subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.theme-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    transition: all 0.3s;
    padding-bottom: 2px;
}
.theme-btn:hover {
    background-color: var(--hover-bg);
}

.search-section {
    margin-bottom: 30px;
}

.search-container {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

input[type="text"] {
    flex: 1;
    padding: 14px 20px;
    padding-left: 20px;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 30px;
    color: var(--text-main);
    font-size: 1rem;
    transition: all 0.3s;
    outline: none;
    box-shadow: 0 2px 5px var(--shadow-color);
}

input[type="text"]:focus {
    border-color: var(--accent-color);
}

button.search-btn {
    padding: 12px 32px;
    background-color: var(--accent-color);
    color: var(--accent-text);
    border: none;
    border-radius: 4px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

button.search-btn:hover {
    opacity: 0.9;
}

.view-controls {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.view-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-right: 5px;
}

.view-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.view-btn:hover {
    border-color: var(--text-secondary);
    color: var(--text-main);
}

.view-btn.active {
    background-color: var(--accent-color);
    color: var(--accent-text);
    border-color: var(--accent-color);
}

.results {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.results.grid-1 { grid-template-columns: 1fr; }
.results.grid-2 { grid-template-columns: repeat(2, 1fr); }
.results.grid-3 { grid-template-columns: repeat(3, 1fr); }
.results.grid-4 { grid-template-columns: repeat(4, 1fr); }

.train-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column; 
    padding: 20px;
    gap: 15px;
    cursor: pointer;
}

.train-card:hover {
    border-color: var(--accent-color);
    box-shadow: 0 2px 8px var(--shadow-color);
}

.train-info {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.train-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    word-break: break-word;
}

.train-details {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    gap: 10px;
}

.detail-item {
    background: var(--hover-bg);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
}

.train-image {
    width: 100%;
    height: 120px;
    background: linear-gradient(135deg, var(--art-grad-1) 0%, var(--art-grad-2) 100%);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.train-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 10px;
}

.loading, .no-results, .error {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 1rem;
}
.error { color: #d32f2f; }

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 95vw; 
    max-width: 1600px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 30px;
    box-shadow: 0 4px 30px rgba(0,0,0,0.2);
    position: relative;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.3s ease;
    line-height: 1;
    z-index: 10;
}

.modal-close:hover {
    color: var(--text-main);
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 20px;
    padding-right: 40px;
}

.modal-details {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-detail-item {
    display: flex;
    flex-direction: column;
}

.modal-detail-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-detail-value {
    font-size: 1rem;
    color: var(--text-main);
    font-weight: 500;
}

.modal-image {
    width: 100%;
    min-height: 200px;
    background: linear-gradient(135deg, var(--art-grad-1) 0%, var(--art-grad-2) 100%);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px 10px;
}

.modal-image img {
    width: 100%;
    height: auto;
    max-height: 60vh;
    object-fit: contain;
    padding: 0;
}

@media (max-width: 800px) {
    .results.grid-4 { grid-template-columns: repeat(2, 1fr); }
    .results.grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
    h1 { font-size: 1.8rem; }
    .header-top { flex-direction: column; gap: 15px; }
    .search-container { flex-direction: column; }
    button.search-btn { width: 100%; }
    
    .results, 
    .results.grid-1, 
    .results.grid-2, 
    .results.grid-3, 
    .results.grid-4 { 
        grid-template-columns: 1fr; 
    }
    
    .view-controls { display: none; }
}