/* ==========================================================================
   Design System & Themes
   ========================================================================== */
:root {
    /* DEFAULT THEME: SEPIA */
    --bg-color: #f4ecd8;
    --card-bg: rgba(253, 246, 227, 0.7);
    --text-primary: #433422;
    --text-secondary: #705e4c;
    --accent-color: #c05a11;
    --accent-glow: rgba(192, 90, 17, 0.3);
    --success-color: #2e7d32;
    --warning-color: #ed6c02;
    --danger-color: #d32f2f;
    --glass-border: rgba(67, 52, 34, 0.15);
    --glass-bg: rgba(253, 246, 227, 0.8);
    
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Roboto', sans-serif;
    
    --transition-fast: 0.2s ease;
    --transition-slow: 0.5s ease;
}

/* WHITE THEME */
body.theme-white {
    --bg-color: #f8fafc;
    --card-bg: rgba(255, 255, 255, 0.7);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --accent-color: #0284c7;
    --accent-glow: rgba(2, 132, 199, 0.3);
    --success-color: #16a34a;
    --warning-color: #ca8a04;
    --danger-color: #dc2626;
    --glass-border: rgba(15, 23, 42, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.8);
}

/* DARK THEME */
body.theme-dark {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.3);
    --success-color: #4ade80;
    --warning-color: #fb923c;
    --danger-color: #f87171;
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(15, 23, 42, 0.6);
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

/* Subtle background pattern for Sepia */
body:not(.theme-dark):not(.theme-white) {
    background-image: 
        radial-gradient(at 0% 0%, rgba(192, 90, 17, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(67, 52, 34, 0.05) 0px, transparent 50%);
}

#app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.main-content {
    display: grid;
    grid-template-columns: 3fr 1fr;
    gap: 2rem;
    align-items: start;
    transition: grid-template-columns 0.3s ease;
}

.main-content.sidebar-collapsed {
    grid-template-columns: 1fr;
}

@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* Sidebar */
.sidebar {
    padding: 1.5rem;
    max-height: 80vh;
    overflow-y: auto;
    position: sticky;
    top: 2rem;
    transition: opacity 0.3s ease;
}

.sidebar.collapsed {
    display: none;
}

.sidebar-title {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
}

.stories-list {
    list-style: none;
}

.story-item {
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 0.95rem;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

body.theme-dark .story-item {
    border-bottom-color: rgba(255,255,255,0.05);
}

.story-item:hover {
    background: var(--accent-glow);
    color: var(--accent-color);
    transform: translateX(5px);
}

.story-item.active {
    background: var(--accent-color);
    color: #fff !important;
    font-weight: 600;
}

/* ==========================================================================
   Typography
   ========================================================================== */
h1, h2, h3, h4 {
    font-family: var(--font-heading);
    font-weight: 800;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

/* ==========================================================================
   Header & Theme Switcher
   ========================================================================== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.logo {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 800;
}

.logo-accent {
    color: var(--accent-color);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.theme-switcher {
    display: flex;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.25rem;
    border-radius: 0.5rem;
}

body.theme-dark .theme-switcher {
    background: rgba(255, 255, 255, 0.05);
}

.theme-btn {
    width: 2rem;
    height: 2rem;
    border-radius: 0.25rem;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    transition: background var(--transition-fast);
}

.theme-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

body.theme-dark .theme-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.theme-btn.active {
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

body.theme-dark .theme-btn.active {
    background: #1e293b;
}

.app-info {
    display: flex;
    gap: 1.5rem;
    font-weight: 600;
    color: var(--text-secondary);
}

#score-value {
    color: var(--accent-color);
}

/* ==========================================================================
   Reusable Components
   ========================================================================== */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-heading);
}

.btn-primary {
    background: var(--accent-color);
    color: #fff;
    box-shadow: 0 2px 4px var(--accent-glow);
}

body:not(.theme-dark) .btn-primary {
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--accent-glow);
}

.btn-secondary {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

body.theme-dark .btn-secondary {
    background: rgba(255, 255, 255, 0.05);
}

.btn-secondary:hover {
    background: rgba(0, 0, 0, 0.1);
}

body.theme-dark .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.styled-input {
    width: 100%;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--glass-border);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 1.1rem;
    transition: all var(--transition-fast);
}

body.theme-dark .styled-input {
    background: rgba(15, 23, 42, 0.8);
}

.styled-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 5px var(--accent-glow);
}

/* ==========================================================================
   View Sections
   ========================================================================== */
