/* ═══════════ DUNGEON OF KNOWLEDGE ═══════════ */

/* ── Animações ── */
@keyframes dungeonRoomPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,200,66,0.5); }
  50%      { box-shadow: 0 0 0 10px rgba(245,200,66,0); }
}
@keyframes dungeonBossPulse {
  0%, 100% { box-shadow: 0 0 12px 2px rgba(245,72,66,0.4); transform: scale(1); }
  50%      { box-shadow: 0 0 18px 6px rgba(245,72,66,0.7); transform: scale(1.04); }
}
@keyframes dungeonHitFlash {
  0%, 100% { filter: none; }
  30%      { filter: brightness(2.6) saturate(0); }
  60%      { filter: brightness(0.8) sepia(1) saturate(5) hue-rotate(-30deg); }
}
@keyframes dungeonShake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}
@keyframes dungeonEffectFade {
  0%   { opacity: 0; transform: scale(0.6); }
  20%  { opacity: 1; transform: scale(1.1); }
  80%  { opacity: 0.8; transform: scale(1.3); }
  100% { opacity: 0; transform: scale(1.5); }
}
@keyframes dungeonRoomDoneIn {
  0%   { transform: scale(0.4) rotate(-12deg); opacity: 0; }
  60%  { transform: scale(1.2) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ── Lista de dungeons (Portal do aluno) ── */
.dungeon-list-section {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.dungeon-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
  gap: 12px;
}
.dungeon-card {
  background: linear-gradient(135deg, rgba(167,139,250,0.08), rgba(34,211,238,0.04));
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: rgba(167,139,250,0.25);
}
.dungeon-card:active {
  transform: scale(0.98);
  border-color: var(--purple);
}
@media (hover: hover) and (pointer: fine) {
  .dungeon-card:hover {
    transform: translateY(-3px);
    border-color: var(--purple);
    box-shadow: 0 6px 18px rgba(167,139,250,0.18);
  }
}
.dungeon-card-icon { font-size: 1.8rem; margin-bottom: 4px; }
.dungeon-card-title { font-weight: 800; font-size: 0.92rem; margin-bottom: 4px; }
.dungeon-card-info { font-size: 0.7rem; color: var(--muted2); margin-bottom: 10px; }
.dungeon-card-rewards { display: flex; gap: 10px; font-size: 0.74rem; }
.dungeon-card-progress {
  position: absolute; top: 10px; right: 10px;
  font-size: 0.62rem; padding: 2px 8px; border-radius: 20px;
  background: rgba(34,211,238,0.15); color: var(--teal);
}
.dungeon-card-completed {
  position: absolute; top: 10px; right: 10px;
  font-size: 0.62rem; padding: 2px 8px; border-radius: 20px;
  background: rgba(0,200,100,0.15); color: var(--green);
}

/* ── Mapa da Dungeon ── */
.dungeon-wrap {
  max-width: 720px;
  margin: 0 auto;
}
.dungeon-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
  background: var(--card);
  padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border2);
  margin-bottom: 14px;
}
.dungeon-hp-hearts {
  display: flex; gap: 3px; align-items: center;
  font-size: 1.05rem;
}
.dungeon-hp-hearts .lost { filter: grayscale(1) brightness(0.5); }
.dungeon-title-block {
  flex: 1; min-width: 100px; text-align: center;
}
.dungeon-title-block .dt-title {
  font-family: 'Cinzel', serif;
  font-weight: 700; font-size: 0.92rem;
  color: var(--gold);
}
.dungeon-title-block .dt-sub {
  font-size: 0.66rem; color: var(--muted2);
}
.dungeon-items { display: flex; gap: 6px; }
.ditem-btn {
  position: relative;
  width: 38px; height: 38px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  cursor: pointer; font-size: 1.05rem;
  transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: rgba(245,200,66,0.25);
}
.ditem-btn:not(.ditem-empty):not(.ditem-active):active {
  transform: scale(0.92);
  border-color: var(--gold);
}
@media (hover: hover) and (pointer: fine) {
  .ditem-btn:hover:not(.ditem-empty):not(.ditem-active) {
    border-color: var(--gold); transform: translateY(-2px);
  }
}
.ditem-btn.ditem-active {
  border-color: var(--gold);
  background: rgba(245,200,66,0.2);
  box-shadow: 0 0 8px rgba(245,200,66,0.4);
}
.ditem-btn.ditem-empty {
  opacity: 0.35; cursor: not-allowed;
}
.ditem-count {
  position: absolute; bottom: -5px; right: -5px;
  background: var(--purple); color: white;
  font-size: 0.58rem; font-weight: 800;
  width: 16px; height: 16px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}

