/* ---- RESET ---- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background: #000;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

/* ---- LAYOUT ---- */
#game-container {
    position: relative;
    width: 100vw;
    height: 100svh;
    height: 100vh;
    margin: 0 auto;
    background: #050510;
    overflow: hidden;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    outline: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* ---- SCREENS ---- */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: max(env(safe-area-inset-top, 12px), 16px) 20px max(env(safe-area-inset-bottom, 12px), 20px);
    overflow-y: auto;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.92) 0%, rgba(5, 5, 20, 0.97) 100%);
    pointer-events: auto;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    gap: 14px;
    z-index: 20;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* HUD (ゲーム画面) の設定 */
#screen-hud {
    background: transparent;
    justify-content: space-between;
    pointer-events: none;
    overflow: hidden;
    /* 修正ポイント：下部余白を 28px から 100px に増やしてボタンを上に浮かせました */
    padding: max(env(safe-area-inset-top, 8px), 10px) 10px max(env(safe-area-inset-bottom, 16px), 100px);
    z-index: 20;
}

/* ---- TYPOGRAPHY ---- */
h1 {
    font-size: 28px;
    font-weight: 900;
    color: #0ff;
    text-shadow: 0 0 15px rgba(0, 255, 255, 0.8), 0 0 40px rgba(0, 255, 255, 0.4);
    line-height: 1.2;
    text-align: center;
    margin-top: 10px;
}

h1 .sub-title {
    font-size: 16px;
    display: block;
    color: rgba(0, 255, 255, 0.7);
    font-weight: 400;
    letter-spacing: 2px;
}

h2 {
    font-size: 22px;
    font-weight: 800;
    color: #0ff;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.6);
    margin-top: 8px;
}

/* ---- BUTTONS ---- */
button {
    pointer-events: auto;
    min-height: 52px;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    border: 1.5px solid rgba(0, 255, 255, 0.6);
    border-radius: 12px;
    cursor: pointer;
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.5);
    box-shadow: 0 0 12px rgba(0, 255, 255, 0.2), inset 0 0 6px rgba(0, 255, 255, 0.05);
    transition: transform 0.08s, background 0.08s, box-shadow 0.08s;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
}

button:active,
button:focus-visible {
    transform: scale(0.94);
    background: rgba(0, 255, 255, 0.2);
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.5);
    outline: none;
}

button:disabled {
    opacity: 0.35;
    pointer-events: none;
}

.btn-primary {
    background: linear-gradient(135deg, rgba(0, 150, 255, 0.3), rgba(0, 255, 255, 0.2));
    border-color: #0ff;
    font-size: 18px;
    min-height: 60px;
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.35), inset 0 0 10px rgba(0, 255, 255, 0.1);
}

.btn-danger {
    border-color: #f55;
    color: #f88;
    text-shadow: 0 0 8px rgba(255, 80, 80, 0.6);
}

.btn-back {
    margin-top: auto;
    /* ↓ここを追加：下の余白を作ってボタンを上に押し上げる */
    margin-bottom: 70px; 
    background: transparent;
    border-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.6);
}
/* ---- MENU ---- */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 360px;
}

.menu-row {
    display: flex;
    gap: 8px;
    width: 100%;
}

.menu-row button {
    flex: 1;
    min-height: 46px;
    font-size: 14px;
    padding: 10px 8px;
}

/* ---- CLASS SELECTOR ---- */
.class-selector {
    width: 100%;
    max-width: 360px;
}

.class-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.class-opt input[type="radio"] {
    display: none;
}

.cls-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    touch-action: manipulation;
}

.class-opt input:checked+.cls-card {
    background: rgba(0, 255, 255, 0.1);
    border-color: #0ff;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.2);
}

.cls-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 18px;
    color: #000;
    flex-shrink: 0;
}

.cls-info strong {
    display: block;
    font-size: 15px;
}

.cls-info small {
    color: rgba(255, 255, 255, 0.55);
    font-size: 11px;
}

