/* ===== リセット・ベース ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: 'Press Start 2P', 'Segoe UI', 'Hiragino Sans', monospace;
    touch-action: none;
}

/* ===== タイトル画面 ===== */
#title-screen, #gameover-screen, #clear-screen {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: #0b0b2a;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

/* 星背景キャンバス */
#stars-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
}

/* CRTスキャンライン */
.scanlines {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.15) 2px,
        rgba(0, 0, 0, 0.15) 4px
    );
    pointer-events: none;
    z-index: 2;
}

.title-content {
    text-align: center;
    color: #fff;
    padding: 20px;
}

.title-content.retro {
    position: relative;
    z-index: 1;
}

.retro-title {
    margin-bottom: 10px;
}

.title-sub {
    font-size: 0.6em;
    color: #ffcc00;
    letter-spacing: 2px;
    margin-bottom: 12px;
    text-shadow: 0 0 10px rgba(255, 204, 0, 0.6);
    animation: retro-pulse 2s ease-in-out infinite;
}

.title-content h1 {
    font-family: 'Press Start 2P', monospace;
    font-size: 2.8em;
    margin-bottom: 8px;
    line-height: 1.4;
    color: #fff;
    text-shadow:
        4px 4px 0px #e94560,
        -1px -1px 0px #00d4ff,
        0 0 20px rgba(233, 69, 96, 0.5),
        0 0 40px rgba(233, 69, 96, 0.3);
    letter-spacing: 4px;
    animation: title-glow 3s ease-in-out infinite alternate;
}

@keyframes title-glow {
    0% { text-shadow: 4px 4px 0px #e94560, -1px -1px 0px #00d4ff, 0 0 20px rgba(233, 69, 96, 0.5); }
    100% { text-shadow: 4px 4px 0px #e94560, -1px -1px 0px #00d4ff, 0 0 40px rgba(233, 69, 96, 0.8), 0 0 80px rgba(0, 212, 255, 0.3); }
}

.title-decoration {
    font-size: 0.5em;
    color: #00d4ff;
    letter-spacing: 3px;
    margin-top: 8px;
    text-shadow: 0 0 8px rgba(0, 212, 255, 0.5);
}

.retro-icon-row {
    margin: 15px 0 5px;
}

.title-icon {
    width: 50px;
    height: 50px;
    vertical-align: middle;
    animation: title-bounce 1.5s ease-in-out infinite;
    filter: drop-shadow(0 0 8px rgba(0, 212, 255, 0.6));
    image-rendering: pixelated;
}

@keyframes title-bounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(5deg); }
}

@keyframes retro-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.retro-subtitle {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.55em;
    color: #aaa;
    letter-spacing: 1px;
    margin: 8px 0 5px;
}

.title-content p {
    font-size: 0.7em;
    margin-bottom: 8px;
    color: #ccc;
}

.title-content button,
.retro-btn {
    font-family: 'Press Start 2P', monospace;
    background: transparent;
    color: #ffcc00;
    border: 3px solid #ffcc00;
    padding: 16px 44px;
    font-size: 1.1em;
    border-radius: 0;
    cursor: pointer;
    margin: 20px 0;
    box-shadow:
        0 0 10px rgba(255, 204, 0, 0.3),
        inset 0 0 10px rgba(255, 204, 0, 0.1);
    transition: all 0.1s;
    text-transform: uppercase;
    letter-spacing: 3px;
    position: relative;
}

.retro-btn:hover,
.retro-btn:active {
    background: rgba(255, 204, 0, 0.15);
    box-shadow:
        0 0 20px rgba(255, 204, 0, 0.5),
        inset 0 0 20px rgba(255, 204, 0, 0.2);
    transform: scale(1.02);
}

.btn-blink {
    animation: blink-text 1.2s step-end infinite;
}

@keyframes blink-text {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.title-content button:active {
    transform: scale(0.95);
}

.instructions,
.retro-instructions {
    margin-top: 25px;
    background: rgba(0, 212, 255, 0.08);
    border: 2px solid rgba(0, 212, 255, 0.3);
    border-radius: 0;
    padding: 15px 20px;
}

.instructions-header {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7em !important;
    color: #00d4ff !important;
    margin-bottom: 10px !important;
    text-shadow: 0 0 8px rgba(0, 212, 255, 0.5);
}

.retro-instructions p {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.5em;
    line-height: 2;
    color: #ccc;
}

.retro-hint {
    color: #e94560 !important;
    margin-top: 4px;
}

.retro-copyright {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.4em !important;
    color: #555 !important;
    margin-top: 20px !important;
    letter-spacing: 1px;
}

.instructions p:first-child {
    font-size: 0.7em;
    color: #00d4ff;
    margin-bottom: 8px;
    font-weight: bold;
}

/* ===== ゲームコンテナ ===== */
#game-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    background: #5c94fc;
}

