:root {
  --ui-bg: rgba(10, 10, 10, 0.72);
  --ui-fg: #f4f1ea;
  --ui-dim: #a8a39a;
  --ui-border: rgba(255, 255, 255, 0.12);
  --ui-accent: #c98a5a;
}

* { box-sizing: border-box; }

/* The HTML `hidden` attribute must beat our explicit display rules below
   (flex/grid). Without this, `<div class="error" hidden>` still renders. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: #000;
  color: var(--ui-fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  /* iOS long-press: kill the selection / callout / magnifier gestures so the
     whole page doesn't highlight and so a tap on the canvas still fires a
     click (the gestures otherwise eat the tap). */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Suppress the translucent grey tap-highlight rectangle on every element. */
* { -webkit-tap-highlight-color: transparent; }

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* --- center crosshair --- */
.crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  pointer-events: none;
  z-index: 15;
  color: rgba(255, 255, 255, 0.7);
  transition: color 0.12s ease, transform 0.12s ease;
  transform: scale(1);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.6));
}
.crosshair.active {
  color: #ffd07a;
  transform: scale(1.35);
}
.crosshair svg { width: 100%; height: 100%; display: block; }

/* --- caption (focused item info) --- */
.caption {
  position: fixed;
  left: 50%;
  bottom: max(140px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  min-width: 240px;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 16px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  text-align: center;
  pointer-events: none;
  animation: caption-in 0.22s ease forwards;
}
.caption-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
}
.caption-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--ui-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.caption-meta:empty { display: none; }
.caption-desc {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ui-fg);
  opacity: 0.85;
  line-height: 1.35;
}
.caption-desc:empty { display: none; }
.caption-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--ui-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
@keyframes caption-in {
  from { opacity: 0; transform: translate(-50%, 4px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* --- on-screen +-cross (mobile only) --- */
.controls {
  position: fixed;
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(3, 60px);
  gap: 6px;
  user-select: none;
}
.ctrl {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  line-height: 1;
  color: var(--ui-fg);
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.12s ease;
  font-family: inherit;
  padding: 0;
  touch-action: manipulation;
}
/* Only apply :hover on real hover-capable devices. Mobile Safari otherwise
   sticks the hover state on whichever button you tapped most recently. */
@media (hover: hover) {
  .ctrl:hover { background: rgba(20, 20, 20, 0.82); }
}
.ctrl:active { transform: scale(0.94); background: rgba(40, 40, 40, 0.9); }
.ctrl:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }

.ctrl-up    { grid-column: 2; grid-row: 1; }
.ctrl-left  { grid-column: 1; grid-row: 2; }
.ctrl-right { grid-column: 3; grid-row: 2; }
.ctrl-down  { grid-column: 2; grid-row: 3; }

/* --- pointer-lock prompt (desktop only) --- */
.lock-prompt {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 18;
  cursor: pointer;
  user-select: none;
}
.lock-prompt-card {
  padding: 22px 28px;
  background: rgba(10, 10, 10, 0.85);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  text-align: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  max-width: 380px;
}
.lock-prompt-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ui-fg);
}
.lock-prompt-body {
  margin-top: 10px;
  font-size: 14px;
  color: var(--ui-fg);
  line-height: 1.5;
}
.lock-prompt-foot {
  margin-top: 14px;
  font-size: 11px;
  color: var(--ui-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Primary CTA — the obvious default action. */
.lock-prompt-enter {
  display: block;
  margin: 18px auto 4px;
  padding: 14px 36px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #1a1612;
  background: linear-gradient(180deg, #fff1d8 0%, #e8d4b5 100%);
  border: 1px solid rgba(201, 168, 122, 0.7);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 2px 18px rgba(201, 168, 122, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.lock-prompt-enter:hover,
.lock-prompt-enter:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 4px 26px rgba(201, 168, 122, 0.4);
  outline: none;
}
.lock-prompt-enter:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

/* Secondary affordance — restyled as a subtle text link so people stop
   reading it as the entry button. */
.lock-prompt-back {
  display: inline-block;
  margin-top: 16px;
  padding: 4px 6px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.4);
  background: transparent;
  border: none;
  transition: color 0.12s ease;
}
.lock-prompt-back:hover,
.lock-prompt-back:focus-visible {
  color: var(--ui-dim);
  outline: none;
}

/* --- affiliate disclosure (persistent FTC + Amazon Associates notice) --- */
.affiliate-disclosure {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  padding: 6px 14px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 11px;
  color: var(--ui-dim);
  letter-spacing: 0.04em;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 24px);
}

/* --- back-to-shop pill (mobile only; unhidden by main.js when (pointer: coarse)) --- */
.back-to-shop {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 14;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  text-decoration: none;
  font-size: 13px;
  color: var(--ui-fg);
  letter-spacing: 0.04em;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.back-to-shop:active {
  color: #c9a87a;
  border-color: rgba(201, 168, 122, 0.55);
}

/* --- always-visible desktop controls hint (unhidden by main.js when (pointer: fine)) --- */
.controls-hint {
  position: fixed;
  bottom: max(12px, env(safe-area-inset-bottom));
  right: 12px;
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 11px;
  color: var(--ui-dim);
  letter-spacing: 0.04em;
  pointer-events: none;
  max-width: calc(100vw - 24px);
}
.controls-hint span { display: inline-flex; align-items: center; gap: 4px; }
.controls-hint-sep { color: rgba(255, 255, 255, 0.18); }
.controls-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 500;
  color: var(--ui-fg);
  letter-spacing: 0;
}

/* --- loader --- */
.loader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #000;
  z-index: 20;
  transition: opacity 0.4s ease;
}
.loader.done {
  opacity: 0;
  pointer-events: none;
}
.loader-spinner {
  width: 36px;
  height: 36px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--ui-accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.loader-text {
  font-size: 13px;
  color: var(--ui-dim);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- fatal error overlay --- */
.error {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #100808;
  color: #ffd4d4;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  z-index: 30;
  text-align: left;
  overflow: auto;
}

/* --- mobile tweaks --- */
@media (max-width: 480px) {
  .ctrl { width: 56px; height: 56px; font-size: 24px; }
  .controls { grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); }
  .caption { font-size: 14px; padding: 10px 14px; bottom: max(220px, env(safe-area-inset-bottom)); }
  .caption-name { font-size: 15px; }
  .lock-prompt-card { padding: 18px 22px; }
  .affiliate-disclosure {
    font-size: 10px;
    padding: 5px 12px;
    letter-spacing: 0.02em;
    white-space: normal;
    text-align: center;
    max-width: calc(100vw - 24px);
  }
}
