/*
 * Multi-Tool App Styles
 * 
 * HOW TO ADD A NEW THEME:
 * 
 * 1. In this file (styles.css):
 *    - Copy one of the existing theme blocks (e.g., body.theme-dark)
 *    - Rename it to body.theme-yourthemename
 *    - Customize the CSS variable colors
 * 
 * 2. In script.js:
 *    - Add your theme to the AVAILABLE_THEMES array:
 *      { id: 'yourthemename', name: 'Your Theme Name', icon: '🎨' }
 * 
 * That's it! The theme will automatically appear in the theme switcher.
 * 
 * CSS Variables used in themes:
 * --bg-primary: Main background color
 * --bg-secondary: Secondary background (lighter/darker than primary)
 * --bg-card: Card/modal background
 * --text-primary: Main text color
 * --text-secondary: Secondary/muted text color
 * --accent-primary: Primary accent color (buttons, highlights)
 * --accent-secondary: Secondary accent color
 * --border-color: Border colors
 * --input-bg: Input field backgrounds
 * --shadow: Box shadow color (with opacity)
 * --variable-bg: Variable tag background
 * --variable-color: Variable tag text color
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --text-primary: #eee;
    --text-secondary: #ccc;
    --accent-primary: #e94560;
    --accent-secondary: #533483;
    --border-color: #2d3561;
    --input-bg: #1a1a2e;
    --shadow: rgba(0, 0, 0, 0.3);
}

/* DARK THEME */
body.theme-dark {
    --bg-primary: #0a0e27;
    --bg-secondary: #1a1f3a;
    --bg-card: #252b48;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --accent-primary: #8b5cf6;
    --accent-secondary: #a78bfa;
    --border-color: #3f3f46;
    --input-bg: #18181b;
    --shadow: rgba(0, 0, 0, 0.5);
    --variable-bg: #4c1d95;
    --variable-color: #e9d5ff;
}

/* LIGHT THEME */
body.theme-light {
    --bg-primary: #f8fafc;
    --bg-secondary: #f1f5f9;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --accent-primary: #3b82f6;
    --accent-secondary: #60a5fa;
    --border-color: #e2e8f0;
    --input-bg: #ffffff;
    --shadow: rgba(0, 0, 0, 0.1);
    --variable-bg: #dbeafe;
    --variable-color: #1e40af;
}

/* GIRLY THEME */
body.theme-girly {
    --bg-primary: #fce7f3;
    --bg-secondary: #fbcfe8;
    --bg-card: #ffffff;
    --text-primary: #831843;
    --text-secondary: #9f1239;
    --accent-primary: #ec4899;
    --accent-secondary: #f472b6;
    --border-color: #f9a8d4;
    --input-bg: #fdf2f8;
    --shadow: rgba(236, 72, 153, 0.2);
    --variable-bg: #fce7f3;
    --variable-color: #be185d;
}

/* CYBERPUNK THEME - Example of how easy it is to add a new theme! */
body.theme-cyberpunk {
    --bg-primary: #0a0e27;
    --bg-secondary: #1a1333;
    --bg-card: #16001e;
    --text-primary: #00ff9f;
    --text-secondary: #bd00ff;
    --accent-primary: #ff006e;
    --accent-secondary: #00f5ff;
    --border-color: #bd00ff;
    --input-bg: #1a0033;
    --shadow: rgba(189, 0, 255, 0.3);
    --variable-bg: #3d0066;
    --variable-color: #00ff9f;
}

/* MATRIX THEME - Hidden theme (access via ?theme=matrix) */
body.theme-matrix {
    --bg-primary: #000000;
    --bg-secondary: #001a00;
    --bg-card: #003300;
    --text-primary: #00ff00;
    --text-secondary: #00cc00;
    --accent-primary: #00ff00;
    --accent-secondary: #00cc00;
    --border-color: #00ff00;
    --input-bg: #001100;
    --shadow: rgba(0, 255, 0, 0.3);
    --variable-bg: #004d00;
    --variable-color: #00ff00;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    text-align: center;
    color: var(--text-primary);
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.controls {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
}

.theme-switcher {
    display: flex;
    gap: 8px;
    padding: 4px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 2px solid var(--border-color);
}

.theme-btn {
    width: 45px;
    height: 45px;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.theme-btn:hover {
    background: var(--accent-primary);
    transform: scale(1.1);
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    box-shadow: 0 2px 8px var(--shadow);
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-secondary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-card);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.btn-edit {
    background: #3b82f6;
    color: white;
}

.btn-edit:hover {
    background: #2563eb;
}

.btn-delete {
    background: #ef4444;
    color: white;
}

.btn-delete:hover {
    background: #dc2626;
}

.btn-copy {
    background: var(--accent-primary);
    color: white;
}

.btn-copy:hover {
    background: var(--accent-secondary);
}

.stories-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.story-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 12px var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 2px solid var(--border-color);
}

.story-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px var(--shadow);
    border-color: var(--accent-primary);
}

.story-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

.story-title {
    font-size: 1.5rem;
    color: var(--text-primary);
    font-weight: 700;
}

.story-text {
    background: var(--bg-secondary);
    padding: 18px;
    border-radius: 12px;
    margin-bottom: 15px;
    line-height: 1.8;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

.story-text::-webkit-scrollbar {
    width: 10px;
}

.story-text::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 5px;
}

.story-text::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 5px;
}