.view-section {
    display: none;
    animation: fadeIn var(--transition-slow);
}

.view-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Reader Mode
   ========================================================================== */
.story-container {
    line-height: 1.8;
    font-size: 1.2rem;
}

.story-text span {
    cursor: pointer;
    padding: 0.1rem 0.2rem;
    border-radius: 0.25rem;
    transition: all var(--transition-fast);
}

/* Очертание для слов из БД */
.story-text span.learnable-word {
    border-bottom: 2px dashed var(--accent-color);
    border-radius: 0.25rem;
}

.story-text span.learnable-word:hover {
    background-color: var(--accent-glow);
    border-bottom-style: solid;
}

.story-text span.selected {
    background-color: var(--accent-color);
    color: #fff !important;
}

/* ==========================================================================
   Trainer Mode
   ========================================================================== */
.round-tracker {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2.5rem;
    position: relative;
}

.round-tracker::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: rgba(0, 0, 0, 0.05);
    z-index: 1;
}

body.theme-dark .round-tracker::before {
    background: rgba(255, 255, 255, 0.1);
}

.step {
    width: 2.5rem;
    height: 2.5rem;
    background: #fff;
    border: 2px solid rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-family: var(--font-heading);
    color: var(--text-secondary);
    position: relative;
    z-index: 2;
    transition: all var(--transition-fast);
}

body.theme-dark .step {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.1);
}

.step.active {
    background: var(--bg-color);
    border-color: var(--accent-color);
    color: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-glow);
}

.step.completed {
    background: var(--success-color);
    border-color: var(--success-color);
    color: #fff;
}

.word-display-container {
    text-align: center;
    margin: 3rem 0;
}

.word-display {
    font-size: 4rem;
    font-weight: 800;
    font-family: var(--font-heading);
    letter-spacing: 0.1em;
    color: var(--text-primary);
    text-shadow: 0 2px 4px rgba(0,0,0,0.05);
    margin-bottom: 1rem;
}

.word-display.context-mode {
    font-size: 2rem;
    letter-spacing: 0.02em;
    line-height: 1.4;
}

.word-translation {
    font-size: 1.5rem;
    color: var(--text-secondary);
}

.interaction-area {
    max-width: 600px;
    margin: 0 auto;
}

.input-container {
    display: flex;
    gap: 1rem;
}

/* Anagram / Constructor styles */
.constructor-container {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.letter-box {
    width: 3.5rem;
    height: 3.5rem;
    background: #fff;
    border: 1px solid var(--glass-border);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-heading);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

body.theme-dark .letter-box {
    background: rgba(255, 255, 255, 0.05);
}

.letter-box:hover {
    background: var(--accent-glow);
    border-color: var(--accent-color);
    transform: translateY(-3px);
}

.letter-box.selected {
    background: var(--accent-color);
    color: #fff;
    box-shadow: 0 2px 4px var(--accent-glow);
}

/* ==========================================================================
   Context Menu
   ========================================================================== */
.context-menu {
    position: absolute;
    z-index: 1000;
    border-radius: 0.5rem;
    padding: 0.5rem 0;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    min-width: 200px;
}

.context-menu ul {
    list-style: none;
}

.context-menu li {
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background var(--transition-fast);
    font-size: 0.95rem;
}

.context-menu li:hover {
    background: var(--accent-glow);
    color: var(--accent-color);
}

.hidden {
    display: none;
}

.feedback-message {
    text-align: center;
    margin-top: 1rem;
    font-weight: 600;
    min-height: 1.5rem;
}

.feedback-message.success { color: var(--success-color); }
.feedback-message.danger { color: var(--danger-color); }

/* Language Switcher */
.lang-switcher {
    display: flex;
    gap: 0.25rem;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.25rem;
    border-radius: 0.5rem;
}

body.theme-dark .lang-switcher {
    background: rgba(255, 255, 255, 0.05);
}

.lang-btn {
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    font-family: var(--font-heading);
    background: transparent;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.lang-btn:hover {
    color: var(--text-primary);
}

.lang-btn.active {
    background: var(--accent-color);
    color: #fff !important;
    box-shadow: 0 2px 4px var(--accent-glow);
}

/* Story Paragraphs */
.story-paragraph {
    margin-bottom: 1.5rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-color);
    padding: 2rem;
    border-radius: 1rem;
    width: 90%;
    max-width: 500px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

.text-words-list li {
    padding: 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.text-words-list li:hover {
    background: var(--accent-glow);
}

.text-words-list input[type="checkbox"] {
    cursor: pointer;
}

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