/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&family=Comic+Neue:wght@400;700&display=swap');

/* Variables & Themes */
:root {
    /* Primary Colors (Default Light Theme) */
    --bg-color: #f0f4f8;
    --card-bg: #ffffff;
    --text-color: #2d3748;
    --primary-color: #D5440D;
    /* Logo Orange */
    --secondary-color: #288FA6;
    /* Logo Teal */
    --accent-color: #81AF30;
    /* Logo Green - for success */
    --error-color: #ff6b6b;

    /* Typography */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Comic Neue', cursive;
    --base-font-size: 18px;
    --story-font-size: 1.2rem;
    --letter-spacing: normal;

    /* UI Elements */
    --radius-lg: 24px;
    --radius-md: 16px;
    --shadow-soft: 0 10px 30px -5px rgba(0, 0, 0, 0.1);
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-color: #1a202c;
    --card-bg: #2d3748;
    --text-color: #e2e8f0;
    --primary-color: #F07040;
    /* Lighter orange for dark mode */
    --secondary-color: #4DB8CC;
    /* Lighter teal for dark mode */
    --accent-color: #A5D050;
    /* Lighter green for dark mode */
    --shadow-soft: 0 10px 30px -5px rgba(0, 0, 0, 0.5);
}

/* Sepia Theme */
[data-theme="sepia"] {
    --bg-color: #f4ecd8;
    --card-bg: #fdf6e3;
    --text-color: #5b4636;
    --primary-color: #D5440D;
    --secondary-color: #288FA6;
}

/* Accessibility: OpenDyslexic (Locally hosted) */
@font-face {
    font-family: 'OpenDyslexic';
    src: url('OpenDyslexic-Regular.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

/* Accessibility: Dyslexie Font */
@font-face {
    font-family: 'Dyslexie';
    src: url('Dyslexie.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

[data-font="opendyslexic"] {
    --font-body: 'OpenDyslexic', sans-serif;
    --font-heading: 'OpenDyslexic', sans-serif;
}

[data-font="dyslexie"] {
    --font-body: 'Dyslexie', sans-serif;
    --font-heading: 'Dyslexie', sans-serif;
}

/* Accessibility: DyslexicLogic Font */
@font-face {
    font-family: 'DyslexicLogic';
    src: url('DyslexicLogicFont.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

[data-font="dyslexiclogic"] {
    --font-body: 'DyslexicLogic', sans-serif;
    --font-heading: 'DyslexicLogic', sans-serif;
}

/* Reset & Base */
body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-body);
    font-size: var(--base-font-size);
    letter-spacing: var(--letter-spacing);
    transition: background-color 0.3s ease, color 0.3s ease, letter-spacing 0.3s ease;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    min-height: 100vh;
}

h1,
h2,
h3 {
    font-family: var(--font-heading);
    margin-bottom: 0.5em;
}

/* Utilities */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

.btn {
    padding: 12px 24px;
    border-radius: var(--radius-md);
    border: none;
    font-family: var(--font-heading);
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

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

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

.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 30px;
    box-shadow: var(--shadow-soft);
    margin-bottom: 2rem;
}

/* Header & Configure */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    padding-top: 20px;
}

.logo {
    display: flex;
    align-items: center;
}

.logo img {
    height: 40px;
    /* Mobile default */
    transition: height 0.3s ease;
}

@media (min-width: 768px) {
    .logo img {
        height: 60px;
        /* Desktop */
    }
}

/* Story Section */
.story-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
}

/* Image centered and limited width on larger screens */
@media (min-width: 768px) {
    .story-image-wrapper {
        max-width: 500px;
        margin: 0 auto;
    }
}

.story-image-wrapper {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: var(--shadow-card);
}

.story-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.story-image-wrapper:hover img {
    transform: scale(1.02);
}

.story-text {
    font-size: var(--story-font-size);
    line-height: 1.8;
}

.story-word {
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: border-color 0.2s, background-color 0.2s;
    border-radius: 4px;
    padding: 0 2px;
}

.story-word:hover {
    background-color: rgba(76, 110, 245, 0.1);
    border-bottom-color: var(--primary-color);
}

/* Story Input Group */
.story-input-group {
    display: flex;
    flex-direction: column;
    /* Mobile: Stacked */
    gap: 10px;
}

.story-input-group input {
    width: 100%;
    padding: 12px;
    border-radius: 16px;
    border: 1px solid #ddd;
    box-sizing: border-box;
    /* Important for padding */
}

.story-input-group button {
    width: 100%;
    /* Mobile: Full width */
    justify-content: center;
}

@media (min-width: 768px) {
    .story-input-group {
        flex-direction: row;
        /* Desktop: Side by side */
    }

    .story-input-group input {
        flex: 1;
    }

    .story-input-group button {
        width: auto;
    }
}

/* Quiz Section */
.quiz-options {
    list-style: none;
    padding: 0;
}

.quiz-option {
    background: var(--bg-color);
    margin-bottom: 10px;
    padding: 15px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: 0.2s;
    border: 2px solid transparent;
}

.quiz-option:hover {
    border-color: var(--primary-color);
}

.quiz-option.selected {
    background-color: var(--primary-color);
    color: white;
}

/* Settings Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    /* Hidden by default toggled via JS */
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.settings-modal {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

/* Custom Scrollbar for Modal */
.settings-modal::-webkit-scrollbar {
    width: 8px;
}

.settings-modal::-webkit-scrollbar-track {
    background: transparent;
    margin: 10px 4px;
    /* Added margin right/left effectively isn't supported directly like this, but we can verify */
}

/* To simulate "spacing" from the edge, we can use a border on the track or margin */
/* Actually, standard scrollbars are on the edge. To move it in, we need a transparent border on the scrollbar track */

.settings-modal::-webkit-scrollbar-track {
    background: transparent;
    margin: 10px 0;
}

.settings-modal::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 10px;
    opacity: 0.7;
    background-clip: padding-box;
    /* This is the key */
    border: 2px solid transparent;
    /* Creates padding around the thumb */
}

.settings-modal::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
    background-clip: padding-box;
    border: 2px solid transparent;
}

/* Firefox scrollbar */
.settings-modal {
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) transparent;
}

