:root {
  color-scheme: light;
  font-family: 'Segoe UI', Roboto, sans-serif;
  background-color: #4da768;
  --text-primary: #eaf9ef;
  color: var(--text-primary);
  --text-muted: rgba(218, 244, 228, 0.75);
  --primary: #2f7e4b;
  --primary-dark: #1f5a34;
  --surface: rgba(47, 126, 75, 0.9);
  --surface-strong: rgba(27, 81, 48, 0.95);
  --surface-alt: rgba(12, 46, 27, 0.35);
  --border: rgba(8, 30, 19, 0.35);
  --shadow-soft: 0 24px 48px rgba(6, 26, 15, 0.45);
  --success: #45d079;

  --error: #ef5350;

  --card-glow-border: #0f3d25;
  --card-glow-fill: #4da768;

  --card-blob-strong: rgba(9, 46, 28, 0.6);
  --card-blob-soft: rgba(77, 167, 104, 0.35);
}

@keyframes cardBlobBounce {
  0% {
    transform: translate(-100%, -100%) scale(1);
  }
  25% {
    transform: translate(20%, -120%) scale(1.05);
  }
  50% {
    transform: translate(25%, 10%) scale(1.08);
  }
  75% {
    transform: translate(-120%, 20%) scale(1.02);
  }
  100% {
    transform: translate(-100%, -100%) scale(1);
  }
}

@keyframes cardGlow {
  0% {
    box-shadow: 0 14px 34px rgba(6, 26, 15, 0.5), 0 0 0 0 rgba(15, 61, 37, 0.6);
  }
  60% {
    box-shadow: 0 14px 34px rgba(6, 26, 15, 0.5), 0 0 0 12px rgba(15, 61, 37, 0);
  }
  100% {
    box-shadow: 0 14px 34px rgba(6, 26, 15, 0.5), 0 0 0 0 rgba(15, 61, 37, 0);
  }
}

:is(
    .auth-card,
    .task-card,
    .special-mission-card,
    .country-card,
    .profile-card,
    .edit-card,
    .metric-card,
    .table-card,
    .highlight-card,
    .leaderboard-card,
    .brand,
    .card
  ) {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background-image: linear-gradient(140deg, rgba(77, 167, 104, 0.08), rgba(31, 90, 52, 0.18));
  border: 1px solid rgba(15, 61, 37, 0.75);
}

:is(
    .auth-card,
    .task-card,
    .special-mission-card,
    .country-card,
    .profile-card,
    .edit-card,
    .metric-card,
    .table-card,
    .highlight-card,
    .leaderboard-card,
    .brand,
    .card
  )::before {
  content: '';
  position: absolute;
  inset: -30%;
  background: radial-gradient(circle at 35% 35%, var(--card-blob-strong), transparent 44%),
    radial-gradient(circle at 70% 65%, var(--card-blob-soft), transparent 50%);
  filter: blur(24px);
  animation: cardBlobBounce 8s ease-in-out infinite;
  opacity: 0.9;
  z-index: 0;
  pointer-events: none;
  border-radius: inherit;
}

:is(
    .auth-card,
    .task-card,
    .special-mission-card,
    .country-card,
    .profile-card,
    .edit-card,
    .metric-card,
    .table-card,
    .highlight-card,
    .leaderboard-card,
    .brand,
    .card
  )::after {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: inherit;
  background: linear-gradient(160deg, rgba(77, 167, 104, 0.3), rgba(15, 61, 37, 0.75));
  box-shadow: inset 0 0 0 1px rgba(234, 249, 239, 0.18), 0 0 0 2px rgba(15, 61, 37, 0.55);
  backdrop-filter: blur(14px);
  z-index: 1;
  pointer-events: none;
}

:is(
    .auth-card,
    .task-card,
    .special-mission-card,
    .country-card,
    .profile-card,
    .edit-card,
    .metric-card,
    .table-card,
    .highlight-card,
    .leaderboard-card,
    .brand,
    .card
  ) > * {
  position: relative;
  z-index: 2;
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #4da768 0%, #3c8c5a 100%);

  color: var(--text-primary);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url('/front/logo.png') center/60vmin no-repeat;
  opacity: 2.25;

  pointer-events: none;
  z-index: -1;
}

