:root {
    --bg: #0a0808;
    --text: #e0e0e0;
    --red: #D72638; /* Imperial Red */
    --gold: #FFD700;
    --card-bg: #141414;
    --border: #333;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Space Grotesk', sans-serif;
    min-height: 100vh;
    display: flex; flex-direction: column;
    overflow-x: hidden;
}

/* NAV */
.top-nav { padding: 20px; }
.nav-back {
    font-family: 'Space Mono', monospace; font-size: 0.8rem;
    color: var(--text); text-decoration: none; opacity: 0.6;
    transition: opacity 0.2s;
}
.nav-back:hover { opacity: 1; color: var(--gold); }

/* HEADER */
.hanzi-container {
    width: 90%; max-width: 600px; margin: 0 auto;
    text-align: center; flex-grow: 1; display: flex; flex-direction: column;
}

header { margin-bottom: 2rem; position: relative; }
header h1 {
    font-family: 'Space Mono', monospace; font-size: 2rem;
    color: var(--red); letter-spacing: -1px; margin-bottom: 5px;
    text-shadow: 0 0 10px rgba(215, 38, 56, 0.3);
}
header p { font-size: 0.8rem; color: #666; }

/* CONTROLS */
.controls-bar {
    background: #111; border: 1px solid var(--border);
    padding: 15px; margin-bottom: 2rem; border-radius: 8px;
    display: flex; flex-direction: column; gap: 15px;
}

.level-select label {
    font-family: 'Space Mono', monospace; font-size: 0.7rem; color: var(--gold);
    display: block; margin-bottom: 5px; text-align: left;
}

.level-buttons { display: flex; gap: 5px; justify-content: center; }

.lvl-btn {
    background: transparent; border: 1px solid #444;
    color: #666; padding: 5px 10px; cursor: pointer;
    font-family: 'Space Mono', monospace; transition: all 0.2s;
    flex: 1;
}
.lvl-btn:hover { border-color: var(--red); color: var(--red); }
.lvl-btn.active { background: var(--red); color: #fff; border-color: var(--red); }

/* NEW: Pinyin Button Styles */
.mode-toggle { 
    display: flex; justify-content: center;
}

.pinyin-btn {
    background: transparent;
    border: 1px solid var(--gold);
    color: var(--gold);
    font-family: 'Space Mono', monospace;
    font-size: 0.9rem;
    padding: 10px 20px;
    width: 100%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    border-radius: 4px;
}

.pinyin-btn:hover {
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
    transform: translateY(-1px);
}

/* Active State (When Pinyin is visible) */
.pinyin-btn.active {
    background: var(--gold);
    color: #000;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
    font-weight: bold;
}

/* THE CARD (3D FLIP) */
.card-scene {
    width: 100%; height: 350px;
    perspective: 1000px;
    margin-bottom: 2rem;
}

.card-object {
    width: 100%; height: 100%;
    position: relative;
    transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
    transform-style: preserve-3d;
    cursor: pointer;
}

.card-object.is-flipped {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%; height: 100%;
    backface-visibility: hidden;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

/* FRONT STYLING */
.face-front { border-bottom: 4px solid var(--red); }

.character-display {
    font-family: 'Noto Sans SC', sans-serif; /* Clean Digital Font */
    font-weight: 700;
    font-size: 8rem; color: #fff;
    line-height: 1;
    transition: transform 0.3s ease;
}

.pinyin-front {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    color: var(--gold);
    opacity: 0; /* Hidden by default */
    transition: opacity 0.3s;
    margin-top: 1rem;
    min-height: 2rem; /* Reserve space so it doesn't jump */
}

/* Logic for when the toggle is on */
body.show-pinyin .pinyin-front {
    opacity: 1;
}
body.show-pinyin .character-display {
    transform: translateY(-10px);
}

.click-hint {
    position: absolute; bottom: 20px;
    font-family: 'Space Mono', monospace; font-size: 1.2rem;
    color: #444; letter-spacing: 2px;
}

/* CORNER DECORATION */
.corner-decor {
    position: absolute; width: 20px; height: 20px;
    border: 2px solid var(--gold); opacity: 0.5;
}
.top-left { top: 10px; left: 10px; border-right: none; border-bottom: none; }
.top-right { top: 10px; right: 10px; border-left: none; border-bottom: none; }
.bottom-left { bottom: 10px; left: 10px; border-right: none; border-top: none; }
.bottom-right { bottom: 10px; right: 10px; border-left: none; border-top: none; }

/* BACK STYLING */
.face-back {
    transform: rotateY(180deg);
    background: #1a1a1a;
    border-top: 4px solid var(--gold);
    padding: 2rem;
}

.pinyin-large {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 2rem; color: var(--gold);
    margin-bottom: 1rem;
}
.definition-text {
    font-size: 2rem; color: #ddd; line-height: 1.5;
    margin-bottom: 2rem;
}
.meta-info {
    font-family: 'Space Mono', monospace;
    font-size: 1.6rem; color: #666;
    border: 1px solid #333; padding: 2px 8px; border-radius: 4px;
}

/* ACTIONS */
.action-bar {
    display: flex;
    gap: 15px;
    margin-bottom: 40px;
}

.action-btn {
    width: 100%; padding: 15px;
    border: none; font-family: 'Space Mono', monospace;
    font-size: 1rem; font-weight: bold; cursor: pointer;
    transition: all 0.2s;
}

/* Primary Button (Next) */
.action-btn {
    background: var(--text); color: var(--bg);
}
.action-btn:hover {
    background: var(--red); color: #fff;
    transform: translateY(-2px); box-shadow: 0 5px 15px rgba(215, 38, 56, 0.4);
}

/* Secondary Button (Previous) */
.secondary-btn {
    background: transparent;
    border: 1px solid #444;
    color: #666;
}
.secondary-btn:hover {
    border-color: #fff;
    background: transparent;
    color: #fff;
    transform: translateY(-2px);
    box-shadow: none;
}

/* Mobile */
@media (max-width: 600px) {
    .character-display { font-size: 6rem; }
    .card-scene { height: 300px; }
}