* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--forest);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  cursor: default;
  color: var(--ink);
}

#game {
  position: fixed;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: var(--forest);
}

body.playing {
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#menu {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(240, 207, 106, 0.18), transparent 60%),
    radial-gradient(ellipse at 50% 120%, rgba(0, 0, 0, 0.45), transparent 60%),
    linear-gradient(160deg, var(--forest) 0%, var(--forest-dark) 100%);
  z-index: 100;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(1rem, env(safe-area-inset-top, 0px))
           max(1rem, env(safe-area-inset-right, 0px))
           max(1rem, env(safe-area-inset-bottom, 0px))
           max(1rem, env(safe-area-inset-left, 0px));
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.menu-card {
  background:
    radial-gradient(ellipse at center, rgba(255, 255, 255, 0.35), transparent 70%),
    var(--parchment);
  border: 4px solid var(--wood);
  border-radius: 6px;
  box-shadow: 0 0 0 3px var(--gold), 0 18px 50px rgba(0, 0, 0, 0.55);
  padding: 1.5rem 2rem;
  text-align: center;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto 1rem;
  display: flex;
  flex-direction: column;
}

.menu-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  text-align: left;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.menu-header-text {
  min-width: 0;
  flex: 1;
}

.menu-header .subtitle {
  margin-bottom: 0;
}

@media (min-width: 821px) {
  #menu {
    align-items: center;
    padding: 1rem;
  }

  .menu-card {
    max-height: calc(100vh - 2rem);
    margin: auto;
  }

  .menu-columns {
    flex: 1;
    min-height: 0;
  }
}

.menu-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr) minmax(0, 0.85fr);
  gap: 0;
  align-items: stretch;
  text-align: left;
}

.menu-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 1.25rem;
}

.menu-col + .menu-col {
  border-left: 2px solid var(--wood-light);
}

.menu-col-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.75rem;
  text-align: center;
  flex-shrink: 0;
}

.menu-col:first-child {
  padding-left: 0;
}

.menu-col:last-child {
  padding-right: 0;
}

.menu-col-play {
  justify-content: flex-start;
}

@media (max-width: 820px) {
  .menu-card {
    padding: 1.25rem;
  }

  .menu-header {
    align-items: center;
  }

  .menu-columns {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .menu-col + .menu-col {
    border-left: none;
    border-top: 2px solid var(--wood-light);
    padding: 1.25rem 0 0;
  }

  .menu-col:first-child {
    padding-top: 0;
  }
}

.menu-card h1 {
  color: var(--crimson);
  text-shadow: 1px 1px 0 var(--gold-light), 2px 2px 0 rgba(0, 0, 0, 0.15);
  font-size: 1.8rem;
  margin-bottom: 0.35rem;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.subtitle {
  color: var(--muted);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border: 2px solid var(--wood);
}

.auth-tab {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: none;
  background: var(--parchment);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.auth-tab + .auth-tab {
  border-left: 2px solid var(--wood-light);
}

.auth-tab.active {
  background: var(--wood);
  color: var(--parchment);
}

.auth-panel {
  text-align: left;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.auth-panel input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--wood);
  border-radius: 0;
  background: var(--parchment);
  color: var(--ink);
  font-size: 1rem;
  margin-bottom: 0.55rem;
  outline: none;
}

.auth-panel input:focus {
  background: var(--parchment-2);
}

.auth-hint {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
  margin-top: 0.15rem;
}

.auth-secondary-btn {
  width: 100%;
  padding: 0.65rem 1rem;
  border: 2px solid var(--wood);
  background: var(--parchment);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
  margin-top: 0.25rem;
}

.auth-secondary-btn:hover {
  background: var(--parchment-2);
}

.auth-switch {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.65rem;
  text-align: center;
}

.link-btn {
  border: none;
  background: none;
  color: var(--ink);
  font-weight: bold;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  font-size: inherit;
}

.logged-in-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 2px solid var(--wood);
  background: var(--parchment-2);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.auth-message {
  min-height: 1.2rem;
  font-size: 0.78rem;
  color: var(--ink);
  margin-top: 0.35rem;
}

.auth-message.error {
  color: var(--crimson);
}

.auth-message.success {
  color: #2f6b22;
}

#playerName {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--wood);
  border-radius: 0;
  background: var(--parchment);
  color: var(--ink);
  font-size: 1rem;
  margin-bottom: 0.55rem;
  outline: none;
}

#playerName:focus {
  background: var(--parchment-2);
}

