:root {
  --bg: #07111f;
  --mint: #21f5b5;
  --mint-dark: #14dca4;
  --text: #f8fafc;
  --muted: #6b7280;
  --orange: #ff7a2a;
  --danger: #ef4444;
  --frame: #c9c9cf;
}

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

html,
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  overscroll-behavior: none;
}

button {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.game-header {
  height: 66px;
  padding: 0 6.5%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #07111f;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
  color: var(--text);
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -1px;
  text-decoration: none;
}

.logo span {
  color: var(--mint);
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

#save-status {
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 800;
}

.dashboard-link {
  padding: 9px 13px;
  border-radius: 7px;
  background: var(--mint);
  color: #07111f;
  font-weight: 900;
  text-decoration: none;
}

#reset-view-btn {
  padding: 9px 13px;
  border-radius: 7px;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-weight: 900;
}

.game-layout {
  width: min(98vw, 1740px);
  height: calc(100vh - 82px);
  margin: 8px auto;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 360px;
  overflow: hidden;
  background: var(--frame);
  border: 10px solid var(--frame);
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(255,255,255,0.35);
}

.tools {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 11px;
  align-items: center;
  padding: 14px 8px;
  background: #d4d4d8;
}

.tool {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e7e7eb;
  color: #6b7280;
  font-size: 20px;
  font-weight: 900;
  border: 1px solid #a8a8b0;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55);
}

.tool.active {
  color: #07111f;
  background: var(--mint);
  border-color: #07111f;
  box-shadow: 0 0 0 4px rgba(33,245,181,0.25), inset 0 1px 0 rgba(255,255,255,0.7);
}

.danger-tool {
  background: #fee2e2;
  color: #991b1b;
}

.colours {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.colour {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(7,17,31,0.25);
}

.colour.active {
  border-color: #07111f;
  box-shadow: 0 0 0 3px rgba(33,245,181,0.35);
}

.game-area {
  min-width: 0;
  min-height: 0;
  background: #111827;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mobile-note {
  display: none;
}

.image-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #020617;
  touch-action: pan-y;
}

@media (hover:hover) and (pointer:fine) {
  .image-wrap.precision-cursor-active,
  .image-wrap.precision-cursor-active * { cursor: none !important; }
}

.image-stage {
  position: absolute;
  overflow: visible;
  transform-origin: 0 0;
  will-change: transform, left, top;
}

#game-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

#line-canvas,
#marker-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.coord-readout {
  position: absolute;
  z-index: 45;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  text-shadow: 0 1px 3px rgba(0,0,0,0.85), 0 0 4px rgba(0,0,0,0.65);
  pointer-events: none;
  background: rgba(7, 17, 31, 0.82);
  padding: 6px 11px;
  border: 1px solid rgba(33,245,181,0.45);
  border-radius: 999px;
  white-space: nowrap;
}

.zoom-controls {
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 35;
  display: flex;
  gap: 6px;
  align-items: center;
}

.zoom-controls button {
  min-width: 42px;
  height: 34px;
  border-radius: 7px;
  background: rgba(255,255,255,0.92);
  color: #07111f;
  font-weight: 900;
}

.line-help {
  position: absolute;
  z-index: 34;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: none;
  padding: 7px 11px;
  background: #facc15;
  color: #07111f;
  font-size: 12px;
  font-weight: 900;
  border-radius: 999px;
  pointer-events: none;
}

.line-help.active {
  display: block;
}

