/* Mappa dei quartieri: zoom, "Vai a", righelli, mirino e tooltip delle case.
   Fa parte degli stili del gioco: fragments/game-styles.html li include
   in ordine dopo game.css. */

/* Zoom della mappa. */
.map-zoom-controls {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: .5rem;
}

.map-zoom-value {
    min-width: 3.2rem;
    text-align: center;
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
}

/* Vai a: posizione o giocatore. */
.map-goto {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem 1rem;
}

.map-goto-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem;
}

.map-goto-form input[type="number"] {
    width: 5.2rem;
}

.map-goto-form input[type="search"] {
    width: 12rem;
}

/* Con la mappa ingrandita le case mostrano sigla e nome del proprietario. */
.city-map-frame.map-zoomed .city-cell.occupied {
    flex-direction: column;
    gap: 1px;
}

.city-map-frame.map-zoomed .city-cell.occupied::after {
    content: attr(data-owner);
    max-width: calc(var(--map-cell) - 4px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .5rem;
    line-height: 1;
    color: #f4ead5;
}

/* Posizione raggiunta con "Vai a". */
.map-focus-marker {
    pointer-events: none;
    border: 2px solid var(--aged-gold-bright);
    border-radius: 4px;
    box-shadow: 0 0 0 4px rgba(194, 164, 109, 0.25);
    z-index: 5;
    animation: map-focus-pulse 1s ease-in-out 3;
}

@keyframes map-focus-pulse {
    50% {
        box-shadow: 0 0 0 10px rgba(194, 164, 109, 0.05);
    }
}

@media (prefers-reduced-motion: reduce) {
    .map-focus-marker {
        animation: none;
    }
}

.map-main {
    min-width: 0;
}

/* Griglia con righelli: angolo, righello X in alto, righello Y a sinistra. */
.city-map-frame {
    --map-cell: 20px;
    display: grid;
    grid-template-columns: 26px auto;
    grid-template-rows: 20px auto;
    width: max-content;
}

.map-ruler-corner,
.map-ruler {
    background: #0b0c10;
    z-index: 7;
}

.map-ruler-corner {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 8;
}

.map-ruler {
    display: grid;
    color: var(--text-muted);
    font-size: .6rem;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.map-ruler-x {
    grid-template-columns: repeat(50, var(--map-cell));
    padding-left: 1px;
    position: sticky;
    top: 0;
}

.map-ruler-y {
    grid-template-rows: repeat(50, var(--map-cell));
    padding-top: 1px;
    position: sticky;
    left: 0;
}

/* Tacca per ogni posizione, numero ogni cinque. */
.map-ruler span {
    position: relative;
}

.map-ruler-x span {
    border-left: 1px solid rgba(194, 164, 109, 0.18);
    padding: 3px 0 0 2px;
}

.map-ruler-y span {
    border-top: 1px solid rgba(194, 164, 109, 0.18);
    padding: 2px 4px 0 0;
    text-align: right;
}

.map-ruler span.major {
    color: var(--aged-gold-bright);
    border-color: rgba(194, 164, 109, 0.55);
}

/* Ogni posizione ha la sua riga: sottile per cella, piu' marcata ogni 5,
   piena ogni 10; i blocchi 10x10 si alternano come isolati della citta'. */
.city-map-grid {
    --line-cell: rgba(194, 164, 109, 0.09);
    --line-five: rgba(194, 164, 109, 0.2);
    --line-ten: rgba(194, 164, 109, 0.38);
    display: grid;
    grid-template-columns: repeat(50, var(--map-cell));
    grid-template-rows: repeat(50, var(--map-cell));
    position: relative;
    border: 1px solid var(--line-ten);
    background-color: #14151a;
    background-image:
        linear-gradient(to right, var(--line-ten) 1px, transparent 1px),
        linear-gradient(to bottom, var(--line-ten) 1px, transparent 1px),
        linear-gradient(to right, var(--line-five) 1px, transparent 1px),
        linear-gradient(to bottom, var(--line-five) 1px, transparent 1px),
        linear-gradient(to right, var(--line-cell) 1px, transparent 1px),
        linear-gradient(to bottom, var(--line-cell) 1px, transparent 1px),
        conic-gradient(rgba(194, 164, 109, 0.035) 25%, transparent 0 50%, rgba(194, 164, 109, 0.035) 0 75%, transparent 0);
    background-size:
        calc(var(--map-cell) * 10) calc(var(--map-cell) * 10),
        calc(var(--map-cell) * 10) calc(var(--map-cell) * 10),
        calc(var(--map-cell) * 5) calc(var(--map-cell) * 5),
        calc(var(--map-cell) * 5) calc(var(--map-cell) * 5),
        var(--map-cell) var(--map-cell),
        var(--map-cell) var(--map-cell),
        calc(var(--map-cell) * 20) calc(var(--map-cell) * 20);
}

/* Mirino sulla posizione puntata: riga e colonna evidenziate, cella
   contornata. Lo posiziona il JavaScript. */
.map-crosshair {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.map-crosshair-row,
.map-crosshair-col,
.map-crosshair-cell {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.map-crosshair-row {
    width: 100%;
    height: var(--map-cell);
    background: rgba(194, 164, 109, 0.07);
}

.map-crosshair-col {
    width: var(--map-cell);
    height: 100%;
    background: rgba(194, 164, 109, 0.07);
}

.map-crosshair-cell {
    width: var(--map-cell);
    height: var(--map-cell);
    border: 1px solid var(--aged-gold-bright);
    border-radius: 3px;
    z-index: 4;
}

.map-position {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin: .5rem 0 0;
    min-height: 1.4rem;
    font-size: .8rem;
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
}

.map-position .bi {
    color: var(--aged-gold);
}

.city-cell {
    width: var(--map-cell);
    height: var(--map-cell);
    position: relative;
    border-radius: 3px;
    color: #f7e6bf;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
}

.city-cell.occupied {
    background: linear-gradient(145deg, rgba(75, 30, 42, 0.86), rgba(125, 46, 69, 0.78));
    border-color: rgba(194, 164, 109, 0.45);
    box-shadow: inset 0 0 0 1px rgba(194, 164, 109, 0.34);
}

.map-tooltip {
    display: none;
    position: absolute;
    left: 50%;
    top: calc(100% + 6px);
    transform: translateX(-50%);
    z-index: 5;
    background: #0f1217;
    border: 1px solid rgba(194, 164, 109, 0.4);
    border-radius: .5rem;
    color: #f4ead5;
    padding: .3rem .45rem;
    font-size: .7rem;
    white-space: nowrap;
    box-shadow: 0 .4rem 1rem rgba(0, 0, 0, 0.45);
}

/* Tooltip anche al focus (tastiera e tocco); le celle occupate sono
   selezionabili e quella attiva sta sopra le vicine. */
.city-cell:hover .map-tooltip,
.city-cell:focus .map-tooltip {
    display: block;
}

.city-cell:hover,
.city-cell:focus {
    z-index: 6;
}

.city-cell.occupied {
    cursor: pointer;
}

.city-cell:focus-visible {
    outline: 2px solid var(--aged-gold);
    outline-offset: 1px;
}

.city-cell.own {
    background: linear-gradient(145deg, rgba(24, 50, 45, 0.95), rgba(59, 121, 105, 0.85));
    border-color: rgba(194, 164, 109, 0.6);
}

/* Case dei membri della propria Famiglia: si riconoscono a colpo d'occhio. */
.city-cell.family {
    background: linear-gradient(145deg, rgba(28, 36, 64, 0.95), rgba(70, 96, 160, 0.85));
    border-color: rgba(194, 164, 109, 0.45);
}

.city-cell.selected {
    outline: 2px solid #f5e9d0;
    outline-offset: 1px;
    z-index: 6;
}

/* Vicino ai bordi il tooltip si apre verso l'interno della griglia. */
.city-cell.tooltip-above .map-tooltip {
    top: auto;
    bottom: calc(100% + 6px);
}

.city-cell.tooltip-start .map-tooltip {
    left: 0;
    transform: none;
}

.city-cell.tooltip-end .map-tooltip {
    left: auto;
    right: 0;
    transform: none;
}

.legend-dot.own {
    background: #3b7969;
    border: 1px solid rgba(194, 164, 109, 0.6);
}

.legend-dot.family {
    background: #4660a0;
    border: 1px solid rgba(194, 164, 109, 0.45);
}

.map-selection {
    border-top: 1px solid var(--border-soft);
    padding-top: .75rem;
}

.map-legend {
    border-radius: .9rem;
}

.legend-dot {
    width: .7rem;
    height: .7rem;
    border-radius: 50%;
    display: inline-block;
    margin-right: .45rem;
}

.legend-dot.occupied {
    background: #c06a7c;
}

.legend-dot.empty {
    background: rgba(230, 223, 210, 0.25);
    border: 1px solid rgba(230, 223, 210, 0.5);
}

@media (max-width: 1199px) {
    .map-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 767px) {
    .map-toolbar {
        grid-template-columns: auto 1fr auto;
    }

    .map-toolbar .small {
        grid-column: 1 / -1;
    }
}

/* Modulo della spedizione nel popup della mappa: su schermi stretti restano
   solo tipo, disponibili e scelta, senza scorrere la tabella di lato. */
@media (max-width: 767.98px) {
    #mapActionModal [data-expedition-config] .table th:not(:first-child):not(:nth-last-child(-n+2)),
    #mapActionModal [data-expedition-config] .table td:not(:first-child):not(:nth-last-child(-n+2)) {
        display: none;
    }

    #mapActionModal [data-expedition-config] .table {
        font-size: .8rem;
    }

    /* Nome e categoria vanno a capo invece di allargare la tabella. */
    #mapActionModal [data-expedition-config] .table td:first-child {
        white-space: normal !important;
    }

    #mapActionModal [data-expedition-config] .table th {
        white-space: normal !important;
    }

    #mapActionModal .expedition-unit-cell {
        min-width: 0;
    }

    #mapActionModal .expedition-unit-cell .input-group {
        flex-wrap: nowrap;
    }

    #mapActionModal .expedition-unit-cell .form-control {
        min-width: 2.25rem;
        padding-left: .3rem;
        padding-right: .3rem;
    }

    #mapActionModal .expedition-unit-cell .btn {
        padding-left: .35rem;
        padding-right: .35rem;
    }

    /* Il popup fa gia' da cornice: niente secondo riquadro attorno al modulo. */
    #mapActionModal [data-expedition-config].stats-card {
        padding: 0;
        border: 0;
        background: none;
        box-shadow: none;
    }

    #mapActionModal [data-expedition-config] .table > :not(caption) > * > * {
        padding-left: .25rem;
        padding-right: .25rem;
    }
}

/* Telefoni piu' stretti: categoria e "Max" lasciano spazio a −/+ e al numero
   (i disponibili restano nella loro colonna). */
@media (max-width: 399.98px) {
    #mapActionModal [data-expedition-config] .table td:first-child .badge,
    #mapActionModal .expedition-unit-cell [data-fill-max] {
        display: none;
    }
}