/* Mapa em grid com tile pattern */
.dungeon-map {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding: 24px 16px;
  background:
    linear-gradient(135deg, rgba(0,0,0,0.55), rgba(0,0,0,0.75)),
    url('../assets/tiles/dungeon/Tiles/tile_0049.png');
  background-size: cover, 48px 48px;
  background-repeat: no-repeat, repeat;
  image-rendering: pixelated;
  border-radius: 14px;
  border: 2px solid var(--border2);
  position: relative;
  margin-bottom: 14px;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.7);
}
.dungeon-map.theme-castle  {
  background:
    linear-gradient(135deg, rgba(20,10,40,0.7), rgba(40,20,80,0.6)),
    url('../assets/tiles/dungeon/Tiles/tile_0040.png');
  background-size: cover, 48px 48px;
  background-repeat: no-repeat, repeat;
  box-shadow: inset 0 0 60px rgba(167,139,250,0.35);
}
.dungeon-map.theme-forest  {
  background:
    linear-gradient(135deg, rgba(10,30,15,0.65), rgba(20,60,30,0.55)),
    url('../assets/tiles/dungeon/Tiles/tile_0049.png');
  background-size: cover, 48px 48px;
  background-repeat: no-repeat, repeat;
  box-shadow: inset 0 0 60px rgba(52,211,153,0.28);
  filter: hue-rotate(70deg);
}
.dungeon-map.theme-space   {
  background:
    linear-gradient(135deg, rgba(0,15,40,0.8), rgba(0,40,80,0.7)),
    url('../assets/tiles/dungeon/Tiles/tile_0040.png');
  background-size: cover, 48px 48px;
  background-repeat: no-repeat, repeat;
  box-shadow: inset 0 0 60px rgba(34,211,238,0.35);
  filter: hue-rotate(160deg);
}
.dungeon-map.theme-volcano {
  background:
    linear-gradient(135deg, rgba(60,15,5,0.7), rgba(120,30,10,0.6)),
    url('../assets/tiles/dungeon/Tiles/tile_0049.png');
  background-size: cover, 48px 48px;
  background-repeat: no-repeat, repeat;
  box-shadow: inset 0 0 60px rgba(251,146,60,0.45);
  filter: hue-rotate(-15deg) saturate(1.3);
}

