:root {
  --bg: #0a0f1a;
  --panel: #121a2a;
  --gold: #d4af77;
  --ember: #ff6b4a;
  --frost: #7fd4ff;
  --accent: #a78bfa;
  --text: #e8f0f7;
  --muted: #8fa3b8;
  --wall: #2a3448;
  --floor: #1a2233;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #070b14;
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#title-screen {
  width: min(980px, 94vw);
  text-align: center;
  padding: 24px 20px;
}

.title-art {
  margin-bottom: 12px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(212, 175, 119, 0.15);
}

h1 {
  font-size: 3.2rem;
  letter-spacing: 0.12em;
  margin: 4px 0 6px;
  background: linear-gradient(180deg, #f0d9b0, #d4af77 40%, #a67c52);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 30px rgba(212, 175, 119, 0.3);
}

.tagline {
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0 0 28px;
  letter-spacing: 0.04em;
}

.select-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-bottom: 24px;
}

@media (max-width: 860px) {
  .select-section { grid-template-columns: 1fr; }
}

.select-group h2 {
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  color: var(--gold);
  margin: 0 0 12px;
  text-transform: uppercase;
}

.card-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.hero-card, .dragon-card {
  width: 138px;
  background: var(--panel);
  border: 2px solid rgba(212, 175, 119, 0.2);
  border-radius: 14px;
  padding: 10px 8px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
}

.hero-card:hover, .dragon-card:hover {
  transform: translateY(-3px);
  border-color: var(--gold);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.hero-card.selected, .dragon-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212, 175, 119, 0.25);
  background: #1a2438;
}

.hero-card .preview {
  width: 100%;
  height: 78px;
  border-radius: 8px;
  background: #0d1320;
  margin-bottom: 8px;
  position: relative;
  overflow: hidden;
}

.hero-card .name {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 2px;
}

.hero-card .role {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.3;
}

.dragon-card .preview {
  width: 100%;
  height: 78px;
  border-radius: 8px;
  background: #0d1320;
  margin-bottom: 8px;
  position: relative;
}

.dragon-card .name {
  font-weight: 600;
  font-size: 0.9rem;
}

.dragon-card .element {
  font-size: 0.7rem;
  color: var(--accent);
}

.coop-toggle {
  grid-column: 1 / -1;
  margin-top: 12px;
  background: rgba(18, 26, 42, 0.6);
  border: 1px solid rgba(212, 175, 119, 0.15);
  border-radius: 999px;
  padding: 10px 18px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.coop-toggle label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.95rem;
}

.controls-hint {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.start-btn {
  margin-top: 12px;
  font-size: 1.1rem;
  padding: 14px 56px;
  background: linear-gradient(180deg, #d4af77, #a67c52);
  color: #0a0f1a;
  border: none;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(212, 175, 119, 0.35);
  transition: transform 0.1s ease, box-shadow 0.1s;
}

.start-btn:hover {
  transform: scale(1.02);
  box-shadow: 0 16px 40px rgba(212, 175, 119, 0.45);
}

.footer-note {
  margin-top: 18px;
  font-size: 0.75rem;
  color: #5f6f85;
}

/* GAME */
#game-container {
  position: relative;
  width: min(1040px, 98vw);
  height: min(670px, calc(98vw * 0.644));
  max-height: 94vh;
  border: 1px solid rgba(212, 175, 119, 0.28);
  border-radius: 8px;
  overflow: hidden;
  /* Pass 24: subtle warm ember inner glow + inset gold rim for desktop "framed magical painting / viewport" presence. Makes the entire playable canvas feel like a handcrafted art piece / window into the depths (stronger focal authorship per operator mandate). Mobile unaffected (media query overrides). */
  box-shadow:
    0 0 0 1px rgba(212, 175, 119, 0.09) inset,
    0 0 22px rgba(255, 155, 80, 0.085),
    0 40px 120px rgba(0, 0, 0, 0.7);
  background: #0a0f1a;
  aspect-ratio: 960 / 620;
}

#game-canvas {
  display: block;
  background: #0c1220;
  /* crisp vector art + HiDPI (Pass 7); pixelated removed for authored smooth silhouettes */
  image-rendering: auto;
  width: 100%;
  height: 100%;
  object-fit: contain;
  touch-action: none;
  user-select: none;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: 13px;
}

