/* =========================
   GLOBAL BASE
========================= */

:root {
  --text-color: white;
  --shadow-color: black;
  --panel-bg: rgba(0, 0, 0, 0.9);
  --panel-text: white;
  --button-bg: rgba(0, 0, 0, 0.45);
  --button-text: white;
  --button-border: white;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.light-mode {
  --text-color: black;
  --shadow-color: white;
  --panel-bg: rgba(255, 255, 255, 0.9);
  --panel-text: black;
  --button-bg: rgba(255, 255, 255, 0.75);
  --button-text: black;
  --button-border: black;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  height: 100%;
  background: black;
  font-family: Georgia, "Times New Roman", serif;
  overflow: hidden;
  overscroll-behavior: none;
}

button,
a,
.tier-option {
  -webkit-tap-highlight-color: transparent;
}

/* =========================
   BACKGROUND
========================= */

#bgVideo {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  object-fit: cover;
  object-position: center;
  z-index: 0;
  pointer-events: none;
}

/* =========================
   MAIN UI
========================= */

.ui {
  position: relative;
  z-index: 1;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  box-sizing: border-box;

  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(0.5rem, 2vh, 2rem);

  padding:
    clamp(0.5rem, 2vh, 1.5rem)
    clamp(0.5rem, 2vw, 2rem)
    calc(clamp(0.75rem, 2vh, 1.5rem) + var(--safe-bottom));
}

/* =========================
   TITLE
========================= */

.title {
  justify-self: center;

  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.4rem, 1vw, 0.9rem);

  margin: 0;

  color: var(--text-color);
  font-size: clamp(1.4rem, 4vw, 4rem);
  font-weight: bold;
  text-shadow: 0 0 6px var(--shadow-color);
  white-space: nowrap;
}

.title-icon {
  width: clamp(24px, 5vw, 48px);
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: contain;
}

/* =========================
   PRIMARY CONTROL LAYOUT
========================= */

.left-controls {
  align-self: start;
  justify-self: start;

  display: flex;
  flex-direction: column;
  gap: clamp(0.5rem, 2vh, 1.5rem);

  width: clamp(180px, 24vw, 330px);
}

/* =========================
   BUTTONS
========================= */

#resetButton,
#configureButton,
#spinButton,
#themeToggleButton,
.theme-toggle,
.credits,
.contact-button,
.tier-button,
.configure-footer button {
  background: var(--button-bg);
  color: var(--button-text);
  border: 1px solid var(--button-border);
  border-radius: 5px;

  font-family: Georgia, "Times New Roman", serif;
  font-weight: bold;
  text-shadow: 0 0 5px var(--shadow-color);

  cursor: pointer;

  transition:
    transform 0.08s ease,
    filter 0.08s ease,
    box-shadow 0.08s ease;
}

#resetButton,
#configureButton,
.tier-button {
  width: 100%;
  padding: clamp(0.35rem, 1vh, 0.8rem) clamp(0.5rem, 1vw, 1rem);
  font-size: clamp(1rem, 2.2vw, 2rem);
}

#resetButton {
  width: auto;
}

#spinButton {
  justify-self: center;

  width: clamp(220px, 35vw, 430px);
  padding: clamp(0.5rem, 1.4vh, 1rem) 0;

  font-size: clamp(1.2rem, 2.5vw, 2.2rem);
}

.theme-toggle,
.credits,
.contact-button {
  padding: 4px 10px;
  font-size: clamp(0.7rem, 1vw, 0.95rem);
  text-decoration: none;
}

#resetButton:hover,
#configureButton:hover,
#spinButton:hover,
.theme-toggle:hover,
.credits:hover,
.contact-button:hover,
.tier-button:hover,
.configure-footer button:hover {
  filter: brightness(110%);
}

#resetButton:active,
#configureButton:active,
#spinButton:active,
.theme-toggle:active,
.credits:active,
.contact-button:active,
.tier-button:active,
.configure-footer button:active {
  transform: translateY(2px) scale(0.98);
  filter: brightness(85%);
}

/* =========================
   TIER DROPDOWN
========================= */

.tier-dropdown {
  position: relative;
  width: 100%;
}

.tier-button {
  text-align: left;
}

.tier-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;

  width: min(90vw, 520px);
  max-height: min(65svh, 460px);
  overflow-y: auto;

  background: rgba(0, 0, 0, 0.85);
  color: var(--button-text);
  border: 1px solid var(--button-border);

  z-index: 20;
}

