/* ═══════════════════════════════════════════════
   МОРСКОЙ БОЙ — стили
   Классический, минималистичный, тёмная морская тема
   ═══════════════════════════════════════════════ */

.ihb-wrapper {
    --ihb-water:      #1b2836;
    --ihb-water-line: #2a3b4d;
    --ihb-bg-start:   #0f1620;
    --ihb-bg-end:     #16212e;
    --ihb-ship-a:     #7c8ba1;
    --ihb-ship-b:     #46536a;
    --ihb-hit:        #e8543f;
    --ihb-hit-glow:   rgba(232,84,63,0.45);
    --ihb-miss:       #4c6a86;
    --ihb-sunk:       #5c2a24;
    --ihb-sunk-line:  #7a3a30;
    --ihb-accent:     #4f8aff;
    --ihb-cell: clamp(24px, 7.6vw, 34px);

    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 620px;
    margin: 0 auto;
    padding: 22px 18px 26px;
    box-sizing: border-box;
    background: linear-gradient(180deg, var(--ihb-bg-start), var(--ihb-bg-end));
    border-radius: 22px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.4);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    min-height: 460px; /* без этого обёртка схлопывается, пока все .ihb-phase скрыты — оверлеи авторизации/ожидания обрезаются */
}

/* ── Оверлеи ── */
.ihb-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(5,10,16,0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 200;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
}
.ihb-overlay.ihb-visible { display: flex; }

