* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow: hidden;
}

.game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* 画面共通 */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
}

.screen.active {
    display: flex;
}

/* タイトル画面 */
#titleScreen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    flex-direction: column;
}

.title-content {
    text-align: center;
    color: white;
    animation: fadeIn 1s ease-in;
}

.game-title {
    font-size: 4rem;
    margin-bottom: 1rem;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.3);
    animation: glow 2s ease-in-out infinite;
}

.subtitle {
    font-size: 1.5rem;
    margin-bottom: 3rem;
    opacity: 0.9;
}

.start-btn {
    padding: 1rem 3rem;
    font-size: 1.5rem;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.start-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
}

/* クエスト選択画面 */
#questScreen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.quest-container {
    width: 95%;
    max-width: 1200px;
    max-height: 90vh;
    background: white;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
}

.quest-container h2 {
    color: #667eea;
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 2rem;
}

/* 章タブ */
.chapter-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #e0e0e0;
}

.chapter-tab {
    padding: 0.8rem 2rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: bold;
    color: #999;
    transition: all 0.3s;
}

.chapter-tab:hover {
    color: #667eea;
}

.chapter-tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.quest-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    overflow-y: auto;
    padding-right: 0.5rem;
    max-height: calc(90vh - 200px);
}

/* スクロールバーのスタイル */
.quest-list::-webkit-scrollbar {
    width: 8px;
}

.quest-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.quest-list::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

.quest-list::-webkit-scrollbar-thumb:hover {
    background: #764ba2;
}

.quest-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    padding: 2rem;
    border-radius: 15px;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s, border-color 0.3s;
    border: 3px solid transparent;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.quest-card:hover:not(.locked) {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
    border-color: #667eea;
}

.quest-card.completed {
    background: linear-gradient(135deg, #d4fc79 0%, #96e6a1 100%);
    border-color: #4CAF50;
}

.quest-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: linear-gradient(135deg, #e0e0e0 0%, #bdbdbd 100%);
}

.quest-card h3 {
    color: #333;
    margin-bottom: 0.8rem;
    font-size: 1.3rem;
    font-weight: bold;
}

.quest-card p {
    color: #666;
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 1rem;
}

.quest-status {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    margin-top: 0.5rem;
    font-weight: bold;
}

.quest-status.unlocked {
    background: #667eea;
    color: white;
}

.quest-status.completed {
    background: #4CAF50;
    color: white;
}

.quest-status.locked {
    background: #999;
    color: white;
}

/* レッスン画面 */
#lessonScreen {
    background: #f5f5f5;
}

.lesson-layout {
    width: 100%;
    height: 100%;
    display: flex;
}

.lesson-instruction {
    flex: 1;
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.instruction-header {
    background: #667eea;
    color: white;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.instruction-header h3 {
    font-size: 1.3rem;
}

.back-btn {
    padding: 0.5rem 1rem;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid white;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s;
}

.back-btn:hover {
    background: rgba(255,255,255,0.3);
}

.instruction-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    line-height: 1.6;
}

/* 解説用の図解スタイル */
.visual-box {
    background: #f0f4ff;
    border: 2px solid #667eea;
    border-radius: 10px;
    padding: 1.5rem;
    margin: 1.5rem 0;
}

.variable-demo {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}

.box {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 10px;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    min-width: 100px;
    text-align: center;
}

.box-label {
    font-size: 0.9rem;
    color: #667eea;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.box-small {
    background: #667eea;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    display: inline-block;
    min-width: 60px;
    text-align: center;
}

.arrow {
    font-size: 2rem;
    color: #667eea;
    font-weight: bold;
}

.list-demo {
    display: flex;
    gap: 1rem;
    margin: 1rem 0;
    align-items: flex-start;
}

.list-item {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    padding: 1rem;
    border-radius: 10px;
    font-weight: bold;
    min-width: 60px;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.list-index {
    font-size: 0.8rem;
    color: #666;
    text-align: center;
    margin-top: 0.5rem;
}

.operator-table {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
}

.operator-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    border-bottom: 1px solid #e0e0e0;
}

.operator-row:last-child {
    border-bottom: none;
}

.operator-code {
    background: #667eea;
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
}

/* ヒント・答えのトグル */
.hint-toggle, .answer-toggle {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    margin: 1rem 0;
    width: 100%;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.answer-toggle {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.hint-toggle:hover, .answer-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.3);
}

.toggle-icon {
    font-size: 1.2rem;
    transition: transform 0.3s;
}

.toggle-icon.open {
    transform: rotate(180deg);
}

.hint-content, .answer-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.hint-content.show, .answer-content.show {
    max-height: 1000px;
    transition: max-height 0.5s ease-in;
}

.hint-box {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    padding: 1.5rem;
    border-radius: 8px;
    margin-top: 1rem;
}

.answer-box {
    background: #d1ecf1;
    border-left: 4px solid #0dcaf0;
    padding: 1.5rem;
    border-radius: 8px;
    margin-top: 1rem;
}

.lesson-editor {
    flex: 1;
    background: #1e1e1e;
    display: flex;
    flex-direction: column;
}

.editor-header {
    background: #2d2d2d;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-header h4 {
    color: #fff;
}

.run-code-btn {
    padding: 0.7rem 1.5rem;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.3s;
}

.run-code-btn:hover {
    background: #45a049;
}

.code-editor {
    flex: 1;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    padding: 1rem;
    border: none;
    resize: none;
    outline: none;
}

/* CodeMirror エディタのスタイル調整 */
.CodeMirror {
    height: 100% !important;
    font-size: 14px !important;
    font-family: 'Courier New', monospace !important;
}

.CodeMirror-scroll {
    overflow-y: auto !important;
    overflow-x: auto !important;
}

.CodeMirror-gutters {
    border-right: 1px solid #555 !important;
    background-color: #272822 !important;
    padding-right: 5px !important;
}

.CodeMirror-linenumber {
    padding: 0 15px 0 10px !important;
    min-width: 40px !important;
    text-align: right !important;
    color: #90908a !important;
}

.CodeMirror-lines {
    padding: 4px 0 !important;
}

.CodeMirror-line {
    padding-left: 15px !important;
}

.CodeMirror pre {
    padding-left: 15px !important;
}

.code-hints {
    background: #2d2d2d;
    color: #ffd700;
    padding: 1rem;
    border-top: 1px solid #444;
}

/* バトル画面 */
#battleScreen {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
}