/* ---- HUD ELEMENTS ---- */
.hud-top {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.hud-stats {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#hud-hp-container {
    width: 170px;
    height: 20px;
    background: rgba(100, 0, 0, 0.6);
    border: 1.5px solid #f55;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

#hud-hp-bar {
    height: 100%;
    background: linear-gradient(90deg, #e00, #f88);
    transition: width 0.12s linear;
}

#hud-hp-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
}

#hud-stage {
    font-size: 13px;
    font-weight: 700;
    text-shadow: 1px 1px 2px #000;
}

#hud-money {
    font-size: 13px;
    font-weight: 700;
    color: #fe0;
    text-shadow: 1px 1px 2px #000;
}

.hud-btn-small {
    width: auto;
    min-height: 40px;
    padding: 6px 12px;
    font-size: 14px;
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.6);
    border-color: rgba(255, 255, 255, 0.4);
}

.hud-bottom {
    width: 100%;
    display: flex;
    justify-content: flex-end; /* 右側に配置 */
    align-items: flex-end;
    gap: 12px;
    padding-right: 6px;
}

#lb-info {
    text-align: center;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 0, 255, 0.4);
    border-radius: 8px;
    padding: 6px 10px;
    line-height: 1.2;
}

#lb-stacks-display {
    font-size: 22px;
    font-weight: 900;
    color: #f0f;
    line-height: 1;
}

#lb-stacks-display small {
    font-size: 13px;
    color: rgba(255, 0, 255, 0.6);
}

#lb-info small {
    font-size: 9px;
    color: rgba(255, 0, 255, 0.7);
    letter-spacing: 1px;
}

.circle-btn {
    pointer-events: auto;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    font-size: 15px;
    font-weight: 900;
    border: 2.5px solid #f0f;
    background: rgba(80, 0, 80, 0.5);
    color: #f0f;
    text-shadow: 0 0 8px #f0f;
    box-shadow: 0 0 18px rgba(255, 0, 255, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.circle-btn.glow {
    animation: pulseLb 0.7s infinite alternate;
}

@keyframes pulseLb {
    0% {
        box-shadow: 0 0 18px rgba(255, 0, 255, 0.5);
    }
    100% {
        box-shadow: 0 0 35px #f0f, 0 0 60px rgba(255, 0, 255, 0.4);
        border-color: #fff;
    }
}

/* ---- RESULT / SHOP / OTHER ---- */
.result-stats {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
}

.stat-row strong {
    color: #0ff;
    font-size: 18px;
}

.analysis-box {
    width: 100%;
    max-width: 360px;
    background: rgba(0, 255, 255, 0.07);
    border: 1px dashed rgba(0, 255, 255, 0.4);
    border-radius: 10px;
    padding: 14px;
    text-align: center;
}

.analysis-label {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 2px;
    margin-bottom: 4px;
}

#res-analysis {
    font-size: 18px;
    font-weight: 700;
}

.hidden-power {
    margin-top: 8px;
    color: #f0f;
    font-size: 14px;
    text-shadow: 0 0 8px #f0f;
}

.money-bar {
    font-size: 16px;
    color: #fe0;
    margin-bottom: 4px;
}

.money-bar strong {
    font-size: 20px;
}

.scroll-list {
    width: 100%;
    max-width: 420px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 2px;
    max-height: 65vh;
}

.scroll-item {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.scroll-item-content {
    flex: 1;
}

.scroll-item h4 {
    font-size: 14px;
    color: #fe0;
    margin-bottom: 3px;
}

.scroll-item p {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.55);
}

.scroll-item button {
    width: 64px;
    min-height: 38px;
    padding: 6px;
    font-size: 13px;
    border-color: #fe0;
    color: #fe0;
}

.achv-ready {
    border-color: rgba(0, 255, 0, 0.6);
    background: rgba(0, 30, 0, 0.3);
}

.achv-ready h4 {
    color: #0f0;
    text-shadow: 0 0 6px #0f0;
}

.achv-unlocked {
    border-color: rgba(0, 180, 0, 0.4);
}

.achv-unlocked h4 {
    color: #6f6;
}

.achv-locked {
    opacity: 0.45;
}

/* ---- SETTINGS ---- */
.settings-list {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 14px 16px;
    cursor: pointer;
    font-size: 14px;
    touch-action: manipulation;
}

.toggle {
    width: 24px;
    height: 24px;
    cursor: pointer;
}

/* ---- OVERLAYS ---- */
#lore-display {
    position: absolute;
    top: 35%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    text-align: center;
    font-size: 14px;
    font-style: italic;
    color: #fff;
    text-shadow: 0 0 10px #fff, 0 0 20px #0ff;
    opacity: 0;
    transition: opacity 0.5s;
    z-index: 200;
    pointer-events: none;
    letter-spacing: 1px;
}