.droom {
  aspect-ratio: 1;
  background: var(--bg3);
  border: 2px solid var(--border2);
  border-radius: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  font-size: 1.6rem;
  position: relative;
  transition: all 0.18s;
  font-weight: 800;
  font-family: inherit;
  color: var(--text);
  -webkit-tap-highlight-color: rgba(245,200,66,0.3);
}
.droom:not(.droom-locked):active {
  transform: scale(0.96);
}
@media (hover: hover) and (pointer: fine) {
  .droom:hover:not(.droom-locked) {
    transform: translateY(-3px) scale(1.04);
    z-index: 2;
  }
}
.droom-label {
  font-size: 0.55rem; color: var(--muted2);
  font-weight: 700; margin-top: 2px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.droom-locked {
  opacity: 0.32; cursor: not-allowed;
  filter: grayscale(0.6);
}
.droom-locked .droom-label { color: var(--muted); }
.droom-available {
  background: linear-gradient(135deg, rgba(245,200,66,0.18), rgba(245,200,66,0.05));
  border-color: var(--gold);
  animation: dungeonRoomPulse 2s ease-out infinite;
}
.droom-completed {
  background: rgba(52,211,153,0.18);
  border-color: var(--green);
  animation: dungeonRoomDoneIn 0.4s ease-out;
}
.droom-failed {
  background: rgba(248,113,113,0.18);
  border-color: var(--red);
}
.droom-boss {
  background: linear-gradient(135deg, rgba(245,72,66,0.18), rgba(167,139,250,0.18));
  border-color: var(--gold);
  border-width: 3px;
  font-size: 1.9rem;
  animation: dungeonBossPulse 1.5s ease-in-out infinite;
}
.droom-boss .droom-label { color: var(--gold); font-weight: 900; }
.droom-boss.droom-locked { animation: none; }

/* ── Batalha ── */
.dungeon-battle {
  max-width: 580px;
  margin: 0 auto;
}
.dungeon-canvas-wrap {
  position: relative;
  background:
    radial-gradient(ellipse at center bottom, rgba(245,200,66,0.16), transparent 70%),
    linear-gradient(180deg, rgba(0,0,0,0.4), rgba(0,0,0,0.85));
  border-radius: 12px;
  border: 2px solid var(--border2);
  padding: 14px;
  margin-bottom: 14px;
  overflow: hidden;
}
.dungeon-canvas-wrap.theme-castle  { box-shadow: inset 0 -40px 60px rgba(167,139,250,0.22); }
.dungeon-canvas-wrap.theme-forest  { box-shadow: inset 0 -40px 60px rgba(52,211,153,0.22); }
.dungeon-canvas-wrap.theme-space   { box-shadow: inset 0 -40px 60px rgba(34,211,238,0.22); }
.dungeon-canvas-wrap.theme-volcano { box-shadow: inset 0 -40px 60px rgba(251,146,60,0.30); }

.dungeon-monster-name {
  text-align: center; color: var(--gold);
  font-family: 'Cinzel', serif;
  font-size: 0.95rem; font-weight: 700;
  margin-bottom: 8px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}
.dungeon-canvas {
  display: block; margin: 0 auto;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  max-width: 100%;
  height: auto;
}
.dungeon-canvas.shake { animation: dungeonShake 0.4s ease-out; }
.dungeon-canvas.flash { animation: dungeonHitFlash 0.45s ease-out; }
.dungeon-effect-overlay {
  position: absolute;
  pointer-events: none;
  width: 160px; height: 160px;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  animation: dungeonEffectFade 0.7s ease-out forwards;
  image-rendering: pixelated;
}

.dungeon-question-box {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 14px 16px;
}
.dungeon-question-text {
  font-size: 0.96rem; font-weight: 700;
  line-height: 1.4; margin-bottom: 12px;
  text-align: center;
}
.dungeon-timer-bar-wrap {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
}
.dungeon-timer-bar {
  flex: 1; height: 6px;
  background: var(--bg2);
  border-radius: 4px; overflow: hidden;
}
.dungeon-timer-fill {
  height: 100%; background: var(--teal);
  border-radius: 4px;
  transition: width 1s linear, background 0.3s;
}
.dungeon-timer-num {
  font-size: 0.72rem; font-weight: 800;
  color: var(--teal); min-width: 28px; text-align: right;
}
.dungeon-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.dungeon-opt {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: all 0.18s;
  position: relative;
  font-family: inherit;
}
.dungeon-opt:active:not(:disabled) {
  transform: scale(0.98);
  background: var(--bg3);
}
@media (hover: hover) and (pointer: fine) {
  .dungeon-opt:hover:not(:disabled) {
    background: var(--bg3);
    border-color: var(--purple);
    transform: translateY(-1px);
  }
}
.dungeon-opt:disabled { cursor: not-allowed; }
.dungeon-opt-letter {
  font-weight: 800; color: var(--muted2);
  margin-right: 8px; font-size: 0.78rem;
}
.dungeon-opt.correct {
  background: rgba(52,211,153,0.18);
  border-color: var(--green);
  color: var(--green);
}
.dungeon-opt.wrong {
  background: rgba(248,113,113,0.18);
  border-color: var(--red);
  color: var(--red);
}
.dungeon-opt.disabled-shield {
  opacity: 0.3;
  text-decoration: line-through;
}

/* HP do monstro sobre o canvas */
.dungeon-monster-hp-wrap {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
  justify-content: center;
}
.dungeon-monster-hp-bar {
  width: 130px; height: 8px;
  background: var(--bg2);
  border-radius: 4px; overflow: hidden;
  border: 1px solid var(--border2);
}
.dungeon-monster-hp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--orange));
  border-radius: 4px;
  transition: width 0.4s;
}
.dungeon-monster-hp-num {
  font-size: 0.66rem; color: var(--muted2);
  font-weight: 700;
}

