/* Main Stylesheet */

/* Import readable serif fonts */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+JP:wght@400;500;700&family=Crimson+Text:ital,wght@0,400;0,600;1,400&display=swap');

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --background-color: #f5f5f5;
    --text-color: #333;
    --border-color: #ddd;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --card-background: #fff;
    --hover-color: #f8f9fa;
    
    /* Font family variables */
    --sans-serif-font: system-ui, -apple-system, 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Meiryo', sans-serif;
    --serif-font: 'Noto Serif JP', 'Crimson Text', 'Georgia', 'Times New Roman', 'Yu Mincho', 'YuMincho', 'Hiragino Mincho ProN', serif;
    --current-font: var(--sans-serif-font);
}

[data-theme="dark"] {
    --primary-color: #2d3748;
    --secondary-color: #4299e1;
    --accent-color: #e53e3e;
    --background-color: #1a1a1a;
    --text-color: #e2e8f0;
    --border-color: #4a5568;
    --shadow: 0 2px 4px rgba(0,0,0,0.4);
    --card-background: #2d3748;
    --hover-color: #374151;
}

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

body {
    font-family: var(--current-font);
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    transition: font-family 0.3s ease;
}

/* Font mode classes */
[data-font="serif"] {
    --current-font: var(--serif-font);
}

[data-font="sans-serif"] {
    --current-font: var(--sans-serif-font);
}

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

/* Header */
.site-header {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem 0;
    box-shadow: var(--shadow);
}

.site-title {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.site-title a {
    color: white;
    text-decoration: none;
}

.site-nav ul {
    list-style: none;
    display: flex;
    gap: 2rem;
}

.site-nav a {
    color: white;
    text-decoration: none;
    transition: opacity 0.3s;
}

.site-nav a:hover {
    opacity: 0.8;
}

/* Header Layout */
.site-header .container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.site-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.site-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Control buttons (theme and font toggles) */
.theme-toggle,
.font-toggle {
    background: none;
    border: 2px solid white;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
    white-space: nowrap;
}

.theme-toggle:hover,
.font-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.theme-toggle:focus,
.font-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}

/* Main Content */
.main-content {
    min-height: calc(100vh - 200px);
    padding: 2rem 0;
}

/* Search Functionality */
.search-container {
    margin-bottom: 2rem;
}

.search-input-container {
    position: relative;
    max-width: 600px;
    margin: 0 auto;
}

.search-input {
    width: 100%;
    padding: 1rem;
    padding-right: 3rem;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    font-size: 1rem;
    background-color: var(--card-background);
    color: var(--text-color);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.search-clear {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-color);
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.3s;
}

.search-clear:hover {
    opacity: 1;
}

.search-results {
    position: relative;
    max-width: 600px;
    margin: 1rem auto 0;
    background-color: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-height: 400px;
    overflow-y: auto;
}

.search-result {
    border-bottom: 1px solid var(--border-color);
}

.search-result:last-child {
    border-bottom: none;
}

.search-result a {
    display: block;
    padding: 1rem;
    text-decoration: none;
    color: var(--text-color);
    transition: background-color 0.3s;
}

.search-result a:hover {
    background-color: var(--hover-color);
}

.search-title {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 0.3rem;
}

.search-meta {
    font-size: 0.9rem;
    color: var(--secondary-color);
    margin-bottom: 0.3rem;
}

.search-date {
    font-size: 0.8rem;
    color: var(--text-color);
    opacity: 0.7;
}

.search-snippet {
    font-size: 0.9rem;
    color: var(--text-color);
    opacity: 0.8;
    margin-top: 0.3rem;
    line-height: 1.4;
}

.search-no-results,
.search-message {
    padding: 1rem;
    text-align: center;
    color: var(--text-color);
    opacity: 0.7;
}

.search-result mark {
    background-color: #ffeb3b;
    color: #000;
    padding: 0.1rem 0.2rem;
    border-radius: 3px;
}

[data-theme="dark"] .search-result mark {
    background-color: #ffc107;
    color: #000;
}

/* Search Query Display */
.search-query-display {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    background-color: rgba(52, 152, 219, 0.1);
    border: 1px solid rgba(52, 152, 219, 0.3);
    border-radius: 4px;
    font-size: 0.9rem;
}

.query-label {
    color: var(--secondary-color);
    font-weight: 500;
    margin-right: 0.5rem;
}

.search-keyword {
    background-color: var(--secondary-color);
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.85rem;
}

.search-operator {
    color: var(--accent-color);
    font-weight: 600;
    margin: 0 0.25rem;
}

[data-theme="dark"] .search-query-display {
    background-color: rgba(66, 153, 225, 0.15);
    border-color: rgba(66, 153, 225, 0.4);
}

