/* Sock Mountain - first-person 3D, mobile-first */

:root {
  --bg: #ffe9d6;
  --card: #ffffff;
  --ink: #2d2440;
  --muted: #7a6f8f;
  --brand: #7b5fd6;
  --brand-dark: #5a3fb5;
  --accent: #ff2fa0;
  --good: #2fb67c;
  --line: #eadfcb;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.hud button, .hud .joy { pointer-events: auto; }

.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }

.hud-card {
  background: rgba(255, 255, 255, 0.88);
  border-radius: 14px;
  padding: 6px 12px;
  min-width: 170px;
  max-width: 60vw;
  text-align: center;
}
.left-label { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.left-number { font-size: 1.9rem; font-weight: 900; line-height: 1.05; color: var(--brand-dark); }
.progress { height: 8px; background: #e9e0f7; border-radius: 999px; overflow: hidden; margin: 4px 0; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #ff7aa8, var(--brand)); transition: width 0.2s; }
.hint { font-size: 0.7rem; color: var(--muted); min-height: 1.2em; }

.hud-buttons { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.hand-chip {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 14px;
  padding: 6px 10px;
  font-size: 0.7rem;
  line-height: 1.1;
  font-weight: bold;
}
.swatch {
  width: 22px; height: 30px;
  border-radius: 6px 6px 10px 10px;
  background: repeating-linear-gradient(180deg, #ffd400 0 28%, #ff1f8f 28% 44%, #fff 44% 58%, #ff1f8f 58% 74%, #fff 74% 88%, #ff1f8f 88% 100%);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--ink);
  display: inline-block;
}
.swatch.inline { width: 12px; height: 16px; vertical-align: middle; }

.round-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 0;
  font-size: 1.4rem;
  background: rgba(255, 255, 255, 0.92);
  cursor: pointer;
  touch-action: manipulation;
}

.crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border: 3px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  box-shadow: 0 0 0 1.5px rgba(45, 36, 64, 0.6);
}
.crosshair.pop { animation: crossPop 0.15s; }
@keyframes crossPop { 50% { transform: scale(1.8); } }

.flavour {
  position: absolute;
  left: 50%; top: 24%;
  transform: translateX(-50%);
  max-width: 86vw;
  text-align: center;
  font-weight: bold;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 12px;
  padding: 8px 14px;
  opacity: 0;
  transition: opacity 0.3s;
}
.flavour.show { opacity: 1; }

.pickup-toasts { position: absolute; left: 50%; top: 42%; transform: translateX(-50%); text-align: center; }
.toast {
  font-weight: 900;
  font-size: 1.3rem;
  color: #fff;
  -webkit-text-stroke: 1px var(--brand-dark);
  text-shadow: 0 2px 0 var(--brand-dark);
  animation: toastUp 0.9s ease-out forwards;
}
@keyframes toastUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-60px); } }

.desk-help {
  position: absolute; left: 0; right: 0; bottom: 10px;
  text-align: center; font-size: 0.75rem; color: var(--ink);
  text-shadow: 0 0 4px #fff, 0 0 4px #fff;
}

/* ---------- touch controls (hidden on mouse devices) ---------- */
.controls { display: none; }
body.touch .controls { display: block; }
body.touch .desk-help { display: none; }

