:root {
  --ink: #12100c;
  --paper: #f6efdd;
  --gold: #ffc93c;
  --gold-deep: #e08d1c;
  --poop: #7a4f27;
  --poop-lite: #a9713a;
  --green: #6fdc6f;
  --red: #ff5555;
  --blue: #6ec6ff;
  --panel: rgba(18, 15, 12, 0.92);
  --edge: rgba(255, 201, 60, 0.35);
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #0a0908;
  color: var(--paper);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  cursor: default;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.22);
  border-bottom-width: 2px;
  font: inherit;
  font-size: 0.82em;
  letter-spacing: 0.02em;
}

/* ================= HUD ================= */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

.hud-corner { position: absolute; display: flex; gap: 8px; align-items: flex-start; padding: 16px; }
.hud-corner.tl { top: 0; left: 0; flex-direction: column; }
.hud-corner.tr { top: 0; right: 0; flex-direction: column; align-items: flex-end; }
.hud-corner.bl { bottom: 0; left: 0; flex-direction: column; }
.hud-corner.br { bottom: 0; right: 0; }

.pill {
  background: rgba(10, 9, 8, 0.62);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700;
  letter-spacing: 0.09em;
  font-size: 13px;
  text-transform: uppercase;
  backdrop-filter: blur(6px);
  white-space: nowrap;
}
.pill.big { font-size: 26px; padding: 4px 18px; letter-spacing: 0.04em; color: var(--gold); }
.pill.big.urgent { color: var(--red); animation: pulse 0.7s infinite; }
.pill.dim { opacity: 0.5; font-size: 11px; letter-spacing: 0.06em; }
.pill .ico { margin-right: 6px; }

.pill.btn {
  pointer-events: auto;
  cursor: pointer;
  color: var(--paper);
  background: rgba(224, 141, 28, 0.28);
  border-color: var(--gold);
  transition: transform 0.1s ease, background 0.15s ease;
}
.pill.btn:hover { background: rgba(224, 141, 28, 0.55); transform: translateY(-1px); }

.ammo {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 44px; font-weight: 800; line-height: 1;
  color: var(--poop-lite);
  text-shadow: 0 3px 0 rgba(0,0,0,0.6);
}
.ammo .ico { font-size: 30px; }
.ammo .ammo-max { font-size: 18px; opacity: 0.55; }
.ammo.empty { color: #555; }

#crosshair {
  position: absolute; left: 50%; top: 50%;
  width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border: 2px solid rgba(255,255,255,0.5);
  border-radius: 50%;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
#crosshair .ch-dot {
  position: absolute; left: 50%; top: 50%;
  width: 3px; height: 3px; margin: -1.5px 0 0 -1.5px;
  border-radius: 50%; background: #fff;
}
#crosshair.hot { border-color: var(--green); transform: scale(1.25); }
#crosshair.cooling { border-color: rgba(255,255,255,0.15); }

#prompt {
  position: absolute; left: 50%; top: 58%; transform: translateX(-50%);
  background: rgba(10,9,8,0.75);
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase;
}

#toast-wrap {
  position: absolute; left: 50%; top: 22%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.toast {
  background: rgba(10,9,8,0.7);
  border-left: 3px solid var(--gold);
  padding: 6px 14px;
  font-weight: 700; font-size: 15px;
  border-radius: 4px;
  animation: toastIn 0.25s ease, toastOut 0.4s ease 1.4s forwards;
}
.toast.good { border-color: var(--green); }
.toast.bad  { border-color: var(--red); }
.toast.coin { border-color: var(--gold); color: var(--gold); }

@keyframes toastIn  { from { opacity: 0; transform: translateY(-8px) } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(-14px) } }
@keyframes pulse    { 50% { opacity: 0.45 } }

