:root {
  --bg: #fbf3e7;
  --cream: #fffaf1;
  --brown: #8a5a3b;
  --brown-dark: #5c3a24;
  --peach: #f6b97a;
  --peach-dark: #e08e4f;
  --green: #6fb08f;
  --red: #e46a6a;
  --shadow: rgba(90, 60, 30, 0.18);
  font-size: 16px;
}

* { box-sizing: border-box; }

.site-logo {
  display: block;
  margin: 0 auto 4px;
  height: 90px;
  width: auto;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  font-family: "Segoe UI Rounded", "Segoe UI", Verdana, sans-serif;
  color: var(--brown-dark);
  display: flex;
  justify-content: center;
  padding: 24px 16px 48px;
}

.app { width: 100%; max-width: 1380px; }
.app.hidden { display: none; }

.app-header {
  position: relative;
  text-align: center;
  margin-bottom: 16px;
}

.subtitle {
  margin: 0;
  color: var(--brown);
  opacity: 0.8;
}

.back-link {
  position: absolute;
  left: 0;
  top: 4px;
  width: auto;
  background: transparent;
  color: var(--brown);
  font-weight: 600;
  padding: 6px 10px;
}

.back-link:hover { background: #fff; }

.phase-indicator {
  position: absolute;
  right: 0;
  top: 4px;
  color: var(--brown-dark);
  font-weight: 700;
  font-size: 0.82rem;
  background: var(--peach);
  padding: 6px 12px;
  border-radius: 999px;
}

/* ---------- phase select screen ---------- */
.phase-select {
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: center;
}

.phase-select.hidden { display: none; }

.phase-select-inner {
  text-align: center;
  width: 100%;
}


.chapters-wrap {
  margin-top: 20px;
}

.chapter-block {
  margin-bottom: 32px;
}

.chapter-title {
  margin: 0 0 4px;
  font-size: 1.3rem;
  color: var(--brown-dark);
}

.chapter-note {
  margin: 8px 0 0;
  color: var(--brown);
  opacity: 0.75;
  font-style: italic;
}

.phase-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.phase-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--cream);
  border: 3px solid var(--peach);
  border-radius: 16px;
  padding: 20px 10px;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  width: 100%;
  box-shadow: 0 6px 16px var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.phase-card:hover:not(.locked) {
  transform: translateY(-3px);
  box-shadow: 0 10px 22px var(--shadow);
}

.phase-card .phase-num {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--peach-dark);
  font-weight: 700;
}

.phase-card .phase-name {
  font-family: "Segoe UI Rounded", "Segoe UI", sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--brown-dark);
}

.phase-card .phase-desc {
  font-size: 0.82rem;
  color: var(--brown);
  opacity: 0.75;
  line-height: 1.35;
}

.phase-card.locked {
  cursor: not-allowed;
  border-style: dashed;
  border-color: var(--brown);
  opacity: 0.55;
}

.phase-card.locked .phase-name { color: var(--brown); }

.layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
}

.board-col {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.board-wrap {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 10px 24px var(--shadow);
  border: 6px solid var(--peach);
  line-height: 0;
}

.bestiary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 190px;
  width: 190px;
}

.beast-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--cream);
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 0 2px 6px var(--shadow);
}

.beast-card .beast-icon {
  position: relative;
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
}

.beast-card .beast-icon .crown {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
}

.beast-card .beast-info { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.beast-card .beast-name { font-size: 0.72rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.beast-card .beast-stats { font-size: 0.72rem; color: var(--brown); opacity: 0.85; }
.beast-card.is-boss { background: #fdf0e4; box-shadow: 0 2px 6px rgba(196, 30, 58, 0.3); }

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #cfe7bd;
  cursor: pointer;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(60, 38, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay.hidden { display: none; }

.overlay-card {
  background: var(--cream);
  border-radius: 16px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 12px 28px rgba(0,0,0,0.3);
  /* .board-wrap (o pai, lá fora) zera line-height só pra tirar o espacinho
     embaixo do <canvas> — mas isso herda pra dentro do card e empilhava
     linhas de texto que quebram (mensagens longas) uma em cima da outra. */
  line-height: 1.4;
}

.overlay-card h2 { margin-top: 0; }

.overlay-card button {
  margin-top: 12px;
}

#next-phase-btn { background: var(--green); }
#next-phase-btn.hidden { display: none; }

.btn-secondary {
  background: var(--cream);
  color: var(--brown-dark);
  border: 2px solid var(--brown);
}

.tech-trigger {
  position: relative;
  flex: 0 0 auto;
  width: auto;
  background: var(--peach-dark);
}

.tech-trigger.hidden { display: none; }

/* Selo "Novo!" — usado no Arqueiro (loja, Fase 2) e no botão de Tecnologia
   (Fase 4). Escondido por padrão; a classe .is-new no elemento pai é que
   revela (ver highlightedShopKey/highlightTechBtn em main.js). */
.new-badge { display: none; }

.is-new {
  border-color: var(--green);
  animation: new-pulse 1.4s ease-in-out infinite;
}

.is-new .new-badge {
  display: block;
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--green);
  color: white;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

@keyframes new-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(111, 176, 143, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(111, 176, 143, 0); }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(60, 38, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}

.modal.hidden { display: none; }

.modal-card {
  position: relative;
  background: var(--cream);
  border-radius: 16px;
  padding: 28px 32px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-card h2 { margin-top: 0; }

.story-card {
  max-width: 480px;
  text-align: left;
}

.sell-confirm-card {
  max-width: 360px;
  text-align: center;
}

#sell-confirm-text {
  margin: 0 0 4px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--brown-dark);
}

#sell-confirm-yes { background: var(--red); }

.story-speaker {
  margin: 0 0 8px;
  font-weight: 700;
  color: var(--brown-dark);
}

.story-text {
  margin: 0 0 16px;
  line-height: 1.4;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--brown-dark);
  font-weight: 700;
  line-height: 1;
}

.sidebar {
  width: 280px;
  flex: 0 0 280px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: var(--cream);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 4px 12px var(--shadow);
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--brown);
}

.stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.stat-label { color: var(--brown); opacity: 0.85; }
.stat-value { font-size: 1.1rem; }

.shop-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shop-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 2px solid var(--peach);
  background: #fff;
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.shop-item:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px var(--shadow);
}