.class-picker {
  text-align: left;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.class-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
  flex-shrink: 0;
}

.class-option {
  display: block;
  border: 2px solid var(--wood);
  padding: 0.55rem 0.65rem;
  cursor: pointer;
  transition: background 0.15s;
  text-align: center;
}

.class-icon {
  display: block;
  margin: 0 auto 0.35rem;
}

.class-option:hover {
  background: var(--parchment-2);
}

/* Cada classe tem sua cor (definida em --class-color pelo classInfo.js). */
.class-option {
  border-left-width: 6px;
  border-left-color: var(--class-color, var(--wood));
}

.class-option.selected {
  background: var(--class-color, var(--wood));
  border-color: var(--ink);
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.class-option input {
  display: none;
}

.class-option .class-name {
  display: block;
  font-weight: bold;
  font-size: 0.85rem;
  line-height: 1.2;
}

.class-option .class-role {
  display: block;
  font-size: 0.68rem;
  margin-top: 0.15rem;
  opacity: 0.75;
}

.class-detail {
  border: 2px solid var(--wood);
  padding: 0.65rem 0.85rem;
  background: var(--parchment-2);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.class-preview-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.class-preview-wrap canvas {
  border: 2px solid var(--wood);
  border-radius: 4px;
  background: radial-gradient(circle at 50% 60%, #9cc674, #6f9e4c);
}

.class-icon {
  border-radius: 4px;
  background: radial-gradient(circle at 50% 60%, #9cc674, #6f9e4c);
}

.class-detail h4 {
  font-size: 1rem;
  margin-bottom: 0.15rem;
}

.class-role-detail {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.class-detail-list {
  list-style: none;
  font-size: 0.8rem;
  line-height: 1.45;
}

.class-detail-list li {
  margin-bottom: 0.35rem;
  padding-left: 0.75rem;
  position: relative;
}

.class-detail-list li::before {
  content: '—';
  position: absolute;
  left: 0;
}

.class-detail-list li.tip {
  color: var(--muted);
  font-style: italic;
}

.class-detail-list li.tip::before {
  content: '·';
}

#playBtn {
  width: 100%;
  padding: 1.25rem 0.75rem;
  background: linear-gradient(180deg, #a83424, var(--crimson));
  border: 3px solid var(--gold);
  border-radius: 4px;
  box-shadow: 0 0 0 2px var(--ink), 0 4px 0 var(--crimson-dark);
  color: #fff4d6;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  line-height: 1.3;
  flex-shrink: 0;
}

#playBtn:hover {
  background: linear-gradient(180deg, #c03f2c, #a0301f);
}

#playBtn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 2px var(--ink), 0 1px 0 var(--crimson-dark);
}

.controls {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--wood-light);
  text-align: left;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.controls h3 {
  color: var(--ink);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.controls p {
  color: var(--ink-soft);
  font-size: 0.85rem;
  margin: 0.3rem 0;
}

.controls-desktop,
.controls-touch {
  display: block;
}

.controls[data-input-mode="desktop"] .controls-touch {
  display: none;
}

.controls[data-input-mode="mobile"] .controls-desktop {
  display: none;
}

.controls[data-input-mode="both"] .controls-touch {
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--wood-light);
}

kbd {
  background: var(--parchment);
  border: 1px solid var(--wood);
  border-radius: 0;
  padding: 0.1rem 0.4rem;
  color: var(--ink);
  font-size: 0.8rem;
}

#hud {
  position: fixed;
  top: max(1rem, var(--safe-top, 0px));
  left: max(1rem, var(--safe-left, 0px));
  display: flex;
  gap: 0.75rem;
  z-index: 10;
}

.hud-item {
  background: rgba(244, 232, 200, 0.93);
  border: 2px solid var(--wood);
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  padding: 0.5rem 0.85rem;
  color: var(--ink);
}

.hud-item .label {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hud-item span:last-child {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--ink);
}

#leaderboard {
  position: fixed;
  top: max(1rem, var(--safe-top, 0px));
  right: max(1rem, var(--safe-right, 0px));
  background: rgba(244, 232, 200, 0.93);
  border: 2px solid var(--wood);
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  padding: 0.75rem 1rem;
  min-width: 180px;
  z-index: 10;
}

#leaderboard h3 {
  color: var(--ink);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#ranking {
  list-style: none;
  color: var(--ink);
  font-size: 0.85rem;
}

#ranking li {
  padding: 0.2rem 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

#ranking li.me {
  font-weight: bold;
  background: rgba(212, 166, 42, 0.35);
  margin: 0 -0.35rem;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
  border-radius: 3px;
}

