* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.hidden {
    display: none !important;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: #0e1420;
    color: #eef1f6;
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
    overscroll-behavior: none;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 480px;
    margin: 0 auto;
    background: #131a2a;
    position: relative;
    overflow: hidden;
}

/* ============ タイトル / ステージ選択（フルスクリーンパネル） ============ */
.fullscreen-panel {
    position: absolute;
    inset: 0;
    z-index: 20;
    background: linear-gradient(180deg, #0e1420, #131a2a 60%, #0a0f1a);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.fullscreen-panel.hidden {
    display: none;
}

.title-inner {
    width: 100%;
    text-align: center;
}

/* ステージ選択画面はコンテンツ量が可変（Wave数などで伸びる）ため、
   固定vh指定ではなく実際の残りスペースいっぱいまでflexで埋める。
   （#stageSelectScreenのみ縦stretchにして select-inner を全高化する） */
#stageSelectScreen {
    align-items: stretch;
}

.select-inner {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    text-align: center;
    min-height: 0;
}

.game-title {
    font-size: 30px;
    margin: 0 0 12px;
    letter-spacing: 1px;
}

.game-subtitle {
    color: #9fb0cc;
    font-size: 14px;
    line-height: 1.7;
    margin-bottom: 36px;
}

.screen-heading {
    font-size: 18px;
    margin: 0 0 18px;
    letter-spacing: 1px;
}

.mode-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-shrink: 0;
}

#stageListPane, #survivalPane {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#survivalPane {
    justify-content: center;
}

#survivalPane .big-button {
    flex: none;
}

.mode-tab {
    flex: 1;
    padding: 10px 0;
    font-size: 14px;
    font-weight: bold;
    border: 2px solid #384a6b;
    border-radius: 8px;
    background: #1b2436;
    color: #9fb0cc;
    cursor: pointer;
}

.mode-tab.active {
    background: #2a3d5f;
    color: #eef1f6;
    border-color: #5ad1ff;
}

.stage-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.stage-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: #1b2436;
    border: 2px solid #384a6b;
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
}

.stage-card:active {
    background: #232f47;
}

.stage-card .stage-name {
    font-weight: bold;
    font-size: 15px;
}

.stage-card .stage-desc {
    font-size: 12px;
    color: #9fb0cc;
    margin-top: 2px;
}

.stage-card .stage-arrow {
    font-size: 18px;
    color: #5ad1ff;
}

.survival-desc {
    color: #9fb0cc;
    font-size: 13px;
    line-height: 1.8;
    margin-bottom: 24px;
}

.link-button {
    margin-top: 8px;
    background: none;
    border: none;
    color: #9fb0cc;
    font-size: 13px;
    padding: 8px;
    cursor: pointer;
}

/* ============ WAVE開始バナー ============ */
#waveBanner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(10, 15, 26, 0.85);
    border: 2px solid #5ad1ff;
    border-radius: 12px;
    padding: 14px 32px;
    font-size: 22px;
    font-weight: bold;
    letter-spacing: 2px;
    color: #eef1f6;
    z-index: 8;
    pointer-events: none;
    text-align: center;
}

#waveBanner.hidden {
    display: none;
}

#waveBanner .sub {
    display: block;
    font-size: 12px;
    color: #9fb0cc;
    letter-spacing: 1px;
    margin-top: 4px;
    font-weight: normal;
}

/* ============ 上部ステータスバー ============ */
#statusBar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: #1b2436;
    border-bottom: 2px solid #2b3752;
    font-weight: bold;
    font-size: 14px;
    flex-shrink: 0;
}

.status-item {
    white-space: nowrap;
}

/* ============ MAPエリア ============ */
#mapArea {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background: #0a0f1a;
    padding: 8px;
    position: relative;
}

#gameCanvas {
    background: #0a0f1a;
    touch-action: none;
    border-radius: 6px;
}

/* ============ 下部操作パネル ============ */
#controlPanel {
    flex-shrink: 0;
    background: #1b2436;
    border-top: 2px solid #2b3752;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
}

.panel.hidden {
    display: none;
}

#machinePanel {
    position: relative;
}

#machineList {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 8px;
}

.machine-card {
    background: #232f47;
    border: 2px solid #384a6b;
    border-radius: 8px;
    padding: 5px 2px;
    text-align: center;
    cursor: pointer;
}