@supports ((-webkit-backdrop-filter: blur(6px)) or (backdrop-filter: blur(6px))) {
  .tier-menu {
    background: rgba(0, 0, 0, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
  }
}
body.light-mode .tier-menu {
  background: rgba(255, 255, 255, 0.85);
}

@supports ((-webkit-backdrop-filter: blur(6px)) or (backdrop-filter: blur(6px))) {
  body.light-mode .tier-menu {
    background: rgba(255, 255, 255, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
  }
}
.tier-option {
  display: grid;
  grid-template-columns: minmax(80px, 120px) 1fr;
  gap: clamp(0.4rem, 1vw, 0.8rem);

  padding: clamp(0.35rem, 1vw, 0.6rem);

  color: var(--button-text);
  font-size: clamp(0.8rem, 1.5vw, 1.1rem);
}

.tier-option:hover {
  background: rgba(128, 128, 128, 0.35);
}

.tier-option span {
  font-weight: bold;
}

.tier-option small {
  color: var(--button-text);
  opacity: 0.8;
}

.tier-option.selected-flash {
  animation: tierClickFlash 0.18s ease;
}

@keyframes tierClickFlash {
  from {
    background: rgba(255, 255, 255, 0.55);
  }

  to {
    background: transparent;
  }
}

/* =========================
   RESULT TEXT STYLES
========================= */

.output-heading {
  margin-bottom: clamp(0.2rem, 1vh, 0.6rem);

  color: var(--text-color);
  font-size: clamp(1.1rem, 2vw, 2rem);
  font-weight: bold;
}

.map-output {
  margin-bottom: clamp(1rem, 4vh, 3rem);
}

.map-name {
  margin-bottom: clamp(0.3rem, 1vh, 1rem);

  color: var(--text-color);
  font-size: clamp(1rem, 1.8vw, 1.8rem);
  font-weight: bold;
}

.map-placeholder {
  min-height: clamp(3rem, 8vh, 5.8rem);
}

.relic-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(0.4rem, 2vw, 2.25rem);

  margin-bottom: clamp(0.2rem, 1vh, 0.75rem);
}

.relic-item {
  min-width: clamp(90px, 18vw, 220px);

  color: var(--text-color);
  font-size: clamp(0.8rem, 1.6vw, 1.5rem);
  font-weight: bold;
  text-align: center;
}

/* =========================
   MR. PEEKS RESULT IMAGE
========================= */

#mrPeeksImage {
  justify-self: center;
  align-self: center;

  width: clamp(70px, 10vw, 150px);
  height: auto;

  display: none;
  z-index: 5;
}

#mrPeeksNoseZone {
  display: none;
}

/* =========================
   BOTTOM UTILITY BUTTONS
========================= */

.bottom-links {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 0.5rem;
}

.bottom-left {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* =========================
   MODALS
========================= */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;

  display: flex;
  justify-content: center;
  align-items: center;

  padding: 1rem;
  box-sizing: border-box;
}

.hidden {
  display: none;
}

.modal-title-bar {
  min-height: 30px;

  display: flex;
  align-items: center;

  background: #ab51e7;
  padding: 0 10px;

  font-family: Arial, sans-serif;
  font-size: 13px;
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 8px;

  font-weight: bold;
}

.modal-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.modal-box,
.configure-box {
  width: min(92vw, 900px);
  max-height: 90svh;

  background: var(--panel-bg);
  color: var(--panel-text);
  border: 1px solid var(--button-border);
  border-radius: 8px;

  overflow: hidden;
  box-shadow: 0 0 20px rgba(0,0,0,0.6);
}

.modal-box {
  max-width: 650px;
  font-family: Georgia, "Times New Roman", serif;
}

.modal-content {
  padding: clamp(0.75rem, 2vw, 1.5rem);
  font-size: clamp(0.9rem, 1.5vw, 1rem);
}

.modal-content p {
  margin: 3px 0;
}

.modal-content a {
  color: #0078d7;
  font-weight: bold;
  text-decoration: none;
}

.modal-content a:hover {
  text-decoration: underline;
}

/* =========================
   CONFIGURE MODAL
========================= */

.configure-box {
  display: flex;
  flex-direction: column;

  height: min(90svh, 520px);
  font-family: Arial, sans-serif;
}