#ranking li .class-dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  border: 1px solid var(--ink);
  margin-right: 0.3rem;
  vertical-align: middle;
}

.hidden {
  display: none !important;
}

:root {
  /* Tema medieval: pergaminho, madeira, carmesim e dourado. */
  --ink: #2a1d12;
  --ink-soft: #4a3826;
  --muted: #6b5a42;
  --parchment: #f4e8c8;
  --parchment-2: #ead9ae;
  --parchment-3: #dcc58e;
  --wood: #6b4423;
  --wood-light: #a8743f;
  --gold: #d4a62a;
  --gold-light: #f0cf6a;
  --crimson: #8e2a1e;
  --crimson-dark: #6a1d14;
  --forest: #2f4a24;
  --forest-dark: #1d3016;
  --minimap-size: 130px;
  --minimap-margin: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

#gameControls {
  position: fixed;
  right: max(var(--minimap-margin), var(--safe-right));
  bottom: max(var(--minimap-margin), var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.6rem;
  z-index: 10;
}

.game-btn {
  position: relative;
  min-width: 5.5rem;
  padding: 0.65rem 1rem;
  border: 3px solid var(--ink);
  border-radius: 6px;
  background: var(--parchment);
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  overflow: hidden;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.game-btn-attack {
  background: linear-gradient(180deg, #b23a28, var(--crimson));
  color: #fff4d6;
}

.game-btn-skill {
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  color: var(--ink);
}

.game-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  filter: brightness(0.9);
}

.game-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.game-btn-key {
  display: block;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.65;
}

.game-btn-label {
  display: block;
  font-size: 0.95rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.game-btn-skill.active {
  background: var(--wood);
  color: var(--gold-light);
}

.game-btn-cooldown {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: 0%;
  background: var(--ink);
  opacity: 0.6;
  pointer-events: none;
}

/* Faixa discreta na parte de baixo: a animação da morte continua visível. */
.dead-overlay {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 22%;
  display: flex;
  justify-content: center;
  z-index: 50;
  pointer-events: none;
  animation: dead-banner-in 0.35s ease-out;
}

.dead-overlay span {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  color: var(--crimson);
  font-size: 1.5rem;
  font-weight: bold;
  border: 3px solid var(--crimson);
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--gold), 0 6px 20px rgba(0, 0, 0, 0.45);
  padding: 0.6rem 1.6rem;
  background: rgba(244, 232, 200, 0.95);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.dead-overlay small {
  font-size: 0.8rem;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}

@keyframes dead-banner-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.music-toggle {
  border: 2px solid var(--wood);
  background: var(--parchment);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.music-toggle.muted {
  opacity: 0.55;
  text-decoration: line-through;
}

.music-toggle:active {
  background: var(--wood);
  color: var(--parchment);
}

.hud-music {
  align-self: stretch;
  padding: 0.5rem 0.7rem;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

@media (max-width: 900px), (pointer: coarse) {
  .music-toggle {
    font-size: 0.68rem;
    padding: 0.35rem 0.5rem;
  }

  .hud-music {
    padding: 0.12rem 0.4rem;
  }

  #hud {
    top: max(6px, var(--safe-top));
    left: max(6px, var(--safe-left));
    gap: 4px;
    flex-wrap: wrap;
    max-width: min(58vw, 220px);
  }

  .hud-item {
    padding: 0.12rem 0.35rem;
    border-width: 1.5px;
    line-height: 1.15;
  }

  .hud-item .label {
    font-size: 0.48rem;
    letter-spacing: 0.3px;
  }

  .hud-item span:last-child {
    font-size: 0.72rem;
  }

  #leaderboard {
    top: max(6px, var(--safe-top));
    right: max(6px, var(--safe-right));
    padding: 0.3rem 0.45rem;
    min-width: 0;
    max-width: 36vw;
    border-width: 1.5px;
  }

  #leaderboard h3 {
    font-size: 0.62rem;
    margin-bottom: 0.2rem;
    letter-spacing: 0.4px;
  }

  #ranking {
    font-size: 0.62rem;
  }

  #ranking li {
    padding: 0.05rem 0;
    gap: 0.35rem;
  }

  #ranking li:nth-child(n+4) {
    display: none;
  }

  #ranking li small {
    font-size: 0.55rem;
  }

  #gameControls {
    right: max(14px, var(--safe-right));
    bottom: max(14px, var(--safe-bottom));
    gap: 0.75rem;
  }

  .game-btn {
    width: 4.75rem;
    height: 4.75rem;
    min-width: 4.75rem;
    padding: 0.4rem;
    border-radius: 999px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 3px rgba(244, 232, 200, 0.85), 0 3px 8px rgba(0, 0, 0, 0.35);
  }

  .game-btn-key {
    display: none;
  }

  .game-btn-label {
    font-size: 0.78rem;
    line-height: 1.1;
  }

  .game-btn-cooldown {
    height: 5px;
  }

  #minimap,
  :root {
    --minimap-size: 96px;
  }
}