/* ── Tela de fim ── */
.dungeon-end {
  max-width: 460px;
  margin: 0 auto;
  text-align: center;
  padding: 24px 16px;
}
.dungeon-end-icon { font-size: 3.5rem; margin-bottom: 8px; }
.dungeon-end-title {
  font-family: 'Cinzel Decorative', serif;
  font-size: 1.4rem; font-weight: 900;
  margin-bottom: 18px;
}
.dungeon-end-title.victory { color: var(--gold); }
.dungeon-end-title.defeat  { color: var(--red); }
.dungeon-end-stats {
  background: var(--bg3);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  text-align: left;
}
.dungeon-end-stat-label {
  font-size: 0.65rem; color: var(--muted2);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.dungeon-end-stat-val {
  font-size: 1.05rem; font-weight: 800;
  color: var(--text);
}

/* ── Teacher: criação de dungeon ── */
.dungeon-form-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}
.dungeon-mode-card {
  background: var(--bg3);
  border: 2px solid var(--border2);
  border-radius: 12px;
  padding: 18px 14px;
  cursor: pointer;
  text-align: center;
  transition: all 0.18s;
}
.dungeon-mode-card:active {
  transform: scale(0.98);
  border-color: var(--purple);
}
@media (hover: hover) and (pointer: fine) {
  .dungeon-mode-card:hover {
    border-color: var(--purple);
    transform: translateY(-2px);
  }
}
.dungeon-mode-card .dmc-icon { font-size: 2rem; margin-bottom: 8px; }
.dungeon-mode-card .dmc-title { font-weight: 800; font-size: 0.88rem; margin-bottom: 4px; }
.dungeon-mode-card .dmc-desc { font-size: 0.7rem; color: var(--muted2); }

.dungeon-theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.dungeon-theme-chip {
  background: var(--bg3);
  border: 2px solid var(--border2);
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 700;
  transition: all 0.15s;
}
@media (hover: hover) and (pointer: fine) {
  .dungeon-theme-chip:hover { border-color: var(--gold); }
}
.dungeon-theme-chip.active {
  background: rgba(245,200,66,0.15);
  border-color: var(--gold);
  color: var(--gold);
}

.dungeon-rooms-list {
  display: flex; flex-direction: column;
  gap: 8px; margin-bottom: 12px;
}
.dungeon-room-row {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.dungeon-room-row.is-boss {
  border-color: var(--gold);
  background: rgba(245,200,66,0.05);
}
.dungeon-room-num {
  width: 28px; height: 28px;
  background: var(--purple); color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.78rem;
  flex-shrink: 0;
}
.dungeon-room-row.is-boss .dungeon-room-num {
  background: var(--gold); color: black;
}
.dungeon-room-q {
  flex: 1; min-width: 0;
  font-size: 0.78rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dungeon-room-monster {
  font-size: 0.7rem;
  color: var(--muted2);
  display: flex; align-items: center; gap: 4px;
}

/* Editor de sala (modal) */
.dungeon-monster-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  background: var(--bg2);
  border-radius: 8px;
}
.dungeon-monster-pick {
  background: var(--bg3);
  border: 2px solid var(--border2);
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}
@media (hover: hover) and (pointer: fine) {
  .dungeon-monster-pick:hover { border-color: var(--purple); }
}
.dungeon-monster-pick.active {
  border-color: var(--gold);
  background: rgba(245,200,66,0.1);
}
.dungeon-monster-pick img {
  width: 56px; height: 56px;
  object-fit: none;
  object-position: 0 0;
  image-rendering: pixelated;
  display: block;
  margin: 0 auto 4px;
}
.dungeon-monster-pick .dmp-name {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text);
}
.dungeon-monster-pick .dmp-tier {
  font-size: 0.55rem;
  color: var(--muted2);
}

/* ── Mobile ── */
@media (max-width: 540px) {
  .dungeon-map {
    gap: 10px;
    padding: 16px 10px;
  }
  .droom { font-size: 1.3rem; border-width: 2px; }
  .droom-boss { font-size: 1.5rem; }
  .droom-label { font-size: 0.5rem; }
  .dungeon-header {
    padding: 8px 10px;
    gap: 6px;
  }
  .dungeon-title-block .dt-title { font-size: 0.82rem; }
  .ditem-btn { width: 32px; height: 32px; font-size: 0.9rem; }
  .ditem-count { width: 14px; height: 14px; font-size: 0.55rem; }
  .dungeon-canvas-wrap { padding: 10px; }
  .dungeon-question-text { font-size: 0.86rem; }
  .dungeon-opt { padding: 8px 10px; font-size: 0.78rem; }
  .dungeon-form-modes { grid-template-columns: 1fr; }
  .dungeon-theme-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 380px) {
  .dungeon-list-grid { grid-template-columns: 1fr; }
}