.marker {
  position: absolute;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.marker::before,
.marker::after {
  content: "";
  position: absolute;
  background: #38bdf8;
  box-shadow: 0 0 8px rgba(56,189,248,0.85);
}

.marker::before {
  width: 2px;
  height: 18px;
  top: 0;
  left: 8px;
}

.marker::after {
  height: 2px;
  width: 18px;
  top: 8px;
  left: 0;
}

.marker.active::before,
.marker.active::after {
  background: #38bdf8;
}

.magnifier-canvas {
  position: absolute;
  z-index: 40;
  display: none;
  width: 128px;
  height: 128px;
  left: 0;
  top: 0;
  border: 2px solid var(--mint);
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 14px 34px rgba(0,0,0,0.48), 0 0 26px rgba(33,245,181,0.32);
  will-change: transform;
}

.magnifier-canvas.active {
  display: block;
}

.tickets {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: #fff;
  color: #111827;
  padding: 20px 12px 0;
}

.tickets h2 {
  margin-bottom: 12px;
  color: #4b5563;
  font-size: 20px;
  font-weight: 500;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.ticket-summary {
  margin-bottom: 12px;
  padding: 10px;
  background: #f3f4f6;
  border-radius: 8px;
  text-align: center;
}

.ticket-summary strong,
.ticket-summary span {
  display: block;
}

.ticket-summary strong {
  color: #111827;
  font-size: 14px;
}

.ticket-summary span {
  color: #6b7280;
  font-size: 12px;
}

.ticket-list {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 6px 14px 0;
  border-top: 1px solid #eef0f3;
  border-bottom: 1px solid #eef0f3;
}

.ticket-list::-webkit-scrollbar {
  width: 8px;
}

.ticket-list::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 999px;
}

.ticket-list::-webkit-scrollbar-thumb {
  background: var(--mint);
  border-radius: 999px;
}

.ticket-card {
  flex: 0 0 auto;
  position: relative;
  min-height: 158px;
  display: grid;
  grid-template-columns: 76px 1fr 34px;
  grid-template-rows: auto auto auto auto;
  gap: 8px 10px;
  padding: 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  overflow: hidden;
}

.ticket-card.active {
  border: 2px solid var(--mint);
}

.ticket-img {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 76px;
  height: 82px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.ticket-img img {
  max-width: 66px;
  max-height: 82px;
  object-fit: contain;
  filter: drop-shadow(0 5px 8px rgba(0,0,0,0.18));
}

.ticket-main {
  grid-column: 2;
  grid-row: 1 / span 2;
  min-width: 0;
}

.ticket-title {
  max-width: none;
  margin: 0 0 4px;
  color: #111827;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.12;
  white-space: normal;
}

.ticket-count {
  margin: 0 0 4px;
  color: #6b7280;
  font-size: 12px;
  font-weight: 900;
}

.ticket-coords {
  margin: 0;
  color: #000;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.25;
}

.duplicate-ticket-btn {
  grid-column: 3;
  grid-row: 1;
  width: 30px;
  height: 30px;
  align-self: start;
  justify-self: end;
  display: grid;
  place-items: center;
  color: #07111f;
  background: var(--mint);
  border-radius: 50%;
  font-size: 20px;
  font-weight: 900;
}

.ticket-status {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  gap: 7px;
  align-items: center;
  color: #9ca3af;
  font-size: 12px;
  font-weight: 700;
}

.status-dot {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #c4c4c4;
  font-size: 12px;
  font-weight: 900;
}

.ticket-card.placed .status-dot {
  color: #07111f;
  background: var(--mint);
}

.ticket-actions {
  grid-column: 1 / -1;
  grid-row: 4;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.ticket-actions button {
  min-height: 30px;
  padding: 6px 8px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #6b7280;
  font-size: 12px;
  font-weight: 800;
}

.ticket-actions .select-btn {
  color: #07111f;
  background: rgba(33,245,181,0.25);
}

.ticket-card.active .select-btn {
  background: var(--mint);
}

.ticket-actions .delete-btn {
  color: #fff;
  background: var(--danger);
}

.checkout-bar {
  position: relative;
  z-index: 200;
  margin: 0 -12px;
  padding: 14px 12px 16px;
  background: #fff;
  border-top: 2px solid #e5e7eb;
  box-shadow: 0 -10px 22px rgba(15,23,42,0.1);
}

.checkout-summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  color: #111827;
}

.checkout-summary strong {
  font-size: 22px;
  font-weight: 900;
}

.checkout-summary span {
  color: #6b7280;
  font-size: 13px;
  font-weight: 800;
}

.confirm-btn,
.add-btn {
  width: 100%;
  padding: 13px 12px;
  border-radius: 6px;
  font-weight: 900;
  text-transform: uppercase;
}

.confirm-btn {
  color: #07111f;
  background: var(--mint);
}

.add-btn {
  margin-top: 10px;
  color: #4b5563;
  background: transparent;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(7,17,31,0.78);
}

.modal-backdrop.active {
  display: flex;
}

.ticket-modal,
.finished-modal {
  position: relative;
  max-height: 88vh;
  overflow-y: auto;
  padding: 28px;
  background: #111827;
  color: #f8fafc;
  border: 2px solid var(--mint);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.55);
}

.ticket-modal {
  width: min(940px, 96vw);
}

.finished-modal {
  width: min(540px, 94vw);
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #07111f;
  font-size: 24px;
  font-weight: 900;
  background: var(--mint);
  border-radius: 50%;
}

.ticket-modal h2,
.finished-modal h2 {
  margin-bottom: 8px;
  font-size: 28px;
}

.modal-subtitle,
.finished-modal p {
  margin-bottom: 22px;
  color: #cbd5e1;
  font-weight: 700;
}

.modal-products {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.modal-product {
  padding: 14px;
  background: #0b1220;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
}

.modal-product-img {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.modal-product-img img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.modal-product strong {
  display: block;
  min-height: 34px;
  font-size: 14px;
  line-height: 1.15;
}

.modal-product span {
  display: block;
  margin: 5px 0 12px;
  color: var(--mint);
  font-weight: 900;
}

.modal-product button,
.finished-actions button {
  width: 100%;
  padding: 10px;
  color: #07111f;
  font-weight: 900;
  background: var(--mint);
  border-radius: 8px;
}

.finished-actions {
  display: grid;
  gap: 10px;
}

.finished-actions button:nth-child(2) {
  background: var(--danger);
  color: #fff;
}

.finished-actions button:last-child {
  background: var(--orange);
  color: #fff;
}

#duplicate-modal h2,
#remove-all-modal h2 {
  color: #ff4d6d;
}

@media (max-width: 980px) {
  html,
  body {
    width: 100%;
    overflow-x: hidden;
  }

  .game-header {
    height: 56px;
    padding: 0 14px;
  }

  .logo {
    font-size: 23px;
  }

  #save-status {
    display: none;
  }

  .dashboard-link {
  padding: 9px 13px;
  border-radius: 7px;
  background: var(--mint);
  color: #07111f;
  font-weight: 900;
  text-decoration: none;
}

#reset-view-btn {
    padding: 8px 10px;
    font-size: 12px;
  }

  .game-layout {
    width: 100%;
    height: auto;
    min-height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    overflow: visible;
    background: #07111f;
  }

  .game-area {
    order: 1;
    width: 100%;
    padding: 8px;
    background: #07111f;
  }

  .mobile-note {
    display: block;
    margin-bottom: 8px;
    padding: 9px 10px;
    color: #cbd5e1;
    background: #111827;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 800;
    text-align: center;
  }

  .image-wrap {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    border: 4px solid #c9c9cf;
    border-radius: 10px;
  }

  .coord-readout {
    top: 10px;
    font-size: 12px;
  }

  .zoom-controls {
    right: 8px;
    top: 8px;
  }

  .zoom-controls button {
    min-width: 36px;
    height: 30px;
    font-size: 12px;
  }

  .tools {
    order: 2;
    position: sticky;
    bottom: 0;
    z-index: 300;
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 7px;
    padding: 8px;
    background: #d4d4d8;
  }

  .tool {
    width: 38px;
    height: 38px;
    font-size: 17px;
  }

  .colours {
    display: flex;
    flex-direction: row;
    gap: 5px;
    margin: 0 0 0 4px;
  }

  .colour {
    width: 26px;
    height: 26px;
  }

  .tickets {
    order: 3;
    height: auto;
    grid-template-rows: auto auto minmax(220px, 460px) auto;
    padding: 16px 10px 0;
  }

  .ticket-list {
    max-height: 460px;
    min-height: 220px;
  }

  .ticket-card {
    min-height: 146px;
    grid-template-columns: 68px 1fr 32px;
    padding: 10px;
  }

  .ticket-img {
    width: 68px;
    height: 76px;
  }

  .ticket-img img {
    max-width: 58px;
    max-height: 76px;
  }

  .ticket-title {
    font-size: 12px;
  }

  .ticket-count,
  .ticket-coords,
  .ticket-status {
    font-size: 11px;
  }

  .checkout-bar {
    position: sticky;
    bottom: 54px;
    margin: 0 -10px;
    padding: 12px 10px 14px;
  }

  .magnifier-canvas {
    display: none !important;
  }

  .ticket-modal,
  .finished-modal {
    width: 94vw;
    max-height: 86vh;
    padding: 22px 16px;
  }

  .modal-products {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-product-img {
    height: 92px;
  }
}


/* ==========================================================
   PRECISION MAGNIFIER VERSION
   - User does not need to manually zoom the map
   - Map remains full-view
   - Magnifier is the precision zoom
   - Crosshair/magnifier is centred exactly on the coordinate selected
   ========================================================== */

.zoom-controls {
  display: none !important;
}

.line-help {
  bottom: 12px !important;
}

.image-stage {
  transform: none !important;
}

.magnifier-canvas {
  width: 180px !important;
  height: 180px !important;
  border-width: 3px !important;
}

@media (max-width: 980px) {
  .magnifier-canvas {
    display: block !important;
    width: 150px !important;
    height: 150px !important;
  }

  .mobile-note {
    display: block !important;
  }
}

/* Final precision magnifier override */
.magnifier-canvas {
  display: none !important;
  width: 164px !important;
  height: 164px !important;
}

.magnifier-canvas.active {
  display: block !important;
}

@media (max-width: 980px) {
  .magnifier-canvas {
    display: none !important;
    width: 164px !important;
    height: 164px !important;
  }

  .magnifier-canvas.active {
    display: block !important;
  }
}


/* How to Play popup */
.how-to-play-popup {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(7, 17, 31, 0.62);
  backdrop-filter: blur(5px);
}

.how-to-play-popup.hidden {
  display: none;
}

.how-to-play-card {
  width: min(760px, 88vw);
  max-height: 86vh;
  cursor: pointer;
  animation: howToPlayPop 0.22s ease-out;
}

.how-to-play-card img {
  display: block;
  width: 100%;
  max-height: 86vh;
  object-fit: contain;
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  user-select: none;
  -webkit-user-drag: none;
}

@keyframes howToPlayPop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 768px) {
  .how-to-play-popup {
    padding: 12px;
  }

  .how-to-play-card {
    width: min(94vw, 520px);
    max-height: 82vh;
  }

  .how-to-play-card img {
    max-height: 82vh;
    border-radius: 14px;
  }
}

