:root {
    /* Desaturated Pastels Palette */
    --bg-color: #EEECE3;
    /* Warm Oatmeal */
    --text-main: #5C5C5C;
    /* Soft Charcoal */
    --text-sub: #8E8E8E;
    /* Medium Grey */
    --accent-sage: #9FA8A3;
    /* Muted Sage */
    --accent-sand: #C5B4A1;
    /* Muted Sand */
    --accent-clay: #BFAEA8;
    /* Muted Clay */
    --white-glass: rgba(255, 255, 255, 0.4);
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.05);
}

.dark-theme {
    --bg-color: #2C2C2C;
    --text-main: #E0E0E0;
    --text-sub: #A0A0A0;
    --accent-sage: #5A6660;
    --accent-sand: #7D7065;
    --accent-clay: #8C7B75;
    --white-glass: rgba(0, 0, 0, 0.4);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: 'Nanum Myeongjo', serif;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease-out;
}

#loader-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#lottie-loader {
    width: 200px;
    height: 200px;
}

/* Abstract Background Shapes for "Experimental" feel */
.bg-shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    z-index: -1;
    opacity: 0.6;
}

.shape-1 {
    width: 300px;
    height: 300px;
    background: var(--accent-sage);
    top: -50px;
    right: -50px;
}

.shape-2 {
    width: 400px;
    height: 400px;
    background: var(--accent-sand);
    bottom: -100px;
    left: -100px;
}

#app {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding: 2rem;
    padding-bottom: 8rem;
    /* Space for nav */
}

/* Card Container - Glassmorphism */
.card {
    width: 100%;
    max-width: 400px;
    min-height: 500px;
    margin: auto;
    background: var(--white-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    transition: opacity 0.5s ease;
}

.card.fade-out {
    opacity: 0;
}

/* Bookmark Button */
.bookmark-btn {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    z-index: 20;
    /* Above hanja */
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bookmark-btn:hover {
    transform: scale(1.1);
    background: rgba(0, 0, 0, 0.05);
}

.bookmark-btn:active {
    transform: scale(0.95);
}

.bookmark-icon {
    width: 28px;
    height: 28px;
    stroke: var(--accent-sand);
    stroke-width: 1.5;
    fill: none;
    transition: all 0.3s ease;
}

.bookmark-btn.active .bookmark-icon {
    fill: #FFD700;
    /* Gold */
    stroke: #DAA520;
}

.dark-theme .bookmark-btn.active .bookmark-icon {
    fill: #FFD700;
    stroke: #FFD700;
}

/* TTS Button - Floating next to Bookmark */
.tts-btn {
    position: absolute;
    background: none;
    border: none;
    cursor: pointer;
    z-index: 20;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;

    /* Default: Korean Mode (Below Bookmark) */
    top: 4.5rem;
    right: 1.5rem;
}

.tts-btn:hover {
    transform: scale(1.1);
    background: rgba(0, 0, 0, 0.05);
}

.tts-btn:active {
    transform: scale(0.95);
}

.tts-icon {
    width: 28px;
    height: 28px;
    fill: var(--accent-sand);
    /* Using fill for solid icons */
    transition: all 0.3s ease;
}

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

/* Hanja - Vertical Layout, Large, Asymmetric */
.hanja-container {
    flex: 2;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    /* Push to right */
    padding-right: 5rem;
    padding-top: 2rem;
}

.hanja {
    font-size: 4rem;
    font-weight: 800;
    writing-mode: vertical-rl;
    text-orientation: upright;
    letter-spacing: 0.5rem;
    color: var(--text-main);
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.05);
}

/* Hangul - Small, floating elsewhere */
.hangul-container {
    position: absolute;
    top: 2rem;
    left: 2rem;
}

.hangul {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-clay);
    letter-spacing: 0.2rem;
    writing-mode: vertical-rl;
    /* Matches Hanja orientation */
    text-orientation: upright;
}

/* Meaning - Bottom area */
.meaning-container {
    flex: 1;
    padding: 2rem;
    display: flex;
    align-items: flex-end;
}

.text-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.hanja-breakdown {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    width: 100%;
}

.char-info {
    display: inline-flex;
    align-items: baseline;
    gap: 0.2rem;
    padding: 0.3rem 0.6rem;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.dark-theme .char-info {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.char-meaning {
    font-size: 0.85rem;
    color: var(--text-sub);
    font-weight: 400;
}

.char-sound {
    font-size: 1rem;
    color: var(--text-main);
    font-weight: 800;
}

.meaning {
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--text-main);
    min-height: 2.2rem;
    /* Reduced min-height slightly */
}

.example-text {
    font-size: 0.85rem;
    color: var(--text-sub);
    line-height: 1.4;
    min-height: 1.2rem;
    /* Keep layout stable even if empty */
}

/* Hide example if empty to avoid layout shift? No, min-height is better or just let it collapse */
.example-text:empty {
    display: none;
}

.cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background-color: var(--text-main);
    animation: blink 1s infinite;
    vertical-align: sub;
    margin-left: 4px;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Floating Bottom Menu */
.bottom-nav {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0.8rem 1.5rem;
    border-radius: 100px;
    display: flex;
    gap: 1rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.6);
    z-index: 100;
    transition: background 0.3s ease;
}

