:root {
    --bg-color: #2c3e50;
    --text-color: #ecf0f1;
    --accent-color: #e74c3c;
    --accent-hover: #c0392b;
    --stamina-full: #2ecc71;
    --stamina-low: #e74c3c;
    --panel-bg: rgba(44, 62, 80, 0.9);
}

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

body {
    background-color: #1a1a1a;
    color: var(--text-color);
    font-family: 'Noto Sans JP', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

#game-wrapper {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: #2c3e50;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.back-link-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

.update-date {
    font-size: 0.65rem;
    color: #95a5a6;
    letter-spacing: 0.05em;
}

.back-link {
    color: #bdc3c7;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.2s;
}

.back-link:hover { color: #fff; }

.logo {
    font-family: 'Press Start 2P', cursive;
    font-size: 1.2rem;
    color: #fff;
}

.game-area {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

#game-container {
    position: relative;
    width: 400px;
    height: 600px;
    background-color: #87CEEB;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    flex-shrink: 0;
}

/* Side ranking panel — テトリス準拠 */
#ranking-panel {
    width: 200px;
    height: 600px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}

.ranking-panel-title {
    padding: 16px 14px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    text-align: center;
    flex-shrink: 0;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.48rem;
    color: #f39c12;
    letter-spacing: 2px;
    line-height: 1.8;
}

#side-ranking-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

#side-ranking-list::-webkit-scrollbar { width: 3px; }
#side-ranking-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

canvas { display: block; }

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 15px;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#hud.hidden { display: none; }

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.score-box {
    background: rgba(0, 0, 0, 0.5);
    padding: 5px 15px;
    border-radius: 20px;
    text-align: right;
    font-family: 'Press Start 2P', cursive;
    text-shadow: 1px 1px 0 #000;
}

.score-box .label {
    display: block;
    font-size: 0.5rem;
    color: #f39c12;
    margin-bottom: 4px;
}

#score { font-size: 1.2rem; color: #fff; }

.unit {
    font-size: 0.8rem;
    color: #bdc3c7;
    margin-left: 2px;
}

.stamina-container {
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 15px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 200px;
}

.stamina-container .label {
    font-size: 0.7rem;
    font-weight: bold;
    color: #fff;
}

.stamina-bar-bg {
    flex-grow: 1;
    height: 10px;
    background: rgba(255,255,255,0.2);
    border-radius: 5px;
    overflow: hidden;
}

.stamina-bar-fill {
    height: 100%;
    width: 100%;
    background-color: var(--stamina-full);
    transition: width 0.1s linear, background-color 0.3s;
}

/* Combo */
.combo-box {
    background: rgba(0, 0, 0, 0.5);
    padding: 5px 12px;
    border-radius: 20px;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.65rem;
    color: #f39c12;
    text-shadow: 1px 1px 0 #000;
    transition: opacity 0.2s;
    align-self: flex-start;
}

.combo-box.hidden { opacity: 0; pointer-events: none; }

@keyframes combo-flash {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.35); color: #e74c3c; }
    100% { transform: scale(1); }
}

.combo-box.flash { animation: combo-flash 0.35s ease-out forwards; }