[data-theme="dark"] .search-keyword {
    background-color: var(--secondary-color);
    color: white;
}

[data-theme="dark"] .search-operator {
    color: var(--accent-color);
}

/* Filter Functionality */
.filter-container {
    margin-bottom: 2rem;
    background-color: var(--card-background);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.filter-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: end;
    margin-bottom: 1rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-weight: bold;
    color: var(--text-color);
    font-size: 0.9rem;
}

.filter-select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--card-background);
    color: var(--text-color);
    font-size: 0.9rem;
    min-width: 150px;
}

.filter-select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.1);
}

.filter-clear {
    padding: 0.5rem 1rem;
    background-color: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.3s;
}

.filter-clear:hover {
    background-color: #2980b9;
}

.filter-results {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.results-count {
    color: var(--text-color);
    font-size: 0.9rem;
    opacity: 0.8;
}

.no-events-message {
    text-align: center;
    padding: 3rem;
    color: var(--text-color);
    opacity: 0.7;
}

.no-events-message p {
    margin: 0;
    font-size: 1.1rem;
}

/* Responsive filters */
@media (max-width: 768px) {
    .filter-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    
    .filter-group {
        width: 100%;
    }
    
    .filter-select {
        min-width: auto;
        width: 100%;
    }
}

/* Responsive header */
@media (max-width: 768px) {
    .site-header-top {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
    
    .site-nav ul {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .site-controls {
        justify-content: center;
        gap: 0.5rem;
    }
    
    .theme-toggle,
    .font-toggle {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
}

/* Hero Section */
.hero {
    text-align: center;
    padding: 3rem 0;
    background-color: var(--card-background);
    border-radius: 8px;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.hero h2 {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

/* Events Grid */
.events-section {
    margin-bottom: 3rem;
}

.events-section h2 {
    font-size: 1.8rem;
    color: var(--primary-color);
    margin-bottom: 2rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--secondary-color);
}

/* Unified card grid layout */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

/* Legacy support for events-grid */
.events-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

/* Unified card styling */
.card {
    background-color: var(--card-background);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.3s, box-shadow 0.3s;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.card-header {
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.2rem;
    margin: 0.5rem 0;
    font-weight: bold;
}

.card-title a {
    color: var(--text-color);
    text-decoration: none;
}

.card-title a:hover {
    color: var(--secondary-color);
}

.card-body {
    flex-grow: 1;
    margin-bottom: 1rem;
}

.card-footer {
    margin-top: auto;
}

/* Main story card specific styling */
.main-story-card {
    border-left: 4px solid var(--accent-color);
}

.chapter-indicator {
    background-color: var(--accent-color);
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: bold;
    display: inline-block;
    margin-bottom: 0.5rem;
}

.card-subtitle {
    color: var(--text-color);
    font-size: 0.95rem;
    margin: 0.5rem 0;
    opacity: 0.8;
}

/* Legacy event card support */
.event-card {
    background-color: var(--card-background);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.3s, box-shadow 0.3s;
}

.event-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.event-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.event-title {
    font-size: 1.2rem;
    color: var(--primary-color);
}

.event-title a {
    color: inherit;
    text-decoration: none;
}

.event-title a:hover {
    color: var(--secondary-color);
}

.event-type {
    background-color: var(--secondary-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.event-date {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

[data-theme="dark"] .event-date {
    color: #a0aec0;
}

.event-stories {
    color: #666;
    font-size: 0.9rem;
}

[data-theme="dark"] .event-stories {
    color: #a0aec0;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    text-decoration: none;
    transition: all 0.3s;
    cursor: pointer;
}

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

.btn-primary:hover {
    background-color: #2980b9;
}

[data-theme="dark"] .btn-primary {
    background-color: #4299e1;
    color: #1a1a1a;
}

[data-theme="dark"] .btn-primary:hover {
    background-color: #63b3ed;
    color: #1a1a1a;
}

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

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

[data-theme="dark"] .btn-secondary {
    background-color: #718096;
    color: #1a1a1a;
}

[data-theme="dark"] .btn-secondary:hover {
    background-color: #a0aec0;
    color: #1a1a1a;
}

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

.btn-back:hover {
    background-color: #34495e;
}

[data-theme="dark"] .btn-back {
    background-color: #4a5568;
    color: #e2e8f0;
}

[data-theme="dark"] .btn-back:hover {
    background-color: #718096;
    color: #e2e8f0;
}

/* Breadcrumb */
.breadcrumb {
    margin-bottom: 2rem;
}

.breadcrumb ol {
    list-style: none;
    display: flex;
    gap: 0.5rem;
}

.breadcrumb li::after {
    content: ">";
    margin-left: 0.5rem;
    color: #999;
}

.breadcrumb li:last-child::after {
    content: "";
}

.breadcrumb a {
    color: var(--secondary-color);
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.breadcrumb .active {
    color: var(--text-color);
}

/* Stories List */
.stories-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.story-item {
    background-color: var(--card-background);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.story-item .story-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.story-title {
    font-size: 1.1rem;
    color: var(--primary-color);
}

.story-title a {
    color: inherit;
    text-decoration: none;
}

.story-title a:hover {
    color: var(--secondary-color);
}

.story-code {
    background-color: #ecf0f1;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-family: monospace;
}

[data-theme="dark"] .story-code {
    background-color: #4a5568;
    color: #e2e8f0;
}

.story-summary {
    color: #666;
    margin-bottom: 1rem;
}

[data-theme="dark"] .story-summary {
    color: #a0aec0;
}

/* Story meta information */
.story-meta {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.story-phase {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-weight: bold;
    text-transform: uppercase;
}

.story-phase-before {
    background: #e3f2fd;
    color: #1565c0;
}

[data-theme="dark"] .story-phase-before {
    background: #2d3748;
    color: #90cdf4;
}

.story-phase-after {
    background: #f3e5f5;
    color: #7b1fa2;
}

[data-theme="dark"] .story-phase-after {
    background: #2d3748;
    color: #d6bcfa;
}

.story-phase-story {
    background: #e8f5e8;
    color: #2e7d32;
}

[data-theme="dark"] .story-phase-story {
    background: #2d3748;
    color: #9ae6b4;
}

.danger-level {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    background: var(--hover-color);
    color: #e65100;
    border-radius: 12px;
    font-weight: bold;
}

[data-theme="dark"] .danger-level {
    background: #4a5568;
    color: #fbb6ce;
}

/* Word count styles */
.word-count {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    background: #e3f2fd;
    color: #1565c0;
    border-radius: 12px;
    font-weight: bold;
}

[data-theme="dark"] .word-count {
    background: #2d3748;
    color: #63b3ed;
}

.total-wordcount {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--card-background);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.wordcount-label {
    font-weight: bold;
    color: var(--text-color);
}

.wordcount-value {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--secondary-color);
}

/* Story no content styles */
.story-no-content {
    opacity: 0.7;
    background-color: var(--hover-color);
}

[data-theme="dark"] .story-no-content {
    background-color: #374151;
}

.story-title-no-link {
    color: var(--text-color);
    opacity: 0.8;
}

.no-story-indicator {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    background: #ffebee;
    color: #c62828;
    border-radius: 12px;
    font-weight: bold;
}

[data-theme="dark"] .no-story-indicator {
    background: #4a5568;
    color: #fbb6ce;
}

.btn-disabled {
    background-color: #bdbdbd;
    color: #757575;
    cursor: not-allowed;
    opacity: 0.6;
}

[data-theme="dark"] .btn-disabled {
    background-color: #4a5568;
    color: #a0aec0;
}

/* Footer */
.site-footer {
    background-color: var(--primary-color);
    color: white;
    padding: 2rem 0;
    text-align: center;
    margin-top: 3rem;
}

.disclaimer {
    margin-top: 1rem;
    font-size: 0.9rem;
    opacity: 0.8;
}

.disclaimer a {
    color: white;
    text-decoration: underline;
}

/* Links */
a {
    color: var(--secondary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

[data-theme="dark"] a {
    color: #4299e1;
}

[data-theme="dark"] a:hover {
    color: #63b3ed;
}

/* N-gram search specific styles */
.search-relevance {
    font-size: 0.75rem;
    color: #666;
    margin-top: 0.25rem;
    font-weight: normal;
}

[data-theme="dark"] .search-relevance {
    color: #a0a0a0;
}

.search-snippet {
    max-height: 3em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.search-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    color: #666;
    font-style: italic;
}

.search-loading::before {
    content: "⏳";
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

[data-theme="dark"] .search-loading {
    color: #a0a0a0;
}

/* About Section */
.about-section {
    background-color: var(--card-background);
    border-radius: 8px;
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-top: 3rem;
}

.about-section h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.about-section p {
    margin-bottom: 1rem;
}

.about-section a {
    color: var(--secondary-color);
}

/* Responsive */
@media (max-width: 768px) {
    .cards-grid,
    .events-grid {
        grid-template-columns: 1fr;
    }
    
    .site-nav ul {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .hero h2 {
        font-size: 1.5rem;
    }
    
    .card,
    .event-card {
        padding: 1rem;
    }
    
    .chapter-indicator {
        font-size: 0.8rem;
        padding: 0.25rem 0.6rem;
    }
}