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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    font-size: 16px;
}

#app {
    display: grid;
    grid-template-areas:
        "header header"
        "main sidebar"
        "footer footer";
    grid-template-columns: 1fr 300px;
    grid-template-rows: auto 1fr auto;
    min-height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
#game-header {
    grid-area: header;
    background: #2c3e50;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

#story-title {
    font-size: 1.8rem;
    font-weight: 300;
}

.stats-container {
    display: flex;
    gap: 2rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-label {
    font-size: 0.875rem;
    opacity: 0.8;
}

.stat-value {
    font-weight: bold;
    font-size: 1.1rem;
}

.stat-bar {
    width: 100px;
    height: 8px;
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    background: #3498db;
    transition: width 0.3s ease;
}

/* Main Story Container */
#story-container {
    grid-area: main;
    padding: 2rem;
    background: white;
    margin: 1rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.story-text {
    margin-bottom: 2rem;
    line-height: 1.8;
    color: #2c3e50;
}

.story-text p {
    margin-bottom: 1rem;
}

.story-text p:last-child {
    margin-bottom: 0;
}

/* Choices */
.choices {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.choice-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    text-align: left;
    transition: all 0.2s ease;
}

.choice-btn:hover {
    background: #2980b9;
    transform: translateX(5px);
}

.choice-btn:active {
    transform: translateX(3px);
}

.choice-btn:disabled {
    background: #95a5a6;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Sidebar */
#sidebar {
    grid-area: sidebar;
    padding: 1rem;
    background: #ecf0f1;
    overflow-y: auto;
}

.sidebar-section {
    background: white;
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.sidebar-section.collapsible {
    padding: 0;
}

.sidebar-section h3 {
    margin-bottom: 0.75rem;
    color: #2c3e50;
    font-size: 1.1rem;
}

.sidebar-section.collapsible .section-header {
    padding: 1rem;
    margin: 0;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s ease;
}

.sidebar-section.collapsible .section-header:hover {
    background: #f8f9fa;
}

.toggle-icon {
    font-size: 0.8rem;
    transition: transform 0.2s ease;
    display: inline-block;
    min-width: 1rem;
}

.section-content {
    padding: 0 1rem 1rem 1rem;
    overflow: hidden;
    transition: max-height 0.3s ease;
    max-height: 1000px;
}

.sidebar-section.collapsed .section-content {
    max-height: 0 !important;
    padding-top: 0;
    padding-bottom: 0;
}

/* Character Info */
#character-info {
    font-size: 0.9rem;
}

.character-stat {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

/* Equipment */
.equipment-slot {
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color, #ddd);
    border-radius: 3px;
}

.slot-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.slot-item {
    font-size: 0.9rem;
    padding: 0.25rem;
    border-radius: 2px;
}

.slot-item.equipped {
    background: var(--success-color);
    color: white;
}

.slot-item.empty {
    background: var(--bg-tertiary);
    color: var(--text-light);
    font-style: italic;
}

/* Inventory */
.inventory-item {
    padding: 0.5rem;
    margin-bottom: 0.25rem;
    background: #f8f9fa;
    border-radius: 3px;
    font-size: 0.9rem;
}

/* Relationships */
.relationship-item {
    margin-bottom: 0.75rem;
}

.relationship-name {
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.relationship-bar {
    width: 100%;
    height: 10px;
    background: #e0e0e0;
    border-radius: 5px;
    overflow: hidden;
}

.relationship-bar-fill {
    height: 100%;
    transition: width 0.3s ease;
}

.relationship-bar-fill.friendly {
    background: #2ecc71;
}

.relationship-bar-fill.romantic {
    background: #e74c3c;
}

.relationship-bar-fill.neutral {
    background: #95a5a6;
}

/* Footer */
#game-footer {
    grid-area: footer;
    background: #34495e;
    padding: 1rem;
    text-align: center;
}

.game-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.control-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s ease;
}

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

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 2rem;
    cursor: pointer;
    color: #95a5a6;
}

.close:hover {
    color: #2c3e50;
}

/* Settings */
.settings-group {
    margin-top: 1.5rem;
}

.settings-group label {
    display: block;
    margin-bottom: 1rem;
    cursor: pointer;
}

.settings-group input[type="checkbox"] {
    margin-right: 0.5rem;
}

.settings-group input[type="range"] {
    margin-left: 0.5rem;
}