h1,
h2,
h3 {
  margin-top: 0;
}

.button,
button,
input,
select,
textarea {
  font: inherit;
}

.button,
button {
  position: relative;
  display: inline-block;
  padding: 10px 20px;
  text-align: center;
  font-size: 15px;
  letter-spacing: 0.5px;
  text-decoration: none;
  color: var(--primary);
  background: transparent;
  cursor: pointer;
  transition: color 0.5s ease-out, box-shadow 0.5s ease-out, transform 0.1s ease-out;
  border: 2px solid var(--primary);
  border-radius: 8px;
  box-shadow: inset 0 0 0 0 var(--primary);
  font-weight: 600;
}

.button.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 12px 30px rgba(6, 26, 15, 0.4);
}

.button.secondary {
  background: rgba(12, 46, 27, 0.25);
  color: #e2f5e9;
  box-shadow: inset 0 0 0 1px rgba(8, 30, 19, 0.35);
}

.button.primary:hover {
  transform: translateY(-1px);
}

.button:hover,
button:hover {
  color: white;
  box-shadow: inset 0 -100px 0 0 var(--primary);
}

.button:active,
button:active {
  transform: scale(0.9);
}

.button:disabled,
button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-card {
  background: linear-gradient(180deg, var(--card-glow-fill), #3c8c5a);
  padding: 2.5rem;
  border-radius: 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 30px rgba(6, 26, 15, 0.55), 0 0 0 6px rgba(15, 61, 37, 0.35);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  text-align: center;
  border: 1px solid rgba(15, 61, 37, 0.8);
  animation: cardGlow 2.8s ease-in-out infinite;
  color: #eaf9ef;
}

.auth-card .form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: left;
}

.form input,
.form select,
.form textarea {
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(8, 30, 19, 0.45);
  background: rgba(12, 46, 27, 0.3);
  color: #f2fff6;
  box-shadow: inset 0 1px 3px rgba(4, 18, 10, 0.35);
}

.form label {
  font-weight: 600;
  color: #ddf3e2;
}

.form-feedback {
  min-height: 1.5rem;
}

.auth-links {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.link-button {
  background: transparent;
  color: #a4efc0;
  padding: 0;
}

.auth-links a,
.auth-links button {
  color: #a4efc0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  border-radius: 24px;
  border: 1px solid rgba(8, 30, 19, 0.45);
  color: #eaf9ef;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
}

.player-info .points,
.player-info .streak {
  background: rgba(12, 46, 27, 0.45);
  padding: 0.5rem 1rem;
  border-radius: 12px;
  color: #eaf9ef;
}

.level-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.95rem;
  border-radius: 999px;
  border: 1px solid rgba(234, 249, 239, 0.25);
  background: rgba(12, 46, 27, 0.35);
  font-weight: 600;
  color: #eaf9ef;
}

.profile-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  font-weight: 600;
  color: #eaf9ef;
  background: rgba(12, 46, 27, 0.45);
}

.game-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
}

.level-picker {
  background: var(--surface-strong);
  padding: 1.5rem;
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(8, 30, 19, 0.45);
  color: #eaf9ef;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 999;
}

.modal[aria-hidden='true'] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 13, 23, 0.75);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--surface-strong);
  padding: clamp(1.5rem, 2vw, 2.75rem);
  border-radius: 28px;
  width: min(620px, calc(100% - 1.75rem));
  max-height: min(90vh, 720px);
  overflow: auto;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #f5fff9;
}

.modal-body {
  display: grid;
  gap: 1.25rem;
}

.modal-close {
  position: absolute;
  top: 1.1rem;
  right: 1.1rem;
  background: transparent;
  color: inherit;
  font-size: 1.5rem;
  padding: 0.25rem;
  width: auto;
  height: auto;
}

.modal-intro {
  margin: 0;
  color: var(--text-muted);
}

.tutorial-steps {
  margin: 0;
  padding-left: 0.25rem;
  display: grid;
  gap: 0.05rem;
}

.tutorial-steps li {
  background: rgba(12, 46, 27, 0.35);
  padding: 0.45rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  -webkit-border-radius: 12px;
  -moz-border-radius: 12px;
  -ms-border-radius: 12px;
  -o-border-radius: 12px;
}

