* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    background: #0d0f14;
    color: #c9c4b8;
    font-family: monospace, monospace;
    overflow: hidden;
}

#game {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    z-index: 1;
}

#ui {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

/* Слой UI прозрачен для мыши, чтобы клики по миру доходили до canvas,
   но сами панели и кнопки обязаны кликаться — иначе меню недоступно. */
#ui > * {
    pointer-events: auto;
}

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.auth-box {
    width: 320px;
    padding: 24px;
    border: 1px solid #3a3f4a;
    background: #14171f;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.auth-box h1 {
    font-size: 22px;
    text-align: center;
    margin-bottom: 16px;
    color: #e0a03a;
}

.tabs {
    display: flex;
    margin-bottom: 16px;
    border-bottom: 1px solid #3a3f4a;
}

.tab {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: none;
    color: #8a8f9a;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
}

.tab.active {
    color: #c9c4b8;
    border-bottom: 2px solid #e0a03a;
}

.form {
    display: none;
}

.form.active {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-box label {
    font-size: 12px;
    color: #8a8f9a;
}

.auth-box input {
    padding: 8px;
    background: #0d0f14;
    border: 1px solid #3a3f4a;
    color: #c9c4b8;
    font-family: inherit;
    font-size: 14px;
}

.auth-box input:focus {
    outline: none;
    border-color: #e0a03a;
}

.auth-box button[type="submit"] {
    margin-top: 8px;
    padding: 10px;
    background: #3a2a1a;
    border: 1px solid #8a6a3a;
    color: #e0c08a;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
}

.auth-box button[type="submit"]:hover {
    background: #4a3a2a;
}

.error {
    min-height: 18px;
    margin-bottom: 8px;
    font-size: 12px;
    color: #c34b4b;
    text-align: center;
}

/* ---- Модалки боя: левелап и лавка ------------------------------------- */

.modal {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: rgba(10, 11, 14, 0.94);
    border: 1px solid #3a3f4a;
    padding: 18px 20px;
    color: #c9c4b8;
    font-family: monospace;
    max-height: 92vh;
    overflow-y: auto;
    box-sizing: border-box;
}

.modal.wide { width: min(1040px, 96vw); }

.modal-title { font-size: 18px; margin-bottom: 4px; color: #e0c07a; }
.modal-sub { font-size: 12px; color: #7a7568; margin-bottom: 12px; }

.choice-row { display: flex; gap: 10px; }

.choice {
    flex: 1 1 0;
    min-width: 130px;
    background: #181b22;
    border: 1px solid #3a3f4a;
    color: #c9c4b8;
    font-family: monospace;
    padding: 14px 10px;
    cursor: pointer;
    text-align: center;
}
.choice:hover { background: #22262f; }
.choice-name { font-size: 13px; margin-bottom: 6px; }
.choice-value { font-size: 20px; }

.shop-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.shop-top .ash { color: #c8a35a; margin-right: auto; }

.btn {
    background: #22262f;
    border: 1px solid #3a3f4a;
    color: #c9c4b8;
    font-family: monospace;
    padding: 7px 14px;
    cursor: pointer;
}
.btn:hover:not(:disabled) { background: #2c313c; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.go { border-color: #6a8f4a; color: #a8d07a; }

.shop-slots { display: flex; gap: 10px; margin-bottom: 16px; }

.card {
    position: relative;
    flex: 1 1 0;
    min-height: 128px;
    background: #181b22;
    border: 1px solid #3a3f4a;
    padding: 10px;
    cursor: pointer;
    font-size: 12px;
}
.card:hover:not(.sold):not(.empty) { background: #22262f; }
.card.sold { opacity: 0.35; cursor: default; }
.card.empty { cursor: default; }
.card.locked { box-shadow: inset 0 0 0 1px #c8a35a; }
.card.warn::after {
    content: attr(data-msg);
    position: absolute;
    left: 0; right: 0; bottom: 0;
    background: #6a2020;
    color: #e8d8d0;
    padding: 3px;
    text-align: center;
}
.card-name { font-size: 13px; margin-bottom: 2px; }
.card-tier { color: #7a7568; font-size: 11px; margin-bottom: 6px; }
.card-line { color: #9a9488; }
.card-desc { color: #7a7568; margin-top: 6px; font-style: italic; }
.card-price { position: absolute; right: 10px; bottom: 8px; color: #c8a35a; }

.lock {
    position: absolute;
    right: 6px;
    top: 6px;
    background: none;
    border: none;
    color: #7a7568;
    cursor: pointer;
    font-size: 13px;
}
.lock.on { color: #c8a35a; }

.shop-cols { display: flex; gap: 18px; }
.col { flex: 1 1 0; }
.col-title { color: #7a7568; font-size: 12px; margin-bottom: 8px; }

.inv-cell {
    position: relative;
    border: 1px solid #3a3f4a;
    background: #181b22;
    padding: 7px 9px;
    margin-bottom: 6px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.inv-cell.empty { opacity: 0.3; min-height: 18px; }
.inv-name { margin-right: auto; }

.mini {
    background: #22262f;
    border: 1px solid #3a3f4a;
    color: #9a9488;
    font-family: monospace;
    font-size: 11px;
    padding: 2px 7px;
    cursor: pointer;
}
.mini:hover { color: #c9c4b8; }
.mini.merge { border-color: #c8a35a; color: #c8a35a; }

.stat-row { display: flex; justify-content: space-between; font-size: 12px; padding: 1px 0; }

.tooltip {
    position: fixed;
    z-index: 20;
    background: rgba(10, 11, 14, 0.97);
    border: 1px solid #3a3f4a;
    color: #c9c4b8;
    font-family: monospace;
    font-size: 12px;
    padding: 8px 10px;
    max-width: 260px;
    pointer-events: none;
}
.tooltip .stat { padding: 1px 0; }

/* ---- Меню и лобби ------------------------------------------------------ */

.menu {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 260px;
    background: rgba(10, 11, 14, 0.94);
    border: 1px solid #3a3f4a;
    padding: 22px 26px;
    font-family: monospace;
}
.menu-title { color: #e0c07a; font-size: 20px; margin-bottom: 6px; text-align: center; }
.join-row { display: flex; gap: 8px; }
.join-row input {
    flex: 1 1 0;
    background: #181b22;
    border: 1px solid #3a3f4a;
    color: #c9c4b8;
    font-family: monospace;
    padding: 7px 10px;
    text-transform: uppercase;
    min-width: 0;
}

.lobby-code { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.lobby-code .code {
    font-size: 30px;
    letter-spacing: 5px;
    color: #c8a35a;
}
.lobby-warn { color: #a8564a; font-size: 12px; margin-bottom: 14px; }
.lobby-players .inv-cell, .lobby-chars .inv-cell, .lobby-setup .inv-cell {
    justify-content: space-between;
    cursor: pointer;
    width: 100%;
    text-align: left;
    box-sizing: border-box;
}
.lobby-setup .inv-cell:disabled { cursor: default; opacity: 0.5; }

/* ---- Реликварий -------------------------------------------------------- */

.meta-tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.btn.tab { padding: 5px 12px; font-size: 12px; }
.btn.tab.active { border-color: #c8a35a; color: #c8a35a; }

.meta-body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 10px;
    max-height: 60vh;
    overflow-y: auto;
}

.meta-card {
    position: relative;
    border: 1px solid #3a3f4a;
    background: #181b22;
    padding: 10px 12px 30px;
    font-size: 12px;
}
.meta-card.owned { opacity: 0.75; }
.meta-card.locked-out { opacity: 0.35; }
.meta-name { font-size: 13px; margin-bottom: 3px; }
.meta-sub { color: #7a7568; font-style: italic; margin-bottom: 6px; }
.meta-line { color: #9a9488; }
.meta-line.done { color: #a8d07a; }
.meta-foot { position: absolute; left: 12px; bottom: 8px; }
.meta-foot .price { color: #c8a35a; }
.owned-tag { color: #a8d07a; }
.mini.buy { position: absolute; right: 10px; bottom: 6px; }

/* ---- Экран итогов ------------------------------------------------------ */

.result-rows { margin: 10px 0 12px; min-width: 300px; }
.result-awards { margin-bottom: 10px; }
.result-award { color: #a8d07a; font-size: 12px; padding: 2px 0; }
.result-flag { color: #c34b4b; font-size: 12px; padding: 4px 0; }

/* ---- Мобильный режим --------------------------------------------------- */

@media (max-width: 820px), (pointer: coarse) {
    .modal { padding: 12px 14px; width: 96vw; max-height: 88vh; }
    .modal.wide { width: 96vw; }
    .shop-slots { flex-wrap: wrap; }
    .card { min-width: 44%; min-height: 108px; }
    .shop-cols { flex-direction: column; gap: 10px; }
    .meta-body { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    /* Пальцем нужно куда попадать: увеличиваем все интерактивные элементы */
    .btn, .mini, .choice { min-height: 40px; padding: 10px 14px; font-size: 13px; }
    .lock { width: 32px; height: 32px; font-size: 18px; }
    .choice-row { flex-wrap: wrap; }
    .choice { min-width: 45%; }
    .menu { min-width: 74vw; }
    .lobby-code .code { font-size: 22px; letter-spacing: 3px; }
}
