/* ===================================
   GENERATORE DI FIABE PROPP
   Mobile-First Responsive CSS
   =================================== */

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

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #8b5cf6;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;

    --bg-color: #f9fafb;
    --card-bg: #ffffff;
    --text-color: #1f2937;
    --text-light: #6b7280;
    --border-color: #e5e7eb;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

    --border-radius: 12px;
    --transition: all 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px; /* Minimo 16px per evitare zoom iOS */
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Typography */
h1, h2, h3, h4 {
    line-height: 1.2;
    margin-bottom: 1rem;
    color: var(--text-color);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

p {
    margin-bottom: 1rem;
}

/* Layout */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

main {
    flex: 1;
    padding: 1.5rem 0;
}

/* Header / Navbar */
header {
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar {
    padding: 1rem 0;
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.logo {
    font-size: 1.5rem;
    margin: 0;
}

.nav-menu {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.username {
    font-weight: 600;
    color: var(--primary-color);
}

.nav-link {
    color: var(--text-color);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
    min-height: 44px; /* Touch target */
    display: flex;
    align-items: center;
}

.nav-link:hover {
    background: var(--bg-color);
}

/* Footer */
footer {
    background: var(--card-bg);
    padding: 2rem 0;
    margin-top: 3rem;
    text-align: center;
    color: var(--text-light);
    font-size: 0.875rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    min-height: 44px; /* Touch target minimo */
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    touch-action: manipulation; /* Previene double-tap zoom */
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

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

.btn-secondary:hover:not(:disabled) {
    background: #7c3aed;
}

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

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-block {
    width: 100%;
    display: block;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.125rem;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    min-height: auto;
}

/* Forms */
.form-control {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem; /* Minimo 16px */
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-color);
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Alerts */
.alert {
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
}

.alert-success { background: #d1fae5; color: #065f46; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info { background: #dbeafe; color: #1e40af; }

/* === LOGIN PAGE === */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 70vh;
    padding: 1rem;
}

.login-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

.login-card h2 {
    text-align: center;
    margin-bottom: 0.5rem;
}

.subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 2rem;
}

.help-text {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-light);
}

/* === WELCOME PAGE === */
.welcome-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

.welcome-text {
    font-size: 1.125rem;
    color: var(--text-light);
    margin-bottom: 2rem;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.info-box {
    background: var(--bg-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-top: 2rem;
}

.info-box h3 {
    margin-bottom: 1rem;
}

.info-box ol {
    padding-left: 1.5rem;
}

.info-box li {
    margin-bottom: 0.5rem;
}

/* === STORY PAGE === */
.progress-bar {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-light);
}

.progress-track {
    height: 8px;
    background: var(--border-color);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width 0.3s ease;
}

.function-card {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-md);
}

.function-card h2 {
    color: white;
}

.variants-selector {
    margin-top: 1rem;
}

.variants-selector label {
    display: block;
    margin-bottom: 0.5rem;
}

.variants-selector select {
    background: white;
    color: var(--text-color);
}

.story-text-container {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.story-content {
    max-height: 300px;
    overflow-y: auto;
    padding: 1rem;
    background: var(--bg-color);
    border-radius: var(--border-radius);
}

.empty-message {
    color: var(--text-light);
    font-style: italic;
}

.choices-container {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.alternatives {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.alternative-card {
    background: var(--bg-color);
    border: 3px solid transparent;
    border-radius: var(--border-radius);
    padding: 1rem;
    cursor: pointer;
    transition: var(--transition);
    min-height: 80px; /* Touch target generoso */
    display: flex;
    gap: 1rem;
}

.alternative-card:hover {
    border-color: var(--primary-color);
    background: white;
}

.alternative-card.selected {
    border-color: var(--primary-color);
    background: white;
    box-shadow: var(--shadow-md);
}

.alternative-number {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.25rem;
}

.alternative-text {
    flex: 1;
    margin: 0;
}

.custom-input-section {
    margin-bottom: 1.5rem;
}

.custom-input-section label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.custom-input-section textarea {
    min-height: 100px;
}

/* Complete Container */
.complete-container {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}

.complete-card h2 {
    text-align: center;
    color: var(--success-color);
    margin-bottom: 2rem;
}

.complete-story {
    margin-bottom: 2rem;
}

.final-story-text {
    background: var(--bg-color);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    max-height: 400px;
    overflow-y: auto;
}

.complete-schema {
    background: var(--bg-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
}

.schema-text {
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    word-break: break-all;
}

.save-section {
    margin-top: 2rem;
}

.save-section input {
    margin-bottom: 1rem;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay p {
    color: white;
    font-size: 1.125rem;
    margin-top: 1rem;
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === ARCHIVE PAGE === */
.stories-grid {
    display: grid;
    gap: 1.5rem;
    margin-top: 2rem;
}

.story-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    transition: var(--transition);
}

.story-card:hover {
    box-shadow: var(--shadow-lg);
}

.story-title {
    margin-bottom: 1rem;
}

.story-meta {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-light);
    margin-bottom: 1rem;
}

.story-preview {
    color: var(--text-light);
    margin-bottom: 1rem;
}

.story-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 2rem;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-light);
}

.modal-story-text {
    margin: 1.5rem 0;
    white-space: pre-wrap;
}

.modal-schema {
    background: var(--bg-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-top: 1.5rem;
}

/* === RESPONSIVE === */

/* Tablet (768px+) */
@media (min-width: 768px) {
    .container {
        padding: 0 2rem;
    }

    main {
        padding: 2rem 0;
    }

    .alternatives {
        flex-direction: row;
    }

    .alternative-card {
        flex: 1;
    }

    .action-buttons {
        flex-direction: row;
    }

    .stories-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
    h1 { font-size: 2.5rem; }
    h2 { font-size: 2rem; }

    .story-content {
        max-height: 400px;
    }

    .stories-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Badge Styles for Partial Stories */
.story-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.badge-success {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.story-card.partial {
    border-left: 4px solid var(--warning-color);
}
