:root {
  --panel-bg: rgba(16, 20, 26, 0.55);
  --box-bg: rgba(16, 20, 26, 0.55);
  --border: rgba(255, 255, 255, 0.18);
  --glass-shadow: 0 8px 32px 0 rgba(13, 38, 38, 0.5);
  --text: #e8eaed;
  --muted: #9aa3ad;
  --accent: #e8eaed;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #10141a;
  font-family: "Average Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
}

canvas { display: block; touch-action: none; }

/* --- square icon boxes (⚙, ✕, ?) ------------------------------------------ */
.icon-box {
  position: fixed;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  color: var(--text);
  background: var(--box-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--glass-shadow);
  transition: all 0.1s ease-in-out;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  z-index: 20;
}
.icon-box:hover { background: rgba(255, 255, 255, 0.25); transform: translateY(-2px); }
.icon-box:active { transform: scale(0.9); }
.icon-box svg { width: 20px; height: 20px; display: block; }

/* icon + small label underneath: fixed width, same as plain icon buttons */
.icon-box.labelled {
  flex-direction: column;
  gap: 1px;
  width: 42px;
  height: 42px;
  font-size: 8px;
  letter-spacing: 0.02em;
}
.icon-box.labelled svg { width: 15px; height: 15px; }
.icon-box.on { color: #ffd166; } /* sun active: warm gold icon on the same glass */
.btn-label { line-height: 1; }

#sunBtn { position: static; flex-shrink: 0; } /* lives in the nav bar, first slot */

/* --- gems button: premium, constant rainbow shine ------------------------------- */
@property --gem-angle { syntax: '<angle>'; initial-value: 0deg; inherits: false; }

#gemsBtn {
  position: fixed;
  top: 12px;
  left: 12px; /* top-left corner */
  border: none; /* the rainbow ring replaces it */
  overflow: visible;
}
/* soft rainbow halo behind the button */
#gemsBtn::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 17px;
  background: conic-gradient(from var(--gem-angle),
    #ff5964, #ffd166, #7ee081, #7ec8e3, #b48ef7, #ff5964);
  filter: blur(4px);
  opacity: 0.85;
  animation: gem-spin 3s linear infinite;
  pointer-events: none;
}
/* crisp rainbow ring hugging the glass */
#gemsBtn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 14px;
  padding: 1.5px; /* ring thickness */
  background: conic-gradient(from var(--gem-angle),
    #ff5964, #ffd166, #7ee081, #7ec8e3, #b48ef7, #ff5964);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask-composite: exclude;
  animation: gem-spin 3s linear infinite;
  pointer-events: none;
}
/* icon rides the hue wheel; label is kept plain white below */
#gemsBtn svg {
  position: relative;
  z-index: 2;                    /* above the ::before/::after overlays */
  color: #ffd166;
  animation: gem-hue 3s linear infinite;
}
/* keep the label plain and readable — the rainbow lives on the ring */
#gemsBtn .btn-label {
  position: relative;
  z-index: 2;                    /* always above the ::before/::after overlays */
  color: #ffffff;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
@keyframes gem-spin { to { --gem-angle: 360deg; } }
@keyframes gem-hue { to { filter: hue-rotate(360deg); } }

/* --- nav bar: search + dice (top center, always) ----------------------------------- */
#navBar {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: stretch; /* search bar and buttons share one height */
  width: min(60vw, 420px);
  z-index: 20;
}

/* --- bottom column: location row + exaggeration bar --------------------------------- */
#bottomCol {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column; /* two rows: location+share on top, slider below */
  gap: 8px;
  width: min(80vw, 340px);
  z-index: 19;
}

#locRow {
  display: flex;
  gap: 8px;
}

#locRow #shareBtn {
  position: static;
  flex-shrink: 0;
}

