:root {
  --hull: #080b16;
  --hull-2: #0d1326;
  --panel: #141c34;
  --panel-edge: #2a3a63;
  --grid: #18324a;
  --amber: #ffc266;
  --amber-deep: #ff9a3c;
  --ink: #e9f1ff;
  --ink-dim: #8ea0c8;
  --glomp: #7CFF6B;
  --skitter: #FF8C42;
  --driftling: #45E0D8;
  --nibblet: #C86BFF;
  --danger: #ff3b5c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  background: #03050c;
  overflow: hidden;
  font-family: 'Chakra Petch', sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#stage {
  position: relative;
  width: 100vw; height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(120% 90% at 50% 0%, #101a35 0%, #060912 60%, #03050c 100%);
}
canvas#game {
  display: block;
  width: 100%; height: 100%;
  image-rendering: optimizeQuality;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- Fullscreen button ---------- */
#sg-fs-btn {
  position: fixed; top: 8px; right: 8px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  padding: 0; border: 0; border-radius: 6px;
  background: rgba(0,0,0,.45); color: #fff; cursor: pointer; z-index: 9999;
}
#sg-fs-btn:hover { background: rgba(0,0,0,.7); }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 10px 44px 10px 14px;
  pointer-events: none;
  z-index: 50;
  font-weight: 600;
  letter-spacing: .06em;
}
#hud .hud-left, #hud .hud-right { display: flex; gap: 14px; align-items: center; }
#hud .hud-right { pointer-events: auto; }
.hud-round, .hud-score, .hud-loose {
  font-size: 13px; color: var(--ink-dim);
  text-shadow: 0 1px 3px #000;
}
.hud-round span, .hud-score span, .hud-loose span {
  font-family: 'VT323', monospace; font-size: 22px; color: var(--amber);
  margin-left: 4px; vertical-align: -2px;
}
#chaos-wrap { width: min(40vw, 320px); text-align: center; }
#chaos-label { font-size: 10px; letter-spacing: .25em; color: var(--ink-dim); margin-bottom: 3px; }
#chaos-bar {
  height: 9px; border-radius: 6px;
  background: #0a0f1f; border: 1px solid var(--panel-edge);
  overflow: hidden; box-shadow: inset 0 0 8px #000;
}
#chaos-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #3ad17a, var(--amber) 55%, var(--danger));
  transition: width .12s linear;
}
#pause-btn, #mute-btn {
  pointer-events: auto;
  width: 30px; height: 30px; border-radius: 7px;
  border: 1px solid var(--panel-edge);
  background: rgba(10,16,32,.7); color: var(--ink);
  cursor: pointer; font-weight: 700; font-size: 13px;
  letter-spacing: 1px;
}
#pause-btn:hover, #mute-btn:hover { border-color: var(--amber); color: var(--amber); }

/* ---------- Proximity hint ---------- */
#hint {
  position: absolute; left: 50%; bottom: 14%;
  transform: translateX(-50%);
  background: rgba(8,12,24,.82);
  border: 1px solid var(--hc, var(--amber));
  color: var(--ink);
  padding: 7px 16px; border-radius: 20px;
  font-size: 15px; font-weight: 600; letter-spacing: .03em;
  box-shadow: 0 0 18px -4px var(--hc, var(--amber));
  z-index: 40; pointer-events: none; white-space: nowrap;
}
#hint b { color: var(--hc, var(--amber)); }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 100% at 50% 30%, rgba(6,10,22,.7), rgba(3,5,12,.92));
  backdrop-filter: blur(2px);
  padding: 18px;
}
.panel {
  background: linear-gradient(180deg, var(--panel), var(--hull-2));
  border: 1px solid var(--panel-edge);
  border-radius: 16px;
  padding: 26px 30px;
  text-align: center;
  max-width: 560px; width: 100%;
  box-shadow: 0 20px 60px -20px #000, inset 0 1px 0 rgba(255,255,255,.05);
  position: relative;
}
.panel.wide { max-width: 660px; }
.panel::before {
  content: ""; position: absolute; inset: 0; border-radius: 16px;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(0,0,0,.10) 3px 4px);
  mix-blend-mode: multiply;
}

