/* =============================================
   IMPORTAÇÃO DE FONTE
   ============================================= */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&family=Space+Mono:wght@400;700&display=swap');

/* =============================================
   VARIÁVEIS DE TEMA
   ============================================= */
:root {
  --primary-color-light: #ffffff;
  --secondary-color-light: #f0f4f8;
  --text-color-light: #2d3748;
  --maze-wall-light: #2c3e50;
  --maze-path-light: #ecf0f1;
  --goal-color-light: #f1c40f;
  --border-light: #e2e8f0;
  --card-shadow-light: 0 4px 20px rgba(0,0,0,0.08);

  --primary-color-dark: #1a1a2e;
  --secondary-color-dark: #16213e;
  --text-color-dark: #e2e8f0;
  --maze-wall-dark: #c8d6e5;
  --maze-path-dark: #2a2a3e;
  --goal-color-dark: #ffd700;
  --border-dark: #2d3748;
  --card-shadow-dark: 0 4px 20px rgba(0,0,0,0.4);

  --accent: #1abc9c;
  --accent-hover: #16a085;
  --danger: #e74c3c;
  --warning: #e67e22;
}

body.light-theme {
  --primary-color: var(--primary-color-light);
  --secondary-color: var(--secondary-color-light);
  --text-color: var(--text-color-light);
  --maze-wall: var(--maze-wall-light);
  --maze-path: var(--maze-path-light);
  --goal-color: var(--goal-color-light);
  --border-color: var(--border-light);
  --card-shadow: var(--card-shadow-light);
}

body.dark-theme {
  --primary-color: var(--primary-color-dark);
  --secondary-color: var(--secondary-color-dark);
  --text-color: var(--text-color-dark);
  --maze-wall: var(--maze-wall-dark);
  --maze-path: var(--maze-path-dark);
  --goal-color: var(--goal-color-dark);
  --border-color: var(--border-dark);
  --card-shadow: var(--card-shadow-dark);
}

/* =============================================
   RESET E BASE
   ============================================= */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}

html, body {
  height: 100%;
  font-family: 'Nunito', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--secondary-color);
  color: var(--text-color);
  transition: background-color 0.3s, color 0.3s;
}

button {
  cursor: pointer;
  outline: none;
  border: none;
  font-family: inherit;
  min-height: 44px;
  padding: 8px 16px;
}

/* =============================================
   LAYOUT PRINCIPAL
   ============================================= */
.container {
  display: flex;
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

.sidebar-left {
  width: 200px;
  min-width: 200px;
  background-color: var(--primary-color);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  z-index: 10;
  overflow-y: auto;
  transition: background-color 0.3s;
}

.sidebar-right {
  width: 200px;
  min-width: 200px;
  background-color: var(--primary-color);
  padding: 16px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border-color);
  align-items: center;
  transition: background-color 0.3s;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* nunca deixa o labirinto vazar */
  padding: 10px;
  min-width: 0; /* flex fix para não extrapolar */
}

/* =============================================
   SIDEBAR: CABEÇALHO
   ============================================= */
.sidebar-left h1 {
  font-size: 1.1rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: -0.3px;
  color: var(--accent);
  margin-bottom: 8px;
}

.diff-badge-side-wrap {
  text-align: center;
  margin-bottom: 4px;
}

#diffBadgeSide {
  display: none;
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  padding: 2px 10px;
  border-radius: 20px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 8px 0;
}

/* =============================================
   AVATARES
   ============================================= */
.avatar-title {
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 6px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.7;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-bottom: 6px;
}

.avatar-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 8px;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.avatar-grid img:hover {
  border-color: var(--accent);
  transform: scale(1.08);
  box-shadow: 0 2px 8px rgba(26,188,156,0.3);
}

/* =============================================
   DIFICULDADE E BOTÃO INICIAR
   ============================================= */
.difficulty {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
}

.difficulty label {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.7;
}

.difficulty select {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--border-color);
  background-color: var(--secondary-color);
  color: var(--text-color);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%231abc9c' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  transition: border-color 0.2s;
}

.difficulty select:focus {
  outline: none;
  border-color: var(--accent);
}

#btnStart {
  background: linear-gradient(135deg, var(--accent), #2ecc71);
  color: #ffffff;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  box-shadow: 0 3px 12px rgba(26,188,156,0.35);
  text-transform: uppercase;
}

#btnStart:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(26,188,156,0.45);
}

#btnStart:active {
  transform: translateY(0);
}

/* =============================================
   INFO BOX + BARRA DE TEMPO
   ============================================= */
.info-box {
  margin-top: 6px;
  font-size: 0.85rem;
  line-height: 1.5;
}

.info-box p {
  margin: 3px 0;
}

