:root {
  --gold: #f4a261;
  /* --page-bg and --frame-bg are set per game in index.php */
  --frame-border: #d4a373;
  --hud-height: 5.5rem;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: Nunito, system-ui, sans-serif;
  overflow: hidden;
  background: var(--page-bg);
}

.hidden {
  display: none !important;
}

#loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page-bg);
  color: #fff;
  z-index: 2000;
  padding: 1rem;
  text-align: center;
}

#loading-screen p {
  text-shadow:
    0 1px 3px rgba(0, 0, 0, 0.65),
    0 2px 12px rgba(0, 0, 0, 0.45);
}

#loading-screen.hidden {
  display: none;
}

#game-page {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background-color: var(--page-bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

#game-page.final-puzzle-view #control-hud {
  grid-template-columns: minmax(0, 1fr) auto;
}

#game-page.final-puzzle-view .hud-left {
  grid-column: 1;
  justify-self: start;
}

#game-page.final-puzzle-view .nav-right {
  grid-column: 2;
  justify-self: end;
}

#game-page.final-puzzle-view .code-center {
  display: none !important;
}

#game-page.final-puzzle-view .hints-left .hint-btn {
  display: none;
}

#game-page.final-puzzle-view #reset-btn {
  display: inline-flex !important;
  visibility: visible !important;
}

#game-page.game-won .hints-left .hint-btn {
  display: none;
}

#puzzle-stage {
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(0.75rem, 2.5vw, 1.5rem);
}

#puzzle-frame {
  position: relative;
  width: min(100%, 1280px, calc((100vh - var(--hud-height) - 3rem) * 16 / 9));
  max-height: calc(100vh - var(--hud-height) - 3rem);
  aspect-ratio: 16 / 9;
  border: 4px solid var(--frame-border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  background: var(--frame-bg);
  overflow: hidden;
}

#puzzle-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: var(--frame-bg);
}

#puzzle-image.no-image {
  display: none;
}

#hotspot-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.hotspot-hit {
  position: absolute;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: zoom-in;
  pointer-events: auto;
  border-radius: 2px;
}

.hotspot-hit:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

#hotspot-modal-text-wrap .hotspot-modal-icon {
  font-size: 3.5rem;
  line-height: 1;
}

#hotspot-modal-image {
  max-height: min(70vh, 600px);
  width: auto;
  margin: 0 auto;
}

#hint-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1rem 2.5rem 1rem 1rem;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
}

#hint-overlay #hint-text {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.4;
  text-align: center;
}

#hint-close {
  position: absolute;
  top: 0.35rem;
  right: 0.5rem;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

#control-hud {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  min-height: var(--hud-height);
  background: #2d2d2d;
  border-top: 3px solid var(--gold);
  z-index: 10;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-self: start;
  min-width: 0;
}

.hints-left {
  display: flex;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.hints-left.hints-hidden {
  display: none;
}

#solve-btn.continue-only-btn {
  min-width: 140px;
}

.hint-btn,
.nav-btn,
#reset-btn,
.reset-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: #40916c;
  color: #fff;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.hint-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: #4a4a4a;
}

.hint-btn:not(:disabled):hover,
.nav-btn:not(:disabled):hover,
#reset-btn:hover,
.reset-btn:hover {
  background: #52b788;
}

.code-center {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  justify-self: center;
  width: max-content;
  max-width: 100%;
}

#code-selects {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
}

#code-selects select {
  min-width: 3rem;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  border: 2px solid var(--gold) !important;
  border-radius: 6px;
  padding: 0.35rem;
  background: #3a3a3a;
  color: #fff;
  outline: none !important;
  box-shadow: none !important;
  appearance: auto;
}

#code-selects select:hover,
#code-selects select:focus,
#code-selects select:focus-visible,
#code-selects select:active,
#code-selects select:disabled {
  border: 2px solid var(--gold) !important;
  outline: none !important;
  box-shadow: none !important;
}

#solve-btn {
  min-width: 100px;
}

.nav-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  justify-self: end;
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
}

.nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#reset-btn {
  display: none;
}

#game-page.final-puzzle-view #reset-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 5.5rem;
  padding: 0 1.25rem;
  border-radius: 8px;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

@media (max-width: 600px) {
  :root {
    --hud-height: auto;
  }
  #control-hud {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .hud-left,
  .nav-right,
  .code-center {
    justify-self: center;
    width: 100%;
    justify-content: center;
  }
  .nav-right {
    justify-content: center;
  }
}