/* ================= CROWD PRESSURE ================= */
#crowd {
  position: absolute; left: 50%; top: 66%; transform: translateX(-50%);
  width: 260px; text-align: center;
}
.crowd-label {
  font-size: 12px; font-weight: 800; letter-spacing: 0.16em;
  color: var(--red); margin-bottom: 5px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.9);
}
.crowd-label span { opacity: 0.75; }
.crowd-bar {
  height: 9px; border-radius: 5px; overflow: hidden;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,85,85,0.5);
}
.crowd-bar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, #ff8a4c, var(--red));
  transition: width 0.08s linear;
}
.crowd-hint {
  margin-top: 5px; font-size: 10.5px; letter-spacing: 0.14em;
  opacity: 0.65; text-shadow: 0 2px 6px rgba(0,0,0,0.9);
}
#crowd.pinned .crowd-label { animation: pulse 0.45s infinite; }

#alert-vignette {
  position: absolute; inset: 0;
  box-shadow: inset 0 0 160px 20px rgba(255, 40, 40, 0.75);
  opacity: 0; transition: opacity 0.25s ease;
}
#alert-vignette.on { opacity: 1; }

/* ================= VIEWMODEL ================= */
#viewmodel {
  position: fixed; right: 6%; bottom: -2%;
  width: 320px; height: 320px;
  z-index: 9; pointer-events: none;
  transform-origin: 80% 100%;
  transition: transform 0.09s ease-out;
}
#viewmodel.throwing { transform: translateY(60px) rotate(-24deg); }
/* A forearm coming in from the lower right, fur stripes and all. */
#viewmodel .arm {
  /* right/rotation are tuned together: the 250px arm swings its paw a long way
     right as it rotates, and the held poop must stay inside the viewport. */
  position: absolute; bottom: -30px; right: 112px;
  width: 86px; height: 250px;
  background:
    repeating-linear-gradient(84deg, rgba(0,0,0,0.16) 0 3px, transparent 3px 11px),
    linear-gradient(96deg, #4a2c17 0%, #7d4f2c 38%, #93613a 55%, #4a2c17 100%);
  border-radius: 44px 40px 16px 16px;
  transform: rotate(16deg);
  transform-origin: 50% 100%;
  box-shadow: inset -16px 0 26px rgba(0,0,0,0.5), -8px 0 26px rgba(0,0,0,0.4);
}
/* the cupped paw at the top of the arm */
#viewmodel .paw {
  position: absolute; top: -34px; left: -20px;
  width: 126px; height: 104px;
  background: linear-gradient(150deg, #9a6a3c 0%, #6b4326 60%, #43280f 100%);
  border-radius: 54% 46% 38% 42%;
  box-shadow: inset -10px -10px 20px rgba(0,0,0,0.5), inset 6px 8px 14px rgba(255,220,180,0.12);
}
/* knuckle bumps so the paw doesn't read as a mitten */
#viewmodel .paw::after {
  content: ''; position: absolute; top: 8px; left: 14px; right: 16px; height: 26px;
  background:
    radial-gradient(circle at 14% 50%, rgba(0,0,0,0.28) 0 9px, transparent 10px),
    radial-gradient(circle at 45% 42%, rgba(0,0,0,0.28) 0 10px, transparent 11px),
    radial-gradient(circle at 78% 52%, rgba(0,0,0,0.28) 0 9px, transparent 10px);
}
/* Held above the paw so it reads as a distinct object, not part of the hand. */
#viewmodel .held {
  position: absolute; top: -74px; left: 12px;
  width: 88px; height: 72px;
  border-radius: 52% 48% 44% 46%;
  background: radial-gradient(circle at 34% 24%, #9b6631 0%, #6a4420 42%, #2b1a09 100%);
  box-shadow:
    0 0 0 2px rgba(0,0,0,0.5),
    0 10px 18px rgba(0,0,0,0.6),
    inset -10px -12px 16px rgba(0,0,0,0.55),
    inset 8px 8px 12px rgba(255,214,160,0.18);
}
/* the little swirl on top, because of course */
#viewmodel .held::before {
  content: ''; position: absolute; top: -16px; left: 50%; margin-left: -17px;
  width: 34px; height: 26px; border-radius: 50% 50% 44% 44%;
  background: radial-gradient(circle at 36% 28%, #9b6631, #4a2e13);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.5);
}
/* a couple of flies, obviously */
#viewmodel .held::after {
  content: ''; position: absolute; top: -30px; right: -14px;
  width: 5px; height: 5px; border-radius: 50%;
  background: #1a1a1a;
  box-shadow: 16px 10px 0 -1px #1a1a1a, 6px 26px 0 -1px #1a1a1a;
  animation: buzz 1.6s ease-in-out infinite;
}
@keyframes buzz {
  33%  { transform: translate(4px, -3px) }
  66%  { transform: translate(-3px, 2px) }
}
#viewmodel.empty .held { display: none; }

