:root {
  --bg: #1c2b18;
  --card: #fffaf0;
  --card-glass: rgba(255, 250, 240, 0.92);
  --ink: #2b2118;
  --muted: #6e5f4f;
  --brown: #5c3c24;
  --line: #d7c4aa;
  --good: #dcfce7;
  --bad: #fee2e2;
  --gold: #f59e0b;
  --accent: #10b981;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.stage {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* ==========================================================================
   HUD Overlay Top Bar
   ========================================================================== */
.hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  pointer-events: none;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}

.hud-bar {
  pointer-events: auto;
  max-width: 960px;
  margin: 0 auto;
  background: var(--card-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(215, 196, 170, 0.8);
  border-radius: 18px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.hud-brand {
  display: flex;
  flex-direction: column;
}

.hud-logo {
  font-weight: 900;
  font-size: clamp(16px, 4vw, 20px);
  letter-spacing: -0.5px;
  color: var(--brown);
  line-height: 1;
}

.hud-subtitle {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-stat-chip {
  background: #f3ead9;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1;
}

.stat-val {
  font-size: 13px;
  font-weight: 900;
  color: var(--brown);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-btn {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 800;
  color: var(--brown);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.hud-btn:hover {
  background: #fdf3e3;
  transform: translateY(-1px);
}

.hud-btn:active {
  transform: translateY(1px);
}

/* ==========================================================================
   Proximity Floating Prompt
   ========================================================================== */
.proximity-prompt-wrap {
  position: absolute;
  bottom: clamp(20px, 6vh, 40px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  animation: floatBounce 1.8s infinite ease-in-out;
}

@keyframes floatBounce {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -6px); }
}

.proximity-btn {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffffff;
  border: 2px solid #fef3c7;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(217, 119, 6, 0.45);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s ease;
}

.proximity-btn:hover {
  transform: scale(1.04);
  box-shadow: 0 12px 28px rgba(217, 119, 6, 0.6);
}

.proximity-btn:active {
  transform: scale(0.96);
}

.prox-icon {
  font-size: 20px;
}

.prox-key {
  background: rgba(0, 0, 0, 0.25);
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 10px;
  letter-spacing: 0.05em;
}

/* ==========================================================================
   Modals & Glassmorphism Backdrops
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 15, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  animation: fadeIn 0.25s forwards ease-out;
}

@keyframes fadeIn {
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  background: var(--card-glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: modalPop 0.3s ease-out;
}

@keyframes modalPop {
  0% { transform: scale(0.9) translateY(10px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-hero {
  font-size: 48px;
  text-align: center;
  margin: 4px 0;
}

.modal-card h2 {
  margin: 0;
  text-align: center;
  font-size: clamp(20px, 5vw, 26px);
  color: var(--brown);
  font-weight: 900;
}

.modal-lead {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 8px 0;
  line-height: 1.4;
}

.topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.badge {
  background: #eee0cc;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 900;
  color: var(--brown);
  text-transform: uppercase;
}

.meta {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.photo-wrap {
  width: 100%;
  height: 220px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.clue {
  text-align: center;
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.4;
}

.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}

@media (max-width: 480px) {
  .answers {
    grid-template-columns: 1fr;
  }
}

.btn.ans-btn {
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.btn.ans-btn:hover {
  border-color: var(--brown);
  background: #fff8eb;
  transform: translateY(-2px);
}

.btn.ans-btn:active {
  transform: scale(0.97);
}

.modal-primary-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--brown), #3d2510);
  color: #ffffff;
  border: none;
  border-radius: 16px;
  padding: 14px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-top: 8px;
  box-shadow: 0 6px 18px rgba(60, 35, 15, 0.3);
}

.modal-primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(60, 35, 15, 0.4);
}

.modal-primary-btn:active {
  transform: scale(0.98);
}

/* Start Card Guide */
.controls-guide {
  background: #f4ead8;
  border-radius: 16px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ink);
}

.c-key {
  font-weight: 900;
  background: #ffffff;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

/* Result Cards */
.result-card.good {
  background: linear-gradient(180deg, #f0fdf4, #ffffff);
  border-color: #86efac;
}

.result-card.bad {
  background: linear-gradient(180deg, #fef2f2, #ffffff);
  border-color: #fca5a5;
}

.explanation {
  text-align: center;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  margin-top: 10px;
}

/* Zone Ceremony & Final Score */
.ceremony-rating {
  text-align: center;
  font-size: 16px;
  font-weight: 900;
  color: var(--gold);
  margin: 4px 0;
}

.ceremony-subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

.ceremony-boxes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 10px 0;
}

.ceremony-box {
  background: #fdf6ea;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  text-align: center;
}

.ceremony-box-label {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--muted);
}

.ceremony-box-val {
  font-size: 24px;
  font-weight: 900;
  color: var(--brown);
}

.ceremony-box-sub {
  font-size: 11px;
  color: var(--muted);
}

.teaser-text {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--brown);
  background: #f5ebe0;
  padding: 8px 12px;
  border-radius: 12px;
}

.final-score-badge {
  background: #fef3c7;
  border: 2px solid #f59e0b;
  border-radius: 999px;
  padding: 8px 16px;
  text-align: center;
  font-size: 16px;
  font-weight: 900;
  color: var(--brown);
  width: fit-content;
  margin: 8px auto;
}

.progress-bar-wrap {
  width: 100%;
  margin-top: 8px;
}

.progress-bar-head {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 4px;
}

.progress-bar-track {
  width: 100%;
  height: 10px;
  background: #e2d5c3;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #059669);
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* Journal & Map Modal */
.journal-card {
  max-width: 640px;
}

.journal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

@media (max-width: 520px) {
  .journal-grid {
    grid-template-columns: 1fr;
  }
}

.journal-zone-card {
  background: #fefbf6;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.journal-zone-card.cleared {
  background: #f0fdf4;
  border-color: #86efac;
}

.jzone-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.jzone-title {
  font-size: 13px;
  font-weight: 900;
  color: var(--brown);
}

.jzone-status {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
}

.jzone-tp-btn {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--brown);
  cursor: pointer;
  transition: all 0.15s ease;
}

.jzone-tp-btn:hover {
  background: #fdf3e3;
}

.close-modal-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  font-weight: 900;
  color: var(--muted);
  cursor: pointer;
}

/* Bristol Stool Scale CSS Illustrations */
.bristol {
  width: 100%;
  height: 160px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #f4ead8;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.bristol.type1::after {
  content: "🧆 🧆 🧆 🧆";
  font-size: 32px;
}

.bristol.type4::after {
  content: "🌭";
  font-size: 50px;
}

.bristol.type7::after {
  content: "🌊 💩 💧";
  font-size: 36px;
}

/* Mobile Touch Virtual Joystick */
.touch-joystick {
  position: absolute;
  bottom: 24px;
  left: 24px;
  width: 100px;
  height: 100px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  z-index: 15;
  display: none;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

#joystick-stick {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: transform 0.05s ease-out;
}

@media (pointer: coarse), (max-width: 768px) {
  .touch-joystick {
    display: flex;
  }
}
