@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    position: fixed;
    background: #060614;
}

body {
    font-family: 'Orbitron', monospace;
    color: #fff;
}

#game {
    position: absolute;
    top: 0;
    left: 0;
    touch-action: none;
    display: block;
}

.hidden { display: none !important; }

/* ============ HUD ============ */
#hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
    padding: calc(8px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(10px + env(safe-area-inset-left, 0px));
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

#hud-top {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.hud-box {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 10px;
    background: rgba(4, 10, 26, 0.55);
    border: 1px solid rgba(0, 255, 255, 0.35);
    backdrop-filter: blur(6px);
    font-size: 14px;
    white-space: nowrap;
}

.hud-box .lbl {
    font-size: 9px;
    opacity: 0.7;
    letter-spacing: 1px;
}

.hud-box .val {
    font-weight: 700;
    text-shadow: 0 0 8px currentColor;
}

.hud-box.cyan { color: #4df3ff; }
.hud-box.gold { color: #ffd54d; border-color: rgba(255, 213, 77, 0.35); }
.hud-box.dim  { color: #9aa7c7; border-color: rgba(154, 167, 199, 0.25); }

#hud-combo {
    color: #ff7bda;
    font-weight: 900;
    font-size: 13px;
    text-shadow: 0 0 10px #ff7bda;
}

.hud-btns {
    margin-left: auto;
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1px solid rgba(0, 255, 255, 0.4);
    background: rgba(4, 10, 26, 0.6);
    color: #4df3ff;
    font-size: 17px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    font-family: inherit;
}

.icon-btn:active { transform: scale(0.92); background: rgba(0, 255, 255, 0.2); }

#hud-bottom {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
}

#bars { flex: 1; max-width: 260px; }

.bar-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
}

.bar-lbl {
    font-size: 9px;
    letter-spacing: 1px;
    opacity: 0.75;
    width: 34px;
}

.bar {
    flex: 1;
    height: 12px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.25);
    overflow: hidden;
}

.bar > div {
    height: 100%;
    width: 100%;
    border-radius: 6px;
    transition: width 0.15s linear;
}

#hp-fill { background: linear-gradient(90deg, #ff3355, #ff9d4d); box-shadow: 0 0 10px rgba(255, 80, 80, 0.8); }
#sh-fill { background: linear-gradient(90deg, #2bd2ff, #7bffea); box-shadow: 0 0 10px rgba(60, 220, 255, 0.8); }

#btn-bomb {
    pointer-events: auto;
    width: 74px;
    height: 74px;
    border-radius: 50%;
    border: 2px solid rgba(255, 213, 77, 0.7);
    background: radial-gradient(circle at 35% 30%, rgba(255, 213, 77, 0.35), rgba(120, 60, 0, 0.45));
    color: #ffd54d;
    font-family: inherit;
    font-weight: 900;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 18px rgba(255, 213, 77, 0.35);
}

#btn-bomb .bomb-ico { font-size: 26px; line-height: 1; }
#btn-bomb #bomb-count { font-size: 14px; }
#btn-bomb:active { transform: scale(0.9); }
#btn-bomb.empty { opacity: 0.35; box-shadow: none; }

/* ============ Joystick mode (fire LEFT, stick RIGHT) ============ */
#joy-fire-zone {
    position: absolute;
    left: calc(14px + env(safe-area-inset-left, 0px));
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    pointer-events: auto;
    z-index: 11;
}

#btn-fire {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    border: 2px solid rgba(77, 243, 255, 0.7);
    background: radial-gradient(circle at 35% 30%, rgba(77, 243, 255, 0.3), rgba(0, 60, 120, 0.45));
    color: #4df3ff;
    font-family: inherit;
    font-weight: 900;
    font-size: 26px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 22px rgba(77, 243, 255, 0.35);
    touch-action: none;
}