.dark-theme .bottom-nav {
    background: rgba(40, 40, 40, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    transform: translateY(-2px);
}

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

.nav-btn:active {
    transform: translateY(0);
}

.nav-btn.active .nav-icon {
    fill: var(--text-main);
}

#btn-level {
    font-weight: 700;
    font-size: 0.9rem;
    min-width: 40px;
    padding: 0 10px;
    border-radius: 20px;
}

.nav-icon {
    width: 24px;
    height: 24px;
    stroke: var(--text-main);
    stroke-width: 1.5;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Primary Button (Install CTA) */
.primary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.8rem 2rem;
    background-color: var(--text-main);
    color: var(--bg-color);
    border-radius: 50px;
    text-decoration: none;
    font-weight: 700;
    transition: all 0.2s ease;
    margin-top: 2rem;
    border: 1px solid var(--text-main);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.primary-btn:hover {
    opacity: 0.9;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.primary-btn:active {
    transform: scale(0.95);
}

/* Toast Notification */
.toast {
    position: fixed;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.8rem 1.5rem;
    border-radius: 50px;
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 300;
    white-space: nowrap;
}

.dark-theme .toast {
    background: rgba(255, 255, 255, 0.9);
    color: black;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(238, 236, 227, 0.95);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.dark-theme .modal {
    background: rgba(44, 44, 44, 0.95);
}

.modal.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    text-align: center;
    color: var(--text-main);
}

.close-btn {
    margin-top: 2rem;
    padding: 0.5rem 2rem;
    background: transparent;
    border: 1px solid var(--text-main);
    color: var(--text-main);
    border-radius: 50px;
    font-family: inherit;
    cursor: pointer;
}

/* Quiz Styles */
.quiz-content {
    width: 90%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    height: 85vh;
    justify-content: center;
    padding: 1rem;
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 1rem;
}

.quiz-score {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
}

.quiz-close-btn {
    margin-top: 0;
    padding: 0.3rem 1rem;
    font-size: 0.9rem;
}

.quiz-question-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2rem;
}

#quiz-hanja {
    font-size: 3.5rem;
    /* Slightly smaller to ensure fit */
    font-weight: 900;
    color: #000000 !important;
    text-align: center;
    letter-spacing: 0.1rem;
    opacity: 1;
    white-space: nowrap;
    /* Force visibility */
    text-shadow: none;
    z-index: 10;
}

.dark-theme #quiz-hanja {
    color: #FFFFFF;
}

.quiz-options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.8rem;
    width: 100%;
}

.quiz-btn {
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid var(--text-main);
    color: var(--text-main);
    padding: 0.8rem;
    border-radius: 15px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

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

.dark-theme .quiz-btn {
    background: rgba(50, 50, 50, 0.4);
}

.quiz-btn.correct {
    background-color: #A3C9A8 !important;
    /* Pastel Green */
    border-color: #5A8F62 !important;
    color: #1A3C20;
}

.quiz-btn.wrong {
    background-color: #E3B5A4 !important;
    /* Pastel Red */
    border-color: #B85C4A !important;
    color: #5C2A20;
}

.quiz-btn .btn-hangul {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.2rem;
}

.quiz-btn .btn-meaning {
    font-size: 0.85rem;
    opacity: 0.9;
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    /* Keep it compact */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@keyframes shake {

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

    20%,
    60% {
        transform: translateX(-5px);
    }

    40%,
    80% {
        transform: translateX(5px);
    }
}

@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

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

.anim-shake {
    animation: shake 0.4s ease;
}

.anim-pop {
    animation: pop 0.3s ease;
}

#feedback-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 15rem;
    font-weight: 900;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 50;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

#feedback-overlay.show {
    opacity: 0.8;
    transform: translate(-50%, -50%) scale(1.2);
}

#feedback-overlay.correct {
    color: #4CAF50;
    /* Green */
}

#feedback-overlay.wrong {
    color: #F44336;
    /* Red */
}

/* English Mode Overrides */
.lang-en .hanja {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    font-size: 3rem;
    letter-spacing: 0;
    text-align: center;
    width: 100%;
}

.lang-en .hanja-container {
    padding-right: 0;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.lang-en .hangul-container {
    top: 1.5rem;
    left: 2rem;
}

.lang-en .hangul {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    font-size: 1rem;
    letter-spacing: 0;
}

/* TTS Position for English Mode (Left of Bookmark) */
.lang-en .tts-btn {
    top: 1.5rem;
    right: 4.5rem;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--text-main);
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--text-main);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Timer Bar */
.timer-container {
    width: 100%;
    height: 6px;
    background: rgba(0,0,0,0.1);
    border-radius: 3px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.dark-theme .timer-container {
    background: rgba(255,255,255,0.1);
}

.timer-bar {
    width: 100%;
    height: 100%;
    background: var(--text-main);
    transform-origin: left;
    /* Transition handled in JS via inline style for restart capability or CSS class */
}

/* Range Input Customization */
input[type=range] {
  -webkit-appearance: none; /* Hides the slider so that custom slider can be made */
  width: 100%; /* Specific width is required for Firefox. */
  background: transparent; /* Otherwise white in Chrome */
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: var(--text-main);
  cursor: pointer;
  margin-top: -8px; /* You need to specify a margin in Chrome, but in Firefox and IE it is automatic */
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

input[type=range]::-moz-range-thumb {
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: var(--text-main);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: #ccc;
  border-radius: 2px;
}

input[type=range]::-moz-range-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: #ccc;
  border-radius: 2px;
}

input[type=range]:focus {
  outline: none;
}