.battle-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    gap: 1rem;
}

.battle-field {
    flex: 2;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: linear-gradient(135deg, #3a5a78 0%, #2c3e50 100%);
    border-radius: 20px;
    padding: 2rem;
    position: relative;
    box-shadow: inset 0 5px 20px rgba(0,0,0,0.3);
}

.character {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.character-sprite {
    font-size: 6rem;
    animation: float 3s ease-in-out infinite;
}

.player-side .character-sprite {
    animation-delay: 0s;
}

.enemy-side .character-sprite {
    animation-delay: 1.5s;
}

.character-info {
    background: rgba(255,255,255,0.95);
    padding: 1rem;
    border-radius: 15px;
    min-width: 250px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.name-tag {
    font-weight: bold;
    font-size: 1.2rem;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    text-align: center;
}

.hp-bar-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.hp-label {
    font-weight: bold;
    color: #e74c3c;
    min-width: 30px;
}

.hp-bar {
    flex: 1;
    height: 20px;
    background: #ddd;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid #333;
}

.hp-fill {
    height: 100%;
    transition: width 0.5s ease;
    border-radius: 8px;
}

.player-hp {
    background: linear-gradient(90deg, #4CAF50 0%, #8BC34A 100%);
}

.enemy-hp {
    background: linear-gradient(90deg, #f44336 0%, #e91e63 100%);
}

.hp-text {
    min-width: 80px;
    text-align: right;
    font-weight: bold;
    color: #2c3e50;
}

.stats {
    font-size: 0.85rem;
    color: #666;
    text-align: center;
}

/* バトルログ */
.battle-log {
    flex: 1;
    background: rgba(0,0,0,0.8);
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.log-header {
    background: #34495e;
    color: white;
    padding: 0.8rem;
    font-weight: bold;
    text-align: center;
}

.log-content {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    color: #ecf0f1;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.log-entry {
    margin-bottom: 0.5rem;
    padding: 0.3rem;
    border-left: 3px solid #3498db;
    padding-left: 0.5rem;
    animation: slideIn 0.3s ease;
}

.log-entry.damage {
    border-left-color: #e74c3c;
    color: #ff6b6b;
}

.log-entry.heal {
    border-left-color: #2ecc71;
    color: #51cf66;
}

.log-entry.info {
    border-left-color: #f39c12;
    color: #ffd43b;
}

/* バトルアクション */
.battle-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.action-btn {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.action-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.4);
}

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

.attack-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.heal-btn {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.heal-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ダメージ数値エフェクト */
#damageNumbers {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.damage-number {
    position: absolute;
    font-size: 2rem;
    font-weight: bold;
    animation: damageFloat 1s ease-out forwards;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

.damage-number.player-damage {
    color: #ff6b6b;
}

.damage-number.enemy-damage {
    color: #ffd43b;
}

.damage-number.heal {
    color: #51cf66;
}

/* リザルト画面 */
#resultScreen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.result-container {
    text-align: center;
    color: white;
}

.result-content {
    font-size: 3rem;
    margin-bottom: 2rem;
    animation: scaleIn 0.5s ease;
}

.result-content.victory {
    color: #ffd700;
}

.result-content.defeat {
    color: #ff6b6b;
}

.continue-btn {
    padding: 1rem 2rem;
    font-size: 1.2rem;
    background: white;
    color: #667eea;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.3s;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.continue-btn:hover {
    transform: scale(1.1);
}

/* アニメーション */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes glow {
    0%, 100% { text-shadow: 3px 3px 6px rgba(0,0,0,0.3); }
    50% { text-shadow: 3px 3px 20px rgba(255,255,255,0.8); }
}

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

@keyframes slideIn {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes damageFloat {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(-100px) scale(1.5);
        opacity: 0;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0);
    }
    to {
        transform: scale(1);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}
