@import url("https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap");

:root {
  --fire: #ff5b3d;
  --nature: #5bd65b;
  --earth: #c99a4a;
  --lightning: #f5e64c;
  --water: #4ac9f5;
  --bg-dark: #12121a;
  --panel: #1c1c28;
  --panel-light: #2a2a3a;
  --border: #3a3a4e;
  --text: #e8e8f0;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg-dark);
  color: var(--text);
  font-family: "Press Start 2P", monospace;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px;
  max-height: 75vh;
  overflow: hidden;
}

#spells-sidebar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 76px;
  flex-shrink: 0;
}

#spells-tray {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#main {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#title-row {
  display: flex;
  align-items: center;
  margin: 4px 0;
}
#title {
  font-size: clamp(12px, 2vw, 20px);
  letter-spacing: 2px;
  text-shadow: 3px 3px 0 #000;
  background: linear-gradient(
    90deg,
    var(--fire),
    var(--nature),
    var(--earth),
    var(--lightning),
    var(--water),
    var(--fire)
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: title-shimmer 4s ease-in-out infinite;
}

#toolbar {
  display: flex;
  gap: 6px;
  margin: 4px 0;
}
#toolbar button {
  font-family: "Press Start 2P", monospace;
  font-size: 7px;
  padding: 6px 10px;
  background: var(--panel-light);
  color: var(--text);
  border: 2px solid var(--border);
  cursor: pointer;
  border-radius: 3px;
  transition:
    border-color 0.1s ease,
    background 0.1s ease;
}
#toolbar button:hover {
  border-color: #fff;
  background: var(--panel);
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 900px;
  max-width: 80vw;
  margin-bottom: 4px;
  font-size: 9px;
}
.hud-side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: clamp(120px, 15vw, 220px);
}
.hp-bar-wrap {
  background: #000;
  border: 2px solid var(--border);
  height: 16px;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.hp-bar-fill {
  height: 100%;
  background: linear-gradient(180deg, #8bc34a, #4caf50);
  transition: width 0.3s ease-out;
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.2);
}
.hp-bar-fill.enemy {
  background: linear-gradient(180deg, #ff8080, #e05353);
}
.hp-bar-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 18px,
    rgba(0, 0, 0, 0.15) 18px,
    rgba(0, 0, 0, 0.15) 19px
  );
  pointer-events: none;
}
.hp-label {
  font-size: 7px;
  margin-bottom: 2px;
  text-shadow: 1px 1px 0 #000;
}

#game-area {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
#legend-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 4px;
  border: 2px solid var(--border);
  border-radius: 4px;
}

#timer-wrap {
  width: 100px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#timer-display {
  font-size: 11px;
  color: #e8e8f0;
  text-align: center;
  letter-spacing: 1px;
}
#timer-bar-wrap {
  background: #000;
  border: 2px solid var(--border);
  height: 6px;
  width: 100%;
}
#timer-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7a3fb0, #ffd76a);
  transition: width 0.5s linear;
}
#elixir-wrap {
  width: clamp(120px, 15vw, 220px);
}
#elixir-bar-wrap {
  background: #000;
  border: 2px solid #7a3fb0;
  height: 16px;
  width: 100%;
  display: flex;
}
.elixir-seg {
  flex: 1;
  border-right: 1px solid #000;
  position: relative;
}
.elixir-seg.filled {
  background: linear-gradient(180deg, #c165f5, #7a3fb0);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.2);
}
#elixir-wrap.double .elixir-seg.filled {
  background: linear-gradient(180deg, #ffd76a, #ff9a3d);
}
#double-tag {
  display: none;
  text-align: center;
  font-size: 6.5px;
  color: #ffd76a;
  margin-top: 2px;
  letter-spacing: 1px;
  text-shadow: 0 0 6px #ffd76a;
}
#double-tag.show {
  display: block;
}

#board-wrap {
  position: relative;
  border: 4px solid var(--border);
  box-shadow:
    0 0 0 4px #000,
    0 0 30px rgba(150, 100, 255, 0.2),
    0 0 60px rgba(150, 100, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
  max-width: 900px;
  max-height: 460px;
}
canvas {
  display: block;
}
#board {
  background: #3d7530;
  width: auto;
  height: auto;
  max-width: 80vw;
  max-height: 85vh;
  aspect-ratio: 900/460;
  image-rendering: pixelated;
}
#legend-wheel {
  max-height: 50vh;
  aspect-ratio: 160/280;
}

#tray {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
  justify-content: center;
  width: 1200px;
  max-width: 80vw;
}
.card {
  width: clamp(60px, 8vw, 92px);
  background: linear-gradient(180deg, var(--panel-light), var(--panel));
  border: 2px solid var(--border);
  border-radius: 5px;
  padding: 4px 3px 5px 3px;
  cursor: pointer;
  font-size: 6px;
  text-align: center;
  user-select: none;
  position: relative;
  transition:
    transform 0.1s ease,
    border-color 0.1s ease,
    box-shadow 0.1s ease;
  overflow: hidden;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}