.machine-card.selected {
    border-color: #5ad1ff;
    background: #2a3d5f;
    box-shadow: 0 0 8px rgba(90, 209, 255, 0.6);
}

.machine-card.disabled {
    opacity: 0.4;
}

.machine-card .icon {
    font-size: 22px;
    line-height: 1;
}

.machine-card .name {
    font-size: 10px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.machine-card .price {
    font-size: 10px;
    color: #ffd85a;
    margin-top: 1px;
}

/* ============ マシン説明ポップアップ ============ */
/* #mapArea内に絶対配置し、仮置きしたセルの近くにJSでleft/topを指定して表示する。
   レイアウトの高さには影響しない（マップの表示サイズは変わらない）。 */
.machine-info {
    position: absolute;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: #1b2436;
    border: 1px solid #5ad1ff;
    border-radius: 10px;
    padding: 8px 10px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    z-index: 7;
    pointer-events: none;
}

/* ポップアップがセルの下側にある場合（矢印は上向き＝セル方向を指す） */
.machine-info.mi-arrow-up::after {
    content: "";
    position: absolute;
    bottom: 100%;
    left: var(--arrow-left, 20px);
    margin-left: -7px;
    border: 7px solid transparent;
    border-bottom-color: #5ad1ff;
}

/* ポップアップがセルの上側にある場合（矢印は下向き＝セル方向を指す） */
.machine-info.mi-arrow-down::after {
    content: "";
    position: absolute;
    top: 100%;
    left: var(--arrow-left, 20px);
    margin-left: -7px;
    border: 7px solid transparent;
    border-top-color: #5ad1ff;
}

.machine-info .mi-icon {
    font-size: 26px;
    line-height: 1;
    flex-shrink: 0;
}

.machine-info .mi-body {
    flex: 1;
    min-width: 0;
}

.machine-info .mi-name {
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 2px;
}

.machine-info .mi-stats {
    font-size: 11px;
    color: #9fb0cc;
    margin-bottom: 3px;
}

.machine-info .mi-stats span {
    margin-right: 8px;
    white-space: nowrap;
    display: inline-block;
}

.machine-info .mi-desc {
    font-size: 11px;
    color: #c6cfe0;
    line-height: 1.5;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.big-button {
    flex: 1;
    width: 100%;
    padding: 14px;
    font-size: 18px;
    font-weight: bold;
    letter-spacing: 2px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(180deg, #4fd0ff, #1e93c9);
    color: #06202c;
    cursor: pointer;
}

.big-button:active {
    filter: brightness(0.9);
}

.reset-button {
    flex: 0 0 78px;
    padding: 14px 0;
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 1px;
    border: 2px solid #4a5b7c;
    border-radius: 10px;
    background: #232f47;
    color: #c6cfe0;
    cursor: pointer;
}

.reset-button:active {
    filter: brightness(0.9);
}

.speed-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.speed-btn {
    flex: 1;
    max-width: 100px;
    padding: 12px 0;
    font-size: 16px;
    font-weight: bold;
    border: 2px solid #384a6b;
    border-radius: 8px;
    background: #232f47;
    color: #eef1f6;
    cursor: pointer;
}

.speed-btn.active {
    background: #5ad1ff;
    color: #06202c;
    border-color: #5ad1ff;
}

/* ============ オーバーレイ（結果画面） ============ */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(4, 8, 16, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.overlay.hidden {
    display: none;
}

#overlayBox {
    background: #1b2436;
    border: 2px solid #384a6b;
    border-radius: 14px;
    padding: 28px 24px;
    width: 82%;
    max-width: 340px;
    text-align: center;
}

#overlayTitle {
    margin: 0 0 12px;
    font-size: 24px;
    letter-spacing: 1px;
}

#overlayBody {
    font-size: 14px;
    line-height: 1.8;
    color: #c6cfe0;
    margin-bottom: 20px;
}

#overlayButtons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#overlayButtons button {
    padding: 12px;
    font-size: 15px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    background: #384a6b;
    color: #eef1f6;
    cursor: pointer;
}

#overlayButtons button.primary {
    background: linear-gradient(180deg, #4fd0ff, #1e93c9);
    color: #06202c;
}

/* ============ 選択中マシン情報トースト ============ */
#placeToast {
    position: absolute;
    left: 50%;
    bottom: 190px;
    transform: translateX(-50%);
    background: rgba(20, 28, 46, 0.95);
    border: 1px solid #384a6b;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 5;
}

#placeToast.hidden {
    display: none;
}