.joy {
  position: absolute;
  left: 22px; bottom: 28px;
  width: 130px; height: 130px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  border: 3px solid rgba(255, 255, 255, 0.8);
  touch-action: none;
}
.joy-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 56px; height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(123, 95, 214, 0.85);
}
.act-btn {
  position: absolute;
  border: 0;
  border-radius: 50%;
  font-weight: 900;
  color: #fff;
  touch-action: none;
}
.act-btn.dig {
  right: 22px; bottom: 36px;
  width: 112px; height: 112px;
  font-size: 1.4rem;
  background: var(--brand);
  box-shadow: 0 5px 0 var(--brand-dark);
}
.act-btn.dig.down { background: var(--brand-dark); transform: translateY(3px); }
.act-btn.magnet {
  right: 40px; bottom: 170px;
  width: 76px; height: 76px;
  font-size: 1.6rem;
  background: #3d8bfd;
  box-shadow: 0 4px 0 #2563c4;
}
.act-btn.magnet:disabled { background: #9fb4d8; box-shadow: none; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(45, 36, 64, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 10;
}
.card {
  background: var(--card);
  border-radius: 24px;
  padding: 22px 20px;
  width: 100%;
  max-width: 440px;
  max-height: 94vh;
  overflow-y: auto;
  text-align: center;
}
.card h1 { margin: 0; font-size: 2rem; color: var(--brand-dark); }
.card h2 { margin: 4px 0; font-size: 1.8rem; color: var(--brand-dark); }
.big-emoji { font-size: 3.5rem; }
.sub { color: var(--muted); margin: 6px 0 12px; }
.how { text-align: left; font-size: 0.9rem; padding-left: 20px; margin: 0 0 16px; line-height: 1.5; }