/* ===== HUD ===== */
#hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    padding: 10px 15px;
    font-size: 1.1em;
    color: #fff;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    z-index: 10;
    pointer-events: none;
}

/* ===== キャンバス ===== */
#gameCanvas {
    flex: 1;
    width: 100%;
    display: block;
}

/* ===== モバイルコントロール ===== */
#controls {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 15px 20px;
    padding-bottom: max(15px, env(safe-area-inset-bottom));
    pointer-events: none;
    z-index: 10;
}

#dpad {
    display: flex;
    gap: 12px;
    pointer-events: auto;
}

#action-buttons {
    pointer-events: auto;
}

.ctrl-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.6);
    background: rgba(255,255,255,0.2);
    color: #fff;
    font-size: 1.5em;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    cursor: pointer;
    transition: background 0.1s;
}

.ctrl-btn:active {
    background: rgba(255,255,255,0.5);
}

.jump-btn {
    width: 85px;
    height: 85px;
    font-size: 1.8em;
    border-color: rgba(233, 69, 96, 0.8);
    background: rgba(233, 69, 96, 0.3);
}

.jump-btn:active {
    background: rgba(233, 69, 96, 0.6);
}

.down-btn {
    width: 55px;
    height: 55px;
    font-size: 1.2em;
    border-color: rgba(39, 174, 96, 0.8);
    background: rgba(39, 174, 96, 0.3);
}

.down-btn:active {
    background: rgba(39, 174, 96, 0.6);
}

/* ===== レスポンシブ ===== */
@media (max-height: 500px) {
    .ctrl-btn {
        width: 55px;
        height: 55px;
        font-size: 1.2em;
    }
    .jump-btn {
        width: 65px;
        height: 65px;
        font-size: 1.4em;
    }
    #controls {
        padding: 8px 15px;
    }
    #hud {
        font-size: 0.9em;
        padding: 5px 10px;
    }
}

@media (min-width: 768px) {
    .ctrl-btn {
        width: 80px;
        height: 80px;
    }
    .jump-btn {
        width: 95px;
        height: 95px;
    }
}

/* ===== ニックネーム入力画面 ===== */
#nickname-screen {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: #0b0b2a;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

#stars-canvas-nick {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
}

.nickname-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 2em !important;
    color: #00d4ff !important;
    text-shadow:
        3px 3px 0px #0066aa,
        0 0 20px rgba(0, 212, 255, 0.5);
    margin-bottom: 15px !important;
    line-height: 1.5 !important;
}

.nickname-form {
    margin-top: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

#nickname-input {
    font-family: 'Press Start 2P', monospace;
    font-size: 1.2em;
    background: rgba(0, 0, 0, 0.6);
    border: 3px solid #ffcc00;
    color: #ffcc00;
    padding: 14px 20px;
    text-align: center;
    width: 260px;
    max-width: 80vw;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 3px;
    box-shadow: 0 0 10px rgba(255, 204, 0, 0.2);
}

#nickname-input::placeholder {
    color: rgba(255, 204, 0, 0.3);
}

#nickname-input:focus {
    border-color: #fff;
    color: #fff;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

/* ===== ランキング ===== */
#ranking-container {
    margin: 20px auto;
    max-width: 340px;
    width: 90vw;
}

.ranking-header {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7em;
    color: #ffcc00;
    text-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
    margin-bottom: 12px;
    letter-spacing: 2px;
}

#ranking-list {
    border: 2px solid rgba(255, 204, 0, 0.4);
    background: rgba(0, 0, 0, 0.5);
    padding: 8px;
}

.ranking-row {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.5em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    color: #ccc;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

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

.ranking-row.current {
    color: #ffcc00;
    background: rgba(255, 204, 0, 0.08);
    text-shadow: 0 0 6px rgba(255, 204, 0, 0.4);
}

.ranking-row.gold {
    color: #ffd700;
}

.ranking-row.silver {
    color: #c0c0c0;
}

.ranking-row.bronze {
    color: #cd7f32;
}

.ranking-rank {
    min-width: 30px;
    text-align: left;
}

.ranking-name {
    flex: 1;
    text-align: left;
    margin: 0 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ranking-score {
    min-width: 60px;
    text-align: right;
}
