@import url('https://fonts.googleapis.com/css2?family=Syncopate:wght@700&family=Share+Tech+Mono&display=swap');

* { box-sizing: border-box; user-select: none; -webkit-tap-highlight-color: transparent; }

body {
    background: #000;
    color: #00f2ff;
    font-family: 'Share Tech Mono', monospace;
    text-align: center;
    margin: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    touch-action: manipulation;
}

/* 共通レイヤー */
.screen-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    pointer-events: none; transition: opacity 0.3s; z-index: 10;
    background: rgba(0, 5, 10, 0.85);
    backdrop-filter: blur(5px);
}
.interactive { pointer-events: auto; }
/* ★修正: hiddenを強力にして表示残り防止 */
.hidden { opacity: 0; pointer-events: none !important; z-index: -1; display: none !important; }
.overlay { background: rgba(0,0,0,0.95); z-index: 50; }

/* テキスト */
h1, h2, h3 { font-family: 'Syncopate', sans-serif; text-transform: uppercase; margin: 10px 0; }
.main-title { font-size: 42px; color: #fff; text-shadow: 0 0 20px #00f2ff; }
.sub-title { color: #ff0055; letter-spacing: 5px; margin-bottom: 30px; }
.gold-text { color: #ffd700; text-shadow: 0 0 10px #ffd700; }
.alert-text { color: #ff0055; text-shadow: 0 0 10px #ff0055; }

/* ボタン */
.big-btn {
    background: rgba(0, 20, 40, 0.8); color: #00f2ff; border: 2px solid #00f2ff;
    padding: 12px 30px; font-family: 'Syncopate', sans-serif; font-size: 14px;
    cursor: pointer; transition: 0.2s; margin: 5px; min-width: 200px;
    text-shadow: 0 0 5px #00f2ff; box-shadow: 0 0 10px rgba(0, 242, 255, 0.2);
}
.big-btn:hover { background: #00f2ff; color: #000; box-shadow: 0 0 30px #00f2ff; }
.big-btn:disabled { border-color: #444; color: #444; box-shadow: none; cursor: not-allowed; }
.btn-gold { border-color: #ffd700; color: #ffd700; }
.btn-gray { border-color: #aaa; color: #aaa; }
.btn-group { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.btn-group-vertical { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.mt-20 { margin-top: 20px; }

/* UI要素 */
.currency-display {
    position: absolute; top: 20px; right: 20px;
    font-size: 18px; color: #ffd700; text-shadow: 0 0 10px #ffd700;
    border: 1px solid #ffd700; padding: 5px 15px; border-radius: 4px;
}
.level-select-container { margin: 20px 0; width: 80%; max-width: 300px; }
#level-display { color: #00f2ff; font-size: 20px; }
input[type=range] { width: 100%; accent-color: #00f2ff; cursor: pointer; }

/* HUD */
#hud { justify-content: space-between; padding: 20px; background: none; backdrop-filter: none; }
.hud-top { width: 100%; display: flex; justify-content: space-between; }
.stat-panel {
    background: rgba(0, 10, 20, 0.6); border: 1px solid rgba(0, 242, 255, 0.3);
    padding: 10px 20px; backdrop-filter: blur(4px); border-radius: 4px;
}
#ui-level { font-size: 20px; color: #fff; }
#ui-score { font-size: 20px; color: #00f2ff; }
.hud-bottom { margin-bottom: 20px; }

/* 円形ゲージ & カウンター */
#center-counter { 
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); 
    pointer-events: none; z-index: 5;
    display: flex; align-items: center; justify-content: center;
}
#count-num { font-size: 80px; font-family: 'Syncopate'; color: rgba(0, 242, 255, 0.8); text-shadow: 0 0 20px #00f2ff; z-index: 6; }

.timer-ring { position: absolute; width: 200px; height: 200px; pointer-events: none; }
.timer-bg { fill: none; stroke: rgba(255,255,255,0.1); stroke-width: 10; }
.timer-bar { 
    fill: none; stroke: #ff0055; stroke-width: 10; 
    stroke-dasharray: 565; stroke-dashoffset: 565; 
    transition: stroke-dashoffset 0.1s linear;
}

/* ★修正: 日本語警告の位置を上部に移動し、盤面とかぶらないように */
.rotation-display {
    position: absolute; top: 70px; left: 50%; transform: translateX(-50%);
    font-size: 14px; color: #888; font-family: 'Syncopate';
    pointer-events: none;
}
#challenge-warning {
    position: absolute; top: 95px; left: 50%; transform: translateX(-50%);
    color: #ff0055; font-size: 14px; font-weight: bold;
    border: 1px solid #ff0055; padding: 5px 15px;
    background: rgba(0, 0, 0, 0.8); /* 背景を濃くして読みやすく */
    border-radius: 4px;
    animation: blink 1s infinite alternate;
    pointer-events: none; white-space: nowrap;
    text-shadow: 0 0 5px #ff0055; font-family: sans-serif;
    z-index: 50;
}
@keyframes blink { from { opacity: 0.8; } to { opacity: 1; } }

/* リザルト & モーダル */
.result-box {
    background: rgba(0, 10, 20, 0.95); border: 2px solid #ff0055; padding: 30px;
    border-radius: 10px; width: 90%; max-width: 400px; box-shadow: 0 0 50px rgba(255, 0, 85, 0.2);
}
#res-stage { color: #fff; font-size: 24px; }
#res-score { color: #00f2ff; font-size: 24px; }
#res-earned { color: #ffd700; font-size: 24px; }

.name-input {
    background: rgba(0,0,0,0.5); border: 1px solid #00f2ff; color: #fff;
    padding: 10px; width: 100%; font-family: 'Share Tech Mono';
    text-align: center; font-size: 16px; margin: 20px 0; outline: none;
}

.rank-list { text-align: left; margin: 20px 0; width: 90%; max-width: 400px; max-height: 50vh; overflow-y: auto; }
.rank-item { display: flex; justify-content: space-between; padding: 10px; border-bottom: 1px solid #333; font-size: 14px; }
.rank-1 { color: #ffd700; text-shadow: 0 0 5px #ffd700; font-weight: bold; }
.rank-2 { color: #c0c0c0; font-weight: bold; }
.rank-3 { color: #cd7f32; font-weight: bold; }

/* ガチャアイテム & アニメーション */
#gacha-result-area { min-height: 100px; display: flex; align-items: center; justify-content: center; flex-direction: column; margin: 20px; }
.collection-header { margin-bottom: 10px; color: #00f2ff; }
.gacha-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 15px; width: 95%; max-width: 800px; max-height: 60vh; overflow-y: auto;
    padding: 10px; border: 1px solid #333;
}
.item-card {
    background: #0a0a0a; border: 1px solid #333; padding: 5px;
    display: flex; flex-direction: column; align-items: center; justify-content: space-between;
    height: 130px; text-align: center; color: #555; position: relative;
    transition: transform 0.2s;
    opacity: 0;
}
.item-card.reveal { animation: cardPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
@keyframes cardPop { 0% { opacity: 0; transform: scale(0.5) translateY(20px); } 100% { opacity: 1; transform: scale(1) translateY(0); } }
.item-card img { width: 40px; height: 40px; margin-bottom: 5px; display: block; }
.item-name { font-size: 9px; line-height: 1.1; margin-top: 5px; color: #aaa; }
.item-stars { font-size: 10px; letter-spacing: 1px; margin-top: 2px; }
.item-card.owned { border-color: #555; color: #fff; opacity: 1; }
.item-card.owned:hover { transform: scale(1.05); z-index: 10; }

.rank-1 { border-color: #666; } .rank-1 .item-name { color: #ccc; }
.rank-2 { border-color: #00ff00; box-shadow: 0 0 5px rgba(0, 255, 0, 0.2); } .rank-2 .item-name { color: #00ff00; }
.rank-3 { border-color: #00f2ff; box-shadow: 0 0 10px rgba(0, 242, 255, 0.4); animation: pulseBlue 2s infinite; } .rank-3 .item-name { color: #00f2ff; }
.rank-4 { border-color: #d000ff; box-shadow: 0 0 15px rgba(208, 0, 255, 0.6); animation: pulsePurple 1.5s infinite; } .rank-4 .item-name { color: #d000ff; }
.rank-5 { border: 2px solid #ffd700; box-shadow: 0 0 20px #ffd700; animation: legendaryShine 1s infinite alternate; } .rank-5 .item-name { color: #ffd700; }

@keyframes pulseBlue { 0% { box-shadow: 0 0 5px #00f2ff; } 50% { box-shadow: 0 0 15px #00f2ff; } 100% { box-shadow: 0 0 5px #00f2ff; } }
@keyframes pulsePurple { 0% { box-shadow: 0 0 8px #d000ff; } 50% { box-shadow: 0 0 20px #d000ff; } 100% { box-shadow: 0 0 8px #d000ff; } }
@keyframes legendaryShine { 0% { box-shadow: 0 0 15px #ffd700; transform: scale(1); } 100% { box-shadow: 0 0 30px #ffd700; transform: scale(1.02); } }
.new-badge { position: absolute; top: -5px; right: -5px; background: #ff0055; color: #fff; font-size: 9px; padding: 2px 5px; border-radius: 2px; animation: flash 0.5s infinite alternate; box-shadow: 0 0 5px #ff0055; }
@keyframes flash { from { opacity: 0.8; } to { opacity: 1; transform: scale(1.1); } }

/* Orbital Drop Animation */
.gacha-target { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0); width: 200px; height: 200px; border-radius: 50%; border: 2px dashed #fff; opacity: 0; }
.gacha-target.anim-target { animation: targetLock 1s forwards; }
@keyframes targetLock { 0% { transform: translate(-50%, -50%) scale(2) rotate(0deg); opacity: 0; border-color: #00f2ff; } 50% { opacity: 1; border-color: #ff0055; } 100% { transform: translate(-50%, -50%) scale(1) rotate(90deg); opacity: 1; border-color: #ff0055; box-shadow: 0 0 20px #ff0055; } }
.gacha-beam { position: absolute; top: -100%; left: 50%; transform: translateX(-50%); width: 50px; height: 150%; background: #fff; opacity: 0; box-shadow: 0 0 50px #fff; }
.gacha-beam.anim-beam { animation: orbitalBeam 0.5s ease-out forwards; }
@keyframes orbitalBeam { 0% { top: -100%; opacity: 0; width: 10px; } 20% { opacity: 1; } 50% { width: 100px; } 100% { top: 0; opacity: 0; width: 0px; } }
.gacha-shockwave { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 10px; height: 10px; border-radius: 50%; border: 5px solid #fff; opacity: 0; }
.gacha-shockwave.anim-wave { animation: shockwave 0.6s ease-out forwards; }
@keyframes shockwave { 0% { transform: translate(-50%, -50%) scale(0); opacity: 1; border-width: 50px; } 100% { transform: translate(-50%, -50%) scale(20); opacity: 0; border-width: 0px; } }
.beam-blue { background: #00f2ff; box-shadow: 0 0 50px #00f2ff; }
.beam-purple { background: #d000ff; box-shadow: 0 0 60px #d000ff; }
.beam-gold { background: #ffd700; box-shadow: 0 0 80px #ffd700; }
.gacha-flash { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #fff; opacity: 0; pointer-events: none; }
.anim-flash { animation: screenFlash 0.5s ease-out forwards; }
@keyframes screenFlash { 0% { opacity: 0; } 10% { opacity: 1; } 100% { opacity: 0; } }

#floating-text { position: fixed; top: 30%; font-family: 'Syncopate'; font-weight: bold; font-size: 24px; pointer-events: none; opacity: 0; z-index: 100; transition: 0.1s; }
canvas#gameCanvas { display: block; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; }