/* TerraMine Miner v1 — 1920×1080 aspect, responsive */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a120c;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #f5e6c8;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

#game-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}

#bg {
  position: absolute;
  inset: 0;
  background: #2a1e14 url("../assets/background-mine-interior-1920x1080.jpg") center / cover no-repeat;
  z-index: 0;
}

#bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(10,6,2,0.55) 0%, rgba(10,6,2,0.25) 35%, rgba(10,6,2,0.35) 100%);
  pointer-events: none;
}

#ui-layer {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(180px, 28%) 1fr;
  width: 100%;
  height: 100%;
  padding: clamp(12px, 2vw, 28px);
  gap: clamp(8px, 1.5vw, 24px);
}

/* —— Left panel —— */
#left-panel {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 14px;
  padding-bottom: clamp(24px, 8vh, 80px);
  padding-left: clamp(8px, 2vw, 32px);
}

.brand h1 {
  font-size: clamp(1.6rem, 3.2vw, 2.8rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 12px rgba(0,0,0,0.8), 0 0 24px rgba(212,160,60,0.35);
  color: #f0d080;
}

.brand .tagline {
  font-size: clamp(0.85rem, 1.4vw, 1.1rem);
  opacity: 0.85;
  margin-top: 2px;
  color: #cbb89a;
}

.btn-primary, .btn-secondary {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 14px 28px;
  font-size: clamp(1rem, 1.6vw, 1.25rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.btn-primary {
  background: linear-gradient(180deg, #e8b84a 0%, #b87820 100%);
  color: #1a1008;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.35);
}

.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(1px); filter: brightness(0.95); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: rgba(40,28,18,0.75);
  color: #f0d080;
  border: 1px solid rgba(212,160,60,0.5);
}

.status-msg {
  max-width: 260px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(20,12,6,0.8);
  border: 1px solid rgba(212,160,60,0.4);
  font-size: 0.95rem;
  line-height: 1.35;
}

.status-msg.win { border-color: #6ecf6e; color: #b8f0b8; }
.status-msg.lose { border-color: #cf6e6e; color: #f0b8b8; }

/* —— Right panel —— */
#right-panel {
  display: flex;
  flex-direction: column;
  align-items: center; /* center HUD, goals, board as a stack */
  justify-content: flex-start;
  gap: 0;
  min-width: 0;
  height: 100%;
}

.goals-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 14px;
  border-radius: 14px;
  background: rgba(18,12,6,0.72);
  border: 1px solid rgba(180,140,70,0.35);
  backdrop-filter: blur(6px);
  max-width: 100%;
  flex-wrap: wrap;
  margin: 0 auto 15px; /* 15px gap above the board */
}

.goals-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.7;
}

.goals-list {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.goal-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: rgba(50,36,20,0.7);
  border: 1px solid rgba(255,255,255,0.08);
  font-weight: 700;
  font-size: 0.95rem;
  min-width: 72px;
}

.goal-chip.done {
  opacity: 0.55;
  text-decoration: line-through;
  border-color: #6ecf6e;
}

.goal-chip img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.hud {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 12px;
  background: rgba(18,12,6,0.65);
  border: 1px solid rgba(180,140,70,0.3);
  margin: 0 auto 8px; /* sits just above goals */
}

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.hud-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.7;
}

.hud-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: #f0d080;
  min-width: 2ch;
}

.gravity-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(145deg, #3a2a18, #1e140c);
  border: 2px solid #c89840;
  font-size: 1.4rem;
  line-height: 1;
  color: #f0d080;
  transition: transform 0.35s ease;
}

/* —— Board —— */
#board-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  min-height: 0;
  padding-right: 0;
}

.board {
  --cols: 7;
  --gap: 4px;
  overflow: visible;
  --cell: min(
    calc((min(52vw, 72vh) - (var(--cols) - 1) * var(--gap)) / var(--cols)),
    72px
  );
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--cols), var(--cell));
  gap: var(--gap);
  padding: 10px;
  border-radius: 16px;
  background: rgba(12,8,4,0.45);
  border: 1px solid rgba(180,140,70,0.25);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  touch-action: none;
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  overflow: visible; /* allow gem slides across cell borders */
  cursor: pointer;
}