.title-panel { padding-top: 36px; padding-bottom: 34px; }
.game-title {
  display: flex; flex-direction: column; align-items: center; line-height: .92;
  font-weight: 700; letter-spacing: .04em; margin-bottom: 8px;
}
.t-perkins {
  font-size: clamp(40px, 11vw, 78px);
  color: var(--amber);
  text-shadow: 0 0 24px rgba(255,154,60,.55), 0 4px 0 #6b3410;
}
.t-in {
  font-family: 'VT323', monospace;
  font-size: clamp(18px, 4vw, 26px);
  color: var(--driftling); letter-spacing: .5em; margin: 2px 0;
}
.t-space {
  font-size: clamp(40px, 11vw, 78px);
  color: var(--ink);
  text-shadow: 0 0 20px rgba(69,224,216,.4);
}
.subtitle { color: var(--ink-dim); margin-bottom: 22px; font-size: 16px; }

h2 { font-size: clamp(26px, 6vw, 38px); letter-spacing: .04em; margin-bottom: 6px; color: var(--amber); }
.lead, p.warn, #rb-sub, #go-sub { color: var(--ink-dim); margin-bottom: 16px; font-size: 15px; line-height: 1.5; }
p.warn { color: #ffd0d8; }
p.warn b { color: var(--danger); }

.big-btn {
  display: inline-block; margin: 8px 6px 4px;
  padding: 13px 32px; border: 0; border-radius: 12px;
  background: linear-gradient(180deg, var(--amber), var(--amber-deep));
  color: #2a1606; font-weight: 700; font-size: 18px; letter-spacing: .08em;
  cursor: pointer; box-shadow: 0 6px 0 #8a4a14, 0 10px 24px -8px var(--amber-deep);
  transition: transform .06s, box-shadow .06s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #8a4a14; }
.ghost-btn {
  display: block; margin: 12px auto 0;
  background: none; border: 1px solid var(--panel-edge);
  color: var(--ink-dim); padding: 8px 18px; border-radius: 10px;
  cursor: pointer; font-size: 14px; letter-spacing: .05em;
}
.ghost-btn:hover { color: var(--amber); border-color: var(--amber); }
.hi-line { margin-top: 18px; color: var(--ink-dim); font-size: 13px; }
.hi-line span { color: var(--amber); font-family: 'VT323', monospace; font-size: 18px; }

/* Creature guide */
.creature-guide { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0 16px; text-align: left; }
.cg {
  background: rgba(8,12,24,.5); border: 1px solid var(--panel-edge);
  border-left: 4px solid var(--c); border-radius: 10px; padding: 10px 12px;
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto;
  column-gap: 9px; align-items: center;
}
.cg-dot { grid-row: 1 / 3; width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6, var(--c));
  box-shadow: 0 0 14px -2px var(--c); }
.cg b { color: var(--c); font-size: 16px; }
.cg span { grid-column: 2; font-size: 12.5px; color: var(--ink-dim); line-height: 1.35; }

#rb-new { margin: 6px 0 14px; min-height: 24px; font-size: 15px; }
#rb-new .nc { color: var(--nc); font-weight: 700; }

.go-stats { display: flex; justify-content: center; gap: 26px; margin: 16px 0 6px; }
.go-stats div { font-size: 12px; color: var(--ink-dim); letter-spacing: .12em; }
.go-stats b { display: block; font-family: 'VT323', monospace; font-size: 30px; color: var(--amber); }
#go-newbest { color: var(--glomp); font-weight: 700; letter-spacing: .2em; margin: 4px 0 8px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* ---------- Touch controls ---------- */
#touch-controls { position: absolute; inset: 0; z-index: 60; pointer-events: none; }
#joystick {
  position: absolute; left: 26px; bottom: 26px;
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(12,20,40,.45); border: 2px solid var(--panel-edge);
  pointer-events: auto; touch-action: none;
}
#joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff5, var(--amber));
  box-shadow: 0 0 16px -2px var(--amber);
}
#touch-buttons { position: absolute; right: 22px; bottom: 30px; display: flex; gap: 14px; align-items: flex-end; pointer-events: auto; }
.tbtn {
  border-radius: 50%; border: 2px solid var(--panel-edge);
  background: rgba(12,20,40,.6); color: var(--ink);
  font-weight: 700; letter-spacing: .04em; cursor: pointer;
  font-family: 'Chakra Petch', sans-serif;
}
#sneak-btn { width: 76px; height: 76px; font-size: 13px; }
#sneak-btn.on { background: var(--driftling); color: #05201e; border-color: var(--driftling); }
#action-btn { width: 104px; height: 104px; font-size: 16px; }
.tbtn.primary { background: rgba(255,154,60,.25); border-color: var(--amber); color: var(--amber); }
.tbtn.primary:active { background: var(--amber); color: #2a1606; }

@media (max-width: 560px) {
  .creature-guide { grid-template-columns: 1fr; }
  #hud { padding-right: 40px; }
  #chaos-wrap { width: 42vw; }
}