.info-box strong {
  font-weight: 700;
  opacity: 0.7;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.info-box span {
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
}

/* Barra de tempo progressiva */
.time-bar-wrap {
  margin-top: 8px;
  background: var(--border-color);
  border-radius: 10px;
  height: 8px;
  overflow: hidden;
}

#timeBarFill {
  height: 100%;
  width: 100%;
  background-color: var(--accent);
  border-radius: 10px;
  transition: width 1s linear, background-color 0.5s;
}

/* =============================================
   BOTÕES NO RODAPÉ (LATERAL ESQUERDA)
   ============================================= */
.bottom-buttons {
  margin-top: auto;
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  padding-top: 10px;
}

.circle-btn {
  background-color: var(--secondary-color);
  color: var(--text-color);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--border-color);
  transition: background-color 0.2s, transform 0.15s, border-color 0.2s;
  min-height: unset;
  padding: 0;
}

.circle-btn:hover {
  background-color: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: scale(1.1);
}

/* =============================================
   LABIRINTO
   ============================================= */
#maze-container {
  position: relative;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  background-color: var(--maze-path);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  flex-shrink: 0; /* não deixa o flexbox comprimir o labirinto */
}

/* Badge de dificuldade sobre o labirinto */
.diff-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 20;
  font-family: 'Space Mono', monospace;
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  opacity: 0.85;
  pointer-events: none;
}

/* Tremor */
.shake {
  animation: shake 0.18s infinite;
}

@keyframes shake {
  0%   { transform: translate(1px, 0px)  rotate(0deg); }
  20%  { transform: translate(-1px, 2px) rotate(-0.8deg); }
  40%  { transform: translate(1px, -1px) rotate(0.8deg); }
  60%  { transform: translate(-1px, 2px) rotate(0deg); }
  80%  { transform: translate(1px, 1px)  rotate(0.8deg); }
  100% { transform: translate(-1px, 0px) rotate(-0.8deg); }
}

/* Célula (mantida para compatibilidade, mas usamos canvas agora) */
.cell {
  position: absolute;
  box-sizing: border-box;
}
.wall { background-color: var(--maze-wall); }
.path { background-color: var(--maze-path); }

/* Player */
#player {
  position: absolute;
  object-fit: cover;
  border-radius: 50%;
  user-select: none;
  pointer-events: none;
  transition: left 0.08s ease, top 0.08s ease;
  z-index: 10;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* Feedback de bater na parede */
@keyframes wallBump {
  0%   { transform: scale(1); filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3)); }
  40%  { transform: scale(1.25); filter: drop-shadow(0 0 8px rgba(231,76,60,0.8)); }
  100% { transform: scale(1); filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3)); }
}

#player.wall-bump {
  animation: wallBump 0.22s ease;
}

/* Goal */
#goal {
  position: absolute;
  background-color: var(--goal-color);
  border-radius: 3px;
  z-index: 5;
  animation: goalPulse 1.2s ease-in-out infinite;
}

@keyframes goalPulse {
  0%   { box-shadow: 0 0 0 0 rgba(241,196,15,0.6); }
  50%  { box-shadow: 0 0 0 8px rgba(241,196,15,0); }
  100% { box-shadow: 0 0 0 0 rgba(241,196,15,0); }
}

/* =============================================
   CONTROLES D-PAD
   ============================================= */
.controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 14px;
  z-index: 100;
}

.dpad-row {
  display: flex;
  gap: 4px;
}

