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

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: #ffffff;
    overflow: hidden;
}

#game-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 画面共通 */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    max-width: 900px;
    padding: 10px;
    overflow-y: auto;
}

.screen.active {
    display: flex;
}

/* タイトル画面 */
#title-screen {
    text-align: center;
}

.game-title {
    font-size: 48px;
    margin-bottom: 10px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
}

.game-subtitle {
    font-size: 20px;
    margin-bottom: 40px;
    opacity: 0.8;
}

.start-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 20px;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s;
}

.start-btn:hover {
    transform: scale(1.05);
}

/* 職業選択 */
#class-selection h2 {
    margin-bottom: 30px;
    font-size: 28px;
}

.class-cards {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.class-card {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    padding: 20px;
    width: 200px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.class-card:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-5px);
    border-color: #667eea;
}

.class-icon {
    font-size: 60px;
    margin-bottom: 10px;
}

.class-card h3 {
    margin-bottom: 10px;
    font-size: 22px;
}

.class-stats {
    font-size: 12px;
    opacity: 0.8;
    margin-bottom: 10px;
}

.class-desc {
    font-size: 11px;
    opacity: 0.7;
}

/* 探索画面 */
#explore-screen {
    max-width: 100%;
}

#status-bar {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 10px;
}

.status-item {
    font-size: 14px;
}

.status-label {
    color: #ffd700;
    margin-right: 5px;
}

#dungeon-canvas {
    background: #1a1a2e;
    border: 3px solid #667eea;
    border-radius: 10px;
    margin-bottom: 15px;
    max-width: 100%;
    height: auto;
}

#controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.control-row {
    display: flex;
    gap: 10px;
}

.control-btn {
    background: rgba(102, 126, 234, 0.8);
    color: white;
    border: none;
    padding: 15px 20px;
    font-size: 20px;
    border-radius: 8px;
    cursor: pointer;
    min-width: 60px;
}

.control-btn:hover {
    background: rgba(102, 126, 234, 1);
}

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

.menu-btn {
    background: rgba(118, 75, 162, 0.8);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
}

.menu-btn:hover {
    background: rgba(118, 75, 162, 1);
}

#message-box {
    min-height: 40px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 8px;
    margin-top: 10px;
    text-align: center;
    font-size: 14px;
}

/* 中央メッセージオーバーレイ */
#message-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    animation: fadeIn 0.3s;
}

#message-overlay.active {
    display: flex;
}

.overlay-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px 50px;
    border-radius: 20px;
    font-size: 28px;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.5s ease-out;
}

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

/* ポイント獲得アニメーション */
.point-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 48px;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    z-index: 10000;
    pointer-events: none;
    animation: pointPop 1.5s ease-out forwards;
}

@keyframes pointPop {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -80%) scale(1.2);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -120%) scale(1);
        opacity: 0;
    }
}

/* バトル画面 */
.battle-area {
    display: flex;
    align-items: center;
    justify-content: space-around;
    width: 100%;
    margin-bottom: 20px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
}

.enemy-area,
.player-area {
    text-align: center;
}

.enemy-icon,
.player-icon {
    width: 128px;
    height: 128px;
    margin-bottom: 10px;
    image-rendering: pixelated; /* ピクセルアートをくっきり表示 */
}

.vs-text {
    font-size: 32px;
    font-weight: bold;
    color: #ff6b6b;
}

.hp-bar {
    width: 200px;
    height: 20px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    overflow: hidden;
    margin: 10px auto;
}

.hp-fill {
    height: 100%;
    background: linear-gradient(90deg, #11998e 0%, #38ef7d 100%);
    transition: width 0.3s;
}

#battle-log {
    background: rgba(0, 0, 0, 0.5);
    padding: 15px;
    border-radius: 10px;
    min-height: 150px;
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 20px;
    font-size: 14px;
}

.battle-log-entry {
    margin-bottom: 5px;
    padding: 5px;
    border-left: 3px solid #667eea;
    padding-left: 10px;
}

.battle-commands {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 500px;
}