.config-column h3,
.config-column label {
  color: var(--panel-text);
}

.configure-content {
  flex: 1;

  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: clamp(0.5rem, 2vw, 1.75rem);

  padding: clamp(0.5rem, 2vw, 0.9rem);

  overflow-y: auto;
}

.config-column h3 {
  margin: 0 0 8px 0;
  font-size: clamp(0.75rem, 1.2vw, 0.9rem);
}

.config-column label {
  display: block;

  margin-bottom: 8px;

  font-size: clamp(0.7rem, 1.1vw, 0.85rem);
  white-space: nowrap;
}

.configure-footer {
  flex-shrink: 0;

  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;

  padding: 8px 12px;
  box-sizing: border-box;
}

.configure-footer button {
  padding: 0.5rem;
  font-size: clamp(0.7rem, 1.1vw, 0.85rem);
}

.disabled-map {
  color: #777;
  text-decoration: line-through;
  cursor: default;
}

.disabled-map input {
  pointer-events: none;
}

.coming-soon-map {
  margin-bottom: 8px;
}

.coming-soon-text {
  margin-left: 22px;
  margin-top: -2px;

  font-size: clamp(0.6rem, 1vw, 0.75rem);
  font-style: italic;
  color: #999;
}
/* =========================
   ANIMATIONS
========================= */

@keyframes shake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
  100% { transform: translateX(0); }
}

.shake {
  animation: shake 0.2s ease;
}

@keyframes saveGlow {
  0% { box-shadow: 0 0 0 rgba(0,0,0,0); }
  50% { box-shadow: 0 0 18px #3fa9ff; }
  100% { box-shadow: 0 0 0 rgba(0,0,0,0); }
}

.save-glow {
  animation: saveGlow .6s ease;
}

/* =========================
   COMPACT LANDSCAPE SCALING
========================= */

@media (max-width: 950px) and (orientation: landscape) {
  .ui {
    grid-template-rows: auto 1fr auto;
    gap: 0.35rem;
    padding: 0.4rem 0.5rem calc(0.5rem + var(--safe-bottom));
  }

  .title {
    font-size: clamp(1rem, 3vw, 1.5rem);
  }

  .title-icon {
    width: 22px;
  }

  .left-controls {
    width: clamp(135px, 22vw, 190px);
    gap: 0.35rem;
  }

  #resetButton,
  #configureButton,
  .tier-button {
    font-size: clamp(0.75rem, 1.8vw, 0.9rem);
    padding: 0.3rem 0.4rem;
  }

  .tier-option {
    grid-template-columns: 75px 1fr;
    gap: 6px;
    padding: 5px;
    font-size: 0.72rem;
  }

  #output {
    margin-top: 0;
    width: min(65vw, 700px);
  }

  .output-heading {
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
  }

  .map-output {
    margin-bottom: 0.6rem;
  }

  .map-name {
    font-size: 0.75rem;
    margin-bottom: 0.2rem;
  }

  .relic-row {
    gap: 6px;
    margin-bottom: 1px;
  }

  .relic-item {
    min-width: 82px;
    font-size: 0.65rem;
    line-height: 1.05;
  }

  #spinButton {
    width: clamp(170px, 30vw, 300px);
    padding: 0.35rem 0;
    font-size: 0.9rem;
  }

  .theme-toggle,
  .credits,
  .contact-button {
    font-size: 0.6rem;
    padding: 3px 7px;
  }

  .configure-box {
    height: 88svh;
  }

  .configure-content {
    grid-template-columns: repeat(5, minmax(80px, 1fr));
    gap: 0.4rem;
    padding: 0.45rem;
  }

  .config-column h3 {
    font-size: 10px;
    margin-bottom: 5px;
  }

  .config-column label {
    font-size: 9px;
    margin-bottom: 4px;
  }

  .coming-soon-text {
    margin-left: 18px;
    font-size: 7px;
  }

  .configure-footer {
    gap: 5px;
    padding: 4px 6px;
  }

  .configure-footer button {
    min-height: 28px;
    font-size: 9px;
    line-height: 1;
    padding: 2px 6px;
  }

  .modal-content {
    font-size: 12px;
    padding: 10px 18px;
  }
}

/* =========================
   PORTRAIT LAYOUT ADJUSTMENTS
========================= */