/* ================= OVERLAYS ================= */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: none;
  align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, rgba(24,18,10,0.82), rgba(4,4,3,0.96));
  backdrop-filter: blur(4px);
  overflow-y: auto;
}
.overlay.show { display: flex; }

.panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 18px;
  padding: 30px 34px;
  max-width: 560px; width: 100%;
  box-shadow: 0 24px 70px rgba(0,0,0,0.7), inset 0 1px 0 rgba(255,255,255,0.06);
  text-align: center;
}
.panel.wide { max-width: 880px; }
.panel.slim { max-width: 320px; }
.panel.lock-panel { max-width: 500px; }

.title {
  font-size: clamp(44px, 9vw, 86px);
  line-height: 0.92;
  letter-spacing: -0.02em;
  font-weight: 900;
  color: var(--poop-lite);
  text-shadow: 0 5px 0 rgba(0,0,0,0.55);
}
.title span { display: block; color: var(--gold); }
.tag { margin: 14px 0 26px; opacity: 0.75; font-size: 16px; letter-spacing: 0.03em; }
.fine { margin-top: 18px; font-size: 12px; opacity: 0.42; }

.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 26px; text-align: left; }
.card { background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 12px; padding: 16px; }
.card h3 { font-size: 14px; letter-spacing: 0.08em; margin-bottom: 8px; color: var(--gold); }
.card p { font-size: 13px; line-height: 1.5; opacity: 0.72; }

.menu-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.big-btn {
  font-family: var(--font);
  font-size: 19px; font-weight: 800; letter-spacing: 0.12em;
  padding: 14px 44px;
  border: none; border-radius: 999px;
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  color: #2a1c05;
  cursor: pointer;
  box-shadow: 0 6px 0 #8a5410, 0 12px 24px rgba(0,0,0,0.5);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.big-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #8a5410, 0 16px 28px rgba(0,0,0,0.55); }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #8a5410; }
.big-btn.ghost { background: transparent; color: var(--gold); border: 2px solid var(--gold); box-shadow: none; }
.big-btn.ghost:hover { background: rgba(255,201,60,0.14); }

.link-btn {
  background: none; border: none; color: inherit;
  opacity: 0.45; font-family: var(--font); font-size: 13px;
  cursor: pointer; text-decoration: underline; padding: 6px;
}
.link-btn:hover { opacity: 0.9; }

/* ================= LOCK PUZZLE ================= */
#lock-canvas { width: 100%; max-width: 420px; height: auto; aspect-ratio: 1; touch-action: none; cursor: pointer; }

/* The clock keeps running while you fumble with the padlock, so it has to be
   readable from in here — the overlay dims the HUD behind it. */
.lock-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 12px;
}
#lock-title { font-size: 17px; letter-spacing: 0.14em; color: var(--gold); text-align: left; }
.lock-clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1; }
.lock-clock-label { font-size: 9px; letter-spacing: 0.18em; opacity: 0.5; margin-bottom: 3px; }
#lock-timer {
  font-size: 28px; font-weight: 800; letter-spacing: 0.02em; color: var(--gold);
  font-variant-numeric: tabular-nums;
}
#lock-timer.urgent { color: var(--red); animation: pulse 0.7s infinite; }
#lock-status { margin-top: 8px; font-size: 14px; min-height: 22px; opacity: 0.8; }
#lock-status.fail { color: var(--red); font-weight: 800; opacity: 1; }
#lock-status.win  { color: var(--green); font-weight: 800; opacity: 1; }
.pips { display: flex; gap: 7px; justify-content: center; margin: 12px 0 4px; }
.pip { width: 26px; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.16); }
.pip.on { background: var(--green); box-shadow: 0 0 10px var(--green); }

