/* ==========================================================================
   EcoCity — Cidade isométrica, legenda de regiões e painel de detalhes
   ========================================================================== */

.city-frame {
    position: relative;
    background: var(--green-frame);
    border-radius: var(--radius-lg);
    padding: 12px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.06);
}

.city-map { border-radius: var(--radius-md); overflow: hidden; background: #E8F5E9; }
.city-svg { display: block; width: 100%; height: auto; }
.city-svg-enter .city-board { animation: city-in 0.6s ease-out; }
@keyframes city-in { from { opacity: 0.35; filter: saturate(0.4); } to { opacity: 1; filter: none; } }

.city-selos {
    position: absolute; top: 22px; left: 22px; z-index: 2;
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.city-level-badge, .city-relogio {
    display: inline-flex; align-items: center; gap: 6px;
    background: rgba(255, 255, 255, 0.94); color: var(--text-green);
    padding: 6px 14px; border-radius: var(--radius-pill);
    font-size: 13px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.city-relogio { font-weight: 700; font-variant-numeric: tabular-nums; }
.city-relogio[hidden] { display: none; }
.city-relogio svg { width: 16px; height: 16px; color: #F57F17; }
.city-relogio.is-noite svg { color: #3949AB; }

.city-zoom {
    position: absolute; top: 22px; right: 22px; z-index: 2;
    display: flex; flex-direction: column; gap: 6px;
}
.city-zoom-btn {
    width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer;
    background: rgba(255, 255, 255, 0.94); color: var(--text-green);
    font-size: 20px; font-weight: 700; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); transition: background 0.2s;
}
.city-zoom-btn:hover:not(:disabled) { background: var(--green-soft); }
.city-zoom-btn:focus-visible { outline: 3px solid var(--accent-gold); outline-offset: 2px; }
.city-zoom-btn:disabled { opacity: 0.45; cursor: default; }
.city-map { touch-action: pan-y; }
.city-svg.is-zoomed { cursor: grab; touch-action: none; }
.city-svg.is-zoomed:active { cursor: grabbing; }

.city-hint { text-align: center; font-size: 12px; color: var(--text-green); margin: 10px 0 8px; }

/* Áreas de região (destaque ao passar o mouse / selecionada) */
.region-hit { cursor: pointer; }
.region-hit polygon { transition: fill 0.2s, stroke 0.2s; }
.region-hit:hover polygon,
.region-hit.is-hover polygon { fill: rgba(255, 255, 255, 0.16); stroke: rgba(255, 255, 255, 0.9); stroke-width: 2.5; }
.region-hit.is-active polygon { fill: rgba(255, 255, 255, 0.2); stroke: #FFFFFF; stroke-width: 3; stroke-dasharray: 8 5; }

/* Pontos de interação */
.city-pin { cursor: pointer; outline: none; }
.city-pin-body { transition: transform 0.2s; transform-box: fill-box; transform-origin: center; }
.city-pin:hover .city-pin-body,
.city-pin:focus-visible .city-pin-body { transform: scale(1.12); }
.city-pin:focus-visible .city-pin-body { stroke: var(--accent-gold); stroke-width: 5; }
.city-pin-pulse { opacity: 0; transform-box: fill-box; transform-origin: center; animation: pin-pulse 2.6s ease-out infinite; }
@keyframes pin-pulse { 0% { opacity: 0.45; transform: scale(1); } 100% { opacity: 0; transform: scale(1.9); } }

/* Animações do cenário */
.cloud { animation: cloud-drift 18s ease-in-out infinite alternate; }
@keyframes cloud-drift { from { translate: -18px 0; } to { translate: 18px 0; } }

.sun-glow { filter: drop-shadow(0 0 14px rgba(255, 213, 79, 0.9)); }

.smoke-puff { animation: smoke-rise 3.2s ease-in infinite; transform-box: fill-box; transform-origin: center; }
@keyframes smoke-rise {
    0%   { opacity: 0;    transform: translateY(8px) scale(0.6); }
    30%  { opacity: 0.75; }
    100% { opacity: 0;    transform: translateY(-26px) scale(1.4); }
}

.turbine-rotor { animation: turbine-spin 4s linear infinite; }
.turbine-b { animation-duration: 5.2s; }
@keyframes turbine-spin { to { transform: rotate(360deg); } }

.water-ripple { animation: ripple 3.5s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes ripple { 0% { opacity: 0.8; transform: scale(0.6); } 100% { opacity: 0; transform: scale(1.5); } }

/* Legenda de regiões (também é navegação acessível) */
.city-legend { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.legend-chip {
    display: flex; align-items: center; gap: 8px; text-align: left;
    background: var(--card-bg); border: 1px solid transparent; border-radius: var(--radius-md);
    padding: 8px 10px; cursor: pointer; transition: border-color 0.2s, transform 0.2s;
}
.legend-chip:hover { border-color: var(--primary-color); transform: translateY(-1px); }
.legend-icon { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.legend-name { font-size: 12px; font-weight: 600; line-height: 1.25; flex: 1; }
.legend-stage { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }

/* Cores dos estágios (1 crítico → 4 referência) */
.stage-1, .stage-tag-1 { background: #EFEBE9; color: #5D4037; }
.stage-2, .stage-tag-2 { background: #FFF3CD; color: #856404; }
.stage-3, .stage-tag-3 { background: #E8F5E9; color: #2E7D32; }
.stage-4, .stage-tag-4 { background: #C8E6C9; color: #1B5E20; }

/* --------------------------------------------------------------------------
   Painel de detalhes da região
   -------------------------------------------------------------------------- */
.region-panel {
    position: fixed; right: 24px; bottom: 24px; z-index: 150;
    width: min(380px, calc(100% - 32px)); max-height: calc(100vh - 48px); overflow-y: auto;
    background: var(--card-bg); border: 2px solid var(--primary-color); border-radius: var(--radius-md);
    box-shadow: var(--shadow-float); padding: 20px;
    animation: slide-up 0.3s ease-out;
}
.region-panel-close {
    position: absolute; top: 10px; right: 10px;
    width: 32px; height: 32px; border-radius: 50%; border: none;
    background: var(--locked-bg); color: var(--text-color); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.region-panel-close:hover { background: var(--track); }

.region-panel-head { display: flex; gap: 12px; align-items: center; padding-right: 36px; margin-bottom: 12px; }
.region-panel-head h3 { font-size: 16px; line-height: 1.25; margin-bottom: 4px; }
.region-panel-icon { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.region-panel-icon .icon { width: 24px; height: 24px; }

.region-panel-media {
    aspect-ratio: 16 / 9; border-radius: var(--radius-sm); overflow: hidden;
    background: var(--locked-bg); margin-bottom: 12px;
}
.region-panel-media img { width: 100%; height: 100%; object-fit: cover; }
.region-panel-placeholder {
    height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    color: var(--text-muted); font-size: 12px; text-align: center; padding: 12px;
}
.region-panel-placeholder .icon { width: 30px; height: 30px; }
.region-panel-placeholder code { font-size: 10px; background: #CFD8DC; color: #37474F; padding: 2px 6px; border-radius: 4px; }

.region-panel-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.region-panel-indicator { background: #F9FBF9; border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 12px; }

/* --------------------------------------------------------------------------
   Responsividade
   -------------------------------------------------------------------------- */
@media (max-width: 1023px) {
    .city-legend { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 767px) {
    .city-frame { padding: 8px; }
    .city-selos { position: static; margin-bottom: 8px; }
    .city-level-badge, .city-relogio { font-size: 12px; }
    .city-legend { grid-template-columns: repeat(2, 1fr); }
    .region-panel {
        right: 0; left: 0; bottom: 0; width: 100%; max-height: 80vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0; border-width: 2px 0 0;
    }
}

@media (max-width: 400px) {
    .city-legend { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   Construção nos lotes de expansão
   -------------------------------------------------------------------------- */
.city-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0 8px; }
.city-toolbar .city-hint { margin: 0; }

.city-svg.is-building { cursor: crosshair; }
.build-grid line { stroke: rgba(255, 255, 255, 0.45); stroke-width: 0.8; pointer-events: none; }
.preview-ok     { color: rgba(102, 187, 106, 0.45); stroke: #2E7D32; stroke-width: 2; }
.preview-bad    { color: rgba(229, 57, 53, 0.4);    stroke: #C62828; stroke-width: 2; }
.preview-remove { color: rgba(229, 57, 53, 0.35);   stroke: #C62828; stroke-width: 2.5; stroke-dasharray: 6 4; }
.preview-ghost  { opacity: 0.75; pointer-events: none; }

/* Tráfego e pessoas (traffic.js) */
.city-traffic { pointer-events: none; }
.city-svg.is-building .city-traffic { display: none; }
.trafego-agente { transition: opacity 0.5s; }
.trafego-agente.is-saindo { opacity: 0; }
.pessoa-anda { animation: pessoa-anda 0.5s ease-in-out infinite alternate; }
@keyframes pessoa-anda { from { transform: translateY(0); } to { transform: translateY(-1.5px); } }
@media (prefers-reduced-motion: reduce) { .pessoa-anda { animation: none; } }
#build-overlay  { pointer-events: none; }

.build-panel {
    background: var(--card-bg); border-radius: var(--radius-md); box-shadow: var(--shadow);
    padding: 12px 14px; margin-top: 10px; display: flex; flex-direction: column; gap: 10px;
}
.build-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.build-head > strong { display: inline-flex; align-items: center; gap: 6px; color: var(--primary-color); margin-right: auto; }
.build-lots { display: flex; gap: 6px; }
.build-cats { display: flex; flex-wrap: wrap; gap: 6px; }
.build-cat {
    border: 1px solid var(--border-color); background: var(--card-bg); color: var(--text-color);
    border-radius: var(--radius-pill); padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.build-cat:hover { border-color: var(--secondary-color); }
.build-cat.is-active { background: var(--primary-color); border-color: var(--primary-color); color: #FFFFFF; }
.build-palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.build-effect { font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; }
.build-effect.is-bad { background: #FFF3CD; color: #856404; }
.build-effect.is-ok  { background: var(--green-soft); color: var(--primary-color); }
.build-pollution { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 12px; }
.build-pollution span { display: inline-flex; align-items: center; gap: 4px; }
.build-pollution .icon { width: 14px; height: 14px; }
.build-pollution .is-bad { color: #856404; font-weight: 600; }
.build-pollution .is-ok  { color: var(--primary-color); }
.build-item {
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
    background: #F7F9F7; border: 2px solid transparent; border-radius: var(--radius-sm);
    padding: 8px 10px; font-size: 12px; cursor: pointer; transition: border-color 0.2s;
}
.build-item strong { font-size: 13px; }
.build-item:hover:not(:disabled) { border-color: var(--secondary-color); }
.build-item.is-selected { border-color: var(--primary-color); background: var(--green-soft); }
.build-item:disabled { opacity: 0.55; cursor: not-allowed; }
.build-cost { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; color: var(--credits-color); }
.build-cost.is-short { color: var(--error-fg); }
.build-lock { display: inline-flex; align-items: center; gap: 3px; color: var(--error-fg); font-weight: 600; }
.build-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.build-status { flex: 1 1 220px; font-size: 13px; color: var(--text-color); }
#build-remove.is-active { background: var(--error-bg); }

@media (max-width: 767px) {
    /* No celular o zoom sai de cima do mapa (que é pequeno) e vira uma linha acima dele */
    .city-zoom { position: static; flex-direction: row; justify-content: flex-end; margin-bottom: 8px; }
    .city-zoom-btn { width: 44px; height: 44px; }   /* área de toque */
    .city-toolbar { flex-direction: column; align-items: stretch; }
    .build-palette { grid-template-columns: repeat(2, 1fr); }
    .build-cat { min-height: 44px; }
    .build-actions { order: -1; }   /* status e "Construir aqui" logo abaixo do mapa, sem rolar */
    .build-actions .btn { flex: 1; }
}

/* Efeitos das estruturas (RN77–RN79): habitantes, renda e moedas no mapa */
.city-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.city-pop { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-green); background: var(--green-soft); border-radius: 20px; padding: 6px 12px; }
.city-pop svg { width: 16px; height: 16px; }
.city-collect svg { width: 16px; height: 16px; }
.city-coin { cursor: pointer; }
.city-coin-body { animation: coin-bob 1.6s ease-in-out infinite; }
.city-coin:focus-visible .city-coin-body circle:first-child { stroke: #1B5E20; stroke-width: 3.5; }
@keyframes coin-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.build-effect.is-info { background: #E1F5FE; color: #01579B; }
@media (prefers-reduced-motion: reduce) { .city-coin-body { animation: none; } }
@media (max-width: 767px) {
    .city-actions { justify-content: stretch; }
    .city-actions > * { flex: 1 1 auto; justify-content: center; min-height: 44px; }
}

/* Cidade viva (vida.js): noite, luzes, atitudes das pessoas e animais */
.city-noite, .city-luzes, .city-vida-topo { pointer-events: none; }
.city-noite { transition: opacity 0.4s linear; }
.city-svg.is-building .city-noite, .city-svg.is-building .city-estrelas, .city-svg.is-building .city-luzes, .city-svg.is-building .city-vida-topo { display: none; }
.trafego-agente.is-parada .pessoa-anda { animation: none; }
.trafego-agente .pessoa-anda { transform-box: fill-box; }
.trafego-agente.faz-sentar .pessoa-anda { transform: translateY(2.5px) scaleY(0.78); transform-origin: center bottom; }
.trafego-agente.faz-cata .pessoa-anda { transform: rotate(22deg); transform-origin: center bottom; }
.trafego-agente.faz-colher .pessoa-anda { transform: translateY(-1px); }
.trafego-agente.faz-brincar .pessoa-anda { animation: vida-balanca 0.9s ease-in-out infinite alternate; transform-origin: center top; }
.trafego-agente.faz-jogar .pessoa-anda { animation: vida-pula 0.45s ease-in-out infinite alternate; }
@keyframes vida-balanca { from { transform: rotate(-14deg); } to { transform: rotate(14deg); } }
@keyframes vida-pula { from { transform: translateY(0); } to { transform: translateY(-3px); } }
.vida-balao { transform-box: fill-box; transform-origin: center bottom; animation: vida-balao 0.3s ease-out; }
@keyframes vida-balao { from { transform: scale(0.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.vida-bola { animation: vida-bola 0.45s ease-in infinite alternate; }
@keyframes vida-bola { from { transform: translateY(-7px); } to { transform: translateY(0); } }
.vida-gotas { animation: vida-gotas 0.8s linear infinite; }
@keyframes vida-gotas { from { transform: translateY(0); opacity: 1; } to { transform: translateY(4px); opacity: 0; } }
.vida-fruta { animation: vida-pula 0.6s ease-in-out infinite alternate; }
.vida-cachorro { animation: vida-pula 0.3s ease-in-out infinite alternate; }
.is-parada .vida-cachorro { animation: none; }
.vida-pombo { animation: vida-bica 0.9s ease-in-out infinite; transform-box: fill-box; transform-origin: center bottom; }
@keyframes vida-bica { 0%, 60%, 100% { transform: rotate(0); } 75% { transform: rotate(25deg); } }
.vida-asa { transform-box: fill-box; transform-origin: center bottom; animation: vida-asa 0.35s ease-in-out infinite alternate; }
@keyframes vida-asa { from { transform: scaleY(1); } to { transform: scaleY(-0.6); } }
.vida-luz-balada { animation: vida-luz 1.1s ease-in-out infinite alternate; }
@keyframes vida-luz { from { opacity: 0.35; } to { opacity: 1; } }

/* Céu do dia e da noite (roda girada por traffic.js) */
.estrela-pisca { animation: estrela-pisca 2.4s ease-in-out infinite alternate; }
@keyframes estrela-pisca { from { opacity: 1; } to { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .estrela-pisca { animation: none; } }
