/* LiveDefense — Layout responsivo (mobile-first) */

/* ===== Base / Mobile ===== */
#topbar {
  position: absolute;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  height: 52px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  background: linear-gradient(180deg, rgba(9, 11, 16, 0.97), rgba(9, 11, 16, 0.7));
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 150px;
}

.sigil {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  color: var(--gold-bright);
  background: radial-gradient(circle, rgba(212, 160, 23, 0.25), rgba(212, 160, 23, 0.02));
  border: 1px solid rgba(212, 160, 23, 0.45);
  transform: rotate(45deg);
}
.sigil span { transform: rotate(-45deg); font-size: 14px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong {
  font-family: 'Cinzel', serif;
  font-size: 14px;
  letter-spacing: 0.06em;
}
.brand-text small {
  font-size: 8px;
  color: var(--faint);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.resources {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.res {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line-soft);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
}
.res-ico {
  width: 8px; height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 7px currentColor;
}
.res-ico.gold { background: #d4a017; color: #d4a017; }
.res-ico.wood { background: #8b5a2b; color: #8b5a2b; }
.res-ico.iron { background: #8d99a8; color: #8d99a8; }
.res-ico.gems { background: #9b59b6; color: #9b59b6; }

.territory {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: right;
}
.territory strong {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: 13px;
  letter-spacing: 0.04em;
}
.territory small {
  color: var(--muted);
  font-size: 9px;
}
.level {
  padding: 3px 8px;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--gold-bright);
  background: var(--gold-soft);
  border: 1px solid rgba(212, 160, 23, 0.35);
}

.top-actions {
  display: none; /* oculto por padrão no mobile, ícones no menu */
  gap: 4px;
}
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #262d3c, #1a1f2a);
  color: var(--text);
  border-radius: 7px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.14s, border-color 0.14s, background 0.14s, opacity 0.14s;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, #e7b62a, #b8890f);
  color: #17120a;
  border-color: #f0c94a;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 8px; font-size: 10px; }
.btn.icon {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-size: 16px;
}

/* ===== Wave card ===== */
#wavecard {
  position: absolute;
  top: 64px;
  left: 10px;
  width: calc(100% - 20px);
  max-width: 260px;
  z-index: 35;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(24, 29, 40, 0.92), rgba(12, 15, 21, 0.92));
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.wave-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.wave-head strong {
  font-family: 'Cinzel', serif;
  font-size: 20px;
  color: var(--gold-bright);
  line-height: 1;
}
.wave-head .status {
  margin-left: auto;
  font-size: 9px;
  color: var(--muted);
}
.progress {
  height: 4px;
  border-radius: 2px;
  background: #0a0c11;
  overflow: hidden;
  margin: 8px 0 7px;
  border: 1px solid var(--line-soft);
}
.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #8f6a10, var(--gold-bright));
  transition: width 0.25s linear;
}
.wave-foot {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wave-foot .threat {
  font-size: 9px;
  color: var(--muted);
}
.wave-foot .threat.low { color: var(--green); }
.wave-foot .threat.mid { color: var(--gold-bright); }
.wave-foot .threat.high { color: var(--red); }
.wave-foot .btn { margin-left: auto; }

/* ===== Hotbar (âncora inferior, sensível ao safe area) ===== */
#hotbar {
  position: absolute;
  left: 50%;
  bottom: env(safe-area-inset-bottom);
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 35;
  padding: 2px 4px 8px;
  max-width: calc(100vw - 8px);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  transition: transform 0.32s ease, opacity 0.2s ease;
  pointer-events: auto;
}
#hotbar::-webkit-scrollbar { display: none; }
#hotbar .slot { flex: 0 0 auto; }
body.panel-open #hotbar {
  transform: translateX(-50%) translateY(8px);
  opacity: 0.5;
  pointer-events: none;
}
.slot {
  position: relative;
  width: 56px;
  height: 62px;
  padding: 5px 3px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: linear-gradient(180deg, rgba(34, 40, 54, 0.95), rgba(14, 17, 24, 0.96));
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.14s, border-color 0.14s, box-shadow 0.14s;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  touch-action: manipulation;
}
.slot:active { transform: translateY(-2px); }
.slot.selected {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(212, 160, 23, 0.28), rgba(60, 44, 10, 0.9));
  box-shadow: 0 0 0 1px rgba(212, 160, 23, 0.5), 0 10px 26px rgba(212, 160, 23, 0.18);
}
.slot.unaffordable { opacity: 0.45; }
.slot .key {
  position: absolute;
  top: 3px;
  left: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--faint);
}
.slot .icon {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  color: var(--gold-bright);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}
.slot .icon svg { width: 18px; height: 18px; }
.slot.selected .icon { color: #ffe08a; }
.slot.unaffordable .icon { color: #6a7180; }
.slot .sname {
  font-size: 7.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.1;
}
.slot .cost {
  font-family: 'JetBrains Mono', monospace;
  font-size: 7.5px;
  color: var(--gold);
}
.slot.unaffordable .cost { color: var(--red); }

/* Build hint */
#buildhint {
  position: absolute;
  bottom: env(safe-area-inset-bottom);
  left: 50%;
  transform: translate(-50%, 10px);
  padding: 7px 14px;
  border-radius: 999px;
  z-index: 45;
  background: rgba(212, 160, 23, 0.18);
  border: 1px solid rgba(212, 160, 23, 0.55);
  color: var(--gold-bright);
  font-size: 11px;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 14px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#buildhint.hidden { opacity: 0; transform: translate(-50%, 14px); pointer-events: none; }

/* ===== Minimap ===== */
#minimap {
  position: absolute;
  bottom: env(safe-area-inset-bottom);
  right: 10px;
  z-index: 35;
  width: 150px;
  padding: 6px 6px 7px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(24, 29, 40, 0.94), rgba(11, 14, 20, 0.95));
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow);
}
.mm-head {
  display: flex;
  justify-content: space-between;
  padding: 1px 3px 5px;
  font-size: 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.mm-head .coords { font-family: 'JetBrains Mono', monospace; letter-spacing: 0; color: var(--gold); }
#minimap-canvas {
  width: 100%;
  display: block;
  border-radius: 6px;
  cursor: pointer;
  touch-action: none;
}