/* ================= SHOP ================= */
.shop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.shop-head h2 { font-size: 22px; letter-spacing: 0.08em; }
.shop-head small { opacity: 0.4; font-size: 12px; letter-spacing: 0.05em; }
.wallet { font-size: 26px; font-weight: 800; color: var(--gold); }
.wallet .ico { margin-right: 6px; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 10px; cursor: pointer;
  font-family: var(--font); font-size: 13px; font-weight: 700; letter-spacing: 0.08em;
  background: rgba(255,255,255,0.05); color: var(--paper);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 10px;
}
.tab.active { background: rgba(255,201,60,0.2); border-color: var(--gold); color: var(--gold); }

.shop-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-bottom: 20px; text-align: left; }

.item {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px; padding: 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.item.owned { border-color: rgba(111,220,111,0.5); }
.item.equipped { border-color: var(--green); background: rgba(111,220,111,0.09); }
.item.locked { opacity: 0.42; }
.item-top { display: flex; align-items: center; gap: 10px; }
.item-emoji { font-size: 28px; }
.item-name { font-size: 15px; font-weight: 800; letter-spacing: 0.03em; }
.item-desc { font-size: 12.5px; line-height: 1.45; opacity: 0.7; }
.item-bar { display: flex; gap: 3px; margin-bottom: 8px; }
.item-bar i { flex: 1; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.14); }
.item-bar i.on { background: var(--gold); }
.buy {
  display: block; width: 100%;
  margin-top: auto; padding: 9px; border: none; border-radius: 8px;
  font-family: var(--font); font-weight: 800; font-size: 13px; letter-spacing: 0.06em;
  background: var(--gold); color: #2a1c05; cursor: pointer;
}
.buy:hover:not(:disabled) { background: #ffd75e; }
.buy:disabled { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.35); cursor: not-allowed; }
.buy.equip { background: var(--green); }
.buy.is-equipped { background: transparent; border: 1px solid var(--green); color: var(--green); }

/* ================= SUMMARY / SCOLD ================= */
.scold {
  font-size: 17px; line-height: 1.6; font-style: italic;
  background: rgba(255,85,85,0.1);
  border-left: 3px solid var(--red);
  padding: 14px 18px; margin: 18px 0; text-align: left;
}
.scold.calm { background: rgba(110,198,255,0.1); border-color: var(--blue); }
.scold .who { display: block; font-style: normal; font-size: 12px; letter-spacing: 0.1em; opacity: 0.6; margin-top: 8px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 18px 0 24px; }
.stat { background: rgba(255,255,255,0.04); border-radius: 10px; padding: 12px 8px; }
.stat b { display: block; font-size: 28px; color: var(--gold); line-height: 1.1; }
.stat span { font-size: 11px; letter-spacing: 0.09em; opacity: 0.6; text-transform: uppercase; }

#sum-title { font-size: 30px; letter-spacing: 0.06em; }

/* ================= FADE / LOADING ================= */
#fade {
  position: fixed; inset: 0; z-index: 40; background: #000;
  opacity: 0; pointer-events: none; transition: opacity 1.1s ease;
}
#fade.on { opacity: 1; }
#fade.instant { transition: none; }
#fade .caption {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 900; letter-spacing: 0.3em; color: var(--gold);
}

.spinner {
  width: 34px; height: 34px; margin: 0 auto 14px;
  border: 3px solid rgba(255,255,255,0.15); border-top-color: var(--gold);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

@media (max-width: 640px) {
  .hud-corner { padding: 10px; }
  .ammo { font-size: 32px; }
  #viewmodel { width: 200px; height: 200px; right: 0; }
  .panel { padding: 22px 18px; }
}