#btn-fire span { font-size: 11px; letter-spacing: 2px; }
#btn-fire.pressed { transform: scale(0.92); background: radial-gradient(circle at 35% 30%, rgba(77, 243, 255, 0.55), rgba(0, 90, 160, 0.6)); }

#joy-zone {
    position: absolute;
    right: calc(14px + env(safe-area-inset-right, 0px));
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    width: 170px;
    height: 170px;
    pointer-events: auto;
    z-index: 11;
    touch-action: none;
}

#joy-base {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.25);
    background: radial-gradient(circle, rgba(20, 30, 60, 0.35), rgba(6, 10, 24, 0.55));
}

#joy-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 64px;
    height: 64px;
    margin: -32px 0 0 -32px;
    border-radius: 50%;
    border: 2px solid rgba(77, 243, 255, 0.8);
    background: radial-gradient(circle at 35% 30%, rgba(77, 243, 255, 0.5), rgba(0, 70, 130, 0.7));
    box-shadow: 0 0 16px rgba(77, 243, 255, 0.5);
}

/* ============ Screens ============ */
.screen {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 4, 14, 0.72);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.35s ease-out;
    padding: 16px;
}

.panel {
    text-align: center;
    background: linear-gradient(160deg, rgba(10, 18, 40, 0.95), rgba(16, 10, 40, 0.9));
    border: 2px solid rgba(0, 255, 255, 0.45);
    border-radius: 22px;
    padding: 28px 32px;
    max-width: 440px;
    width: 100%;
    max-height: 96vh;
    overflow-y: auto;
    box-shadow: 0 0 60px rgba(0, 255, 255, 0.18), 0 24px 60px rgba(0, 0, 0, 0.7);
    animation: slideUp 0.4s ease-out;
}

.panel.small { max-width: 340px; }
.panel.wide-panel { max-width: 560px; text-align: left; }
.panel.wide-panel .pause-title, .panel.wide-panel .btn-col, .panel.wide-panel .menu-label { text-align: center; }