.story-text::-webkit-scrollbar-thumb:hover {
    background: var(--accent-secondary);
}

.variable {
    background: var(--variable-bg);
    padding: 3px 8px;
    border-radius: 6px;
    font-weight: 700;
    color: var(--variable-color);
    border: 1px solid var(--accent-primary);
}

.story-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.story-actions .btn {
    flex: 1;
    min-width: 100px;
    padding: 10px 16px;
    font-size: 0.9rem;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: var(--bg-card);
    margin: 5% auto;
    padding: 0;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 8px 32px var(--shadow);
    animation: slideIn 0.3s;
    border: 2px solid var(--border-color);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.variable-modal-large {
    max-width: 900px;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 24px;
    background: var(--accent-primary);
    color: white;
    border-radius: 14px 14px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

.close {
    color: white;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.close:hover,
.close:focus {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.modal-body {
    padding: 24px;
    max-height: 70vh;
    overflow-y: auto;
    flex: 1;
}

.modal-body::-webkit-scrollbar {
    width: 10px;
}

.modal-body::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 5px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 5px;
}

.modal-footer {
    padding: 20px 24px;
    background: var(--bg-secondary);
    border-radius: 0 0 14px 14px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    border-top: 2px solid var(--border-color);
    flex-shrink: 0;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1.05rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 14px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.3s;
    background: var(--input-bg);
    color: var(--text-primary);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.form-group small,
.info-text {
    display: block;
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.variables-edit-container {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 10px;
    border: 2px solid var(--border-color);
    min-height: 60px;
}

.variable-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
    padding: 16px;
    background: var(--input-bg);
    border-radius: 12px;
    border: 2px solid var(--border-color);
    transition: all 0.3s ease;
}

.variable-item:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px var(--shadow);
}

.variable-item label {
    margin: 0;
    font-weight: 700;
    color: var(--accent-primary);
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.variable-item input {
    margin: 0;
    padding: 12px 14px;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.variable-item input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
    background: var(--input-bg);
}

.variable-item input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
    grid-column: 1 / -1;
}

.empty-state h2 {
    font-size: 2rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.empty-state p {
    font-size: 1.1rem;
}

.variable-editor-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.variables-section,
.preview-section {
    min-height: 300px;
}

.variables-section h3,
.preview-section h3 {
    color: var(--text-primary);
    margin-bottom: 16px;
    font-size: 1.2rem;
}

.variables-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 4px;
}

.story-preview {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    min-height: 250px;
    max-height: 400px;
    overflow-y: auto;
    line-height: 1.8;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.story-preview::-webkit-scrollbar {
    width: 8px;
}

.story-preview::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 4px;
}

.story-preview::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 4px;
}

.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--accent-primary);
    color: white;
    padding: 18px 28px;
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--shadow);
    z-index: 2000;
    animation: slideInRight 0.3s, slideOutRight 0.3s 2.7s;
    font-weight: 600;
    border: 2px solid var(--accent-secondary);
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

@media (max-width: 968px) {
    .variable-editor-layout {
        grid-template-columns: 1fr;
    }
    
    .preview-section {
        order: -1;
        margin-bottom: 20px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .stories-container {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .modal {
        padding: 0;
    }
    
    .modal-content {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
        border: none;
    }
    
    .modal-header {
        border-radius: 0;
        padding: 16px;
    }
    
    .modal-header h2 {
        font-size: 1.3rem;
    }
    
    .modal-body {
        padding: 16px;
        max-height: none;
    }
    
    .modal-footer {
        border-radius: 0;
        padding: 16px;
        flex-wrap: wrap;
    }
    
    .modal-footer .btn {
        flex: 1;
        min-width: 120px;
    }
    
    .controls {
        flex-direction: column;
        gap: 12px;
    }
    
    .theme-switcher {
        order: -1;
        width: 100%;
        justify-content: center;
    }
    
    .btn {
        width: 100%;
        padding: 14px 20px;
    }
    
    .story-card {
        padding: 16px;
    }
    
    .story-title {
        font-size: 1.3rem;
    }
    
    .story-actions {
        flex-direction: column;
    }
    
    .story-actions .btn {
        width: 100%;
        min-width: auto;
    }
    
    .variable-item {
        padding: 12px;
    }
    
    .variable-item label {
        font-size: 0.9rem;
    }
    
    .variable-item input {
        padding: 10px 12px;
        font-size: 0.95rem;
    }
    
    .form-group input,
    .form-group textarea {
        padding: 12px;
        font-size: 0.95rem;
    }
    
    .toast {
        bottom: 20px;
        right: 20px;
        left: 20px;
        padding: 14px 18px;
        font-size: 0.9rem;
    }
    
    .story-preview {
        font-size: 0.95rem;
        padding: 15px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }
    
    .subtitle {
        font-size: 0.9rem;
    }
    
    .story-text {
        font-size: 0.9rem;
        padding: 12px;
    }
    
    .theme-btn {
        width: 40px;
        height: 40px;
        font-size: 1.3rem;
    }
    
    .variable-editor-layout {
        gap: 16px;
    }
    
    .variables-section h3,
    .preview-section h3 {
        font-size: 1.1rem;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .btn {
        padding: 16px 24px;
        font-size: 1.05rem;
    }
    
    .story-card {
        padding: 20px;
    }
    
    .variable-item input,
    .form-group input,
    .form-group textarea {
        padding: 14px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .close {
        width: 48px;
        height: 48px;
        font-size: 36px;
    }
}