@media (max-width: 600px) and (orientation: portrait) {
  .ui {
    grid-template-rows: auto auto 1fr auto;
  }

  .title {
    white-space: normal;
    text-align: center;
  }

  .left-controls {
    justify-self: center;
    width: min(92vw, 330px);
  }

  .configure-content {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }
}

/* =========================
   FIXED HUD POSITIONING
========================= */

#output {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;

  width: min(90vw, 900px);
  margin: 0;

  color: var(--text-color);
  text-align: center;
  text-shadow: 0 0 5px var(--shadow-color);

  pointer-events: none;
}

#spinButton {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
}

#spinButton:active {
  transform: translateX(-50%) translateY(2px) scale(0.98);
}

#mrPeeksImage {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;
}

#mrPeeksNoseZone {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  z-index: 40;
  cursor: pointer;
  pointer-events: auto;

  background: transparent;
  border: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.bottom-links {
  position: fixed;
  left: clamp(0.5rem, 2vw, 2rem);
  right: clamp(0.5rem, 2vw, 2rem);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1.2vh);
  z-index: 30;

  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 0.5rem;
}

.bottom-left {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

@media (orientation: portrait) {
  #spinButton {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 14vh);
  }

  #mrPeeksImage {
    top: 42vh;
    width: clamp(135px, 30vw, 190px);
  }

  #mrPeeksNoseZone {
    top: 48.5vh;
    left: 56%;
    width: 58px;
    height: 58px;
  }

  .tier-button {
    text-align: center;
  }

  .tier-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    text-align: center;
    gap: 3px;
  }

  .tier-option span,
  .tier-option small {
    display: block;
    width: 100%;
    text-align: center;
  }
}

@media (orientation: landscape) {
  #output {
    top: 18vh;
    max-height: 48vh;
    overflow: hidden;
  }

  #spinButton {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 3vh);
  }

  #mrPeeksImage {
    top: 36vh;
    width: clamp(85px, 9vw, 135px);
  }

  #mrPeeksNoseZone {
    top: 38vh;
    width: 42px;
    height: 42px;
  }
}

/* =========================
   PORTRAIT & LANDSCAPE OVERRIDES
========================= */

@media (orientation: portrait) {
  #output {
    top: 34vh;
    max-height: 44vh;
    overflow: hidden;
  }

  .tier-menu {
    left: 50%;
    transform: translateX(-50%);
    width: min(88vw, 520px);
    box-sizing: border-box;
  }
}

@media (orientation: landscape) {
  .left-controls {
    width: max-content;
    min-width: 0;
    max-width: none;
  }

  #resetButton,
  #configureButton,
  .tier-button {
    width: 24ch;
    box-sizing: border-box;
    text-align: left;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .tier-menu {
    width: min(50vw, 340px);
    box-sizing: border-box;
  }

  .tier-option {
    display: block;
    text-align: left;
  }

  .tier-option span,
  .tier-option small {
    display: block;
    text-align: left;
  }

  .bottom-links {
    left: 0.6rem;
    right: 0.6rem;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 2vh);
    transform: none;
  }

  .bottom-left {
    flex-direction: column;
  }
}
/* =========================
   CLICK LAYER + PORTRAIT BOTTOM BUTTON FIX
========================= */

/* Keeps Spin clickable above fixed bottom HUD elements */
#spinButton {
  pointer-events: auto;
  z-index: 60;
}

/* Prevent bottom wrapper from blocking Spin in landscape */
@media (orientation: landscape) {
  .bottom-links {
    pointer-events: none;
  }

  .bottom-links button,
  .bottom-links a {
    pointer-events: auto;
  }
}

/* Portrait bottom utility button layout */
@media (orientation: portrait) {
  .bottom-links {
    left: 0;
    right: 0;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 3vh);
    transform: none;

    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    justify-items: center;

    padding: 0 1rem;
    box-sizing: border-box;
    pointer-events: none;
  }

  .bottom-left {
    display: contents;
  }

  #themeToggleButton {
    grid-column: 1;
    justify-self: start;
  }

  #creditsButton {
    grid-column: 2;
    justify-self: center;
  }

  #contactButton {
    grid-column: 3;
    justify-self: end;
  }

  #themeToggleButton,
  #creditsButton,
  #contactButton {
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.05;
    pointer-events: auto;
  }
}
