
:root {
    --ink-black: #2c2c2c;
    --paper-bg: #f4f1ea;
    --scroll-gold: #d4af37;
    --danger-red: #c0392b;
    --magic-blue: #2980b9;
    --font-title: 'Ma Shan Zheng', cursive;
    --font-body: 'Noto Serif SC', serif;
    --shadow-soft: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-hard: 4px 4px 0px rgba(0,0,0,0.2);
}

* {
    box-sizing: border-box;
    user-select: none;
}

body {
    margin: 0;
    padding: 0;
    background-color: #1a1a1a;
    font-family: var(--font-body);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-image: radial-gradient(circle at center, #333 0%, #000 100%);
}

#game-container {
    width: 100%;
    max-width: 900px;
    height: 100vh;
    max-height: 650px;
    background-color: var(--paper-bg);
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
    border: 10px solid var(--ink-black);
    border-radius: 5px;
}

/* Background Layer */
.bg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 50% 50%, rgba(255,255,255,0.9), transparent 80%),
        url('data:image/svg+xml;utf8,<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"><path d="M20 20 Q 100 100 180 20" stroke="%23ddd" fill="none" stroke-width="2" opacity="0.3"/></svg>');
    opacity: 0.6;
    z-index: 0;
    pointer-events: none;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    z-index: 1;
    transition: opacity 0.5s;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.5s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Start Screen */
#start-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    background: linear-gradient(135deg, var(--paper-bg) 0%, #e6e2d8 100%);
}

.main-title {
    font-family: var(--font-title);
    font-size: 5rem;
    color: var(--ink-black);
    margin: 0;
    text-shadow: 4px 4px 0px rgba(0,0,0,0.1);
    animation: floatTitle 3s ease-in-out infinite;
}

@keyframes floatTitle {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.sub-title {
    font-size: 2rem;
    color: var(--danger-red);
    margin-top: -10px;
    letter-spacing: 8px;
    font-weight: bold;
}

.grade-selector {
    margin: 40px 0;
}

.grade-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    justify-content: center;
    max-width: 700px;
    margin: 0 auto;
}

.grade-btn {
    padding: 12px 25px;
    border: 3px solid var(--ink-black);
    background: transparent;
    font-family: var(--font-title);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 8px;
    color: var(--ink-black);
}

.grade-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hard);
}

.grade-btn.selected {
    background: var(--ink-black);
    color: var(--paper-bg);
    box-shadow: var(--shadow-hard);
}

.ink-btn {
    padding: 15px 50px;
    font-size: 1.8rem;
    background: var(--ink-black);
    color: white;
    border: none;
    border-radius: 50px 5px 50px 5px;
    font-family: var(--font-title);
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.ink-btn::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.2), transparent 60%);
    transform: scale(0);
    transition: transform 0.3s;
}

.ink-btn:hover::after {
    transform: scale(1);
}

.ink-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
}

.secondary-btn {
    padding: 10px 30px;
    font-size: 1.2rem;
    background: transparent;
    color: var(--ink-black);
    border: 2px solid var(--ink-black);
    border-radius: 30px;
    font-family: var(--font-title);
    cursor: pointer;
    transition: all 0.2s;
}

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

/* Battle Screen */
.top-bar {
    height: 70px; /* Reduced from 90px */
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    background: rgba(255,255,255,0.9);
    border-bottom: 4px solid var(--ink-black);
    box-shadow: 0 5px 10px rgba(0,0,0,0.1);
    z-index: 10;
}

.stage-info {
    font-family: var(--font-title);
    font-size: 1.5rem;
    color: var(--ink-black);
}

.player-status, .enemy-status {
    display: flex;
    align-items: center;
    gap: 15px;
}

.avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid var(--ink-black);
    background-color: #fff;
    background-size: cover;
    box-shadow: var(--shadow-soft);
}

.player-avatar {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" fill="%232c2c2c"/><text x="50" y="65" font-size="40" text-anchor="middle" fill="white">师</text></svg>');
}

.enemy-avatar {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" fill="%23c0392b"/><text x="50" y="65" font-size="40" text-anchor="middle" fill="white">魔</text></svg>');
}

