body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #0a0a0a;
    color: #e0e0e0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    display: block;
}

/* Title screen */
#title-screen {
    position: fixed;
    inset: 0;
    background: radial-gradient(1200px 700px at 50% 35%, rgba(0,255,255,0.10), rgba(0,0,0,0.82) 55%, rgba(0,0,0,0.92));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30; /* settings보다 아래(타이틀에서 설정 열 수 있어야 함) */
}

#title-screen.hidden { display: none; }

.title-card {
    position: relative;
    width: min(760px, calc(100vw - 40px));
    background: rgba(12, 12, 12, 0.95);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 16px;
    box-shadow: 0 18px 65px rgba(0,0,0,0.78);
    padding: 22px;
    text-align: center;
}

.title-settings-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.14);
    background: rgba(0,0,0,0.35);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: grid;
    place-items: center;
}

.title-settings-btn:hover {
    border-color: rgba(0,255,255,0.35);
    box-shadow: 0 0 0 2px rgba(0,255,255,0.08);
}

.title-layout {
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    gap: 14px;
    margin-top: 14px;
    align-items: start;
}

.title-left { text-align: center; }
.title-right { display: grid; gap: 12px; }

.panel {
    text-align: left;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 12px;
}

.panel-title {
    font-weight: 900;
    color: #fff;
    font-size: 13px;
    margin-bottom: 6px;
}

.panel-sub {
    color: #bdbdbd;
    font-size: 12px;
    margin-bottom: 10px;
}

.panel-hint {
    margin-top: 8px;
    color: #9a9a9a;
    font-size: 12px;
    min-height: 14px;
}

.input {
    width: 100%;
    box-sizing: border-box;
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.14);
    color: #fff;
    border-radius: 10px;
    padding: 10px 11px;
    outline: none;
    font-size: 13px;
}

.input:focus {
    border-color: rgba(0,255,255,0.45);
    box-shadow: 0 0 0 2px rgba(0,255,255,0.10);
}

.auth-form {
    display: grid;
    gap: 8px;
}

.auth-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.leaderboard {
    display: grid;
    gap: 6px;
}

.lb-row {
    display: grid;
    grid-template-columns: 22px 1fr 66px 44px;
    gap: 8px;
    align-items: center;
    font-size: 12.5px;
    padding: 6px 8px;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 10px;
    background: rgba(0,0,0,0.18);
}

.lb-row.me {
    border-color: rgba(0,255,255,0.35);
    box-shadow: 0 0 0 2px rgba(0,255,255,0.08);
}
.lb-rank { color: #9ad1ff; font-weight: 900; text-align: right; }
.lb-name { color: #eee; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: #ffd24d; font-weight: 900; text-align: right; }
.lb-floor { color: #cfcfcf; font-weight: 700; text-align: right; }
.muted { opacity: 0.7; }

@media (max-width: 820px) {
    .title-card { width: min(760px, calc(100vw - 24px)); padding: 16px; }
    .title-layout { grid-template-columns: 1fr; }
}

.title-name {
    font-size: 34px;
    font-weight: 900;
    color: #fff;
    letter-spacing: 1px;
}

.title-sub {
    margin-top: 8px;
    color: #bdbdbd;
    font-size: 14px;
}

.title-controls {
    margin: 16px auto 18px;
    width: min(560px, 100%);
    text-align: left;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 12px;
}

.title-controls-title {
    font-weight: 800;
    color: #fff;
    margin-bottom: 10px;
    font-size: 13px;
}

.title-controls-grid {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 8px 10px;
    font-size: 13px;
}

.title-controls-grid .k {
    color: #9ad1ff;
    font-weight: 900;
}

.title-controls-grid .v {
    color: #ddd;
    font-weight: 600;
}

.btn-primary {
    background: rgba(0,255,255,0.16);
    border-color: rgba(0,255,255,0.35);
}

.title-hint {
    margin-top: 10px;
    color: #9a9a9a;
    font-size: 12px;
}

/* Ability modal */
.hidden { display: none; }

#ability-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* `.hidden`이 제대로 동작하도록, 표시(display)는 hidden 여부에 따라 결정 */
#ability-modal:not(.hidden) {
    display: flex;
}

.settings-card {
    width: min(680px, calc(100vw - 24px));
    background: rgba(12, 12, 12, 0.95);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px;
    box-shadow: 0 18px 55px rgba(0,0,0,0.75);
    padding: 22px;
}

#settings-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.72);
    align-items: center;
    justify-content: center;
    z-index: 35; /* title보다 위 */
}

#settings-modal:not(.hidden) {
    display: flex;
}