/* Mobile game scroll + touch compatibility update */
@media (max-width: 980px) {
  html,
  body {
    overscroll-behavior-y: auto !important;
    touch-action: manipulation;
  }

  .image-wrap {
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch;
  }

  .game-area,
  .game-layout {
    overflow: visible !important;
  }

  .mobile-note {
    line-height: 1.35;
  }
}


/* Mobile precision/gameplay update */
.tool[data-tool="pan"] { display:none !important; }
@media (max-width:980px) {
  .image-wrap { touch-action: pan-y pinch-zoom !important; }
  .tools { flex-direction: row; justify-content: center; width:100%; order:2; padding:10px; gap:10px; flex-wrap:wrap; }
  .tool { width:42px; height:42px; }
  .colours { display:flex; margin-top:0; }
  .magnifier-canvas { width:172px; height:172px; }
  .line-help.active { display:block; max-width:92vw; white-space:normal; text-align:center; }
}

/* Login gate: direct /game.html visits cannot play until Firebase confirms a user. */
body:not(.auth-ok) .game-layout { pointer-events:none; filter: blur(2px); opacity:0.35; }
body:not(.auth-ok)::before {
  content:"Checking your HiddenHit login...";
  position:fixed; inset:0; z-index:9999; display:grid; place-items:center;
  background:rgba(7,17,31,0.92); color:#21f5b5; font-weight:900; font-size:18px;
}