#gate-tips {
    position: absolute;
    top: 20%;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    color: #ff0;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
    z-index: 160;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

#lb-cutin {
    position: absolute;
    top: 38%;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 30px;
    font-weight: 900;
    font-style: italic;
    color: #fff;
    text-shadow: 0 0 12px #f0f, 0 0 40px rgba(255, 0, 255, 0.6);
    letter-spacing: 4px;
    background: rgba(0, 0, 0, 0.55);
    padding: 12px 0;
    z-index: 210;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.25s;
    transform: scale(1.4);
}

#debug-info {
    display: none;
    position: absolute;
    top: 68px;
    right: 10px;
    font-size: 10px;
    font-family: monospace;
    color: #0f0;
    text-align: right;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
}

/* ---- LANDSCAPE (横画面) 対応 ---- */
@media (orientation: landscape) and (max-height: 500px) {
    #screen-hud {
        padding: 5px 15px 40px; /* 横画面ではメニューバーの影響が少ないため少し控えめに調整 */
    }
    .circle-btn {
        width: 60px;
        height: 60px;
        font-size: 12px;
    }
}
/* ===== 改善v2 追加スタイル ===== */

/* #07 音量スライダー */
.volume-wrap { display: flex; align-items: center; gap: 8px; flex: 1; }
.volume-slider {
    -webkit-appearance: none; appearance: none;
    flex: 1; height: 4px; border-radius: 2px;
    background: rgba(0,255,255,0.2); outline: none;
}
.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 16px; height: 16px;
    border-radius: 50%; background: #0ff;
    box-shadow: 0 0 6px rgba(0,255,255,0.6); cursor: pointer;
}
.volume-label { font-size: 11px; color: #0ff; min-width: 34px; text-align: right; }

/* #11 ショップ プレビュー */
.shop-preview { font-size: 10px; color: #0ff; opacity: 0.8; }
.shop-max { color: #fe0; font-size: 11px; font-weight: bold; }

/* #13 ポーズ統計 */
.pause-stats {
    display: flex; flex-wrap: wrap; gap: 6px 12px;
    justify-content: center; margin: 12px 0;
    background: rgba(0,0,0,0.35); border-radius: 8px;
    padding: 10px 14px; max-width: 320px; margin-left: auto; margin-right: auto;
}
.pstat { font-size: 12px; color: rgba(255,255,255,0.75); }
.pstat strong { color: #0ff; }

/* #03 リザルト履歴グラフ */
.res-history {
    margin-top: 12px; padding: 10px 14px;
    background: rgba(0,0,0,0.3); border-radius: 8px;
    max-width: 320px; margin-left: auto; margin-right: auto;
}
.hist-label { font-size: 10px; color: rgba(255,255,255,0.4); letter-spacing: 2px; margin-bottom: 6px; }
.hist-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.hist-num { font-size: 10px; color: rgba(255,255,255,0.5); min-width: 28px; text-align: right; }
.hist-bar-wrap { flex: 1; height: 8px; background: rgba(255,255,255,0.07); border-radius: 4px; overflow: hidden; }
.hist-bar { height: 100%; border-radius: 4px; transition: width 0.4s ease; }
.hist-val { font-size: 10px; color: rgba(255,255,255,0.6); min-width: 64px; }
