:root {
  --ink: #2b2a30;
  --ink-2: #3a393f;
  --paper: #f1e6cf;
  --paper-2: #d2c3a2;
  --grey: #a6a7ab;
  --teal: #33b5a6;
  --teal-2: #22827a;
  --amber: #b06f22;
  --pink: #ff6b9d;
  --blue: #3f6fd8;
  --font: 'Press Start 2P', 'Courier New', monospace;
  --hud-h: 96px;
  --actions-h: 118px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--paper); font-family: var(--font); overscroll-behavior: none; }
body { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
button { font-family: var(--font); cursor: pointer; }

#app {
  display: flex; flex-direction: column;
  height: 100dvh; max-width: 480px; margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- HUD ---------- */
.hud { padding: 8px 12px 6px; background: var(--ink); flex: 0 0 auto; }
.hud-top { display: flex; justify-content: space-between; align-items: center; font-size: 11px; letter-spacing: 1px; margin-bottom: 8px; }
.hud-top .name { color: var(--paper); }
.hud-top .bond { color: var(--pink); font-size: 12px; }
.hud-top .day { color: var(--grey); font-size: 9px; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.stat { display: flex; align-items: center; gap: 4px; }
.stat .icon { width: 16px; height: 16px; flex: 0 0 16px; }
.bar { flex: 1; height: 10px; background: var(--ink-2); border: 2px solid var(--paper-2); position: relative; }
.bar .fill { position: absolute; inset: 0; width: 60%; background: var(--teal); transition: width .3s; }
.stat.low .fill { background: var(--pink); }
.stat.mid .fill { background: #f2c94c; }

/* ---------- SCENE ---------- */
.scene { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; background: #1e1d22; }
#game { display: block; touch-action: none; border-top: 3px solid var(--paper-2); border-bottom: 3px solid var(--paper-2); }
.toast {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); border: 2px solid var(--paper-2);
  font-size: 9px; padding: 8px 10px; line-height: 1.5; max-width: 90%; text-align: center;
  opacity: 0; transition: opacity .2s; pointer-events: none; white-space: pre-line;
}
.toast.show { opacity: 1; }
.scene-ui { position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; gap: 6px; }
.scene-ui button {
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink-2);
  font-size: 9px; padding: 8px 10px; min-height: 40px;
}
.scene-ui .timer { font-size: 9px; background: var(--ink); color: var(--paper); border: 2px solid var(--paper-2); padding: 6px 8px; text-align: center; }

/* ---------- ACTIONS ---------- */
.actions {
  flex: 0 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  padding: 8px 10px 10px; background: var(--ink);
}
.actions button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  min-height: 52px; padding: 6px 2px; font-size: 8px; letter-spacing: 0;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink-2); box-shadow: 0 3px 0 var(--paper-2);
  transition: transform .05s;
}
.actions button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--paper-2); }
.actions button .icon { width: 20px; height: 20px; }
.actions button[disabled] { opacity: .45; }

/* ---------- PANELS ---------- */
.panel {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 480px;
  background: var(--paper); color: var(--ink); border-top: 4px solid var(--ink);
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); z-index: 20;
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translate(-50%, 30px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.panel-head { display: flex; align-items: center; gap: 12px; font-size: 11px; margin-bottom: 8px; }
.panel-head .treats { margin-left: auto; font-size: 9px; color: var(--teal-2); }
.panel-head .close { background: var(--ink); color: var(--paper); border: 0; width: 36px; height: 36px; font-size: 11px; }
.panel-hint { font-size: 8px; line-height: 1.6; color: var(--ink-2); margin: 0 0 10px; }
.trick-list, .menu-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.trick-list button, .menu-list button {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  min-height: 48px; padding: 8px 10px; font-size: 9px;
  background: #fff; color: var(--ink); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink-2);
}
.menu-list button { justify-content: center; }
.menu-list button.danger { border-color: #9c2a2a; color: #9c2a2a; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 8px; height: 8px; background: var(--paper-2); border: 1px solid var(--ink); display: inline-block; }
.pips i.on { background: var(--amber); }
.help { font-size: 8px; line-height: 1.7; margin-top: 10px; }
.help p { margin: 0 0 8px; }

/* ---------- TITLE ---------- */
.overlay { position: fixed; inset: 0; background: var(--ink); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.title-card { text-align: center; }
#title-dog { width: 160px; height: 160px; margin-bottom: 8px; animation: bob 1.2s steps(2) infinite; }
@keyframes bob { 0% { transform: translateY(0); } 100% { transform: translateY(-4px); } }
.title-card h1 { font-size: 26px; margin: 8px 0 6px; color: var(--paper); text-shadow: 4px 4px 0 var(--teal-2); }
.title-card .sub { font-size: 9px; color: var(--grey); margin: 0 0 22px; }
.title-card .tiny { font-size: 8px; color: var(--grey); margin-top: 14px; }
#btn-start {
  font-size: 11px; padding: 14px 20px; background: var(--teal); color: var(--ink);
  border: 3px solid var(--paper); box-shadow: 4px 4px 0 var(--paper-2); animation: pulse 1.4s steps(2) infinite;
}
@keyframes pulse { 0% { transform: scale(1); } 100% { transform: scale(1.04); } }

@media (min-height: 760px) {
  .actions button { min-height: 60px; font-size: 9px; }
  .actions button .icon { width: 24px; height: 24px; }
}
@media (max-height: 640px) {
  .hud-top { margin-bottom: 4px; }
  .actions button { min-height: 44px; }
}
