/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
    padding: 20px;
}

.screen.active {
    display: block;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    color: white;
}

.game-header h1 {
    font-size: 2rem;
    font-weight: 600;
}

/* Configuration Container */
.config-container {
    display: grid;
    grid-template-columns: 1fr; /* Make config panel full width */
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
}

.config-panel {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    height: fit-content;
}

.config-panel h2 {
    font-size: 1.8rem;
    margin-bottom: 25px;
    color: #2d3748;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 10px;
}

.config-group {
    margin-bottom: 25px;
}

.config-group h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: #4a5568;
}

/* Tiles */
.tile-hint {
    color: #718096;
    font-size: 12px;
    margin-top: -8px;
    margin-bottom: 10px;
}

.tile-custom {
    margin-top: 8px;
}
.tile-custom input {
    width: 100%;
    padding: 8px 10px;
    border: 1px dashed #cbd5e0;
    border-radius: 8px;
    font-size: 13px;
}

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.tile {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    min-height: 48px;
    width: 100%;
    position: relative;
}

.tile > span:first-child {
    flex: 1;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tile .chevron {
    font-size: 16px;
    color: #666;
    transition: transform 0.2s ease;
    flex-shrink: 0;
    padding: 4px;
    min-width: 24px;
    text-align: center;
    margin-top: 2px;
    display: inline-block;
    visibility: visible;
}

.tile .chevron.expanded {
    transform: rotate(180deg);
}

.tile:hover {
    border-color: #667eea;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

.tile.selected {
    border-color: #667eea;
    background: #f0f4ff;
}

.tile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: #2d3748;
    font-size: 14px;
}

.tile-chevron {
    font-size: 16px;
    color: #718096;
}

.tile-subgrid {
    display: none;
    grid-template-columns: 1fr;
    gap: 4px;
    margin-top: 6px;
}

.tile.open .tile-subgrid {
    display: grid;
}

.subtile {
    border: 1px dashed #cbd5e0;
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 11px;
    color: #4a5568;
    cursor: pointer;
    transition: border-color 0.15s;
}

.subtile.selected {
    border-color: #667eea;
    background: #f7f9ff;
}

/* New markup variant for prebuilt sub-tiles */
/* Place sub-tiles inside their parent tile visually */
.sub-tiles {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    margin-top: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease;
    background: #f8f9fa;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin: 8px 0;
}
.sub-tiles .tile-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    padding: 8px;
    gap: 6px;
}
.sub-tiles.active {
    max-height: 500px;
    opacity: 1;
    margin-top: 8px;
}

/* Form Elements */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.form-field {
    display: flex;
    flex-direction: column;
}

.form-field label {
    font-weight: 500;
    margin-bottom: 5px;
    color: #4a5568;
}

.form-field input,
.form-field select {
    padding: 10px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-field input:focus,
.form-field select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-field small {
    font-size: 12px;
    color: #718096;
    margin-top: 5px;
}

/* Sliders */
.slider-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.slider-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.slider-item label {
    font-weight: 500;
    color: #4a5568;
    display: flex;
    justify-content: space-between;
}

.slider {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    outline: none;
    transition: background 0.2s;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #667eea;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.slider::-webkit-slider-thumb:hover {
    background: #5a67d8;
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #667eea;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Checkboxes */
.checkbox-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    color: #4a5568;
}

.checkbox-label input[type="checkbox"] {
    margin-right: 8px;
    width: 16px;
    height: 16px;
    accent-color: #667eea;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a67d8;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.btn-secondary:hover {
    background: #cbd5e0;
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: white;
    border: 2px solid white;
}

.btn-outline:hover {
    background: white;
    color: #667eea;
}

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

.btn.locked {
    opacity: 0.5;
    cursor: not-allowed;
    position: relative;
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    border-color: #6c757d;
    color: #fff;
}

.btn.locked::after {
    content: '🔒';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
}

.action-buttons {
    display: flex;
    gap: 15px;
    margin-top: 30px;
    flex-wrap: wrap;
}

.game-controls {
    display: flex;
    gap: 10px;
}

/* Output Panel */
.output-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100%;
}

.output-section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.output-section.full-height {
    flex: 1;
    height: 100%;
}

.output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e2e8f0;
}

.output-header h3 {
    font-size: 1.2rem;
    color: #2d3748;
}