@media (min-width: 768px) {
    .settings-modal {
        max-width: 700px;
    }
}

/* Mobile settings modal - add margin */
@media (max-width: 767px) {
    .settings-modal {
        width: calc(100% - 80px);
        max-height: calc(100vh - 140px);
        padding: 20px;
    }
}

.modal-overlay.active .settings-modal {
    transform: translateY(0);
}

.settings-block {
    background: rgba(0, 0, 0, 0.03);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 20px;
}

.settings-block h4 {
    margin: 0 0 15px 0;
    color: var(--primary-color);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

[data-theme="dark"] .settings-block {
    background: rgba(255, 255, 255, 0.05);
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
}

/* Inputs & Selects */
select {
    width: 100%;
    padding: 10px;
    border-radius: var(--radius-md);
    border: 1px solid #ddd;
    background: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-body);
}

input[type="range"] {
    width: 95%;
    padding: 10px;
    border-radius: var(--radius-md);
    border: 1px solid #ddd;
    background: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-body);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Mobile Styles */
@media (max-width: 767px) {

    /* Center titles in generator section */
    #generator-section h2,
    #generator-section .setting-group>label {
        text-align: center;
    }

    /* Settings button: icon only on mobile */
    #btnSettings .btn-text {
        display: none;
    }

    #btnSettings {
        padding: 12px;
    }
}

/* Header Actions Container */
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Google Login Button */
.btn-google {
    background: white;
    color: #444;
    border: 1px solid #ddd;
    padding: 10px 16px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    text-decoration: none;
    transition: background-color 0.2s, box-shadow 0.2s;
}

.btn-google:hover {
    background: #f8f8f8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

[data-theme="dark"] .btn-google:hover {
    background: #3a4a5e;
}

/* Hide text labels on mobile for auth buttons */
@media (max-width: 767px) {

    .btn-google .btn-text,
    #userInfo .btn-text,
    #userName {
        display: none;
    }

    .btn-google {
        padding: 10px;
    }

    .btn-google svg {
        margin-right: 0 !important;
    }
}

/* ============================================
   RULETA DE LA SUERTE - Lucky Wheel Component
   ============================================ */

/* Mode Selector Tabs */
.mode-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    background: rgba(0, 0, 0, 0.05);
    padding: 6px;
    border-radius: var(--radius-lg);
}