/* Botão Menu no HUD e painel do menu do jogo */
.hud-menu-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 2px solid var(--wood);
  border-radius: 4px;
  background: rgba(244, 232, 200, 0.93);
  color: var(--ink);
  font: bold 0.75rem inherit;
  font-family: inherit;
  text-transform: uppercase;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.hud-menu-icon,
.hud-menu-icon::before,
.hud-menu-icon::after {
  display: block;
  width: 14px;
  height: 2px;
  background: var(--ink);
  position: relative;
}

.hud-menu-icon::before,
.hud-menu-icon::after {
  content: '';
  position: absolute;
}

.hud-menu-icon::before { top: -5px; }
.hud-menu-icon::after { top: 5px; }

.game-menu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  width: min(320px, calc(100vw - 32px));
  padding: 1rem 1.25rem;
  background: var(--parchment);
  border: 3px solid var(--wood);
  border-radius: 6px;
  box-shadow: 0 0 0 3px var(--gold), 0 12px 40px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.game-menu h3 {
  color: var(--crimson);
  text-transform: uppercase;
  letter-spacing: 1px;
  text-align: center;
}

.game-menu-row {
  display: grid;
  grid-template-columns: 4.5rem 1fr 2.8rem;
  align-items: center;
  gap: 0.5rem;
  font-weight: bold;
  font-size: 0.85rem;
}

.game-menu-row input { accent-color: var(--crimson); width: 100%; }
.game-menu-row output { text-align: right; font-variant-numeric: tabular-nums; }

.game-menu-btn {
  padding: 0.6rem;
  border: 2px solid var(--wood);
  border-radius: 4px;
  background: var(--parchment-2);
  color: var(--ink);
  font-family: inherit;
  font-weight: bold;
  text-transform: uppercase;
  cursor: pointer;
}

.game-menu-leave {
  background: linear-gradient(180deg, #a83424, var(--crimson));
  border-color: var(--ink);
  color: #fff4d6;
}