#locationStatus {
  position: static;
  flex: 1;
  min-width: 0; /* allow ellipsis inside flex */
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 42px; /* grows with wrapped text instead of clipping */
  padding: 6px 14px;
  font-size: 13px;
  white-space: normal;
  overflow-wrap: anywhere; /* long unbroken tokens (ids) wrap too */
  text-align: left;
  line-height: 1.35;
  color: var(--text);
  background: var(--box-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--glass-shadow);
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
  z-index: 19;
}
#locationStatus .loc-pin {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--accent);
}
#locationStatus.visible { opacity: 1; }

#searchBar {
  position: relative;
  flex: 1;
  display: flex;
  align-items: stretch; /* input fills whatever height the row has */
}

#searchInput {
  flex: 1;
  align-self: stretch; /* fill the nav row height set by the buttons */
  padding: 0 18px;
  font-size: 16px; /* >=16px prevents iOS focus zoom */
  color: var(--text);
  background: var(--box-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--glass-shadow);
}
#searchInput:focus { border-color: rgba(255, 255, 255, 0.4); }
#searchInput::placeholder { color: var(--muted); }

#searchResults {
  position: absolute;
  top: 100%;
  margin-top: -1px; /* tuck under the input's bottom border — one continuous box */
  left: 0;
  right: 0;
  background: var(--box-bg);
  border: none;
  border-radius: 0 0 20px 20px;
  overflow: hidden;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--glass-shadow);
}

/* --- location gems panel (opens under the gems button) ------------------------------ */
#gemsPanel {
  position: fixed;
  top: 62px;
  left: 12px; /* under the gems button (top-left corner) */
  width: min(60vw, 420px);
  max-height: min(55vh, 460px);
  overflow-y: auto;
  background: var(--box-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--glass-shadow);
  display: none;
  z-index: 21;
}
#gemsPanel.open { display: block; }

.gem-head {
  padding: 10px 14px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.gem-locked { padding: 4px 14px 12px; }
#gemsPanel.unlocked .gem-locked { display: none; }

.gem-note {
  margin: 6px 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}
.gem-note.small { font-size: 11px; }

.gem-buy {
  width: 100%;
  margin: 10px 0 4px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #10141a;
  background: linear-gradient(90deg,
    #ffd166, #7ee081, #7ec8e3, #b48ef7, #ff5964, #ffd166);
  background-size: 200% 100%;
  animation: gem-buy-slide 3s linear infinite;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.gem-buy:active { transform: scale(0.98); }
@keyframes gem-buy-slide { to { background-position: 200% 0; } }

.gem-code-row { display: flex; gap: 8px; }
#gemActivateBtn { position: static; flex-shrink: 0; } /* not fixed — sits beside the input */
.gem-code-row input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 14px;
  font-size: 16px; /* clearly readable */
  color: #ffffff;
  -webkit-text-fill-color: #ffffff; /* beats browser autofill styling */
  caret-color: #ffffff;
  background: rgba(16, 20, 26, 0.55);
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
}
.gem-code-row input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px rgba(16, 20, 26, 0.55) inset; /* keep our bg */
  -webkit-text-fill-color: #ffffff;
}
.gem-code-row input:focus { border-color: rgba(255, 255, 255, 0.4); }
.gem-code-row .icon-box { width: 42px; height: 42px; font-size: 16px; }

#gemsList { display: none; }
#gemsPanel.unlocked #gemsList { display: block; }

.gem-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 8px 14px;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
}
.gem-item:hover { background: rgba(255, 255, 255, 0.15); }
.gem-sub { font-size: 11px; color: var(--muted); }

#gemsStatus {
  margin: 0;
  padding: 6px 14px 10px;
  font-size: 11px;
  color: var(--muted);
  min-height: 12px;
}
#gemsStatus.error { color: #ff8a8a; }

.search-result {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 8px 12px;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
}
.search-result:hover { background: rgba(255, 255, 255, 0.15); }
.search-sub { font-size: 11px; color: var(--muted); }
.search-status { padding: 8px 12px; font-size: 12px; color: var(--muted); }

