:root {
    --bg: #04060f;
    --panel: rgba(10, 18, 38, 0.82);
    --panel-border: rgba(90, 150, 255, 0.25);
    --accent: #5cc6ff;
    --accent-2: #8affc1;
    --warn: #ffcc55;
    --danger: #ff5d5d;
    --text: #d8e6ff;
    --muted: #7f93b8;
    --credits: #ffd76a;
    font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }

canvas { display: block; touch-action: none; }
#gameCanvas { position: fixed; inset: 0; width: 100vw; height: 100vh; background: radial-gradient(ellipse at center, #0a1430 0%, #04060f 70%); }
#uiHud { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 10; }
#minimap { position: fixed; right: 16px; bottom: 16px; z-index: 11; width: 200px; height: 200px; border-radius: 10px;
    border: 1px solid var(--panel-border); box-shadow: 0 0 18px rgba(0,0,0,0.6); background: rgba(4,8,20,0.7); }
#mapOverlay { position: fixed; inset: 0; z-index: 30; display: none; background: rgba(2,5,14,0.92); }
#miniCtrls { position: fixed; right: 22px; bottom: 186px; z-index: 12; display: flex; flex-direction: column; gap: 4px; }
#miniCtrls button { width: 26px; height: 26px; border-radius: 6px; font-size: 16px; font-weight: 700; line-height: 1;
    background: rgba(20,28,44,0.85); color: #cfe0ff; border: 1px solid var(--panel-border); }
#miniCtrls button:hover { border-color: var(--accent); background: rgba(92,198,255,0.2); }

/* ---- HUD ---- */
#hud { position: fixed; left: 14px; top: 14px; z-index: 12; display: flex; flex-direction: column; gap: 10px; max-width: 280px; }
.panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 12px 14px;
    backdrop-filter: blur(6px); box-shadow: 0 4px 20px rgba(0,0,0,0.4); font-size: 13px; }