.tutorial-tips {
  background: rgba(69, 208, 121, 0.1);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  border: 1px solid rgba(69, 208, 121, 0.35);
  color: #d2ffe2;
}

body.modal-open {
  overflow: hidden;
}

.selector {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.selector-help {
  font-size: 0.95rem;
  line-height: 1.5;
  background: rgba(12, 46, 27, 0.35);
  border-radius: 18px;
  padding: 0.85rem 1rem;
  color: var(--text-muted);
}

.task-panel {
  background: var(--surface-strong);
  border-radius: 24px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(8, 30, 19, 0.45);
  color: #eaf9ef;
}

.task-card {
  display: grid;
  gap: 1rem;
  background: linear-gradient(180deg, var(--card-glow-fill), #3c8c5a);
  border-radius: 20px;
  padding: 1.25rem;
  border: 1px solid rgba(15, 61, 37, 0.8);
  box-shadow: 0 18px 38px rgba(6, 26, 15, 0.5), 0 0 0 6px rgba(15, 61, 37, 0.35);
  animation: cardGlow 2.8s ease-in-out infinite;
}

.task-card img {
  width: 100%;
  border-radius: 18px;
  max-height: 320px;
  object-fit: cover;
  box-shadow: 0 20px 45px rgba(6, 26, 15, 0.45);
}

.choices {
  display: grid;
  gap: 0.75rem;
}

.choice-option {
  padding: 1rem;
  border-radius: 14px;
  background: var(--surface-alt);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.choice-option:hover,
.choice-option.selected {
  transform: translateY(-1px);
  border-color: var(--primary);
  box-shadow: 0 12px 24px rgba(6, 26, 15, 0.45);
}

.task-feedback {
  min-height: 1.5rem;
  font-weight: 600;
}

.task-feedback.success {
  color: var(--success);
}

.task-feedback.error {
  color: var(--error);
}

.missions {
  padding: 2rem;
}

.missions ul {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.missions li {
  background: var(--surface-strong);
  padding: 1.25rem;
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(8, 30, 19, 0.45);
  color: #eaf9ef;
}

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

  .player-info {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

.thinking-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 24, 45, 0.8);
  backdrop-filter: blur(2px);
  z-index: 9999;
  padding: 1.5rem;
}

.thinking-overlay[hidden] {
  display: none;
}

body.has-thinking-overlay {
  overflow: hidden;
}

.earth {
  display: grid;
  justify-items: center;
  gap: 0.5em;
  text-align: center;
}

.earth p {
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 0.25em;
  font-size: 1.25em;
  font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
  margin: 0;
}

.earth-loader {
  --watercolor: #3344c1;
  --landcolor: #7cc133;
  width: 7.5em;
  height: 7.5em;
  background-color: var(--watercolor);
  position: relative;
  overflow: hidden;
  border-radius: 50%;
  box-shadow: inset 0em 0.5em rgb(255 255 255 / 25%), inset 0em -0.5em rgb(0 0 0 / 25%);
  border: solid 0.15em white;
  animation: startround 1s;
  animation-iteration-count: 1;
}

.earth-loader svg:nth-child(1) {
  position: absolute;
  bottom: -2em;
  width: 7em;
  height: auto;
  animation: round1 5s infinite linear 0.75s;
}

.earth-loader svg:nth-child(2) {
  position: absolute;
  top: -3em;
  width: 7em;
  height: auto;
  animation: round1 5s infinite linear;
}

.earth-loader svg:nth-child(3) {
  position: absolute;
  top: -2.5em;
  width: 7em;
  height: auto;
  animation: round2 5s infinite linear;
}

.earth-loader svg:nth-child(4) {
  position: absolute;
  bottom: -2.2em;
  width: 7em;
  height: auto;
  animation: round2 5s infinite linear 0.75s;
}

@keyframes startround {
  0% {
    filter: brightness(500%);
    box-shadow: none;
  }
  75% {
    filter: brightness(500%);
    box-shadow: none;
  }
  100% {
    filter: brightness(100%);
    box-shadow: inset 0em 0.5em rgb(255 255 255 / 25%), inset 0em -0.5em rgb(0 0 0 / 25%);
  }
}

@keyframes round1 {
  0% {
    left: -2em;
    opacity: 100%;
    transform: skewX(0deg) rotate(0deg);
  }
  30% {
    left: -6em;
    opacity: 100%;
    transform: skewX(-25deg) rotate(25deg);
  }
  31% {
    left: -6em;
    opacity: 0%;
    transform: skewX(-25deg) rotate(25deg);
  }
  35% {
    left: 7em;
    opacity: 0%;
    transform: skewX(25deg) rotate(-25deg);
  }
  45% {
    left: 7em;
    opacity: 100%;
    transform: skewX(25deg) rotate(-25deg);
  }
  100% {
    left: -2em;
    opacity: 100%;
    transform: skewX(0deg) rotate(0deg);
  }
}

@keyframes round2 {
  0% {
    left: 5em;
    opacity: 100%;
    transform: skewX(0deg) rotate(0deg);
  }
  75% {
    left: -7em;
    opacity: 100%;
    transform: skewX(-25deg) rotate(25deg);
  }
  76% {
    left: -7em;
    opacity: 0%;
    transform: skewX(-25deg) rotate(25deg);
  }
  77% {
    left: 8em;
    opacity: 0%;
    transform: skewX(25deg) rotate(-25deg);
  }
  80% {
    left: 8em;
    opacity: 100%;
    transform: skewX(25deg) rotate(-25deg);
  }
  100% {
    left: 5em;
    opacity: 100%;
    transform: skewX(0deg) rotate(0deg);
  }
}
/* 1. Forçar a caixa a ser Larga (Wide) para não crescer em altura */
#tutorial-modal .modal-content {
    max-width: 850px !important;  /* Muito mais largo */
    width: 95% !important;
    padding: 1rem 2rem !important; /* Reduzimos a margem vertical interna */
    max-height: 98vh !important;   /* Aproveita o ecrã todo se necessário */
    
    /* Centrar tudo caso sobre espaço */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* 2. Apertar o título e introdução para ocuparem menos espaço */
#tutorial-modal h2 {
    font-size: 1.4rem !important;
    margin: 0 0 0.5rem 0 !important; /* Quase sem margem */
    text-align: center;
}

#tutorial-modal .modal-intro {
    font-size: 0.9rem !important;
    margin-bottom: 0.8rem !important;
    text-align: center;
}

#tutorial-modal .modal-body {
    gap: 0.5rem !important; /* Junta os elementos todos */
}