/* Save Slots */
#save-slots {
    margin-top: 1.5rem;
}

.save-slot {
    border: 1px solid #ddd;
    padding: 1rem;
    margin-bottom: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.save-slot:hover {
    background: #f8f9fa;
}

.save-slot-empty {
    color: #95a5a6;
    font-style: italic;
}

.save-slot-info {
    font-size: 0.875rem;
    color: #7f8c8d;
    margin-top: 0.25rem;
}

/* Time Display */
.time-display {
    text-align: center;
    font-size: 0.9rem;
}

.time-display .date {
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.time-display .time {
    font-size: 1.1rem;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.time-display .day,
.time-display .season {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.1rem;
}

/* Responsive */
@media (max-width: 768px) {
    #app {
        grid-template-areas:
            "header"
            "main"
            "sidebar"
            "footer";
        grid-template-columns: 1fr;
    }
    
    #sidebar {
        display: flex;
        gap: 1rem;
        padding: 1rem;
        overflow-x: auto;
    }
    
    .sidebar-section {
        min-width: 250px;
    }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.5s ease;
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

:focus {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

/* Enhanced Responsive Design */
@media screen and (max-width: 768px) {
    body {
        font-size: 16px; /* Increase base font size for mobile */
    }
    
    .sidebar {
        display: none;
    }
    
    #story-container {
        margin-right: 0;
        padding: 1rem;
    }
    
    .choice-item {
        padding: 1.5rem; /* Larger touch targets */
        margin: 1rem 0;
        font-size: 1.1rem;
        min-height: 44px; /* iOS recommended touch target size */
    }
    
    .choice-item:hover {
        transform: scale(1.02); /* Subtle touch feedback */
    }
    
    #game-header {
        padding: 1rem;
        text-align: center;
    }
    
    #story-title {
        font-size: 1.5rem;
    }
    
    .stats-container {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }
    
    .stat-item {
        flex: 1;
        min-width: 80px;
        text-align: center;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #000080;
        --text-primary: #000000;
        --bg-primary: #ffffff;
        --border-color: #000000;
    }
    
    .choice-item {
        border: 2px solid var(--border-color);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print styles */
@media print {
    .sidebar,
    .choices,
    #game-header .stats-container {
        display: none;
    }
    
    #story-container {
        margin: 0;
        max-width: 100%;
    }
    
    .story-text {
        font-size: 12pt;
        line-height: 1.6;
        color: black;
    }
}
/* Storybook Accumulating Layout */
#story-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding-bottom: 2rem;
}

.story-scene {
    padding: 1.5rem;
    border-left: 4px solid #667eea;
    background: linear-gradient(to right, #f9f9ff 0%, #ffffff 10%);
    border-radius: 4px;
    animation: fadeIn 0.5s ease-in;
}

.scene-title {
    color: #4a5fc1;
    font-size: 1.3rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.story-scene .story-text {
    color: #2c3e50;
    line-height: 1.8;
    margin-bottom: 0;
}

.scene-image {
    width: 100%;
    max-width: 600px;
    height: auto;
    margin: 1.5rem 0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Player Choice Display - Enhanced contrast for WCAG AA compliance */
.player-choice {
    background: linear-gradient(135deg, #4a5fc1 0%, #5d3a7e 100%);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin: 1rem 0;
    font-style: italic;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    animation: fadeIn 0.4s ease-in;
}

.player-choice strong {
    font-weight: 600;
    margin-right: 0.5rem;
}

/* AI Generation Indicator - Enhanced contrast for WCAG AA compliance */
.ai-generating {
    background: linear-gradient(90deg, #c74ed4 0%, #d93f52 100%);
    color: white;
    padding: 1rem;
    padding-left: 3rem;
    border-radius: 8px;
    text-align: center;
    font-weight: 600;
    animation: pulse 1.5s ease-in-out infinite;
    margin: 1rem 0;
    position: relative;
}

/* Loading spinner for AI generation */
.ai-generating::before {
    content: '';
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .ai-generating {
        animation: none;
    }

    .ai-generating::before {
        animation: fade-pulse 1.5s ease-in-out infinite;
    }
}

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

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.02);
    }
}

/* Choice Button Disabled State */
.choice-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #ccc;
}

.choice-btn.disabled:hover {
    background: #ccc;
    transform: none;
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Story Content Scrolling */
#story-container {
    overflow-y: auto;
    max-height: calc(100vh - 200px);
}