/* ===== Context panel (entidade selecionada) ===== */
#context {
  position: absolute;
  top: 64px;
  right: 10px;
  width: calc(100% - 20px);
  max-width: 320px;
  z-index: 30;
  padding: 12px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(24, 29, 40, 0.95), rgba(11, 14, 20, 0.96));
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
#context.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.ctx-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--line); background: rgba(255, 255, 255, 0.04); }
#ctx-title {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  letter-spacing: 0.03em;
  margin-bottom: 8px;
}
.ctx-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  margin-bottom: 8px;
}
.stat {
  display: flex;
  justify-content: space-between;
  gap: 5px;
  padding: 4px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
}
.stat span { font-size: 9px; color: var(--muted); }
.stat b {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  font-weight: 600;
}
.hp-line {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--muted);
  margin-bottom: 3px;
}
.hp-line b {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
}
.bar {
  height: 6px;
  border-radius: 3px;
  background: #080a0e;
  border: 1px solid var(--line-soft);
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--green);
  transition: width 0.2s, background 0.2s;
}
.ctx-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}
.ctx-actions .btn {
  flex: 1 1 calc(50% - 6px);
  padding: 6px 7px;
  font-size: 10px;
}
.ctx-actions .btn.danger {
  border-color: rgba(216, 79, 63, 0.5);
  color: #ff9b8f;
}
.ctx-actions .btn.danger:hover {
  border-color: var(--red);
  background: rgba(216, 79, 63, 0.14);
}

/* ===== Side panel ===== */
#sidepanel {
  position: absolute;
  top: 52px;
  right: 0;
  bottom: 0;
  width: min(340px, 92vw);
  z-index: 38;
  background: linear-gradient(180deg, rgba(14, 17, 24, 0.98), rgba(9, 11, 16, 0.99));
  border-left: 1px solid var(--line-soft);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.45);
  transform: translateX(100%);
  transition: transform 0.26s ease;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
