/* === CSS VARIABLES === */
:root {
    /* Light theme colors */
    --bg-main: #faf9f7;
    --bg-container: #ffffff;
    --bg-meta: #f5f5f5;
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --accent: #ff6b6b;
    --accent-secondary: #ff6b6b;
    --border: #e0e0e0;
    --card-front-bg: #ffffff;
    --card-back-bg: #fff5f5;
    --card-border: #ff6b6b;
    --tooltip-bg: #2c3e50;
}

[data-theme="dark"] {
    /* Dark theme colors */
    --bg-main: #0d0d0d;
    --bg-container: #1a1a1a;
    --bg-meta: #252525;
    --text-primary: #f0f0f0;
    --text-secondary: #b0b0b0;
    --accent: #ff385c;
    --accent-secondary: #00d9ff;
    --border: #2a2a2a;
    --card-front-bg: #1a1a1a;
    --card-back-bg: #2a1a1a;
    --card-border: #ff385c;
    --tooltip-bg: #2a2a2a;
}

/* === BASE STYLES === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Crimson Pro', 'Georgia', serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-main);
    padding: 20px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 700px;
    margin: 0 auto;
    background: var(--bg-container);
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

[data-theme="dark"] .container {
    box-shadow: 0 2px 20px rgba(0,0,0,0.5);
}

/* === HEADER WITH THEME TOGGLE === */
header {
    position: relative;
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 3px solid var(--accent);
    transition: border-color 0.3s ease;
}

.theme-toggle {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--accent);
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-toggle svg {
    width: 24px;
    height: 24px;
    color: white;
    transition: transform 0.3s ease;
}

.sun-icon {
    display: block;
}

.moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon {
    display: block;
}

.theme-toggle:hover svg {
    transform: rotate(20deg);
}

/* === TYPOGRAPHY === */
h1 {
    font-size: 2.2em;
    color: var(--text-primary);
    margin-bottom: 10px;
    line-height: 1.2;
    transition: color 0.3s ease;
}

.subtitle {
    font-size: 1.1em;
    color: var(--text-secondary);
    font-style: italic;
    transition: color 0.3s ease;
}

h2 {
    font-size: 1.6em;
    color: var(--text-primary);
    margin: 30px 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border);
    transition: color 0.3s ease, border-color 0.3s ease;
}

[data-theme="dark"] h2 {
    color: var(--accent-secondary);
}

p {
    margin-bottom: 15px;
    font-size: 1.05em;
}

/* === TAPPABLE TEXT === */
.tappable {
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 2px 0;
}

.tappable:hover {
    background-color: rgba(255, 107, 107, 0.15);
}

[data-theme="dark"] .tappable:hover {
    background-color: rgba(255, 56, 92, 0.2);
}

.tappable:active {
    background-color: rgba(255, 107, 107, 0.3);
}

[data-theme="dark"] .tappable:active {
    background-color: rgba(255, 56, 92, 0.35);
}

/* === TOOLTIP === */
.tooltip {
    display: none;
    position: fixed;
    background: var(--tooltip-bg);
    color: white;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 0.95em;
    max-width: 300px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    line-height: 1.4;
    transition: background-color 0.3s ease;
}

[data-theme="dark"] .tooltip {
    border: 1px solid var(--accent);
}

.tooltip::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 20px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid var(--tooltip-bg);
    transition: border-bottom-color 0.3s ease;
}

.tooltip.visible {
    display: block;
}

/* === QUOTES, LISTS, STRUCTURE === */
.quote {
    font-style: italic;
    color: var(--text-secondary);
    padding-left: 20px;
    border-left: 4px solid var(--accent);
    margin: 20px 0;
    transition: color 0.3s ease, border-color 0.3s ease;
}

ul {
    margin: 15px 0 15px 30px;
}

li {
    margin-bottom: 8px;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 30px 0;
    transition: border-color 0.3s ease;
}

/* === STORY SECTION === */
.story {
    background: var(--bg-container);
    transition: background-color 0.3s ease;
}

/* === META SECTIONS (differentiated blocks) === */
.comprehension,
.discussion,
.glosses,
.vocabulary,
.about {
    background: var(--bg-meta);
    margin: 40px -40px 0 -40px;
    padding: 30px 40px;
    border-top: 4px solid var(--accent);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

[data-theme="dark"] .comprehension,
[data-theme="dark"] .discussion {
    border-color: var(--accent-secondary);
}

.comprehension h2,
.discussion h2,
.glosses h2,
.vocabulary h2,
.about h2 {
    margin-top: 0;
    border-bottom: none;
}

/* === FLASHCARDS === */
.flashcard {
    position: relative;
    perspective: 1000px;
    margin: 40px 0;
    z-index: 0;
    transform: translateZ(0);
}

.flashcard-inner {
    position: relative;
    width: 100%;
    min-height: 240px;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    z-index: 1;
}

.flashcard-inner.flipped {
    transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 240px;
    backface-visibility: hidden;
    border: 2px solid var(--card-border);
    border-radius: 8px;
    padding: 25px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.flashcard-front {
    background: var(--card-front-bg);
    z-index: 2;
}

.flashcard-back {
    transform: rotateY(180deg);
    background: var(--card-back-bg);
    z-index: 3;
}

/* === BUTTONS === */
.flip-btn {
    margin-top: 15px;
    padding: 10px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.95em;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    transition: all 0.3s ease;
}

.flip-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

[data-theme="dark"] .flip-btn:hover {
    filter: brightness(1.2);
}

.flip-btn:active {
    transform: scale(0.98);
}

/* === GLOSSES & METRICS === */
dl {
    margin: 20px 0;
}

dt {
    font-weight: bold;
    color: var(--text-primary);
    margin-top: 15px;
    transition: color 0.3s ease;
}

dd {
    margin-left: 20px;
    margin-bottom: 10px;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.metrics {
    background: var(--bg-container);
    padding: 20px;
    border-radius: 6px;
    margin-top: 20px;
    border: 1px solid var(--border);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.metrics ul {
    list-style: none;
    margin: 10px 0 0 0;
}

.metrics li {
    margin: 8px 0;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    .comprehension,
    .discussion,
    .glosses,
    .vocabulary,
    .about {
        margin: 40px -20px 0 -20px;
        padding: 30px 20px;
    }

    h1 {
        font-size: 1.8em;
    }

    h2 {
        font-size: 1.4em;
    }

    .tooltip {
        max-width: 250px;
        font-size: 0.9em;
    }

    .theme-toggle {
        width: 40px;
        height: 40px;
    }
}
