  :root { --accent: #e8d27a; --panel: rgba(14, 12, 6, 0.85); --text: #efe9d2; --blood: #7a0000; --guide: #ffcf6b; }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--text);
    font-family: "Courier New", ui-monospace, monospace; }
  canvas { display: block; }
  #hud { position: fixed; top: 14px; left: 14px; right: 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; pointer-events: none; z-index: 2; }
  .chip { background: var(--panel); padding: 8px 14px; border-radius: 6px; font-weight: 700; display: flex; align-items: center; gap: 8px;
    font-variant-numeric: tabular-nums; border: 1px solid rgba(232,210,122,0.18); transition: opacity 0.3s, color 0.3s; }
  .chip.dim { opacity: 0.5; }
  .chip.missed { opacity: 0.45; text-decoration: line-through; }
  .chip.active { color: var(--guide); border-color: rgba(255,207,107,0.6); box-shadow: 0 0 14px rgba(255,207,107,0.35); }
  #stamina { width: 110px; height: 10px; background: rgba(0,0,0,0.6); border: 1px solid rgba(232,210,122,0.3); border-radius: 5px; overflow: hidden; }
  #staminaFill { height: 100%; width: 100%; background: var(--accent); transition: background 0.2s; }
  #staminaFill.tired { background: #a33; }
  .bat { width: 34px; height: 15px; border: 2px solid var(--text); border-radius: 3px; position: relative; padding: 1px; }
  .bat::after { content: ''; position: absolute; right: -5px; top: 3px; width: 3px; height: 5px; background: var(--text); border-radius: 0 1px 1px 0; }
  #batFill { height: 100%; width: 100%; background: #8fd16a; border-radius: 1px; }
  #batFill.low { background: #d44; animation: blink 0.6s steps(2) infinite; }
  #batChip.on .bat { box-shadow: 0 0 10px rgba(255,241,214,0.5); }
  @keyframes blink { 50% { opacity: 0.3; } }
  #hint { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); background: var(--panel); max-width: calc(100% - 32px);
    padding: 7px 14px; border-radius: 6px; font-size: 12px; opacity: 0.75; pointer-events: none; text-align: center; z-index: 2; }
  #toast { position: fixed; top: 22%; left: 50%; transform: translate(-50%, -8px); background: var(--panel); padding: 12px 20px;
    border-radius: 8px; border: 1px solid rgba(232,210,122,0.3); font-size: 15px; text-align: center; max-width: min(560px, calc(100% - 32px));
    opacity: 0; pointer-events: none; transition: opacity 0.4s, transform 0.4s; z-index: 4; line-height: 1.45; }
  #toast.show { opacity: 1; transform: translate(-50%, 0); }
  #toast b { color: var(--accent); }
  #vignette { position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 1;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(110,0,0,0.55) 75%, rgba(40,0,0,0.95) 100%); }
  #flash { position: fixed; inset: 0; pointer-events: none; background: #900; opacity: 0; z-index: 3; }
  #flash.on { animation: flash 1.6s ease-out forwards; }
  @keyframes flash { 0% { opacity: 0.9; } 10% { opacity: 0.2; } 18% { opacity: 0.75; } 100% { opacity: 0.35; } }
  .overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.72); z-index: 5; overflow-y: auto; padding: 16px 0; }
  .overlay.show { display: flex; }
  .card { background: var(--panel); border: 1px solid rgba(232,210,122,0.2); border-radius: 8px; margin: auto;
    padding: 26px 32px; text-align: center; max-width: 540px; width: calc(100% - 32px); position: relative; z-index: 2; }
  h1 { margin: 0 0 6px; font-size: 40px; letter-spacing: 4px; color: var(--accent); text-shadow: 0 0 18px rgba(232,210,122,0.4); }
  h2 { margin: 0 0 10px; font-size: 26px; letter-spacing: 2px; }
  p { margin: 8px 0; line-height: 1.5; opacity: 0.9; font-size: 14px; }
  .keys { text-align: left; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0; font-size: 13px; }
  kbd { background: #2b2614; border-radius: 4px; padding: 1px 6px; font-family: inherit; font-size: 12px; border-bottom: 2px solid #110f06; }
  button { margin: 14px 6px 0; background: var(--accent); color: #1b1606; border: 0; border-radius: 6px;
    padding: 11px 24px; font-size: 16px; font-weight: 700; cursor: pointer; font-family: inherit; }
  button.ghost { background: transparent; color: var(--text); border: 1px solid rgba(232,210,122,0.4); }
  button.small { padding: 6px 12px; font-size: 13px; margin: 6px 3px 0; }
  button:hover { filter: brightness(1.1); }
  table { margin: 12px auto; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13px; }
  td { padding: 3px 10px; text-align: left; }
  .best { color: var(--accent); }
  .good { color: var(--guide); }
  #dead { background: rgba(30, 0, 0, 0.55); }
  #dead h2 { font-size: 46px; color: #d11; text-shadow: 0 0 20px #600; letter-spacing: 6px; }
  #drips { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 1; }
  .drip { position: absolute; top: 0; background: linear-gradient(#4a0000, #8b0000 80%, #a50000);
    border-radius: 0 0 50% 50%; animation: drip linear forwards; }
  @keyframes drip { from { height: 0; } }
  .warn { color: #d66; font-size: 12px; }
  #levelSelect p { font-size: 12px; margin-top: 14px; opacity: 0.7; }

  /* ---------- Device-specific help: PC sees keyboard/mouse, phones & tablets see touch ---------- */
  .touch-only { display: none; }
  body.touch .touch-only { display: revert; }
  body.touch .keys.touch-only { display: grid; }
  body.touch .pc-only { display: none !important; }
  .suggest { font-size: 12px; color: var(--guide); opacity: 0.85; }

  /* ---------- Touch controls ---------- */
  body.touch { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
  body.touch canvas { touch-action: none; }
  body.touch button { touch-action: manipulation; }
  #touchUI { position: fixed; inset: 0; z-index: 2; display: none; touch-action: none; }
  body.touch #touchUI.active { display: block; }
  #joyBase { position: absolute; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%;
    border: 2px solid rgba(232,210,122,0.35); background: radial-gradient(circle, rgba(232,210,122,0.08), rgba(14,12,6,0.35));
    pointer-events: none; opacity: 0.45; transition: opacity 0.2s; }
  #joyBase.on { opacity: 1; transition: none; }
  #joyKnob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%;
    background: rgba(232,210,122,0.55); border: 2px solid rgba(255,240,190,0.7); box-shadow: 0 0 14px rgba(232,210,122,0.35); }
  #joyBase.sneak #joyKnob { background: rgba(120,140,170,0.55); border-color: rgba(190,210,240,0.7); }
  #joyLabel { position: absolute; left: 0; right: 0; top: 100%; margin-top: 6px; text-align: center; font-size: 11px; font-weight: 700;
    letter-spacing: 1px; opacity: 0.75; text-shadow: 0 1px 3px #000; }
  .tbtn { position: absolute; width: 68px; height: 68px; margin: 0; padding: 0; border-radius: 50%;
    background: rgba(14,12,6,0.55); color: var(--text); border: 2px solid rgba(232,210,122,0.45);
    font-size: 11px; font-weight: 700; letter-spacing: 0.5px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    line-height: 1.1; backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); touch-action: none; }
  .tbtn .ic { font-size: 22px; line-height: 1; }
  .tbtn:hover { filter: none; }
  .tbtn.pressed { transform: scale(0.92); }
  .tbtn.on { background: rgba(232,210,122,0.85); color: #1b1606; border-color: #fff2c0; box-shadow: 0 0 16px rgba(232,210,122,0.5); }
  .tbtn.off { opacity: 0.4; }
  #tFlash { width: 84px; height: 84px; right: calc(22px + env(safe-area-inset-right)); bottom: calc(26px + env(safe-area-inset-bottom)); }
  #tRun   { right: calc(118px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); }
  #tSneak { right: calc(104px + env(safe-area-inset-right)); bottom: calc(98px + env(safe-area-inset-bottom)); }
  #tGuide { right: calc(30px + env(safe-area-inset-right)); bottom: calc(124px + env(safe-area-inset-bottom)); }
  #tCam   { width: 48px; height: 48px; font-size: 10px; right: calc(194px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); }
  #tPause { width: 46px; height: 46px; border-radius: 10px; font-size: 18px;
    right: calc(14px + env(safe-area-inset-right)); top: calc(14px + env(safe-area-inset-top)); }
  #tGuide .n { font-size: 10px; opacity: 0.8; }
  body.touch #hud { top: calc(10px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); right: calc(70px + env(safe-area-inset-right)); gap: 6px; }
  body.touch .chip { padding: 5px 9px; font-size: 12px; gap: 6px; }
  body.touch #stamina { width: 70px; }
  body.touch #hint { display: none; }
  body.touch #toast { font-size: 13px; top: 18%; }
  body.touch .card { padding: 20px 18px; }
  body.touch h1 { font-size: 30px; letter-spacing: 2px; }
  @media (max-height: 500px) {   /* phones held sideways: tighter buttons and HUD */
    body.touch .tbtn { width: 58px; height: 58px; }
    body.touch #tFlash { width: 72px; height: 72px; bottom: calc(16px + env(safe-area-inset-bottom)); }
    body.touch #tRun   { right: calc(102px + env(safe-area-inset-right)); bottom: calc(12px + env(safe-area-inset-bottom)); }
    body.touch #tSneak { right: calc(92px + env(safe-area-inset-right)); bottom: calc(80px + env(safe-area-inset-bottom)); }
    body.touch #tGuide { right: calc(24px + env(safe-area-inset-right)); bottom: calc(100px + env(safe-area-inset-bottom)); }
    body.touch #tCam   { width: 44px; height: 44px; right: calc(168px + env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom)); }
    body.touch #joyBase { width: 110px; height: 110px; margin: -55px 0 0 -55px; }
    body.touch #joyKnob { width: 50px; height: 50px; margin: -25px 0 0 -25px; }
    body.touch .chip { padding: 4px 8px; font-size: 11px; }
    body.touch p { font-size: 13px; }
  }
  body.touch .rotate-tip { display: none; }
  body.touch.portrait .rotate-tip { display: block; }
  /* keep the Enter button reachable while the menu text scrolls on small screens */
  body.touch #startBtn { position: sticky; bottom: 6px; z-index: 3; box-shadow: 0 4px 18px rgba(0,0,0,0.8); padding: 13px 40px; }
  body.touch .keys { font-size: 12px; gap: 5px 10px; }
  .site-back { font-size: 12px; margin-top: 16px; opacity: 0.75; }
  .site-back a { color: var(--accent); }