#sidepanel.show { transform: translateX(0); }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--gold-bright);
}
#panel-body {
  padding: 12px 14px 20px;
  overflow-y: auto;
}
#panel-body::-webkit-scrollbar { width: 5px; }
#panel-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
#panel-body p {
  color: var(--muted);
  line-height: 1.55;
  font-size: 11px;
}
.panel-section { margin-bottom: 16px; }
.panel-section h3 {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 7px;
}
.panel-card {
  padding: 11px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line-soft);
  margin-bottom: 7px;
}
.map-wrap canvas {
  width: 100%;
  border-radius: 7px;
  display: block;
  border: 1px solid var(--line-soft);
}
.legend {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  gap: 5px 12px;
  margin-top: 8px;
  font-size: 9px;
  color: var(--muted);
}
.legend i {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  display: inline-block;
  margin-right: 4px;
}
.inv-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}
.inv-slot {
  aspect-ratio: 1;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line-soft);
  display: grid;
  place-items: center;
  font-family: 'Cinzel', serif;
  font-size: 12px;
  color: var(--muted);
}
.inv-slot.item {
  border-color: rgba(212, 160, 23, 0.4);
  background: rgba(212, 160, 23, 0.09);
  color: var(--gold-bright);
}
.member {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-soft);
}
.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3a4a60, #1d2634);
  border: 1px solid var(--line);
}
.member .name {
  font-weight: 600;
  font-size: 11px;
}
.member .role {
  font-size: 9px;
  color: var(--muted);
}
.member .dot {
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}
.branch {
  padding: 9px;
  border-radius: 7px;
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.03);
  margin-bottom: 7px;
}
.branch-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}
.branch-head strong {
  font-family: 'Cinzel', serif;
  font-size: 12px;
}
.branch-head span {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--gold);
}
.skill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 10px;
  color: var(--muted);
}
.skill b { color: var(--text); font-weight: 500; }
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 11px;
}
.setting small {
  display: block;
  color: var(--faint);
  font-size: 9px;
  margin-top: 1px;
}
.switch {
  position: relative;
  width: 34px;
  height: 18px;
  flex: 0 0 auto;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch i {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #2a3040;
  border: 1px solid var(--line);
  transition: background 0.2s;
  cursor: pointer;
}
.switch i::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #9aa0ad;
  transition: transform 0.2s, background 0.2s;
}
.switch input:checked + i { background: rgba(212, 160, 23, 0.35); border-color: var(--gold); }
.switch input:checked + i::after { transform: translateX(16px); background: var(--gold-bright); }
select, input[type="range"] { accent-color: var(--gold); }
select {
  background: #1a1f2a;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 7px;
  font-family: inherit;
  font-size: 10px;
}

/* ===== Hint / Toasts / Tooltip ===== */
#hint {
  position: absolute;
  left: 10px;
  bottom: env(safe-area-inset-bottom);
  z-index: 20;
  font-size: 9px;
  color: rgba(233, 230, 223, 0.45);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  max-width: 250px;
  line-height: 1.5;
  transition: opacity 0.25s;
  padding-bottom: 8px;
}
body.panel-open #hint { opacity: 0; }
#hint b {
  color: rgba(255, 212, 90, 0.85);
  font-weight: 600;
}

#toasts {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  pointer-events: none;
  padding-bottom: env(safe-area-inset-bottom);
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(20, 24, 33, 0.96);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s ease-out;
  max-width: 85vw;
  pointer-events: auto;
}
.toast .ti {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  flex: 0 0 auto;
  background: rgba(61, 143, 214, 0.2);
  color: #8fc6ff;
}
.toast.success { border-color: rgba(62, 207, 106, 0.45); }
.toast.success .ti { background: rgba(62, 207, 106, 0.18); color: var(--green); }
.toast.error { border-color: rgba(216, 79, 63, 0.5); }
.toast.error .ti { background: rgba(216, 79, 63, 0.18); color: #ff8d7e; }
.toast.warn { border-color: rgba(212, 160, 23, 0.5); }
.toast.warn .ti { background: rgba(212, 160, 23, 0.18); color: var(--gold-bright); }
.toast.out {
  opacity: 0;
  transform: translateY(-6px);
  transition: all 0.28s;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

#tooltip {
  position: absolute;
  z-index: 50;
  display: none;
  pointer-events: none;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(12, 15, 21, 0.96);
  border: 1px solid var(--line);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
  font-size: 9.5px;
  line-height: 1.4;
  max-width: 220px;
}
#tooltip strong {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: 11px;
  color: var(--gold-bright);
}
#tooltip span {
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

/* ===== Desktop enhancements ===== */
@media (min-width: 768px) {
  #topbar { height: 56px; padding: 0 14px; top: env(safe-area-inset-top); }
  .top-actions { display: flex; }
  #wavecard {
    top: 68px;
    left: 14px;
    width: 236px;
    max-width: none;
  }
  #hotbar { bottom: 16px; }
  #buildhint { bottom: 96px; }
  #minimap {
    bottom: 16px;
    right: 16px;
    width: 178px;
    padding: 7px 7px 8px;
  }
  #context {
    top: 68px;
    right: 16px;
    width: 296px;
    max-width: none;
  }
  #sidepanel { width: 344px; top: 56px; }
  #hint {
    left: 16px;
    bottom: 98px;
    font-size: 10px;
    padding-bottom: 0;
  }
  #toasts { top: 66px; padding-bottom: 0; }
  .slot { width: 68px; height: 70px; }
  .slot .sname { font-size: 8px; }
  .slot .cost { font-size: 8.5px; }
}