.bars-container, .hp-bar-container {
    width: 180px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bar-wrap {
    width: 100%;
    height: 16px;
    background: #ddd;
    border: 2px solid var(--ink-black);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.hp-bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #e74c3c, #c0392b);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.ink-bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #34495e, #2c3e50);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Battle Stage */
.battle-stage {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 120px;
    background-image: url('data:image/svg+xml;utf8,<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="g" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="%23fff" stop-opacity="0"/><stop offset="1" stop-color="%23000" stop-opacity="0.1"/></linearGradient></defs><rect width="100%" height="100%" fill="url(%23g)"/></svg>');
}

.character {
    width: 180px;
    height: 180px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    position: relative;
    filter: drop-shadow(0 10px 10px rgba(0,0,0,0.3));
    transition: transform 0.2s;
}

.player {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M30 80 L70 80 L60 30 L40 30 Z" fill="%232980b9"/><circle cx="50" cy="25" r="15" fill="%23f1c40f"/><rect x="45" y="40" width="10" height="40" fill="%232c2c2c"/><path d="M20 50 Q50 60 80 50" stroke="%23ecf0f1" stroke-width="3" fill="none"/></svg>');
}

.enemy {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M20 30 Q50 10 80 30 Q90 60 80 90 Q50 100 20 90 Q10 60 20 30 Z" fill="%232c2c2c"/><circle cx="35" cy="45" r="5" fill="%23e74c3c"/><circle cx="65" cy="45" r="5" fill="%23e74c3c"/><path d="M30 70 Q50 80 70 70" stroke="%23e74c3c" stroke-width="3" fill="none"/></svg>');
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.character.attack-lunge {
    animation: lunge 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes lunge {
    0% { transform: translateX(0) scale(1); }
    50% { transform: translateX(80px) scale(1.1); }
    100% { transform: translateX(0) scale(1); }
}

.enemy.attack-lunge {
    animation: lunge-left 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes lunge-left {
    0% { transform: translateX(0) scale(1); }
    50% { transform: translateX(-80px) scale(1.1); }
    100% { transform: translateX(0) scale(1); }
}

/* Projectiles */
.projectile {
    position: absolute;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    z-index: 20;
    pointer-events: none;
    box-shadow: 0 0 15px currentColor;
}

.projectile.ink { background: #2c2c2c; color: #2c2c2c; }
.projectile.fire { background: #e74c3c; color: #e74c3c; }
.projectile.thunder { background: #f1c40f; color: #f1c40f; }
.projectile.water { background: #3498db; color: #3498db; }

/* Control Panel */
.control-panel {
    height: 320px; /* Increased from 280px */
    background: var(--ink-black);
    color: white;
    position: relative;
    padding: 15px; /* Reduced padding */
    border-top: 8px solid var(--scroll-gold);
    box-shadow: 0 -5px 20px rgba(0,0,0,0.5);
}

.panel-content {
    display: none;
    height: 100%;
    width: 100%;
}

.panel-content.active {
    display: flex;
}

#skill-menu {
    justify-content: center;
    gap: 30px;
    align-items: center;
}

.skill-card {
    width: 160px;
    height: 200px;
    background: linear-gradient(to bottom, #fff, #f4f1ea);
    border: 4px solid var(--scroll-gold);
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    color: var(--ink-black);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative;
    overflow: hidden;
}

.skill-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 5px;
    background: rgba(255,255,255,0.5);
}

.skill-card:hover {
    transform: translateY(-15px) scale(1.05);
    box-shadow: 0 15px 30px rgba(0,0,0,0.4);
    border-color: #f1c40f;
}

.skill-card .icon {
    font-size: 4rem;
    margin-bottom: 15px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.skill-card .name {
    font-family: var(--font-title);
    font-size: 1.5rem;
    font-weight: bold;
}

.skill-card .cost {
    font-size: 0.9rem;
    color: var(--magic-blue);
    font-weight: bold;
    margin-top: 5px;
}

.skill-card .desc {
    font-size: 0.8rem;
    color: #666;
    margin-top: 5px;
    text-align: center;
    padding: 0 10px;
}

#question-panel {
    flex-direction: row; /* Side-by-side layout */
    flex-wrap: wrap;
    align-items: stretch;
    justify-content: center;
    padding: 5px;
    gap: 15px;
    overflow-y: auto; /* Allow scroll if absolutely necessary, but layout is optimized to avoid it */
    height: 100%;
}

.question-text {
    flex: 2 1 55%; /* Increased from 30% to give more space to question */
    font-size: 1.4rem; /* Slightly larger font for better readability */
    margin-bottom: 0;
    text-align: center;
    width: auto;
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px 20px 20px; /* Increased padding */
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    max-height: 100%;
    overflow-y: auto;
    position: relative; /* For absolute positioning of tag */
}

.question-tag {
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 0.9rem;
    font-weight: bold;
    padding: 4px 12px;
    border-radius: 20px; /* Pill shape */
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    font-family: var(--font-body);
    letter-spacing: 1px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 5px;
}

.tag-attack {
    background: linear-gradient(135deg, #c0392b, #e74c3c);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

.tag-defend {
    background: linear-gradient(135deg, #2980b9, #3498db);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

.q-content-text {
    width: 100%;
}

.options-grid {
    flex: 1 1 40%; /* Reduced from 60% to make options smaller */
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr; /* Force 2 rows */
    gap: 8px; /* Reduced gap */
    width: auto;
    max-width: none;
    margin-bottom: 0;
    height: 100%;
}

.option-btn {
    padding: 5px; /* Reduced padding */
    background: linear-gradient(to bottom, #444, #333);
    border: 2px solid #666;
    color: white;
    font-size: 1rem; /* Smaller font for compact options */
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    font-family: var(--font-body);
    box-shadow: 0 3px 0 #222;
    position: relative;
    white-space: normal;
    word-wrap: break-word;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 100%; /* Fill cell */
}

.option-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #222;
}

.option-btn:hover {
    background: linear-gradient(to bottom, #555, #444);
    border-color: #888;
}

.option-btn.correct {
    background: linear-gradient(to bottom, #2ecc71, #27ae60);
    border-color: #2ecc71;
    box-shadow: 0 4px 0 #219150;
}

.option-btn.wrong {
    background: linear-gradient(to bottom, #e74c3c, #c0392b);
    border-color: #e74c3c;
    box-shadow: 0 4px 0 #96281b;
    animation: shake 0.4s;
}

/* Map Screen Polish */
#map-screen {
    background: rgba(0,0,0,0.9);
    justify-content: center;
    align-items: center;
}

.map-scroll {
    width: 95%;
    height: 85%;
    background: #f4f1ea url('data:image/svg+xml;utf8,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><rect width="100" height="100" fill="%23f4f1ea"/><path d="M0 0 L100 100 M100 0 L0 100" stroke="%23e0dcd0" stroke-width="1"/></svg>');
    border: 15px solid var(--ink-black);
    border-radius: 5px;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

.map-title {
    font-family: var(--font-title);
    font-size: 3rem;
    color: var(--ink-black);
    margin-bottom: 20px;
}

.map-nodes {
    display: flex;
    gap: 40px;
    padding: 20px;
    overflow-x: auto;
    width: 100%;
    justify-content: center;
    align-items: center;
    flex: 1;
}

.map-node {
    width: 70px;
    height: 70px;
    border-width: 5px;
    border-style: solid;
    border-color: #7f8c8d;
    font-size: 1.5rem;
    background: #bdc3c7;
    color: #7f8c8d;
    box-shadow: 0 5px 10px rgba(0,0,0,0.2);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-title);
    cursor: not-allowed;
    transition: all 0.3s;
}

.map-node.unlocked {
    background: #fff;
    color: var(--ink-black);
    border-color: var(--ink-black);
    cursor: pointer;
}

.map-node.unlocked:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 15px rgba(0,0,0,0.3);
}

.map-node.completed {
    background: var(--scroll-gold);
    color: #fff;
    border-color: #b7950b;
}

.map-node.boss {
    width: 90px;
    height: 90px;
    border-color: var(--danger-red);
    background: #fff;
    color: var(--danger-red);
}

/* Spirit Screen */
#spirit-screen {
    justify-content: center;
    align-items: center;
    background: rgba(0,0,0,0.85);
}

.spirit-scroll {
    background: #fff;
    border: 15px solid var(--ink-black);
    width: 90%;
    height: 90%;
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
}

.spirit-title {
    font-family: var(--font-title);
    font-size: 3rem;
    margin-bottom: 30px;
}

.spirit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 20px;
    width: 100%;
    padding: 10px;
}

.spirit-card {
    width: 120px;
    height: 160px;
    border: 3px solid #ddd;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: #eee;
    border-radius: 10px;
}

.spirit-card:not(.locked) {
    border-color: var(--scroll-gold);
    background: linear-gradient(135deg, #fff 0%, #f9f9f9 100%);
}

.spirit-icon {
    font-size: 3.5rem;
    margin-bottom: 10px;
}

.spirit-name {
    font-family: var(--font-title);
    font-size: 1.2rem;
    font-weight: bold;
}

.spirit-type {
    font-size: 0.8rem;
    color: #888;
}

/* Result Screen */
#result-screen {
    justify-content: center;
    align-items: center;
    background: rgba(0,0,0,0.85);
}

.result-card {
    background: var(--paper-bg);
    padding: 40px;
    border: 8px solid var(--ink-black);
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 0 50px rgba(255,255,255,0.2);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.result-card h2 {
    font-family: var(--font-title);
    font-size: 4rem;
    margin: 0 0 20px 0;
    color: var(--ink-black);
}

.rewards {
    font-size: 1.5rem;
    margin-bottom: 30px;
    color: #555;
}

.result-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
}

/* Damage Text */
.damage-popup {
    font-family: 'Arial Black', sans-serif;
    text-shadow: 2px 2px 0 #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
    z-index: 100;
    pointer-events: none;
}

/* Shake Animation */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Close Button */
.close-game-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    background: var(--ink-black);
    color: white;
    font-size: 2rem;
    text-decoration: none;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    z-index: 1000;
    font-family: Arial, sans-serif;
    line-height: 1;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    transition: all 0.2s;
    border: 2px solid var(--scroll-gold);
}

.close-game-btn:hover {
    background: var(--danger-red);
    transform: rotate(90deg);
}

/* Boss HP Bar */
.boss-hp-container {
    position: absolute;
    top: 80px; /* Below top bar */
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 25px;
    background: #333;
    border: 3px solid var(--ink-black);
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    z-index: 90;
}

.boss-hp-bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #8e44ad, #c0392b);
    transition: width 0.5s;
}

.boss-hp-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
}

/* Boss Visuals */
.enemy.boss {
    transform: scale(1.5);
    filter: drop-shadow(0 0 15px var(--danger-red));
}

/* Defense Shield */
.shield-effect {
    position: absolute;
    top: -20px;
    left: -20px;
    right: -20px;
    bottom: -20px;
    border: 5px solid var(--magic-blue);
    border-radius: 50%;
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
    transition: all 0.3s;
    box-shadow: 0 0 20px var(--magic-blue);
}

.shield-effect.active {
    opacity: 0.8;
    transform: scale(1);
}

/* Countdown Timer */
.defense-timer {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 5rem;
    color: var(--danger-red);
    font-family: var(--font-title);
    text-shadow: 0 0 10px white;
    z-index: 100;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.2); }
    100% { transform: translateX(-50%) scale(1); }
}

/* New Visual FX */
.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 100;
    animation: particle-pop 0.8s ease-out forwards;
}

@keyframes particle-pop {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

.damage-popup {
    text-shadow: 2px 2px 0 #000;
    z-index: 200;
}


/* Pinyin Font Fix */
.pinyin-text {
    /* Use fonts known for good Pinyin/Unicode support */
    font-family: "Segoe UI", "Microsoft YaHei", "Arial", sans-serif !important;
    letter-spacing: 1px;
    /* Ensure the tone mark is clearly visible */
    font-weight: 500;
}