/* Precision helper - desktop arrow-key guidance */
.precision-tip {
  position: absolute;
  z-index: 44;
  left: 50%;
  top: 52px;
  transform: translateX(-50%);
  max-width: min(92%, 520px);
  padding: 7px 12px;
  color: #07111f;
  background: linear-gradient(90deg, #21f5b5, #67e8f9);
  border: 1px solid rgba(255,255,255,0.75);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.28);
}

@media (max-width: 980px) {
  .precision-tip {
    display: none;
  }
}


/* Mobile gameplay upgrade */
.mobile-play-panel {
  display: none;
}
@media (max-width: 820px), (pointer: coarse) {
  .image-wrap { touch-action: pan-y pinch-zoom; }
  .tools .tool[data-tool="pan"] { display:none !important; }
  .mobile-play-panel {
    position: sticky;
    z-index: 55;
    bottom: 8px;
    left: 8px;
    right: 8px;
    display: block;
    margin: 8px;
    padding: 10px;
    background: rgba(7,17,31,0.92);
    border: 1px solid rgba(33,245,181,0.45);
    border-radius: 14px;
    box-shadow: 0 14px 38px rgba(0,0,0,0.36);
    backdrop-filter: blur(8px);
  }
  .mobile-play-tabs { display:grid; grid-template-columns:1fr 1fr; gap:7px; margin-bottom:8px; }
  .mobile-mode, .mobile-nudge-grid button {
    min-height: 38px;
    border-radius: 10px;
    background: rgba(255,255,255,0.10);
    color: #f8fafc;
    font-weight: 900;
    border: 1px solid rgba(255,255,255,0.12);
  }
  .mobile-mode.active, #mobile-place-btn {
    background: #21f5b5;
    color: #07111f;
  }
  .mobile-nudge-grid {
    display: grid;
    grid-template-columns: 46px 46px 1fr 46px 46px;
    gap: 7px;
    align-items: center;
  }
  .mobile-play-panel p {
    margin-top: 7px;
    color: #cbd5e1;
    font-size: 11px;
    font-weight: 800;
    text-align:center;
  }
  .line-help.active {
    bottom: 142px;
    max-width: calc(100% - 20px);
    white-space: normal;
    text-align:center;
  }
}