.ihb-modal {
    background: #1b232e;
    border-radius: 20px;
    padding: 28px 24px;
    width: 88%;
    max-width: 320px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: center;
    border: 1px solid #24303e;
}
.ihb-modal h2 {
    color: #fff;
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.ihb-modal h2 i { color: var(--ihb-accent); }

.ihb-modal input {
    display: block;
    width: 100%;
    padding: 13px 16px;
    border-radius: 12px;
    border: 2px solid #2a3644;
    background: #101820;
    color: #fff;
    font-size: 15px;
    box-sizing: border-box;
    font-family: inherit;
    transition: border-color 0.2s;
}
.ihb-modal input:focus { border-color: var(--ihb-accent); outline: none; }

.ihb-lb-modal { text-align: left; max-height: 75vh; overflow-y: auto; }
.ihb-lb-modal h3 { color: #fff; text-align: center; font-size: 20px; font-weight: 800; margin: 0 0 12px; }
.ihb-lb-modal ol { padding-left: 20px; color: #fff; margin: 0 0 16px; font-size: 14px; }
.ihb-lb-modal li { padding: 8px 0; border-bottom: 1px solid #263140; display: flex; justify-content: space-between; }
.ihb-lb-modal li:last-child { border-bottom: none; }
.ihb-lb-modal li.ihg-current-player { color: #f4b24e; font-weight: 700; }

/* ── Кнопки ── */
.ihb-btn {
    display: block;
    width: 100%;
    padding: 13px 16px;
    border: none;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    color: #fff;
    font-family: inherit;
    box-sizing: border-box;
    text-align: center;
    transition: transform 0.1s, opacity 0.15s;
}
.ihb-btn:active { transform: scale(0.97); }
.ihb-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.ihb-btn-primary   { background: linear-gradient(90deg, #4c5fc5, #2c9782); box-shadow: 0 4px 14px rgba(44,151,130,0.3); }
.ihb-btn-secondary { background: #2a3644; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.ihb-btn-link      { background: transparent; color: #7f8fa3; box-shadow: none; font-size: 14px; padding: 8px 16px; font-weight: 600; }
.ihb-btn-link:hover { color: #cdd6e0; }
.ihb-btn-danger {
    background: #3d1712;
    color: #ff8a75;
    border: 1px solid #5a241c;
    width: auto;
    padding: 10px 16px;
    box-shadow: none;
}
.ihb-btn-danger:hover { background: #52201a; }

#ihb-auth-buttons { display: flex; flex-direction: column; gap: 10px; }
#ihb-auth-form { display: none; flex-direction: column; gap: 0; }

/* ── Fullscreen ── */
.ihb-fs-btn {
    position: absolute; top: 10px; right: 10px;
    width: 36px; height: 36px;
    border: none; background: transparent;
    cursor: pointer; z-index: 100; padding: 0;
    display: none; align-items: center; justify-content: center;
}
.ihb-fs-btn i { font-size: 20px; color: #4c5b6d; transition: color 0.2s; }
.ihb-fs-btn:hover i { color: #9fb2c7; }
@media (max-width: 768px) { .ihb-fs-btn { display: flex; } }

/* ── Toast ── */
.ihb-toast {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -30%);
    background: #17212b;
    color: #fff;
    padding: 16px 22px;
    border-radius: 16px;
    font-weight: 700;
    font-size: 15px;
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
    box-shadow: 0 12px 32px rgba(0,0,0,0.5);
    text-align: center;
    line-height: 1.6;
    max-width: 85%;
    width: max-content;
    box-sizing: border-box;
    border: 1px solid #263140;
    transition: opacity 0.25s cubic-bezier(0.175,0.885,0.32,1.275),
                transform 0.25s cubic-bezier(0.175,0.885,0.32,1.275);
}
.ihb-toast.show { opacity: 1; transform: translate(-50%, -50%); pointer-events: auto; }
.ihb-toast-btn {
    display: inline-block; margin-top: 10px; padding: 8px 18px;
    background: linear-gradient(90deg, #4c5fc5, #2c9782);
    color: #fff; border: none; border-radius: 10px;
    font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit;
}

/* ── Фазы ── */
.ihb-phase {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.ihb-setup-header { text-align: center; }
.ihb-setup-header h3 {
    color: #fff; margin: 0 0 4px; font-size: 19px; font-weight: 800;
}
.ihb-hint { color: #62748a; font-size: 13px; margin: 0; }

/* ── Трей кораблей ── */
.ihb-tray {
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #131b24;
    border-radius: 14px;
    padding: 10px 14px;
}
.ihb-tray-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}
.ihb-tray-row:hover:not(.ihb-tray-empty) { background: #1c2733; }
.ihb-tray-row.ihb-tray-active {
    background: rgba(79,138,255,0.12);
    box-shadow: inset 0 0 0 1.5px var(--ihb-accent);
}
.ihb-tray-row.ihb-tray-empty { opacity: 0.3; cursor: default; }

.ihb-tray-strip { display: flex; gap: 3px; }
.ihb-tray-block {
    width: 20px; height: 20px;
    border-radius: 4px;
    background: linear-gradient(145deg, var(--ihb-ship-a), var(--ihb-ship-b));
}
.ihb-tray-count {
    color: #9fb2c7;
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ── Контролы расстановки ── */
.ihb-setup-controls {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 340px;
}
.ihb-icon-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 8px;
    border: none;
    border-radius: 12px;
    background: #1c2733;
    color: #b7c4d3;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}
.ihb-icon-btn:hover { background: #253241; color: #fff; }
.ihb-icon-btn i { font-size: 14px; }
.ihb-icon-btn span { white-space: nowrap; }

.ihb-start-btn { max-width: 340px; }

/* ── Игровое поле (общая сетка) ── */
.ihb-board-holder { display: flex; justify-content: center; width: 100%; }

.ihb-grid {
    display: grid;
    grid-template-columns: auto repeat(10, var(--ihb-cell));
    grid-template-rows: auto repeat(10, var(--ihb-cell));
    gap: 2px;
    background: #0d141b;
    padding: 6px;
    border-radius: 12px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}

.ihb-corner { width: 100%; height: 100%; }
.ihb-colhead, .ihb-rowhead {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #56677c;
    font-size: 11px;
    font-weight: 700;
}

.ihb-cell {
    background: var(--ihb-water);
    border-radius: 4px;
    position: relative;
    box-shadow: inset 0 0 0 1px var(--ihb-water-line);
    transition: background 0.12s;
}

/* Клик доступен только на вражеской доске */
.ihb-grid-enemy .ihb-cell { cursor: pointer; }
.ihb-grid-setup .ihb-cell { cursor: pointer; }
.ihb-grid-own .ihb-cell   { cursor: default; }

/* Crosshair-подсветка (наведение на вражескую доску) */
.ihb-cell.ihb-crosshair { background: #22344a; }

/* Корабль на своей доске */
.ihb-cell.ihb-ship {
    background: linear-gradient(145deg, var(--ihb-ship-a), var(--ihb-ship-b));
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15);
}

/* Предпросмотр размещения */
.ihb-cell.ihb-preview-ok  { background: rgba(46,204,113,0.35); box-shadow: inset 0 0 0 1.5px #2ecc71; }
.ihb-cell.ihb-preview-bad { background: rgba(231,76,60,0.35);  box-shadow: inset 0 0 0 1.5px #e74c3c; }

/* Попадание */
.ihb-cell.ihb-hit {
    background: radial-gradient(circle at 40% 35%, #ff9a85, var(--ihb-hit) 65%);
    box-shadow: 0 0 10px var(--ihb-hit-glow), inset 0 0 0 1px rgba(255,255,255,0.2);
    animation: ihbHitPulse 0.35s ease-out;
}
@keyframes ihbHitPulse {
    0%   { transform: scale(0.6); }
    60%  { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* Промах */
.ihb-cell.ihb-miss::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 28%; height: 28%;
    border-radius: 50%;
    background: rgba(255,255,255,0.35);
    transform: translate(-50%,-50%);
    animation: ihbMissAppear 0.3s ease-out;
}
.ihb-cell.ihb-miss.ihb-auto-miss::after { background: rgba(255,255,255,0.18); }
@keyframes ihbMissAppear {
    from { transform: translate(-50%,-50%) scale(0.3); opacity: 0; }
    to   { transform: translate(-50%,-50%) scale(1); opacity: 1; }
}

/* Потопленный корабль */
.ihb-cell.ihb-sunk {
    background: linear-gradient(145deg, var(--ihb-sunk), #3a1712);
    box-shadow: inset 0 0 0 1px var(--ihb-sunk-line);
}
.ihb-cell.ihb-sunk::before,
.ihb-cell.ihb-sunk::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 60%; height: 2px;
    background: rgba(255,255,255,0.4);
    transform-origin: center;
}
.ihb-cell.ihb-sunk::before { transform: translate(-50%,-50%) rotate(45deg); }
.ihb-cell.ihb-sunk::after  { transform: translate(-50%,-50%) rotate(-45deg); }

/* ── Статус-бар боя ── */
.ihb-status {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: #131b24;
    border-radius: 14px;
    padding: 10px 16px;
    box-sizing: border-box;
}
.ihb-status-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.ihb-status-label { font-size: 10.5px; color: #56677c; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.ihb-status-value { font-size: 15px; color: #fff; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ── Доски боя (в ряд) ── */
.ihb-boards-row {
    display: flex;
    gap: 14px;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
}
.ihb-board-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.ihb-board-title {
    color: #7f8fa3;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.ihb-new-btn { max-width: 340px; }

/* ── Адаптивность ── */
@media (max-width: 620px) {
    .ihb-wrapper { --ihb-cell: clamp(20px, 7.6vw, 30px); padding: 16px 10px 20px; border-radius: 18px; }
    .ihb-boards-row { flex-direction: column; align-items: center; }
}
@media (max-width: 360px) {
    .ihb-wrapper { --ihb-cell: clamp(18px, 7.2vw, 26px); }
}

/* ── Полноэкранный режим ── */
.ihb-wrapper.ihb-fullscreen {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    z-index: 999999 !important;
    margin: 0 !important;
    padding: 20px 12px !important;
    overflow-y: auto;
    justify-content: flex-start;
}

/* ════════════════════════════════════════════════════════
   ЭКРАН ВЫБОРА РЕЖИМА
   ════════════════════════════════════════════════════════ */
.ihb-mode-select {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 10px 0 4px;
}
.ihb-mode-select h2 {
    color: #fff;
    font-size: 22px;
    font-weight: 800;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}
.ihb-mode-select h2 i { color: var(--ihb-accent, #4f8aff); }
.ihb-mode-select .ihb-hint { margin: 0 0 6px; }

.ihb-mode-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    text-align: left;
    padding: 16px 18px;
    width: 86%;
    max-width: 380px;
}
.ihb-mode-btn i { font-size: 22px; flex-shrink: 0; opacity: 0.9; }
.ihb-mode-btn span { display: flex; flex-direction: column; gap: 3px; }
.ihb-mode-btn span small { font-weight: 500; opacity: 0.75; font-size: 12px; }

.ihb-mode-btn-classic {
    background: linear-gradient(90deg, #4c5fc5, #2c9782);
    box-shadow: 0 4px 14px rgba(44,151,130,0.3);
}
.ihb-mode-btn-2p {
    background: linear-gradient(90deg, #e8547f, #f0a75c);
    box-shadow: 0 4px 14px rgba(232,84,127,0.3);
}
.ihb-mode-btn-3p {
    background: linear-gradient(90deg, #8e54e9, #4f8aff);
    box-shadow: 0 4px 14px rgba(142,84,233,0.3);
}

/* ════════════════════════════════════════════════════════
   ОЖИДАНИЕ ИГРОКОВ (3P)
   ════════════════════════════════════════════════════════ */
.ihb3-wait-modal h2 {
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    margin: 0 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.ihb3-wait-modal h2 i { color: var(--ihb-accent, #4f8aff); }

.ihb-wait-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #8fa1b3;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 0 4px;
}
.ihb-wait-spinner i { color: var(--ihb-accent, #4f8aff); font-size: 18px; }

.ihb3-wait-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 6px 0 10px;
}
.ihb3-wait-slot {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #121a24;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 700;
    color: #56677c;
}
.ihb3-wait-slot.filled { color: #fff; }
.ihb3-wait-slot i { width: 16px; text-align: center; }
.ihb3-wait-slot.filled i { color: #2ecc71; }

/* ════════════════════════════════════════════════════════
   ФАЗА БОЯ: ТРИ ИГРОКА
   ════════════════════════════════════════════════════════ */

/* Бейджи игроков */
.ihb3-players-row {
    width: 100%;
    display: flex;
    gap: 8px;
}
.ihb3-badge {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: #121a24;
    border-radius: 12px;
    padding: 10px 6px;
    opacity: 0.5;
    transition: opacity 0.2s, box-shadow 0.2s;
    min-width: 0;
}
.ihb3-badge.ihb3-active {
    opacity: 1;
    box-shadow: 0 0 0 2px var(--ihb-accent, #4f8aff), 0 0 14px rgba(79,138,255,0.35);
}
.ihb3-badge.ihb3-me { background: #16202c; }
.ihb3-badge.ihb3-defeated { opacity: 0.35; }
.ihb3-badge.ihb3-disconnected { opacity: 0.3; }
.ihb3-badge-name {
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.ihb3-badge-ships {
    font-size: 11px;
    color: #8fa1b3;
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: center;
    gap: 4px;
}
.ihb3-badge-ships i { font-size: 9px; }
.ihb3-badge-status {
    font-size: 10px;
    font-weight: 700;
    color: #e8543f;
}

/* Баннер placing/turn статуса */
.ihb3-banner {
    width: 100%;
    text-align: center;
    background: #121a24;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    color: #cbd6e2;
}
.ihb3-banner.ihb3-my-turn {
    background: rgba(79,138,255,0.12);
    color: var(--ihb-accent, #4f8aff);
    box-shadow: inset 0 0 0 1px rgba(79,138,255,0.3);
}

/* Панель расстановки (перегенерировать / в бой) */
.ihb3-place-controls {
    width: 100%;
    display: flex;
    gap: 8px;
}
.ihb3-place-controls .ihb-icon-btn { flex: 1; }
.ihb3-place-controls .ihb-btn-primary { flex: 1.4; }

/* Общая карта 17×17 — уменьшенная клетка под большее поле */
.ihb-grid-3p {
    --ihb3-cell: clamp(14px, 4.6vw, 21px);
    grid-template-columns: auto repeat(17, var(--ihb3-cell));
    grid-template-rows: auto repeat(17, var(--ihb3-cell));
    gap: 1px;
    padding: 5px;
}
.ihb-grid-3p .ihb-colhead,
.ihb-grid-3p .ihb-rowhead { font-size: 9px; }
.ihb-grid-3p .ihb-cell { border-radius: 3px; }

/* Своя фишка радара — маленький пульсирующий индикатор поверх клетки */
.ihb-cell.ihb3-radar-mark::before {
    content: '';
    position: absolute;
    top: 3px; right: 3px;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: #22d3ee;
    box-shadow: 0 0 6px #22d3ee;
    animation: ihb3RadarPing 1s ease-in-out infinite;
    z-index: 2;
}
@keyframes ihb3RadarPing {
    0%, 100% { opacity: 1;   transform: scale(1); }
    50%      { opacity: 0.4; transform: scale(1.6); }
}

/* Клетка своего корабля на общей карте — тонкая рамка поверх, чтобы отличать от чужих попаданий */
.ihb-grid-3p .ihb-cell.ihb-ship.ihb-hit {
    /* свой подбитый корабль — тот же красный, но с явной рамкой "это моё" */
    box-shadow: 0 0 10px var(--ihb-hit-glow), inset 0 0 0 2px rgba(255,255,255,0.5);
}

/* Легенда */
.ihb3-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    font-size: 11px;
    color: #8fa1b3;
    font-weight: 600;
}
.ihb3-legend span { display: flex; align-items: center; gap: 6px; }
.ihb3-legend-dot {
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}
.ihb3-legend-own   { background: linear-gradient(145deg, var(--ihb-ship-a), var(--ihb-ship-b)); }
.ihb3-legend-hit    { background: radial-gradient(circle at 40% 35%, #ff9a85, var(--ihb-hit) 65%); }
.ihb3-legend-radar  { background: #0d141b; box-shadow: inset 0 0 0 1px #22344a; position: relative; }
.ihb3-legend-radar::after {
    content: '';
    position: absolute; top: 1px; right: 1px;
    width: 4px; height: 4px; border-radius: 50%;
    background: #22d3ee; box-shadow: 0 0 4px #22d3ee;
}

.ihb3-leave-btn { max-width: 260px; }

/* ── Адаптивность ── */
@media (max-width: 420px) {
    .ihb3-badge-name { font-size: 11px; }
    .ihb3-legend { gap: 10px; font-size: 10px; }
}