.output-actions {
    display: flex;
    gap: 8px;
}

.output-section textarea {
    width: 100%;
    flex: 1;
    min-height: 400px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    padding: 15px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    background: #f7fafc;
}

.output-section textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Tile selectors */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.tile {
    padding: 12px 14px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
    color: #2d3748;
    cursor: pointer;
    user-select: none;
    transition: all .15s ease-in-out;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.tile:hover {
    border-color: #667eea;
    transform: translateY(-1px);
}

.tile.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-color: transparent;
}

/* Duplicate sub-tiles styles removed - using the improved version above */

/* Game Container */
.game-container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

/* Game Status */
.game-status {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
    padding: 20px;
    background: #f7fafc;
    border-radius: 8px;
}

.status-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.status-item label {
    font-weight: 600;
    color: #4a5568;
    font-size: 14px;
}

.hp-display {
    font-size: 1.2rem;
    font-weight: 700;
    color: #38a169;
}

.status-list {
    font-size: 14px;
    color: #718096;
    min-height: 20px;
}

/* Game Main */
.game-main {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 30px;
}

.scene-panel,
.actions-panel {
    background: #f7fafc;
    border-radius: 8px;
    padding: 20px;
}

.scene-panel h3,
.actions-panel h3 {
    margin-bottom: 15px;
    color: #2d3748;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 8px;
}

.scene-content {
    font-size: 16px;
    line-height: 1.6;
    color: #4a5568;
    min-height: 200px;
}

.actions-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.action-button {
    padding: 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.action-button:hover {
    border-color: #667eea;
    background: #f7fafc;
    transform: translateY(-1px);
}

.action-button:active {
    transform: translateY(0);
}

.action-title {
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 5px;
}

.action-description {
    font-size: 14px;
    color: #718096;
    line-height: 1.4;
}

.loading-text {
    text-align: center;
    color: #718096;
    font-style: italic;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
    flex-direction: column;
    gap: 20px;
}

.loading-overlay.active {
    display: flex;
}

/* Blur background when API key gate is open */
#api-key-gate {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: white;
    border-radius: 8px;
    padding: 15px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-left: 4px solid #38a169;
    min-width: 300px;
    animation: slideIn 0.3s ease-out;
}

.toast.error {
    border-left-color: #e53e3e;
}

.toast.warning {
    border-left-color: #dd6b20;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive Design */
@media (max-width: 1024px) {
    .config-container {
        grid-template-columns: 1fr;
    }
    
    .game-main {
        grid-template-columns: 1fr;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .checkbox-group {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 2rem;
    }
    
    .game-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .game-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .action-buttons .btn {
        width: 100%;
    }
    
    .config-panel,
    .game-container {
        padding: 20px;
    }
}

/* Extra-compact layout for small mobile devices */
@media (max-width: 600px) {
    body {
        font-size: 14px;
    }

    .header h1 {
        font-size: 1.6rem;
    }

    .header p {
        font-size: 0.95rem;
    }

    .config-panel,
    .game-container {
        padding: 16px;
    }

    .form-field label {
        font-size: 13px;
    }

    .form-field input,
    .form-field select {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .tile {
        min-height: 52px;
        padding: 10px 12px;
    }
    
    .tile .chevron {
        font-size: 18px;
        min-width: 28px;
        padding: 6px;
    }
    
    .tile-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 8px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 13px;
    }

    .btn-small {
        padding: 5px 10px;
        font-size: 11px;
    }

    .action-buttons {
        gap: 10px;
        margin-top: 20px;
    }

    .game-header h1 {
        font-size: 1.5rem;
    }

    .game-status {
        padding: 12px;
        gap: 12px;
    }

    .status-item label {
        font-size: 13px;
    }

    .hp-display {
        font-size: 1rem;
    }

    .scene-content {
        font-size: 15px;
    }

    .action-button {
        padding: 12px;
    }

    .output-section textarea {
        min-height: 280px;
        padding: 12px;
        font-size: 12px;
    }

    .toast {
        min-width: 220px;
        padding: 12px 16px;
    }
}
/* HP Color Variations */
.hp-display.high {
    color: #38a169;
}

.hp-display.medium {
    color: #dd6b20;
}

.hp-display.low {
    color: #e53e3e;
}