.control-btn {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  background: linear-gradient(145deg, #1abc9c, #16a085);
  color: white;
  border-radius: 12px;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  min-height: unset;
  padding: 0;
  box-shadow: 0 4px 12px rgba(26,188,156,0.3), inset 0 1px 0 rgba(255,255,255,0.2);
  transition: transform 0.08s, box-shadow 0.08s;
}

.control-btn-center {
  /* espaçador para o centro do D-pad */
  width: 64px;
  height: 64px;
  background: transparent;
}

.control-btn:active {
  transform: scale(0.9);
  box-shadow: 0 2px 6px rgba(26,188,156,0.2), inset 0 2px 4px rgba(0,0,0,0.2);
}

@media (hover: hover) {
  .control-btn:hover {
    background: linear-gradient(145deg, #2ecc71, #1abc9c);
    box-shadow: 0 6px 16px rgba(26,188,156,0.4);
  }
}

/* Landscape mobile: d-pad fixo no canto direito */
@media (orientation: landscape) and (max-width: 1024px) {
  .controls {
    position: fixed;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
    background: rgba(255,255,255,0.08);
    backdrop-filter: blur(4px);
    border-radius: 16px;
    padding: 10px;
  }
  .control-btn {
    width: 52px;
    height: 52px;
    font-size: 1.1rem;
  }
  .control-btn-center {
    width: 52px;
    height: 52px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .control-btn {
    width: 44px;
    height: 44px;
    font-size: 1rem;
  }
  .control-btn-center {
    width: 44px;
    height: 44px;
  }
}

/* =============================================
   MENSAGENS DE VITÓRIA/DERROTA
   ============================================= */
.win-message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: var(--primary-color);
  color: var(--text-color);
  padding: 32px 28px;
  border-radius: 20px;
  text-align: center;
  display: none;
  z-index: 999;
  width: 88%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  from { transform: translate(-50%, -50%) scale(0.7); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1);   opacity: 1; }
}

.win-message h2 {
  margin-bottom: 10px;
  font-size: 1.8rem;
  font-weight: 800;
}

.win-message p {
  opacity: 0.7;
  margin-bottom: 4px;
}

.win-message button {
  background: linear-gradient(135deg, var(--accent), #2ecc71);
  color: #ffffff;
  padding: 12px 24px;
  border-radius: 12px;
  margin-top: 18px;
  font-weight: 800;
  font-size: 1rem;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(26,188,156,0.35);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.win-message button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(26,188,156,0.45);
}

.info-list {
  text-align: left;
  margin: 12px 0 0 0;
  line-height: 1.8;
  font-size: 0.9rem;
  list-style: none;
  background: var(--secondary-color);
  padding: 10px 16px;
  border-radius: 10px;
}

.info-list li::before {
  content: '▸ ';
  color: var(--accent);
  font-weight: 700;
}

/* =============================================
   MODAIS
   ============================================= */
.modal {
  display: none;
  position: fixed;
  z-index: 998;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
}

.modal-content {
  background-color: var(--primary-color);
  color: var(--text-color);
  margin: 8% auto;
  padding: 24px;
  border-radius: 16px;
  width: 88%;
  max-width: 420px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  max-height: 90vh;
  overflow-y: auto;
  animation: popIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h2 {
  font-weight: 800;
  font-size: 1.25rem;
}

.close {
  color: var(--text-color);
  font-size: 1.6rem;
  font-weight: bold;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s, color 0.2s;
  line-height: 1;
}

.close:hover {
  opacity: 1;
  color: var(--danger);
}

.modal-body p {
  margin-bottom: 8px;
  line-height: 1.6;
  font-size: 0.92rem;
}

.modal-body ul {
  margin: 4px 0 10px 0;
  padding-left: 0;
  list-style: none;
}

.modal-body ul li {
  padding: 3px 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.modal-body ul li::before {
  content: '▸ ';
  color: var(--accent);
  font-weight: 700;
}

.share-button {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), #2ecc71);
  color: #ffffff;
  padding: 10px 18px;
  margin: 5px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 3px 10px rgba(26,188,156,0.3);
  min-height: unset;
}

.share-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 14px rgba(26,188,156,0.4);
}

/* Footer do modal de alerta */
.modal-footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

.confirm-button, .cancel-button {
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  min-height: unset;
}

.confirm-button {
  background: linear-gradient(135deg, var(--accent), #2ecc71);
  color: #fff;
  box-shadow: 0 3px 10px rgba(26,188,156,0.3);
}
.confirm-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(26,188,156,0.4);
}

.cancel-button {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: #fff;
  box-shadow: 0 3px 10px rgba(231,76,60,0.3);
}
.cancel-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(231,76,60,0.4);
}

/* =============================================
   TABLETS (ATÉ 1024PX)
   ============================================= */
@media (max-width: 1024px) {
  .sidebar-left {
    width: 170px;
    min-width: 170px;
  }
  .sidebar-right {
    width: 160px;
    min-width: 160px;
  }
  .avatar-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* =============================================
   SMARTPHONES (ATÉ 768PX)
   ============================================= */
@media (max-width: 768px) {
  .container {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    padding: 0;
    overflow: visible;
  }

  .sidebar-left {
    width: 100%;
    min-width: unset;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    order: 1;
  }

  .sidebar-left h1 {
    font-size: 1.2rem;
  }

  /* No mobile, reorganiza em layout horizontal compacto */
  .sidebar-left > hr:first-of-type { display: none; }

  .mobile-top-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
  }

  .avatar-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-width: 150px;
    flex-shrink: 0;
  }

  .sidebar-right {
    width: 100%;
    min-width: unset;
    padding: 10px 16px;
    border-left: none;
    border-top: 1px solid var(--border-color);
    order: 4;
  }

  .main-content {
    order: 2;
    padding: 10px 8px 0;
    overflow: visible;
  }

  /* Controles abaixo do labirinto */
  .controls {
    order: 3;
    padding-bottom: 12px;
  }

  #maze-container {
    max-height: none;
    overflow: visible;
  }

  .info-box {
    font-size: 0.9rem;
  }
}

/* =============================================
   ORIENTAÇÃO LANDSCAPE MOBILE
   ============================================= */
@media (orientation: landscape) and (max-width: 900px) {
  .container {
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
  }

  .sidebar-left {
    width: 160px;
    min-width: 160px;
    order: unset;
    border-bottom: none;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
  }

  .sidebar-right {
    display: none; /* Esconde banner no landscape mobile */
  }

  .main-content {
    order: unset;
    overflow: auto;
  }

  /* D-pad fixed no canto — já definido acima */
}
