:root {
  --warm: #f6c98a;
  --warmer: #f59e3a;
  --ink: #0f0d12;
  --paper: #f4ede0;
  --paper-dim: #d8cdb8;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: #050507;
  color: var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    Inter, system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

canvas#canvas {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh;
  display: block;
  cursor: none;
}

/* ---------- Loading ---------- */
#loading {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 35%, #2a1f17 0%, #0a0710 70%, #000 100%);
  z-index: 50;
  transition: opacity 0.8s ease;
}
#loading.gone { opacity: 0; pointer-events: none; }
.loading-inner { text-align: center; }
.loading-inner .title {
  font-family: "Cormorant Garamond", "Times New Roman", serif;
  font-size: 64px; font-weight: 300; letter-spacing: 0.18em;
  color: var(--warm);
  text-shadow: 0 0 40px rgba(245, 158, 58, 0.4);
}
.loading-inner .sub {
  margin-top: 10px;
  font-size: 14px; letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--paper-dim);
}
.bar {
  margin: 36px auto 12px;
  width: 280px; height: 2px;
  background: rgba(255,255,255,0.1);
  overflow: hidden;
}
.fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--warmer), var(--warm));
  transition: width 0.4s ease;
  box-shadow: 0 0 12px rgba(245, 158, 58, 0.6);
}
.status {
  font-size: 11px; letter-spacing: 0.25em;
  color: var(--paper-dim);
  text-transform: uppercase;
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0.35), rgba(0,0,0,0.8));
  z-index: 40;
  transition: opacity 0.5s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.card {
  max-width: 480px;
  padding: 40px 44px 32px;
  background: rgba(20, 16, 14, 0.7);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(245, 201, 138, 0.18);
  border-radius: 4px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
  text-align: center;
}
.card h1 {
  margin: 0 0 6px;
  font-family: "Cormorant Garamond", "Times New Roman", serif;
  font-size: 44px; font-weight: 300; letter-spacing: 0.14em;
  color: var(--warm);
}
.card .lede {
  margin: 0 0 26px;
  font-size: 15px; line-height: 1.6;
  color: var(--paper-dim);
}
.card ul.controls {
  list-style: none; padding: 0; margin: 0 0 28px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px;
  text-align: left;
  font-size: 13px;
  color: var(--paper);
}
.card ul.controls b {
  display: inline-block;
  min-width: 70px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--warm);
  font-weight: 500;
}
.card button {
  appearance: none; -webkit-appearance: none;
  margin: 0 auto;
  display: block;
  padding: 12px 36px;
  background: linear-gradient(180deg, var(--warmer), #c5781f);
  color: #1d1208;
  border: none;
  border-radius: 2px;
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 6px 22px rgba(245, 158, 58, 0.3);
}
.card button:hover { transform: translateY(-1px); box-shadow: 0 10px 28px rgba(245, 158, 58, 0.45); }
.card button:active { transform: translateY(0); }
.card .hint {
  margin: 14px 0 0;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(244, 237, 224, 0.4);
}

/* ---------- HUD ---------- */
#hud {
  position: fixed; inset: 0;
  z-index: 30; pointer-events: none;
  transition: opacity 0.4s ease;
}
#hud.hidden { opacity: 0; }

.crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 4px; height: 4px;
  margin: -2px 0 0 -2px;
  background: rgba(255,255,255,0.85);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 8px rgba(0,0,0,0.5);
  mix-blend-mode: difference;
}

.prompt {
  position: absolute;
  left: 50%; top: calc(50% + 30px);
  transform: translateX(-50%);
  font-size: 12px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--paper);
  text-shadow: 0 1px 6px rgba(0,0,0,0.7);
  opacity: 0;
  transition: opacity 0.25s ease;
  white-space: nowrap;
}
.prompt.show { opacity: 1; }
.prompt .key {
  display: inline-block;
  padding: 3px 8px;
  margin-right: 8px;
  border: 1px solid rgba(245, 201, 138, 0.6);
  border-radius: 3px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--warm);
  background: rgba(0,0,0,0.4);
}