.big-btn {
  width: 100%;
  padding: 16px;
  font: inherit;
  font-size: 1.15rem;
  font-weight: bold;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
}
.big-btn:active { background: var(--brand-dark); }
.small-btn {
  margin-top: 12px;
  font: inherit; font-size: 0.8rem;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.win-stats { margin: 0 0 16px; }
.win-stats div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.win-stats dt { color: var(--muted); }
.win-stats dd { margin: 0; font-weight: bold; }

/* ---------- shop ---------- */
.shop-card { text-align: left; }
.shop-head { display: flex; justify-content: space-between; align-items: center; }
.shop-head h2 { font-size: 1.4rem; margin: 0; }
.shop-head .round-btn { background: #f3edff; }

.wallet { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.wallet-item { background: #faf6ee; border: 2px solid var(--line); border-radius: 14px; padding: 6px 12px; }
.wallet-label { display: block; font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.wallet-item strong { font-size: 1.2rem; }

.upgrades { display: flex; flex-direction: column; gap: 8px; }
.upgrade {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
}
.upgrade.affordable { border-color: var(--good); box-shadow: 0 2px 0 var(--good); }
.upgrade-icon { font-size: 1.8rem; }
.upgrade-name { font-weight: bold; }
.upgrade-name small { color: var(--muted); font-weight: normal; margin-left: 4px; }
.upgrade-desc { font-size: 0.8rem; color: var(--muted); display: block; }
.upgrade-effect { font-size: 0.8rem; color: var(--brand-dark); display: block; }
.upgrade-cost { font-weight: bold; background: #f3edff; border-radius: 10px; padding: 6px 10px; white-space: nowrap; }
.upgrade.affordable .upgrade-cost { background: var(--good); color: #fff; }

@media (max-height: 520px) {
  .hint:not(#eta), .left-label { display: none; }
  .joy { width: 100px; height: 100px; bottom: 14px; }
  .act-btn.dig { width: 88px; height: 88px; bottom: 18px; }
  .act-btn.magnet { bottom: 114px; }
}

.hint.sniff { font-weight: bold; color: var(--brand-dark); }
.find-prompt {
  position: absolute;
  left: 50%; top: 62%;
  transform: translateX(-50%);
  text-align: center;
  font-weight: 900;
  font-size: 1.3rem;
  color: #fff;
  background: var(--accent);
  border-radius: 16px;
  padding: 10px 18px;
  box-shadow: 0 4px 0 #a3105c;
  animation: promptPulse 0.7s infinite alternate;
}
.find-prompt small { display: block; font-size: 0.75rem; font-weight: bold; opacity: 0.9; }
@keyframes promptPulse { to { transform: translateX(-50%) scale(1.07); } }

.station-arrow {
  position: absolute; left: 10px; top: 120px;
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.85); border-radius: 999px; padding: 4px 12px;
  font-size: 0.75rem; font-weight: bold; color: var(--ink);
}
.station-arrow .arrow { display: inline-block; font-size: 1.3rem; color: #c99a00; }
.station-arrow.urgent { background: #ffd400; }
.station-arrow.urgent .arrow { color: var(--ink); }
.carry {
  position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%);
  width: min(240px, 50vw); text-align: center;
  background: rgba(255, 255, 255, 0.88); border-radius: 12px; padding: 5px 10px;
  font-weight: bold; font-size: 0.8rem;
}
.carry-bar { height: 7px; background: #e9e0f7; border-radius: 999px; overflow: hidden; margin-top: 3px; }
.carry-fill { height: 100%; width: 0%; background: #2ec4b6; transition: width 0.1s; }
.carry.full { background: #ff7aa8; color: #fff; }
.carry.full .carry-fill { background: #fff; }
body:not(.touch) .carry { bottom: 40px; }

.book-bonus { font-size: 0.8rem; color: var(--muted); margin: 6px 0 10px; }
.shop-head small { font-size: 0.8rem; color: var(--muted); font-weight: normal; }
.book-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (min-width: 560px) { .book-grid { grid-template-columns: repeat(5, 1fr); } }
.book-cell { background: #faf6ee; border: 2px solid var(--line); border-radius: 12px; padding: 6px 2px; text-align: center; min-height: 92px; }
.book-cell.locked { opacity: 0.55; }
.book-icon { font-size: 1.8rem; line-height: 1.2; }
.book-name { font-size: 0.62rem; font-weight: bold; line-height: 1.1; min-height: 1.4em; padding: 0 2px; }
.book-lvl { font-size: 0.6rem; color: #c99a00; }
.book-cell.uncommon { border-color: #2fb67c; }
.book-cell.rare { border-color: #3d8bfd; }
.book-cell.epic { border-color: #a259ff; }
.book-cell.legendary { border-color: #ffb000; box-shadow: 0 0 8px #ffd400; }

/* ---------- food, water, energy, day ---------- */
.vitals { position: absolute; left: 10px; top: 160px; display: flex; flex-direction: column; gap: 4px; width: 150px; }
.vital { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.85); border-radius: 999px; padding: 2px 8px; font-size: 0.8rem; }
.vbar { position: relative; flex: 1; height: 8px; background: #e9e0f7; border-radius: 999px; overflow: hidden; }
.vbar i { display: block; height: 100%; width: 100%; background: #2ec4b6; transition: width 0.3s; }
.vbar i.amber { background: #ffb703; }
.vbar i.red { background: #ff4d4d; }
.vbar b { position: absolute; right: 0; top: 0; height: 100%; background: rgba(60, 40, 90, 0.35); }   /* energy you can't get back without sleeping */
.day-chip { align-self: flex-start; background: var(--brand); color: #fff; border-radius: 999px; padding: 2px 12px; font-weight: bold; font-size: 0.8rem; }
.vital-note { position: absolute; left: 10px; top: 268px; font-size: 0.75rem; font-weight: bold; background: rgba(255, 255, 255, 0.88); border-radius: 10px; padding: 2px 8px; }
.vital-note:empty { display: none; }
.sleep-overlay { position: fixed; inset: 0; z-index: 9; background: #0b0f2a; display: flex; align-items: center; justify-content: center; color: #cfd6ff; font-size: 1.6rem; font-weight: bold; opacity: 0; transition: opacity 0.5s; pointer-events: none; }
.sleep-overlay.show { opacity: 0.95; }
@keyframes fullPulse { to { transform: translateX(-50%) scale(1.08); } }
.carry.full { animation: fullPulse 0.4s infinite alternate; }

.danger { position: fixed; inset: 0; pointer-events: none; opacity: 0; box-shadow: inset 0 0 90px 30px rgba(255, 0, 0, 0.7); z-index: 5; }
.danger.show { animation: dangerPulse 0.8s infinite alternate; }
@keyframes dangerPulse { from { opacity: 0.15; } to { opacity: 0.9; } }
.vbar i.red { animation: barBlink 0.6s infinite alternate; }
@keyframes barBlink { to { opacity: 0.4; } }