.hud-top {
  position: absolute;
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  pointer-events: none;
}

#room-label {
  background: rgba(10, 15, 26, 0.58);
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.06em;
  border: 1px solid rgba(212, 175, 119, 0.25);
  color: var(--gold);
}

#progress {
  background: rgba(10, 15, 26, 0.5);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid rgba(127, 212, 255, 0.2);
}

.player-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10, 15, 26, 0.55);
  padding: 3px 10px 3px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: auto;
}

.p-label {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: #2a3448;
  color: #c4d4e6;
}

.player-status .bar {
  width: 72px;
  height: 7px;
  background: #1f283d;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.player-status .fill {
  height: 100%;
  background: linear-gradient(90deg, #ff6b4a, #ff9f5a);
  transition: width 0.1s linear;
}

#p2-status .fill { background: linear-gradient(90deg, #7fd4ff, #a5e0ff); }

.cooldowns {
  display: flex;
  gap: 4px;
}

.cd {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #1f283d;
  border: 1px solid rgba(212, 175, 119, 0.3);
  position: relative;
}

.cd::after {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  background: conic-gradient(var(--gold) var(--angle, 0deg), transparent 0);
  mask: radial-gradient(circle at center, transparent 58%, black 59%);
}

#minimap {
  position: absolute;
  bottom: 14px;
  right: 16px;
  width: 108px;
  height: 68px;
  background: rgba(22, 17, 12, 0.68);
  border: 1px solid rgba(212, 175, 119, 0.35);
  border-radius: 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(212,175,119,0.08);
  pointer-events: none;
  /* Pass 30: warmer parchment map frame for authored cartography feel */
  /* Pass 58: lighter to reduce competition with playfield per tallhamn HUD feedback */
}

#overlay {
  position: absolute;
  inset: 0;
  background: rgba(7, 11, 20, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.overlay-panel {
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 16px;
  padding: 22px 28px;
  min-width: 320px;
  max-width: 460px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}

#overlay-title {
  font-size: 1.25rem;
  color: var(--gold);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}

#overlay-body {
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 18px;
  font-size: 0.95rem;
}

#overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

#overlay-actions button {
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.1s;
}

#overlay-actions button.primary {
  background: var(--gold);
  color: #0a0f1a;
  border-color: var(--gold);
}

#overlay-actions button:hover {
  background: rgba(212, 175, 119, 0.15);
}

#overlay-actions button.primary:hover {
  background: #e8c89a;
}

#toast {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 26, 42, 0.9);
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 13px;
  border: 1px solid rgba(212, 175, 119, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 30;
}

#toast.show {
  opacity: 1;
}

.pause-btn, .mute-btn {
  position: absolute;
  top: 14px;
  pointer-events: auto;
  background: rgba(10, 15, 26, 0.7);
  border: 1px solid rgba(212, 175, 119, 0.25);
  color: var(--gold);
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
  z-index: 25;
}

.pause-btn { right: 16px; }

.mute-btn {
  right: 92px;
  font-size: 13px;
  padding: 3px 9px;
}

/* Mobile 390px+ responsive polish for HUD readability (no overlap) */
@media (max-width: 480px) {
  #game-container {
    width: min(100vw, 390px);
    height: min(640px, calc(100vw * 0.645));
    border-radius: 6px;
  }
  .hud-top {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 8px;
    font-size: 11px;
  }
  #room-label, #progress { font-size: 10px; padding: 2px 8px; }
  .player-status { padding: 2px 6px 2px 4px; }
  .player-status .bar { width: 56px; height: 6px; }
  .cd { width: 14px; height: 14px; }
  #minimap {
    bottom: 8px;
    right: 8px;
    width: 82px;
    height: 52px;
  }
  .pause-btn, .mute-btn { top: 8px; font-size: 10px; padding: 2px 8px; }
  .mute-btn { right: 68px; }
}