.stance {
  position: absolute;
  left: 24px; bottom: 24px;
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(244, 237, 224, 0.7);
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}
.stance::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  margin-right: 10px;
  vertical-align: middle;
  background: var(--warm);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--warm);
}

.compass {
  position: absolute;
  right: 24px; bottom: 24px;
  font-family: "Cormorant Garamond", serif;
  font-size: 22px;
  letter-spacing: 0.1em;
  color: var(--warm);
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}

/* ---------- Quality selector (start card) ---------- */
.touch-controls {
  display: none;
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--paper-dim);
}
.touch-controls b { color: var(--warm); font-weight: 600; }
.quality {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 22px;
}
.quality-label {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(244, 237, 224, 0.5);
  margin-right: 4px;
}
.quality button {
  appearance: none; -webkit-appearance: none;
  padding: 7px 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(245, 201, 138, 0.25);
  border-radius: 3px;
  color: var(--paper);
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all 0.15s ease;
}
.quality button:hover { border-color: rgba(245, 201, 138, 0.6); }
.quality button.on {
  background: linear-gradient(180deg, var(--warmer), #c5781f);
  border-color: var(--warmer);
  color: #1d1208;
  font-weight: 600;
}

/* Touch devices: show the touch hint, hide mouse hint */
@media (hover: none) and (pointer: coarse) {
  .touch-controls { display: block; }
  .card .hint { display: none; }
  .card ul.controls { display: none; }
}

/* ---------- On-screen touch controls ---------- */
#touch {
  position: fixed; inset: 0;
  z-index: 35;
  display: none;
  pointer-events: none;
}
#touch.on { display: block; }

.tc-look {
  position: absolute; inset: 0;
  z-index: 1;
  pointer-events: auto;
  touch-action: none;
}
.tc-stick {
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  bottom: max(26px, env(safe-area-inset-bottom));
  width: 132px; height: 132px;
  z-index: 3;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.08), rgba(255,255,255,0.03));
  border: 1px solid rgba(245, 201, 138, 0.28);
  pointer-events: auto;
  touch-action: none;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.tc-knob {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(246,201,138,0.9), rgba(197,120,31,0.85));
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  will-change: transform;
}
.tc-buttons {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(28px, env(safe-area-inset-bottom));
  z-index: 3;
  display: flex; flex-direction: column-reverse; gap: 12px;
  pointer-events: none;
}
.tc-btn {
  pointer-events: auto;
  touch-action: none;
  width: 84px; height: 56px;
  border-radius: 14px;
  border: 1px solid rgba(245, 201, 138, 0.3);
  background: rgba(20,16,14,0.5);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  color: var(--paper);
  font-size: 12px; font-weight: 600; letter-spacing: 0.12em;
  -webkit-user-select: none; user-select: none;
}
.tc-btn.tc-jump {
  width: 92px; height: 72px;
  border-radius: 50%;
  font-size: 13px;
}
.tc-btn.on {
  background: linear-gradient(180deg, rgba(245,158,58,0.9), rgba(197,120,31,0.9));
  color: #1d1208;
  border-color: var(--warmer);
}
.tc-interact {
  position: absolute;
  left: 50%; bottom: 30%;
  transform: translateX(-50%) scale(0.9);
  z-index: 3;
  pointer-events: auto;
  touch-action: none;
  display: none;
  align-items: center; gap: 10px;
  padding: 12px 22px;
  border-radius: 999px;
  border: 1px solid var(--warm);
  background: rgba(20,16,14,0.7);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: var(--warm);
  font-size: 14px; letter-spacing: 0.1em;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: 0 0 24px rgba(245,158,58,0.35);
}
.tc-interact.show { display: inline-flex; opacity: 1; transform: translateX(-50%) scale(1); }
.tc-interact .k {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 6px;
  background: rgba(245,158,58,0.18);
  border: 1px solid rgba(245,201,138,0.6);
  font-family: ui-monospace, Menlo, monospace; font-size: 12px;
}

/* prevent the page itself from scrolling/zooming under the controls */
html, body { overscroll-behavior: none; touch-action: none; }