/* Checkerboard ~70% transparent gradient fills */
.cell.tone-a {
  background: linear-gradient(145deg,
    rgba(90, 90, 95, 0.70) 0%,
    rgba(55, 55, 60, 0.70) 100%);
}
.cell.tone-b {
  background: linear-gradient(145deg,
    rgba(160, 120, 70, 0.70) 0%,
    rgba(110, 75, 40, 0.70) 100%);
}

.cell.selected {
  outline: 2px solid #f0d080;
  outline-offset: -2px;
  box-shadow: inset 0 0 12px rgba(240,208,128,0.45);
}

.gem {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  object-fit: contain;
  pointer-events: none;
  transition: none;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.45));
  z-index: 1;
  will-change: transform;
}

.cell.lift {
  z-index: 6;
}

.gem.sliding {
  z-index: 8;
  pointer-events: none;
}

.gem-flyer {
  position: fixed;
  margin: 0;
  inset: auto;
  object-fit: contain;
  pointer-events: none;
  z-index: 200;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.45));
}

.gem.matching {
  animation: gem-crush 0.3s ease forwards;
}

@keyframes gem-crush {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.2); opacity: 0; }
}

.gem.entering {
  z-index: 3;
}

.gem.jade {
  cursor: pointer;
  pointer-events: none;
  animation: jade-pulse 1.6s ease-in-out infinite;
}

@keyframes jade-pulse {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(80,220,140,0.5)); transform: scale(1); }
  50% { filter: drop-shadow(0 0 10px rgba(80,220,140,0.9)); transform: scale(1.05); }
}


.board.locked { cursor: wait; opacity: 0.92; }
.board.locked .gem.jade { animation: none; }
.board { touch-action: none; }
.cell { touch-action: none; -webkit-user-drag: none; }

.btn-primary.pulse-hint {
  animation: pulse-hint 0.45s ease-in-out 2;
}
@keyframes pulse-hint {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 rgba(240,208,128,0); }
  50% { transform: scale(1.06); box-shadow: 0 0 24px rgba(240,208,128,0.65); }
}

/* Overlay win/lose */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  border-radius: 16px;
  z-index: 10;
}

.overlay[hidden] {
  display: none !important;
}

.overlay-card {
  text-align: center;
  padding: 28px 36px;
  border-radius: 16px;
  background: linear-gradient(180deg, #3a2a18, #1e140c);
  border: 2px solid #c89840;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  max-width: 90%;
}

.overlay-card h2 {
  font-size: 1.8rem;
  color: #f0d080;
  margin-bottom: 8px;
}

.overlay-card p {
  margin-bottom: 18px;
  opacity: 0.9;
}

/* —— Responsive —— */
@media (max-width: 900px) {
  #ui-layer {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    padding: 10px;
  }

  #left-panel {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 0;
    gap: 10px;
  }

  #right-panel {
    align-items: center;
    width: 100%;
  }

  #board-wrap {
    justify-content: center;
    width: 100%;
  }

  .board {
    --cell: min(
      calc((min(92vw, 58vh) - (var(--cols) - 1) * var(--gap)) / var(--cols)),
      64px
    );
  }
}

/* Phones / narrow windows: board fills available width */
@media (max-width: 640px) {
  #ui-layer {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    padding: 8px;
    gap: 8px;
  }

  #left-panel {
    width: 100%;
    padding: 0;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
  }

  #right-panel {
    width: 100%;
    align-items: stretch;
    gap: 8px;
  }

  .goals-strip,
  .hud {
    width: auto;
    max-width: 100%;
    justify-content: center;
  }

  #board-wrap {
    width: 100%;
    max-width: 100%;
    padding: 0;
    justify-content: center;
    align-items: flex-start;
  }

  .board {
    /* Fill almost the full device width; leave room for board padding + outer UI pad */
    --gap: 3px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 6px;
    --board-pad: 12px; /* 6px * 2 */
    --cell: calc(
      (100vw - 16px /* ui-layer pad */ - var(--board-pad) - (var(--cols) - 1) * var(--gap))
      / var(--cols)
    );
  }

  .cell {
    width: var(--cell);
    height: var(--cell);
  }
}

@media (max-aspect-ratio: 4/5) and (min-width: 641px) {
  .board {
    --cell: min(
      calc((min(94vw, 50vh) - (var(--cols) - 1) * var(--gap)) / var(--cols)),
      56px
    );
  }
}