.game-title {
    font-size: clamp(44px, 12vw, 68px);
    font-weight: 900;
    letter-spacing: 6px;
    background: linear-gradient(45deg, #ff2d78, #ff9d4d, #4df3ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 18px rgba(77, 243, 255, 0.45));
}

.game-title.sm { font-size: clamp(34px, 9vw, 48px); }

.game-subtitle {
    font-size: clamp(11px, 3vw, 15px);
    letter-spacing: 5px;
    color: #4df3ff;
    text-shadow: 0 0 12px #4df3ff;
    margin-bottom: 16px;
}

#pilot-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    margin-bottom: 12px;
    border-radius: 20px;
    border: 1px solid rgba(255, 213, 77, 0.5);
    background: rgba(255, 213, 77, 0.08);
    font-size: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

#chip-rank-ico { color: #ffd54d; }
#chip-name { font-weight: 700; color: #fff; }
#chip-rank { color: #ffd54d; letter-spacing: 1px; font-size: 10px; }
#chip-id { color: #9aa7c7; font-size: 10px; }

.hi-line {
    font-size: 13px;
    color: #ffd54d;
    margin-bottom: 18px;
    letter-spacing: 2px;
}

.menu-label {
    font-size: 11px;
    letter-spacing: 3px;
    opacity: 0.7;
    margin-bottom: 12px;
}

.btn-col {
    display: flex;
    flex-direction: column;
    gap: 11px;
    align-items: center;
}

.menu-btn {
    font-family: inherit;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: 3px;
    width: 100%;
    max-width: 280px;
    padding: 13px 20px;
    border-radius: 14px;
    cursor: pointer;
    border: 2px solid;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.menu-btn:active { transform: scale(0.95); }

.menu-btn.easy   { color: #7bff9d; border-color: #2ecc71; box-shadow: 0 0 16px rgba(46, 204, 113, 0.25); }
.menu-btn.normal { color: #4df3ff; border-color: #00c3ff; box-shadow: 0 0 16px rgba(0, 195, 255, 0.3); }
.menu-btn.hard   { color: #ff5d7b; border-color: #ff2d55; box-shadow: 0 0 16px rgba(255, 45, 85, 0.3); }
.menu-btn.dim    { color: #9aa7c7; border-color: rgba(154, 167, 199, 0.5); }

@media (hover: hover) {
    .menu-btn:hover { transform: translateY(-2px); box-shadow: 0 0 26px rgba(0, 255, 255, 0.45); }
    .link-btn:hover { color: #fff; border-color: rgba(255, 255, 255, 0.6); }
}

.menu-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 18px;
}

.link-btn {
    font-family: inherit;
    font-size: 11px;
    letter-spacing: 2px;
    color: #9aa7c7;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(154, 167, 199, 0.4);
    border-radius: 10px;
    padding: 9px 14px;
    cursor: pointer;
}

.link-btn:active { transform: scale(0.94); }
.link-btn.wide { margin-top: 10px; width: 100%; max-width: 280px; color: #ffd54d; border-color: rgba(255, 213, 77, 0.4); }

.controls-note {
    margin-top: 18px;
    font-size: 11px;
    line-height: 1.8;
    color: rgba(255, 255, 255, 0.65);
}

.credits {
    margin-top: 14px;
    font-size: 9px;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.35);
}

/* ============ Auth form ============ */
#auth-form input {
    display: block;
    width: 100%;
    max-width: 280px;
    margin: 0 auto 12px;
    padding: 13px 16px;
    font-family: inherit;
    font-size: 16px;
    letter-spacing: 1px;
    color: #fff;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(0, 255, 255, 0.4);
    border-radius: 12px;
    outline: none;
    user-select: text;
    -webkit-user-select: text;
}

#auth-form input:focus { border-color: #4df3ff; box-shadow: 0 0 12px rgba(77, 243, 255, 0.35); }

#auth-error {
    color: #ff5d7b;
    font-size: 11px;
    min-height: 18px;
    margin-bottom: 8px;
}

/* ============ Story ============ */
.story-text {
    font-size: 13px;
    line-height: 1.9;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 18px;
}

.story-text p { margin-bottom: 12px; }
.story-text b { color: #ffd54d; }
.story-text.small { font-size: 11.5px; color: rgba(255, 255, 255, 0.7); }
.story-sign { color: #4df3ff; font-size: 11px; text-align: right; }

/* ============ Profile / leaderboard ============ */
.profile-head {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.rank-badge {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    background: radial-gradient(circle at 35% 30%, rgba(255, 213, 77, 0.35), rgba(120, 70, 0, 0.4));
    border: 2px solid rgba(255, 213, 77, 0.7);
    box-shadow: 0 0 18px rgba(255, 213, 77, 0.35);
    flex-shrink: 0;
}

.profile-name { font-size: 18px; font-weight: 900; }
.profile-rank { color: #ffd54d; font-size: 12px; letter-spacing: 2px; margin-top: 3px; }
.profile-id { color: #9aa7c7; font-size: 11px; margin-top: 3px; }

.rank-bar-wrap { margin: 12px 0 16px; }
.rank-bar-lbl { display: flex; justify-content: space-between; font-size: 10px; color: #9aa7c7; margin-bottom: 4px; }
.rank-bar { height: 10px; border-radius: 5px; background: rgba(0, 0, 0, 0.5); border: 1px solid rgba(255, 213, 77, 0.35); overflow: hidden; }
.rank-bar > div { height: 100%; background: linear-gradient(90deg, #ffd54d, #ff9d4d); box-shadow: 0 0 10px rgba(255, 213, 77, 0.7); }

.profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.pstat {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(0, 255, 255, 0.2);
    border-radius: 10px;
    padding: 9px 12px;
}

.pstat .k { font-size: 9px; color: #9aa7c7; letter-spacing: 1px; }
.pstat .v { font-size: 16px; font-weight: 700; color: #4df3ff; margin-top: 2px; }

.relic-shelf {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.relic {
    width: 52px;
    height: 62px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 22px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(123, 255, 234, 0.45);
    box-shadow: 0 0 10px rgba(123, 255, 234, 0.2);
}

.relic .rname { font-size: 6.5px; letter-spacing: 0.5px; color: #7bffea; text-align: center; }
.relic.locked { filter: grayscale(1); opacity: 0.3; border-color: rgba(255, 255, 255, 0.15); box-shadow: none; }

.board-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.board-table th {
    text-align: left;
    color: #9aa7c7;
    font-size: 9px;
    letter-spacing: 1px;
    padding: 6px 6px;
    border-bottom: 1px solid rgba(154, 167, 199, 0.3);
}
.board-table td { padding: 8px 6px; border-bottom: 1px solid rgba(154, 167, 199, 0.12); }
.board-table tr.me td { background: rgba(255, 213, 77, 0.08); }
.board-pos { color: #ffd54d; font-weight: 900; }
.board-name { font-weight: 700; }
.board-rank { color: #ffd54d; font-size: 9px; letter-spacing: 1px; }
.board-id { color: #9aa7c7; font-size: 9px; }
.board-score { color: #4df3ff; font-weight: 700; text-align: right; }
.board-relics { font-size: 13px; letter-spacing: 2px; }
.board-empty { text-align: center; color: #9aa7c7; font-size: 12px; padding: 20px 0; }

.pause-title, .over-title {
    font-size: 32px;
    font-weight: 900;
    letter-spacing: 5px;
    margin-bottom: 20px;
    color: #4df3ff;
    text-shadow: 0 0 18px #4df3ff;
}

.over-title { color: #ff5d7b; text-shadow: 0 0 18px #ff2d55; }

#new-record {
    color: #ffd54d;
    font-weight: 900;
    letter-spacing: 3px;
    margin: -8px 0 12px;
    animation: pulse 1s infinite;
}

#promotion {
    color: #7bff9d;
    font-weight: 900;
    font-size: 15px;
    letter-spacing: 2px;
    margin: -4px 0 12px;
    text-shadow: 0 0 14px #2ecc71;
    animation: pulse 1.1s infinite;
}

.stats {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(0, 255, 255, 0.25);
    border-radius: 14px;
    padding: 12px 18px;
    margin-bottom: 16px;
}

.stat-line {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding: 4px 0;
}

.stat-line span:last-child { color: #4df3ff; font-weight: 700; }

#rank-progress { margin-bottom: 18px; }

.loading-text {
    font-size: 22px;
    letter-spacing: 6px;
    color: #4df3ff;
    text-shadow: 0 0 14px #4df3ff;
    animation: pulse 1.2s infinite;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(36px) scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ============ Responsive tweaks ============ */
@media (max-width: 520px) {
    .hud-box { padding: 5px 8px; font-size: 12px; }
    .hud-box.dim { display: none; }
    .panel { padding: 20px 16px; }
    .stat-line { font-size: 12px; }
    #bars { max-width: 170px; }
    .board-table .hide-sm { display: none; }
}

@media (max-height: 520px) and (orientation: landscape) {
    .game-title { font-size: 34px; }
    .game-subtitle { margin-bottom: 8px; }
    .panel { padding: 12px 22px; }
    .menu-btn { padding: 8px 20px; font-size: 14px; }
    .btn-col { gap: 6px; }
    .controls-note { margin-top: 8px; line-height: 1.5; }
    .hi-line { margin-bottom: 8px; }
    #btn-bomb { width: 58px; height: 58px; }
    #btn-bomb .bomb-ico { font-size: 20px; }
    #joy-zone { width: 140px; height: 140px; bottom: calc(46px + env(safe-area-inset-bottom, 0px)); }
    #btn-fire { width: 84px; height: 84px; }
    #joy-fire-zone { bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }
}