.panel.mini { font-size: 11.5px; color: var(--muted); padding: 9px 12px; }
.panel.mini b { color: var(--accent); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 3px 0; }
.row .label { color: var(--muted); }
.credits { color: var(--credits); font-weight: 700; }
.sector .danger { color: var(--danger); font-weight: 700; font-size: 11px; }
.bar { display: flex; align-items: center; gap: 8px; margin: 5px 0; font-size: 11px; color: var(--muted); }
.bar > span { width: 38px; }
.track { flex: 1; height: 8px; background: rgba(255,255,255,0.08); border-radius: 5px; overflow: hidden; }
.fill { height: 100%; width: 100%; transition: width 0.2s; }
.fill.hull { background: linear-gradient(90deg, #ff6a6a, #ffb15c); }
.fill.fuel { background: linear-gradient(90deg, #5cc6ff, #8affc1); }
.fill.cargo { background: linear-gradient(90deg, #b48cff, #ff8cf0); }

/* ---- notices / prompt ---- */
#notices { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.notice { background: var(--panel); border: 1px solid var(--panel-border); border-left: 3px solid var(--accent);
    padding: 9px 16px; border-radius: 8px; font-size: 13px; animation: slideIn 0.25s ease; max-width: 70vw; }
.notice.warn { border-left-color: var(--warn); }
.notice.danger { border-left-color: var(--danger); }
.notice.good { border-left-color: var(--accent-2); }
.notice.big { font-size: 16px; font-weight: 700; padding: 14px 26px; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; } }
#prompt { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 13;
    background: var(--panel); border: 1px solid var(--panel-border); padding: 10px 18px; border-radius: 24px; font-size: 14px; }
#prompt b { color: var(--accent); }

/* ---- overlays ---- */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
    background: rgba(2,5,14,0.78); backdrop-filter: blur(4px); }

/* ---- entry ---- */
.entry-window { width: min(440px, 92vw); background: var(--panel); border: 1px solid var(--panel-border);
    border-radius: 16px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,0.6); text-align: center; }
.entry-window h1 { margin: 0; font-size: 40px; letter-spacing: 6px; font-weight: 800; color: #fff; }
.entry-window h1 span { color: var(--accent); }
.tagline { color: var(--muted); margin: 8px 0 22px; font-size: 13px; }
.entry-body { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; text-align: left; font-size: 12px; color: var(--muted); }
.field em { color: var(--accent); font-style: normal; }
input { background: rgba(255,255,255,0.06); border: 1px solid var(--panel-border); color: var(--text);
    padding: 11px 13px; border-radius: 8px; font-size: 14px; outline: none; }
input:focus { border-color: var(--accent); }
button { cursor: pointer; border: 1px solid var(--panel-border); background: rgba(255,255,255,0.06); color: var(--text);
    padding: 10px 16px; border-radius: 8px; font-size: 14px; transition: all 0.15s; }
button:hover { border-color: var(--accent); background: rgba(92,198,255,0.14); }
button.primary { background: linear-gradient(90deg, #2b7fff, #5cc6ff); border: none; color: #021022; font-weight: 700; }
button.primary:hover { filter: brightness(1.1); }
button.big { padding: 14px; font-size: 16px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--panel-border); }
.auth-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.auth-grid input { grid-column: 1 / 3; }
.returning { margin-top: 6px; }
.error { background: rgba(255,93,93,0.12); border: 1px solid var(--danger); color: #ffb3b3; padding: 9px 12px;
    border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.entry-window footer { margin-top: 22px; color: var(--muted); font-size: 11px; }

/* ---- station ---- */
.station-window { width: min(720px, 94vw); max-height: 86vh; background: var(--panel); border: 1px solid var(--panel-border);
    border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.6); }
.station-window header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px;
    border-bottom: 1px solid var(--panel-border); }
.station-window h2 { margin: 0; font-size: 20px; color: #fff; }
.tabs { display: flex; gap: 4px; padding: 10px 16px 0; }
.tabs button { border-radius: 8px 8px 0 0; border-bottom: none; }
.tabs button.active { background: rgba(92,198,255,0.18); border-color: var(--accent); color: #fff; }
.tabpane { display: none; padding: 16px 20px; overflow-y: auto; }
.tabpane.active { display: block; }
.shop-list { display: flex; flex-direction: column; gap: 8px; }
.shop-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px;
    background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border); border-radius: 8px; }
.shop-item .info { display: flex; flex-direction: column; gap: 2px; }
.shop-item .name { font-weight: 600; }
.shop-item .desc { color: var(--muted); font-size: 11.5px; }
.shop-item .price { color: var(--credits); font-weight: 700; white-space: nowrap; }
.section-title { color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; margin: 16px 0 8px; }
.section-title:first-child { margin-top: 0; }
.rarity-common { color: #cfd8e6; } .rarity-uncommon { color: #6fe07f; } .rarity-rare { color: #5cc6ff; }
.rarity-epic { color: #c08bff; } .rarity-legendary { color: #ffba4d; }
.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* ---- help button + manual ---- */
#helpBtn { position: fixed; top: 16px; right: 232px; z-index: 13; width: 38px; height: 38px; border-radius: 50%;
    font-size: 20px; font-weight: 700; background: var(--panel); border: 1px solid var(--panel-border); color: var(--accent); }
#helpBtn:hover { border-color: var(--accent); background: rgba(92,198,255,0.16); }
#adminBtn { position: fixed; top: 16px; right: 280px; z-index: 13; height: 38px; padding: 0 14px; border-radius: 19px;
    font-size: 13px; font-weight: 700; background: rgba(255,92,108,0.16); border: 1px solid rgba(255,92,108,0.6); color: #ffb3bb; }
#adminBtn:hover { border-color: var(--danger); background: rgba(255,92,108,0.28); }
#manual { z-index: 60; }

/* ---- admin console ---- */
#admin { z-index: 65; }
.admin-window { width: min(760px, 95vw); max-height: 88vh; background: var(--panel); border: 1px solid var(--panel-border);
    border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.6); }
.admin-window header { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--panel-border); }
.admin-window h2 { margin: 0; font-size: 19px; color: #fff; }
.admin-window .tabpane { display: none; padding: 16px 20px; overflow-y: auto; }
.admin-window .tabpane.active { display: block; }
.admin-player { border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.ap-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.ap-head .name { color: #fff; font-weight: 600; }
.ap-head .desc { color: var(--muted); font-size: 12px; }
.ap-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ap-actions button { font-size: 12px; padding: 5px 9px; }
.ap-give { display: inline-flex; gap: 4px; align-items: center; margin-left: auto; }
.ap-give select, .ap-give input { font-size: 12px; padding: 4px; background: rgba(0,0,0,0.3); color: var(--text); border: 1px solid var(--panel-border); border-radius: 6px; }
.ap-give .ap-qty { width: 58px; }
.badge { font-size: 10px; background: rgba(255,92,108,0.3); color: #ffb3bb; padding: 1px 6px; border-radius: 4px; vertical-align: middle; }
.admin-names { display: flex; flex-direction: column; gap: 6px; }
.admin-name { display: flex; align-items: center; gap: 10px; border: 1px solid var(--panel-border); border-radius: 8px; padding: 8px 12px; }
.admin-name .info { flex: 1; display: flex; flex-direction: column; }
.admin-name .name { color: #fff; }
.admin-name .desc { color: var(--muted); font-size: 12px; }
.admin-name button { font-size: 12px; padding: 5px 10px; }
#atab-broadcast textarea { width: 100%; background: rgba(0,0,0,0.3); color: var(--text); border: 1px solid var(--panel-border); border-radius: 8px; padding: 10px; resize: vertical; margin-bottom: 10px; }
.notice.action { display: flex; align-items: center; gap: 12px; pointer-events: auto; }
.notice.action button { font-size: 13px; padding: 6px 12px; white-space: nowrap; }
.manual-window { width: min(900px, 94vw); height: min(82vh, 720px); background: var(--panel); border: 1px solid var(--panel-border);
    border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.6); }
.manual-window header { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--panel-border); }
.manual-window h2 { margin: 0; font-size: 20px; color: #fff; letter-spacing: 1px; }
.manual-body { display: flex; flex: 1; min-height: 0; }
.manual-nav { width: 210px; flex-shrink: 0; border-right: 1px solid var(--panel-border); padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.manual-nav button { text-align: left; border: none; background: transparent; color: var(--muted); padding: 9px 12px; border-radius: 8px; font-size: 13px; }
.manual-nav button:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.manual-nav button.active { background: rgba(92,198,255,0.16); color: #fff; }
.manual-content { flex: 1; overflow-y: auto; padding: 20px 28px; line-height: 1.6; font-size: 14px; }
.manual-content h3 { margin-top: 0; color: var(--accent); font-size: 18px; }
.manual-content b { color: #eaf2ff; }
.manual-content code { background: rgba(255,255,255,0.08); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; color: var(--accent-2); }
.manual-content kbd { background: rgba(255,255,255,0.1); border: 1px solid var(--panel-border); border-bottom-width: 2px; border-radius: 5px; padding: 1px 7px; font-size: 12px; color: #fff; }
.manual-content .tip { background: rgba(138,255,193,0.08); border-left: 3px solid var(--accent-2); padding: 9px 14px; border-radius: 6px; color: #cfeede; }
.manual-content ul, .manual-content ol { padding-left: 22px; }
.manual-content li { margin: 4px 0; }
.manual-content table.kv { width: 100%; border-collapse: collapse; }
.manual-content table.kv td { padding: 6px 10px; border-bottom: 1px solid rgba(255,255,255,0.06); vertical-align: top; }
.manual-content table.kv td:first-child { white-space: nowrap; width: 36%; color: var(--accent); }

@media (max-width: 600px) {
    #controls { display: none; }
    #hud { max-width: 200px; }
    #helpBtn { right: 16px; top: 64px; }
    #adminBtn { right: 64px; top: 64px; }
    .manual-body { flex-direction: column; }
    .manual-nav { width: auto; flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--panel-border); }
}

/* --- Touch controls (phones & tablets) --- */
#touch { position: fixed; inset: 0; z-index: 14; pointer-events: none; touch-action: none; }
#touch.hidden { display: none; }
#touch .joystick, #touch .touch-btn { pointer-events: auto; touch-action: none; -webkit-user-select: none; user-select: none; }
.joystick { position: absolute; left: max(24px, env(safe-area-inset-left)); bottom: max(28px, env(safe-area-inset-bottom));
    width: 124px; height: 124px; border-radius: 50%; background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.18); display: flex; align-items: center; justify-content: center; }
.joy-knob { width: 56px; height: 56px; border-radius: 50%; background: rgba(92,198,255,0.35);
    border: 1px solid rgba(92,198,255,0.7); transition: transform 0.04s linear; }
.touch-btns { position: absolute; right: max(24px, env(safe-area-inset-right)); bottom: max(28px, env(safe-area-inset-bottom));
    display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.touch-row { display: flex; gap: 12px; }
.touch-btn { width: 62px; height: 62px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.22);
    background: rgba(20,28,44,0.6); color: #eaf2ff; font-size: 22px; font-weight: 600; letter-spacing: 0.5px;
    display: flex; align-items: center; justify-content: center; }
.touch-btn.fire { width: 88px; height: 88px; font-size: 16px; background: rgba(255,92,108,0.28); border-color: rgba(255,92,108,0.7); }
.touch-btn.pressed { background: rgba(92,198,255,0.4); transform: scale(0.94); }