[data-theme="dark"] .mode-selector {
    background: rgba(255, 255, 255, 0.08);
}

.mode-tab {
    flex: 1;
    padding: 14px 20px;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
    opacity: 0.6;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.mode-tab:hover {
    opacity: 0.9;
    background: rgba(0, 0, 0, 0.03);
}

.mode-tab.active {
    background: var(--card-bg);
    opacity: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.mode-tab i {
    font-size: 1.2rem;
}

/* Mode Content Areas */
.mode-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.mode-content.active {
    display: block;
}

/* Wheel Container */
.wheel-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
}

.wheel-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* Wheel Pointer */
.wheel-pointer {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 32px;
    color: var(--primary-color);
    z-index: 10;
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
    animation: pointerBounce 1s ease-in-out infinite;
}

@keyframes pointerBounce {

    0%,
    100% {
        transform: translateX(-50%) translateY(0);
    }

    50% {
        transform: translateX(-50%) translateY(5px);
    }
}

/* Canvas Styling */
#wheelCanvas {
    border-radius: 50%;
    box-shadow:
        0 0 0 8px var(--card-bg),
        0 0 0 12px var(--primary-color),
        0 10px 40px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s ease;
}

[data-theme="dark"] #wheelCanvas {
    box-shadow:
        0 0 0 8px var(--card-bg),
        0 0 0 12px var(--primary-color),
        0 10px 40px rgba(0, 0, 0, 0.4);
}

/* Spin Button */
.btn-spin {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 16px 40px;
    font-size: 1.2rem;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    font-family: var(--font-heading);
    font-weight: 700;
    box-shadow: 0 6px 20px rgba(76, 110, 245, 0.4);
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-spin:hover:not(:disabled) {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 10px 30px rgba(76, 110, 245, 0.5);
}

.btn-spin:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
}

.btn-spin:disabled {
    opacity: 0.8;
    cursor: not-allowed;
    transform: none;
}

.btn-spin i {
    margin-right: 8px;
}

/* Celebration Animation */
.wheel-celebrate {
    animation: celebratePulse 0.3s ease;
}

@keyframes celebratePulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }
}

/* Confetti */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    animation: confettiFall 1.5s ease-out forwards;
    pointer-events: none;
    z-index: 100;
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        top: 50%;
        transform: translateY(0) rotate(0deg) scale(1);
    }

    100% {
        opacity: 0;
        top: 120%;
        transform: translateY(100px) rotate(720deg) scale(0.5);
    }
}

/* Selected Result - Modal Overlay */
#wheelResult {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: overlayFadeIn 0.3s ease;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.wheel-result {
    background: var(--card-bg);
    padding: 40px 50px;
    border-radius: var(--radius-lg);
    text-align: center;
    box-shadow:
        0 25px 80px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    animation: resultBounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: relative;
    overflow: hidden;
}

.wheel-result::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(from 0deg,
            transparent,
            rgba(76, 110, 245, 0.1),
            transparent,
            rgba(255, 159, 67, 0.1),
            transparent);
    animation: shimmerRotate 3s linear infinite;
    z-index: -1;
}

@keyframes shimmerRotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@keyframes resultBounceIn {
    0% {
        transform: scale(0.3) translateY(50px);
        opacity: 0;
    }

    50% {
        transform: scale(1.1) translateY(-10px);
    }

    70% {
        transform: scale(0.95) translateY(0);
    }

    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.wheel-result-emoji {
    font-size: 4rem;
    display: block;
    margin-bottom: 15px;
    animation: emojiPulse 1s ease-in-out infinite;
}

@keyframes emojiPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

.wheel-result-label {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1.4rem;
    display: block;
}

/* Responsive Wheel */
@media (max-width: 400px) {
    #wheelCanvas {
        width: 260px !important;
        height: 260px !important;
    }

    .btn-spin {
        padding: 14px 30px;
        font-size: 1rem;
    }
}

/* Mode tab text on mobile */
@media (max-width: 500px) {
    .mode-tab {
        flex-direction: column;
        padding: 12px 10px;
        font-size: 0.85rem;
        gap: 4px;
    }

    .mode-tab i {
        font-size: 1.4rem;
    }
}