/* 3. A LISTA EM GRELHA (Obrigatório para não ter scroll) */
#tutorial-modal .tutorial-steps {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important; /* Duas colunas */
    gap: 8px !important;
    margin: 0 0 0.8rem 0 !important;
    padding: 0 !important;
}

/* Estilo compacto dos itens */
#tutorial-modal .tutorial-steps li {
    font-size: 0.8rem !important; /* Letra mais pequena */
    line-height: 1.25 !important;
    padding: 8px 12px !important;  /* Caixas fininhas */
    background: rgba(12, 46, 27, 0.5) !important;
    border-radius: 10px !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Passo 5 ocupa a largura toda */
#tutorial-modal .tutorial-steps li:last-child {
    grid-column: span 2 !important;
    text-align: center;
}

#tutorial-modal .tutorial-steps li strong {
    font-size: 0.85rem !important;
    margin-bottom: 2px !important;
    display: block;
}

/* 4. Dicas e Botão compactos */
#tutorial-modal .tutorial-tips {
    padding: 0.5rem 1rem !important;
    margin-bottom: 0.8rem !important;
    font-size: 0.75rem !important;
    text-align: center;
}

#tutorial-modal .tutorial-tips p { 
    margin: 0 !important; 
}

#tutorial-modal .button.primary {
    padding: 8px !important; /* Botão mais fino */
    margin-top: 0 !important;
}

/* --- APENAS PARA TELEMÓVEIS (Ecrãs muito pequenos) --- */
/* Aí o scroll é inevitável, por isso voltamos ao normal */
@media (max-width: 700px) {
    #tutorial-modal .tutorial-steps {
        grid-template-columns: 1fr !important;
    }
    #tutorial-modal .tutorial-steps li:last-child {
        grid-column: span 1 !important;
        text-align: left;
    }
    #tutorial-modal .modal-content {
        overflow-y: auto !important; /* Ativa o scroll só no telemóvel */
        display: block; /* Remove o flex centering */
    }
}