.shop-item.selected {
  border-color: var(--green);
  background: #eaf7ee;
}

.shop-item.unaffordable {
  opacity: 0.45;
}

.tower-icon {
  position: relative;
  width: 1.7rem;
  height: 1.7rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  line-height: 1;
}

.tower-icon .badge {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  line-height: 1;
}

.shop-item .info { display: flex; flex-direction: column; }
.shop-item .info .name { font-weight: 700; font-size: 0.9rem; color: var(--brown-dark); }
.shop-item .info .cost { font-size: 0.8rem; color: var(--brown); opacity: 0.8; }
.shop-item .info .extra { font-size: 0.72rem; color: var(--brown); opacity: 0.75; line-height: 1.25; }
.shop-item .info .extra:empty { display: none; }
.shop-item .info .note { font-size: 0.72rem; color: var(--brown); opacity: 0.65; line-height: 1.25; }

.tech-hint { margin: 0 0 10px; }

.tech-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tech-lane {
  display: flex;
  flex-direction: column;
}

.tech-lane-title {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--brown);
}

.tech-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tech-row-2 {
  margin-top: 16px;
}

.tech-row-2 .tech-item,
.tech-empty-slot {
  position: relative;
}

.tech-row-2 .tech-item::before {
  content: "";
  position: absolute;
  top: -16px;
  left: 50%;
  width: 2px;
  height: 16px;
  background: var(--peach-dark);
  transform: translateX(-50%);
}

.tech-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 2px solid var(--peach);
  background: #fff;
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  width: 100%;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.tech-item:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px var(--shadow);
}

.tech-item:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tech-item.acquired {
  border-color: var(--green);
  background: #eaf7ee;
  opacity: 1;
}

.tech-item.locked {
  opacity: 0.4;
  text-decoration: line-through;
  cursor: not-allowed;
}

.tech-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tech-emoji { font-size: 1.2rem; line-height: 1; }
.tech-name { font-weight: 700; font-size: 0.88rem; color: var(--brown-dark); flex: 1; }
.tech-cost {
  font-family: inherit;
  font-size: 0.72rem;
  background: var(--peach);
  color: var(--brown-dark);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.tech-deltas { font-size: 0.76rem; color: var(--brown); opacity: 0.85; }
.tech-note { font-size: 0.72rem; color: var(--brown); opacity: 0.65; line-height: 1.25; }
.tech-status { font-size: 0.72rem; color: var(--red); font-weight: 600; min-height: 1em; }
.tech-item.acquired .tech-status { color: var(--green); }

.tower-info.hidden { display: none; }

.tower-info-stats {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.tower-info-stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.8rem;
}

.tower-info-stats strong { font-size: 1rem; }

button {
  font-family: inherit;
  border: none;
  border-radius: 10px;
  background: var(--peach-dark);
  color: white;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}

button:hover { filter: brightness(1.05); }
button:active { transform: scale(0.98); }

button#sell-btn { background: var(--red); }

button#start-wave-btn.boss-wave {
  background: linear-gradient(135deg, #c41e3a, #e08e4f);
  animation: boss-pulse 1.4s ease-in-out infinite;
}

@keyframes boss-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(196, 30, 58, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(196, 30, 58, 0); }
}

.control-row {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

.control-row button { width: auto; flex: 1; }

.top-bar {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.top-bar #start-wave-btn { flex: 1 1 auto; }

.speed-pill {
  flex: 0 0 auto;
  width: 46px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  padding: 0;
  font-size: 0.85rem;
  background: var(--brown);
}

.hint {
  font-size: 0.78rem;
  color: var(--brown);
  opacity: 0.75;
  margin: 6px 0 0;
  line-height: 1.3;
}

@media (max-width: 760px) {
  .site-logo { height: 64px; }
  /* A etiqueta larga ("Fase N — Nome") não cabe fixada no canto ao lado do
     logo centralizado nessa largura — vira um bloco centralizado, empilhado
     acima do logo. padding-top no header (não margin no indicador — isso
     colapsava e empurrava o "← Fases" absoluto junto) abre espaço pra ela
     sem tocar no back-link. */
  .app-header { padding-top: 40px; }
  .phase-indicator {
    position: static;
    display: block;
    width: fit-content;
    margin: 0 auto 8px;
  }

  .layout { flex-wrap: wrap; }
  .board-col { max-width: 100%; order: 1; }
  .bestiary {
    order: 2;
    width: 100%;
    flex: 1 1 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .beast-card { flex: 1 1 120px; }
  .sidebar { width: 100%; flex-basis: 100%; order: 3; }
  .phase-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}