.gameover-card {
    width: min(620px, calc(100vw - 40px));
    background: rgba(12, 12, 12, 0.96);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 16px;
    box-shadow: 0 20px 70px rgba(0,0,0,0.85);
    padding: 20px;
    text-align: center;
}

#gameover-modal {
    position: fixed;
    inset: 0;
    background: radial-gradient(1100px 700px at 50% 40%, rgba(255,80,80,0.10), rgba(0,0,0,0.82) 55%, rgba(0,0,0,0.92));
    align-items: center;
    justify-content: center;
    z-index: 40; /* title보다 위 */
}

#gameover-modal:not(.hidden) {
    display: flex;
}

.gameover-title {
    font-size: 30px;
    font-weight: 900;
    color: #fff;
    letter-spacing: 1px;
}

.gameover-sub {
    margin-top: 6px;
    color: #bdbdbd;
    font-size: 13px;
}

.gameover-grid {
    margin: 14px auto 16px;
    width: min(520px, 100%);
    text-align: left;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 12px;
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 8px 10px;
    font-size: 13px;
}

.gameover-grid .k {
    color: #ff9aa2;
    font-weight: 900;
}

.gameover-grid .v {
    color: #eee;
    font-weight: 700;
}

.gameover-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
}

.gameover-hint {
    margin-top: 10px;
    color: #9a9a9a;
    font-size: 12px;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.settings-title {
    font-size: 22px;
    font-weight: 800;
    color: #fff;
}

.settings-row {
    display: grid;
    grid-template-columns: 84px 1fr 64px;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
}

#settings-control-row {
    grid-template-columns: 84px 1fr;
    align-items: start;
}

.settings-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.segmented {
    display: inline-flex;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.14);
    background: rgba(0,0,0,0.22);
    overflow: hidden;
}

.seg-btn {
    border: 0;
    background: transparent;
    color: #cfcfcf;
    padding: 10px 14px;
    font-weight: 900;
    cursor: pointer;
}

.seg-btn.active {
    color: #fff;
    background: rgba(0,255,255,0.16);
}

.seg-btn:focus {
    outline: none;
}

.settings-label {
    color: #ddd;
    font-weight: 700;
    font-size: 15px;
}

.settings-val {
    text-align: right;
    color: #9ad1ff;
    font-weight: 800;
    font-size: 15px;
}

.settings-slider {
    width: 100%;
    height: 28px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

.settings-slider::-webkit-slider-runnable-track {
    height: 10px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 999px;
}
.settings-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 26px;
    height: 26px;
    margin-top: -9px; /* (thumb - track)/2 */
    border-radius: 999px;
    background: rgba(0,255,255,0.55);
    border: 2px solid rgba(0,255,255,0.85);
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}

.settings-slider::-moz-range-track {
    height: 10px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 999px;
}
.settings-slider::-moz-range-thumb {
    width: 26px;
    height: 26px;
    border-radius: 999px;
    background: rgba(0,255,255,0.55);
    border: 2px solid rgba(0,255,255,0.85);
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}

.settings-sub {
    margin-top: 10px;
    color: #9a9a9a;
    font-size: 13px;
}

