* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #1d2b1f;
  color: #f3efe2;
  font-family: "Segoe UI", system-ui, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

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

#hud {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.panel {
  position: absolute;
  background: rgba(22, 30, 25, 0.78);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
}

/* left column stacks status and hunger so it never overlaps */
#left {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left));
  top: calc(12px + env(safe-area-inset-top));
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#log {
  right: calc(12px + env(safe-area-inset-right));
  top: calc(12px + env(safe-area-inset-top));
  width: 300px;
  text-align: right;
  font-size: 13px;
  background: rgba(22, 30, 25, 0.6);
}
#log div { line-height: 1.6; }

#help {
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  font-size: 13px;
  white-space: nowrap;
  opacity: 0.9;
}

.title { font-weight: 700; font-size: 16px; letter-spacing: 0.4px; margin-bottom: 4px; }
.row { display: flex; align-items: center; gap: 8px; height: 22px; }
.row span { flex: 1; opacity: 0.85; }
.row b { font-weight: 700; min-width: 24px; text-align: right; }
.chip { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chip.wood { background: #c9a25a; }
.chip.stone { background: #9ca0a6; }
.chip.berry { background: #d8465d; }

.label { font-size: 13px; opacity: 0.85; }
.small { font-size: 12px; opacity: 0.7; margin-top: 2px; }
.bar {
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  margin: 4px 0 8px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 10%;
  border-radius: 4px;
  background: #e9a03b;
  transition: width 0.3s;
}

.key {
  display: inline-block;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 5px;
  padding: 1px 6px;
  margin: 0 4px 0 12px;
  font-weight: 600;
}
.key:first-child { margin-left: 0; }

/* floating stick, positioned by script at the touch origin */
#stick {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  z-index: 2;
  pointer-events: none;
}
#stick .base,
#stick .knob {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
}
#stick .base { background: rgba(255, 255, 255, 0.1); }
#stick .knob { background: rgba(255, 255, 255, 0.34); }

/* on-screen action buttons, touch layouts only */
#actions {
  position: fixed;
  z-index: 3;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: none;
  grid-template-columns: repeat(4, 56px);
  gap: 8px;
}
body.touch #actions { display: grid; }

.act {
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(22, 30, 25, 0.78);
  color: #f3efe2;
  font: 600 12px system-ui, sans-serif;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.act.primary { background: rgba(60, 90, 66, 0.92); }
.act:active { background: #4c7254; }

#menu {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 12, 0.55);
  pointer-events: auto;
}
#menu.hidden, .hidden { display: none !important; }

#menu .card {
  background: #27362b;
  border-radius: 16px;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 240px;
  text-align: center;
}
#menu h2 { margin: 0 0 6px; font-size: 22px; }

button {
  font: inherit;
  color: #f3efe2;
  background: #3c5a42;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
}
button:hover { background: #4c7254; }

/* touch: no keyboard hints, larger targets */
body.touch #help { display: none; }
body.touch #menu button { padding: 14px 16px; font-size: 16px; }

/* compact: phones and small windows */
body.compact #left {
  width: 150px;
  gap: 6px;
  top: calc(8px + env(safe-area-inset-top));
  left: calc(8px + env(safe-area-inset-left));
}
body.compact .panel { padding: 7px 10px; font-size: 12px; }
body.compact .title { font-size: 13px; margin-bottom: 2px; }
body.compact .row { height: 18px; }
body.compact .bar { margin: 3px 0 5px; }
body.compact #settle-info { display: none; }
body.compact #log {
  width: 46vw;
  max-width: 240px;
  right: calc(8px + env(safe-area-inset-right));
  top: calc(8px + env(safe-area-inset-top));
  font-size: 12px;
}
body.compact #help { display: none; }
body.compact #actions {
  grid-template-columns: repeat(4, 52px);
  gap: 6px;
  right: calc(8px + env(safe-area-inset-right));
  bottom: calc(8px + env(safe-area-inset-bottom));
}
body.compact .act { width: 52px; height: 52px; font-size: 11px; }
body.compact #menu .card { min-width: 0; width: min(88vw, 300px); padding: 18px 20px; }

/* 正切AI实验室改动：#left 里的两个面板原来都是 position:absolute，叠在同一个位置（Hunger 压住 Morning），改回文档流 */
#left .panel { position: relative; }
/* 页脚署名 */
#credit {
  position: fixed; z-index: 1; left: 50%; transform: translateX(-50%);
  bottom: calc(52px + env(safe-area-inset-bottom));
  font-size: 11px; color: rgba(243,239,226,0.7); background: rgba(22,30,25,0.5);
  padding: 2px 10px; border-radius: 8px; pointer-events: none; white-space: nowrap;
}
body.touch #credit, body.compact #credit {
  left: calc(8px + env(safe-area-inset-left)); transform: none;
  bottom: calc(8px + env(safe-area-inset-bottom)); font-size: 10px; max-width: 40vw; white-space: normal;
}