/* Active effects badges */
.active-effects {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.effect-badge {
    padding: 3px 8px;
    border-radius: 12px;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.42rem;
    color: #fff;
    text-shadow: none;
    letter-spacing: 0.5px;
}

.badge-shield { background: rgba(52, 152, 219, 0.75); }
.badge-shield.shield-max {
    background: linear-gradient(135deg, #ffd700, #ff9f43);
    color: #1a1a1a;
    font-weight: bold;
    border: 1px solid #ffd700;
    animation: shield-max-pulse 1.5s infinite;
}

@keyframes shield-max-pulse {
    0% {
        box-shadow: 0 0 4px #ffd700, inset 0 0 2px #ffd700;
        border-color: #ffd700;
    }
    50% {
        box-shadow: 0 0 12px #ff9f43, inset 0 0 6px #ff9f43;
        border-color: #ff9f43;
    }
    100% {
        box-shadow: 0 0 4px #ffd700, inset 0 0 2px #ffd700;
        border-color: #ffd700;
    }
}
.badge-fly    { background: rgba(241, 196, 15, 0.8); color: #1a1a1a; }
.badge-wind   { background: rgba(149, 165, 166, 0.65); }
.badge-space  { background: rgba(61, 90, 128, 0.85); border: 1px solid #74b9ff; }
.badge-meteor  { background: rgba(231, 76, 60, 0.85); border: 1px solid #ff7675; }
.badge-wormhole { background: rgba(142, 68, 173, 0.85); border: 1px solid #a29bfe; }
.badge-plasma  { background: rgba(0, 206, 201, 0.85); border: 1px solid #81ecec; }
.badge-void    { background: rgba(0, 0, 0, 0.95); border: 1px solid #a55eea; }

/* Overlays */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    padding: 10px 0;
    z-index: 10;
}

#ui-overlay:has(> .hidden:only-child),
#ui-overlay.hidden {
    display: none;
}

.menu-content {
    background: var(--panel-bg);
    padding: 40px 30px;
    border-radius: 12px;
    text-align: center;
    width: 80%;
    margin: auto;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

.menu-content.hidden { display: none; }

.menu-content h1, .menu-content h2 {
    font-family: 'Press Start 2P', cursive;
    color: #f1c40f;
    margin-bottom: 20px;
    font-size: 1.5rem;
    line-height: 1.4;
}

.menu-content p {
    margin-bottom: 20px;
    font-size: 0.9rem;
    color: #bdc3c7;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-radius: 8px;
    font-size: 0.8rem;
}

kbd {
    background: #ecf0f1;
    color: #2c3e50;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    font-family: monospace;
    border-bottom: 2px solid #bdc3c7;
}

/* Item legend on start screen */
.item-legend {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 24px;
    font-size: 0.75rem;
    color: #bdc3c7;
    background: rgba(0,0,0,0.25);
    padding: 8px 12px;
    border-radius: 8px;
    flex-wrap: wrap;
}

.item-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.stamina-dot { background: #2ecc71; }
.shield-dot  { background: #3498db; }
.fly-dot     { background: #f1c40f; }

/* Game Over Menu */
#game-over-menu { padding: 20px 25px; }
#game-over-menu h2 { font-size: 1.2rem; margin-bottom: 10px; }
#game-over-menu > p { margin-bottom: 12px; font-size: 0.85rem; }

/* Result Grid */
.result-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 14px;
}

.result-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 10px 14px;
    border-radius: 8px;
    text-align: center;
    flex: 1;
    min-width: 100px;
}

.result-item .label {
    display: block;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.45rem;
    color: #bdc3c7;
    margin-bottom: 6px;
}

.result-value {
    font-size: 1.6rem;
    font-family: 'Press Start 2P', cursive;
    color: #fff;
    text-shadow: 2px 2px 0 #000;
}

/* Combo bonus row */
.bonus-item {
    flex-basis: 100%;
    background: rgba(243, 156, 18, 0.15);
    border: 1px solid rgba(243, 156, 18, 0.4);
    padding: 6px 14px;
}

.bonus-item .label {
    color: #f39c12;
}

.bonus-value {
    font-size: 1.2rem !important;
    color: #f1c40f !important;
}

/* Total score row */
.total-item {
    flex-basis: 100%;
    background: rgba(231, 76, 60, 0.15);
    border: 1px solid rgba(231, 76, 60, 0.4);
    padding: 10px 14px;
}

.total-item .label {
    color: #e74c3c;
    font-size: 0.5rem;
}

.total-item .result-value {
    font-size: 1.8rem;
    color: #fff;
    display: inline-block;
    transition: transform 0.1s;
}

/* Bonus row slide-in animation */
@keyframes bonus-slide-in {
    0%   { opacity: 0; transform: translateY(-12px) scale(0.9); }
    60%  { opacity: 1; transform: translateY(2px) scale(1.04); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.bonus-item.slide-in {
    animation: bonus-slide-in 0.45s ease-out forwards;
}

/* Total score glow during count-up */
.total-item.counting {
    border-color: rgba(241, 196, 15, 0.6);
    box-shadow: 0 0 12px rgba(241, 196, 15, 0.3);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.total-item.counting .result-value {
    color: #f1c40f;
    text-shadow: 0 0 8px rgba(241, 196, 15, 0.5), 2px 2px 0 #000;
}

/* Ranking entries — テトリス準拠 */
.ranking-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    padding: 7px 8px;
    border-radius: 8px;
    transition: background 0.15s;
}

.ranking-entry:hover { background: rgba(255, 255, 255, 0.04); }

.ranking-entry.me {
    background: rgba(243, 156, 18, 0.12);
    border: 1px solid rgba(243, 156, 18, 0.3);
}

.rank-num {
    width: 20px;
    text-align: right;
    color: #7f8c8d;
    font-weight: 700;
    font-size: 11px;
    flex-shrink: 0;
}

.ranking-entry:nth-child(1) .rank-num { color: #ffd700; font-size: 13px; }
.ranking-entry:nth-child(2) .rank-num { color: #c0c0c0; }
.ranking-entry:nth-child(3) .rank-num { color: #cd7f32; }

.rank-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: #ecf0f1;
}

.rank-score {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 11px;
    flex-shrink: 0;
    color: #bdc3c7;
}

.ranking-entry.me .rank-name,
.ranking-entry.me .rank-score { color: #f39c12; }

.ranking-empty {
    color: #7f8c8d;
    font-size: 11px;
    text-align: center;
    padding: 20px 0;
}

.btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 1rem;
    font-weight: bold;
    font-family: 'Press Start 2P', cursive;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--accent-hover);
    transition: transform 0.1s, box-shadow 0.1s;
}

.btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--accent-hover);
}

/* Touch Controls */
#touch-controls {
    position: absolute;
    bottom: 10px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    pointer-events: none;
    z-index: 5;
}

.touch-btn {
    pointer-events: all;
    background: rgba(255, 255, 255, 0.18);
    border: 2px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    border-radius: 50%;
    width: 58px;
    height: 58px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: background 0.1s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.93);
}

.touch-jump-btn {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.5rem;
    width: 68px;
    height: 68px;
    background: rgba(231, 76, 60, 0.35);
    border-color: rgba(231, 76, 60, 0.6);
}

.touch-jump-btn:active { background: rgba(231, 76, 60, 0.7); }

/* Ranking submit / name input */
.ranking-submit-section {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.name-input {
    width: 100%;
    padding: 7px 10px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    color: #fff;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 0.85rem;
    text-align: center;
    outline: none;
    box-sizing: border-box;
}

.name-input:focus {
    border-color: rgba(243, 156, 18, 0.7);
    box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.2);
}

.btn-register {
    background: var(--accent-color);
    color: #fff;
    border: none;
    padding: 9px 10px;
    font-size: 0.58rem;
    font-weight: bold;
    font-family: 'Press Start 2P', cursive;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 3px 0 var(--accent-hover);
    width: 100%;
    transition: transform 0.1s, box-shadow 0.1s;
}

.btn-register:active {
    transform: translateY(3px);
    box-shadow: 0 0 0 var(--accent-hover);
}

.btn-register:disabled {
    opacity: 0.6;
    cursor: default;
}

.btn-skip {
    font-size: 0.72rem;
    color: #7f8c8d;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.2s;
    text-align: center;
}

.btn-skip:hover { color: #bdc3c7; }

.rank-result {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.rank-result-text {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.5rem;
    color: #f39c12;
    text-align: center;
    line-height: 1.6;
}

#rank-result .btn {
    font-size: 0.6rem;
    padding: 9px 10px;
    width: 100%;
}

.rank-name {
    flex: 1;
    text-align: left;
    padding: 0 4px;
    font-size: 0.72rem;
    color: #ecf0f1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}


/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 620px) {
    body { align-items: flex-start; padding-top: 10px; }

    /* スマホではサイドパネルを非表示 */
    #ranking-panel { display: none; }

    /* ゲームをスマホ幅に合わせてスケール */
    .game-area { justify-content: center; }
    #game-container {
        transform-origin: top center;
        transform: scale(calc(100vw / 420));
        margin-bottom: calc((100vw / 420 - 1) * 600px);
    }

    header { width: 100%; box-sizing: border-box; }
    #game-wrapper { width: 100%; }
}