/* 인게임 HUD */
.hud {
    position: fixed;
    inset: 0;
    z-index: 15; /* canvas 위, 모달 아래 */
    pointer-events: none;
}
.hud-btn {
    pointer-events: auto;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.16);
    background: rgba(0,0,0,0.42);
    color: #fff;
    font-weight: 900;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.hud-settings {
    position: absolute;
    top: calc(14px + env(safe-area-inset-top));
    right: calc(14px + env(safe-area-inset-right));
    width: 48px;
    height: 48px;
    font-size: 22px;
    line-height: 1;
}
.hud-missile {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(14px + env(safe-area-inset-bottom));
    min-width: 220px;
    height: 56px;
    padding: 0 16px;
    font-size: 16px;
    background: rgba(255, 210, 77, 0.14);
    border-color: rgba(255, 210, 77, 0.35);
}
.hud-missile:disabled {
    opacity: 0.55;
}

.ability-card {
    width: min(720px, calc(100vw - 40px));
    background: rgba(12, 12, 12, 0.95);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px;
    box-shadow: 0 18px 55px rgba(0,0,0,0.75);
    padding: 18px 18px 14px;
}

.ability-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 12px;
}

.ability-title {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
}

.ability-sub {
    font-size: 13px;
    color: #bbb;
}

.ability-meta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
    color: #ddd;
}

.ability-meta-sep { opacity: 0.65; padding: 0 6px; }

.ability-meta::before {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 999px;
    display: inline-block;
}

.ability-meta.meta-coin::before {
    background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.55), rgba(255,210,77,0.85) 45%, rgba(255,160,0,0.85));
    box-shadow: 0 0 0 1px rgba(255,210,77,0.35);
}

.ability-meta.meta-floor::before {
    border-radius: 4px;
    background: linear-gradient(135deg, rgba(154,209,255,0.85), rgba(0,255,255,0.35));
    box-shadow: 0 0 0 1px rgba(154,209,255,0.30);
}

.ability-notice {
    margin-bottom: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(0,255,255,0.18);
    background: rgba(0,255,255,0.06);
    color: #cfefff;
    font-weight: 800;
    font-size: 12.5px;
}

.ability-cost.insufficient {
    color: #ff9aa2;
}

.ability-choices {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.ability-choice {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-height: 150px;
}

.ability-name {
    font-weight: 700;
    color: #fff;
    margin-bottom: 6px;
    font-size: 14px;
}

.ability-desc {
    color: #cfcfcf;
    font-size: 12.5px;
    line-height: 1.5;
    flex: 1;
}

.ability-cost {
    color: #ffd24d;
    font-weight: 700;
    font-size: 12.5px;
    margin-top: 10px;
}

.ability-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
}

.btn {
    pointer-events: auto;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.06);
    color: #fff;
    padding: 9px 12px;
    border-radius: 10px;
    font-weight: 600;
}

.btn:hover { background: rgba(255,255,255,0.10); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-secondary { background: rgba(255,255,255,0.03); }

.btn-buy {
    width: 100%;
    margin-top: 10px;
    background: rgba(0,255,255,0.10);
    border-color: rgba(0,255,255,0.25);
}

.ability-status {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 14px;
    padding: 10px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
}

.stat-item {
    font-size: 11px;
    color: #bbb;
}

.stat-val {
    color: #00ffff;
    font-weight: 700;
}

/* 어빌리티 희귀도 색상 */
.rarity-common { color: #ffffff; border-color: rgba(255,255,255,0.2) !important; }
.rarity-rare { color: #4488ff; border-color: rgba(68,136,255,0.4) !important; }
.rarity-epic { color: #aa44ff; border-color: rgba(170,68,255,0.5) !important; }
.rarity-legendary { color: #ffaa00; border-color: rgba(255,170,0,0.6) !important; text-shadow: 0 0 8px rgba(255,170,0,0.4); }

.rarity-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.bg-common { background: rgba(255,255,255,0.1); color: #fff; }
.bg-rare { background: rgba(68,136,255,0.2); color: #4488ff; }
.bg-epic { background: rgba(170,68,255,0.2); color: #aa44ff; }
.bg-legendary { background: rgba(255,170,0,0.2); color: #ffaa00; }