.card.selected {
  border-color: #fff;
  box-shadow:
    0 0 0 2px #fff inset,
    0 0 12px rgba(255, 255, 255, 0.3);
}
.card.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  filter: grayscale(0.5);
}
.card.disabled:hover {
  transform: none;
  box-shadow: none;
}
.card.dragging {
  opacity: 0.25;
  transform: scale(0.92);
}
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  opacity: 0.9;
  transform: scale(1.1);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.7),
    0 0 20px rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  transition: none;
  background: linear-gradient(180deg, var(--panel-light), var(--panel));
  border: 2px solid #fff;
  padding: 5px;
  width: clamp(60px, 8vw, 92px);
}
.card canvas {
  display: block;
  margin: 0 auto 3px auto;
  image-rendering: pixelated;
}
.card .cost {
  position: absolute;
  top: 3px;
  left: 3px;
  background: linear-gradient(180deg, #9a5fd0, #7a3fb0);
  color: #fff;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 6px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  font-weight: bold;
}
.card .elixir-icon {
  position: absolute;
  top: 3px;
  right: 3px;
  font-size: 5px;
  color: #c165f5;
}
.lane-label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: -2px;
  font-size: 6px;
  color: #6a6a80;
}
.card .name {
  margin-bottom: 2px;
  font-weight: bold;
  letter-spacing: 0.3px;
}
.card .cd {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: #fff;
  border-radius: 3px;
}
.card.spell {
  border-color: #7fe0ff55;
}
.card.spell.selected {
  border-color: #7fe0ff;
  box-shadow:
    0 0 0 2px #7fe0ff inset,
    0 0 12px rgba(127, 224, 255, 0.3);
}
.card .desc {
  font-size: 5.5px;
  color: #9a9ab0;
  margin-top: 2px;
  line-height: 1.4;
}
.card .element-tag {
  display: inline-block;
  padding: 1px 3px;
  border-radius: 2px;
  font-size: 5px;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card .stats-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 5px;
  color: #8888a0;
}
.card .stats-row span {
  display: flex;
  align-items: center;
  gap: 2px;
}
#tray-divider {
  width: 100%;
  text-align: center;
  font-size: 6.5px;
  color: #6a6a80;
  margin: 4px 0 2px 0;
  letter-spacing: 1px;
}

#status {
  margin-top: 4px;
  font-size: clamp(5px, 0.8vw, 8px);
  min-height: 10px;
  color: #ffd76a;
}
#credits {
  position: fixed;
  bottom: 8px;
  right: 12px;
  font-size: 10px;
  color: #55556a;
  letter-spacing: 1px;
  z-index: 50;
}

#overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  z-index: 10;
}
#overlay.show {
  display: flex;
}
#overlay-title {
  font-size: 24px;
  text-shadow:
    2px 2px 0 #000,
    0 0 20px rgba(150, 100, 255, 0.4);
}
#overlay-title.win {
  color: #ffd76a;
}
#overlay-title.lose {
  color: #ff5b3d;
}
#overlay button {
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  padding: 12px 22px;
  background: linear-gradient(180deg, #9a5fd0, #7a3fb0);
  color: #fff;
  border: 2px solid #fff;
  cursor: pointer;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease;
}
#overlay button:hover {
  background: linear-gradient(180deg, #b070e0, #9a5fd0);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

#pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  z-index: 10;
}
#pause-overlay.show {
  display: flex;
}
#pause-title {
  font-size: 22px;
  color: #ffd76a;
}
#resume-btn {
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  padding: 12px 22px;
  background: linear-gradient(180deg, #4ac9f5, #2a8ab5);
  color: #fff;
  border: 2px solid #fff;
  cursor: pointer;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease;
}
#resume-btn:hover {
  background: linear-gradient(180deg, #6ad9ff, #4ac9f5);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}
#pause-hint {
  font-size: 7px;
  color: #8888a0;
}

#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#modal-backdrop.hidden {
  display: none;
}
#modal {
  background: var(--panel);
  border: 3px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  max-width: 70vw;
  max-height: 70vh;
  overflow-y: auto;
  position: relative;
}
#modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  font-family: "Press Start 2P", monospace;
  padding: 4px 8px;
}
#modal-close:hover {
  color: #ff5b3d;
}
#modal-content {
  padding-top: 12px;
}
.modal-title {
  text-align: center;
  font-size: 14px;
  color: #ffd76a;
  margin: 0 0 16px 0;
  text-shadow: 2px 2px 0 #000;
}
.modal-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}
.modal-card {
  background: linear-gradient(180deg, var(--panel-light), var(--panel));
  border: 2px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  width: 160px;
}
.modal-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.modal-card-element {
  font-size: 5px;
  text-transform: uppercase;
}
.modal-card-name {
  font-size: 7px;
  flex: 1;
}
.modal-card-cost {
  font-size: 7px;
  background: linear-gradient(180deg, #9a5fd0, #7a3fb0);
  padding: 2px 5px;
  border-radius: 3px;
}
.modal-card-stats {
  display: flex;
  gap: 8px;
  font-size: 5px;
  color: #8888a0;
  margin-bottom: 6px;
}
.modal-card-special {
  font-size: 5px;
  color: #ffd76a;
  margin-top: 4px;
}
.modal-card-desc {
  font-size: 6px;
  color: #9a9ab0;
  line-height: 1.5;
}
.modal-wheel-container {
  display: flex;
  justify-content: center;
  margin: 10px 0;
}
#modal-wheel-canvas {
  image-rendering: pixelated;
}
.modal-wheel-labels {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 10px 0;
}
.modal-wheel-label {
  font-size: 6px;
}
.modal-wheel-hint {
  text-align: center;
  font-size: 6px;
  color: #8888a0;
  max-width: 320px;
  line-height: 1.6;
}

#desktop-only-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.desktop-only-content {
  text-align: center;
  padding: 24px;
}

.desktop-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.desktop-only-content h1 {
  font-size: 24px;
  color: #ffd76a;
  margin: 0 0 16px 0;
  text-shadow: 2px 2px 0 #000;
}

.desktop-only-content p {
  font-size: 10px;
  color: #e8e8f0;
  margin: 8px 0;
  line-height: 1.6;
}

@media (max-width: 768px) {
  #spells-sidebar,
  #main {
    display: none !important;
  }
  #desktop-only-overlay {
    display: flex;
  }
}