.battle-btn {
    background: rgba(102, 126, 234, 0.8);
    color: white;
    border: none;
    padding: 15px;
    font-size: 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.battle-btn:hover {
    background: rgba(102, 126, 234, 1);
    transform: scale(1.05);
}

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

/* バトルアニメーション */
.shake {
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}

.flash-red {
    animation: flashRed 0.3s;
}

@keyframes flashRed {
    0%, 100% { background-color: transparent; }
    50% { background-color: rgba(255, 0, 0, 0.5); }
}

.attack-effect {
    animation: attackEffect 0.6s ease-out;
}

@keyframes attackEffect {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }
    50% {
        transform: scale(1.2);
        filter: brightness(1.5);
    }
    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

.battle-menu {
    display: none;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 500px;
    margin-bottom: 10px;
}

.battle-menu.active {
    display: flex;
}

/* インベントリ */
#inventory-screen h2 {
    margin-bottom: 20px;
}

#inventory-list {
    background: rgba(0, 0, 0, 0.3);
    padding: 20px;
    border-radius: 10px;
    min-height: 300px;
    width: 100%;
    max-width: 600px;
    margin-bottom: 20px;
}

.inventory-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.inventory-item button {
    background: #667eea;
    color: white;
    border: none;
    padding: 5px 15px;
    border-radius: 5px;
    cursor: pointer;
}

.back-btn,
.retry-btn {
    background: rgba(118, 75, 162, 0.8);
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 16px;
    border-radius: 8px;
    cursor: pointer;
}

.back-btn:hover,
.retry-btn:hover {
    background: rgba(118, 75, 162, 1);
}

/* 結果画面 */
#result-screen {
    text-align: center;
}

#result-title {
    font-size: 48px;
    margin-bottom: 30px;
}

.result-stats {
    background: rgba(0, 0, 0, 0.3);
    padding: 30px;
    border-radius: 15px;
    margin-bottom: 30px;
}

.result-stats p {
    font-size: 20px;
    margin-bottom: 15px;
}

/* タッチデバイス対応 */
#dungeon-canvas {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    body {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }

    .game-title {
        font-size: 28px;
        margin: 10px 0;
    }

    .game-subtitle {
        font-size: 14px;
        margin-bottom: 20px;
    }

    .class-cards {
        flex-direction: column;
        padding: 10px;
    }

    .class-card {
        width: 100%;
        max-width: 300px;
        padding: 15px;
        margin: 5px 0;
    }

    .class-icon {
        font-size: 48px;
    }

    .class-card h3 {
        font-size: 18px;
    }

    .class-stats,
    .class-desc {
        font-size: 12px;
    }

    #explore-screen {
        padding: 5px;
        overflow: hidden;
    }

    #status-bar {
        font-size: 10px;
        gap: 5px;
        padding: 5px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .status-item {
        min-width: 60px;
    }

    #dungeon-canvas {
        width: 100% !important;
        height: auto !important;
        max-width: 100%;
        touch-action: none;
    }

    #controls {
        margin-top: 10px;
    }

    .control-row {
        gap: 8px;
    }

    .control-btn {
        padding: 15px 20px;
        font-size: 24px;
        min-width: 60px;
        min-height: 60px;
        border-radius: 10px;
    }

    .menu-btn {
        padding: 10px 20px;
        font-size: 14px;
        min-height: 44px;
    }

    #message-box {
        font-size: 13px;
        min-height: 40px;
        padding: 10px;
        margin-top: 10px;
    }

    .battle-area {
        flex-direction: column;
        gap: 15px;
        padding: 10px;
    }

    .vs-text {
        transform: rotate(90deg);
        font-size: 20px;
    }

    .enemy-icon,
    .player-icon {
        width: 80px;
        height: 80px;
    }

    .hp-bar {
        width: 140px;
        height: 16px;
    }

    #battle-log {
        font-size: 12px;
        min-height: 80px;
        max-height: 80px;
        padding: 8px;
    }

    .battle-commands {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 10px;
    }

    .battle-btn {
        padding: 15px;
        font-size: 16px;
        min-height: 50px;
    }

    /* インベントリとステータスモーダル */
    .modal-content {
        width: 95%;
        max-width: 400px;
        padding: 15px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .inventory-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 8px;
    }

    .item-card {
        padding: 8px;
    }

    .item-icon {
        font-size: 32px;
    }

    /* リザルト画面 */
    .result-title {
        font-size: 28px;
    }

    .result-stats p {
        font-size: 16px;
        margin: 10px 0;
    }
}

/* アニメーション */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.screen.active {
    animation: fadeIn 0.3s ease-out;
}

/* Hidden utility */
.hidden {
    display: none !important;
}