#diceBtn, #shareBtn { position: static; flex-shrink: 0; }
#diceBtn.rolling {
  animation: diceSpin 0.55s ease infinite;
  pointer-events: none;
}
@keyframes diceSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* --- exaggeration slider (bottom center, always) ------------------------------ */
#exagBar {
  padding: 10px 16px;
  background: var(--box-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--glass-shadow);
}
#exagBar label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 4px;
}
#exagBar output { color: var(--muted); }
#exagBar input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }

.hint {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}
#flySpeed { color: var(--accent); }

/* --- keyboard help (desktop) --------------------------------------------------- */
#keyHelp {
  position: fixed;
  top: 12px;
  right: 12px;
  padding: 14px 16px;
  background: var(--box-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--glass-shadow);
  z-index: 20;
}

.key-groups {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.key-group { display: flex; flex-direction: column; gap: 4px; }

.key-desc {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.key-row { display: flex; gap: 5px; }

kbd {
  min-width: 26px;
  padding: 4px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--text);
  text-align: center;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-bottom-width: 2px;
  border-radius: 6px;
}

/* --- attribution ---------------------------------------------------------------- */
#attrib {
  position: fixed;
  bottom: 8px;
  right: 12px;
  font-size: 10px;
  color: var(--muted);
  background: var(--box-bg);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--glass-shadow);
  z-index: 10;
  max-width: 500px;
}

/* --- teleport overlay -------------------------------------------------------------- */
#teleportOverlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 13, 18, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 50;
  transition: opacity 0.45s;
}
#teleportOverlay.fade-out { opacity: 0; }

.teleport-card { text-align: center; color: var(--text); font-size: 15px; }

.teleport-plane-track {
  position: relative;
  height: 64px;
  width: 280px;
  margin: 0 auto 12px;
  overflow: hidden;
  border-bottom: 2px dashed rgba(255, 255, 255, 0.25);
}
.teleport-plane {
  position: absolute;
  bottom: 4px;
  font-size: 30px;
  animation: planeFly 2.2s linear infinite;
}
@keyframes planeFly {
  from { left: -44px; transform: translateY(0); }
  50% { transform: translateY(-7px); }
  to { left: 292px; transform: translateY(0); }
}

.teleport-spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 12px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- cookie banner ------------------------------------------------------------------ */
#cookieBanner {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(92vw, 420px);
  padding: 14px 18px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--glass-shadow);
  z-index: 40;
  font-size: 13px;
  line-height: 1.4;
}

.cookie-text {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.cookie-icon { font-size: 22px; }

.cookie-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cookie-btn {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  transition: all 0.1s ease-in-out;
}
.cookie-btn:hover { background: rgba(255, 255, 255, 0.15); transform: translateY(-2px); }
.cookie-btn:active { transform: scale(0.9); }

/* --- medium widths: credits are a full-width strip at the very bottom,
     slider stacked above so they never overlap ---------------------------- */
@media (min-width: 641px) and (max-width: 1100px) {
  #bottomCol { bottom: 54px; }

  #attrib {
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    border-radius: 0;
    font-size: 9px;
    line-height: 1.5;
    padding: 4px 10px 6px;
    text-align: center;
    white-space: normal;
    word-break: break-word;
  }
}

/* --- narrow screens --------------------------------------------------------------
   column 1 (left edge): gems button
   column 2 (rest of width): nav bar = Sun + search (flex) + Random */
@media (max-width: 1100px) {
  #navBar {
    top: 12px;
    left: 62px;
    right: 12px;
    transform: none;
    width: auto;
  }

  #gemsPanel {
    top: 62px; /* under the gems button */
    left: 62px;
    right: 12px;
    transform: none;
    width: auto;
    max-height: 48vh;
  }

  #bottomCol { bottom: 52px; } /* above the attrib strip */

  #attrib {
    bottom: 0;
    top: auto;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    border-radius: 0;
    font-size: 8px;
    line-height: 1.5;
    padding: 4px 10px 6px;
    text-align: center;
    white-space: normal;
    word-break: break-word;
  }
}
