/* ===== TerraForge — 採掘×工業自動化ゲーム ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  background: #0b1220;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-container { position: fixed; inset: 0; }
#game-canvas { width: 100%; height: 100%; display: block; cursor: grab; }
#game-canvas:active { cursor: grabbing; }

/* ===== 上部HUD ===== */
#hud-top {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 10px; right: 10px;
  display: flex; justify-content: space-between; align-items: center;
  pointer-events: none;
  z-index: 20;
}
#hud-top > * { pointer-events: auto; }

.hud-chip {
  display: flex; align-items: center; gap: 8px;
  background: rgba(12, 20, 38, 0.85);
  border: 1px solid rgba(255, 200, 60, 0.35);
  color: #ffd75e;
  font-weight: 800; font-size: 18px;
  padding: 8px 16px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
  transition: transform .12s;
}
.hud-chip i { font-size: 15px; }

#hud-left, #hud-top-right { display: flex; gap: 8px; align-items: center; }
#power-display.power-low { color: #ff9d9d; border-color: rgba(255, 110, 110, .55); }

.hud-btn {
  width: 42px; height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(140, 180, 255, 0.25);
  background: rgba(12, 20, 38, 0.85);
  color: #9fc2ff;
  font-size: 17px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: transform .1s, background .15s;
}
.hud-btn:active { transform: scale(.92); background: rgba(60, 90, 160, .7); }
.hud-btn.active { background: rgba(50, 160, 90, .8); color: #fff; border-color: rgba(120,255,170,.5); }

/* ===== カメラパッド(右側) ===== */
#camera-pad {
  position: fixed;
  right: calc(10px + env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-62%);
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
  z-index: 20;
}
#camera-pad-mid { display: flex; gap: 34px; }
#camera-pad-zoom { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }

.cam-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(140, 180, 255, 0.3);
  background: rgba(12, 20, 38, 0.75);
  color: #cfe0ff;
  font-size: 17px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  box-shadow: 0 3px 10px rgba(0,0,0,.35);
  transition: transform .08s, background .12s;
}
.cam-btn:active { transform: scale(.9); background: rgba(70, 110, 190, .8); }

/* ===== 下部ツールバー ===== */
#toolbar {
  position: fixed;
  bottom: calc(8px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 6px;
  max-width: calc(100vw - 12px);
  overflow-x: auto;
  padding: 6px;
  background: rgba(10, 16, 30, 0.85);
  border: 1px solid rgba(140, 180, 255, 0.2);
  border-radius: 18px;
  backdrop-filter: blur(8px);
  z-index: 20;
  scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }

.tool-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  min-width: 64px;
  padding: 7px 6px;
  border-radius: 13px;
  border: 1.5px solid transparent;
  background: rgba(30, 44, 74, 0.6);
  color: #dce7ff;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s, transform .1s;
  flex-shrink: 0;
}
.tool-btn:active { transform: scale(.94); }
.tool-btn.selected {
  background: linear-gradient(160deg, rgba(255,170,40,.35), rgba(255,120,20,.22));
  border-color: #ffb547;
  box-shadow: 0 0 12px rgba(255, 170, 60, .35);
}
.tool-icon { font-size: 21px; line-height: 1.1; }
.tool-name { font-size: 11px; font-weight: 700; }
.tool-cost { font-size: 9px; color: #8fa8d5; font-weight: 500; }
.tool-btn.selected .tool-cost { color: #ffd9a0; }


/* ===== 操作ステータス ===== */
#status-strip {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 20px);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(10, 16, 30, 0.78);
  border: 1px solid rgba(140, 180, 255, 0.24);
  color: #cfe0ff;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(7px);
  z-index: 21;
  pointer-events: none;
}
#status-strip.good { color: #b8ffcb; border-color: rgba(120, 230, 150, .45); }
#status-strip.warn { color: #ffd59d; border-color: rgba(255, 190, 90, .5); }
#status-strip.error { color: #ffb4b4; border-color: rgba(255, 110, 110, .55); }


/* ===== 機械コンテキスト操作 ===== */
#machine-actions {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -120%);
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 18px;
  background: rgba(8, 14, 28, 0.9);
  border: 1px solid rgba(140, 180, 255, 0.32);
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  backdrop-filter: blur(8px);
  z-index: 45;
}
#machine-actions.hidden { display: none; }
#machine-actions button {
  width: 58px; height: 54px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  border-radius: 14px;
  border: 1px solid rgba(140, 180, 255, 0.25);
  background: rgba(28, 42, 72, 0.94);
  color: #e7efff;
  font-family: inherit; font-weight: 800; font-size: 19px;
}
#machine-actions button span { font-size: 10px; }
#machine-actions button:active { transform: scale(.94); background: rgba(70, 110, 190, .9); }
#machine-actions button[data-action="recipe"] {
  background: rgba(40, 72, 120, 0.94);
  border-color: rgba(120, 190, 255, 0.45);
}

/* ===== 一括アップグレード / レシピモーダル ===== */
#upgrade-modal,
#recipe-modal {
  position: fixed; inset: 0;
  background: rgba(4, 8, 18, 0.78);
  backdrop-filter: blur(5px);
  z-index: 51;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
#upgrade-panel,
#recipe-panel {
  background: linear-gradient(170deg, #16223c, #0d1526);
  border: 1px solid rgba(140, 180, 255, 0.3);
  border-radius: 20px;
  padding: 18px;
  max-width: 540px; width: min(540px, 100%);
  max-height: 84vh;
  overflow-y: auto;
  color: #dbe6ff;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
#upgrade-panel h1,
#recipe-panel h1 { font-size: 21px; color: #ffcf6e; margin-bottom: 10px; }
#upgrade-stock-summary,
#recipe-target-label { font-size: 13px; color: #9fb7df; margin-bottom: 10px; }
#upgrade-tree-list,
#recipe-list { display: flex; flex-direction: column; gap: 10px; }
.upgrade-card,
.recipe-card {
  border: 1px solid rgba(140, 180, 255, 0.25);
  background: rgba(18, 30, 54, 0.78);
  border-radius: 14px;
  padding: 10px 12px;
}
.upgrade-card h3,
.recipe-card h3 { font-size: 14px; color: #cfe0ff; margin-bottom: 4px; }
.upgrade-card p,
.recipe-card p { font-size: 12px; color: #9fb7df; }
.upgrade-card button,
.recipe-card button,
#upgrade-actions button,
#recipe-actions button {
  margin-top: 8px;
  border: 1px solid rgba(140, 180, 255, 0.35);
  background: rgba(48, 78, 126, 0.85);
  color: #e8f1ff;
  font-family: inherit;
  font-weight: 800;
  font-size: 13px;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}
.upgrade-card button:disabled,
.recipe-card button:disabled { opacity: 0.45; cursor: not-allowed; }
.upgrade-card button.selected,
.recipe-card button.selected {
  background: linear-gradient(160deg, rgba(255,170,40,.4), rgba(255,120,20,.28));
  border-color: #ffb547;
  color: #ffe8bc;
}
#upgrade-actions,
#recipe-actions { display: flex; justify-content: flex-end; margin-top: 10px; }

/* ===== トースト ===== */
#toast-area {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
  z-index: 40;
  pointer-events: none;
}
.toast {
  background: rgba(15, 24, 44, 0.92);
  color: #fff;
  font-size: 13px; font-weight: 700;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid rgba(140, 180, 255, 0.3);
  animation: toast-in .25s ease, toast-out .4s ease 2.2s forwards;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.toast.error { border-color: rgba(255, 110, 110, .55); color: #ffb4b4; }
.toast.good { border-color: rgba(120, 230, 150, .55); color: #b8ffcb; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px) scale(.9); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

/* ===== ヘルプモーダル ===== */
#help-modal {
  position: fixed; inset: 0;
  background: rgba(4, 8, 18, 0.78);
  backdrop-filter: blur(5px);
  z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
#help-modal.hidden { display: none; }

#help-panel {
  background: linear-gradient(170deg, #16223c, #0d1526);
  border: 1px solid rgba(140, 180, 255, 0.3);
  border-radius: 20px;
  padding: 22px 24px;
  max-width: 520px; width: 100%;
  max-height: 84vh;
  overflow-y: auto;
  color: #dbe6ff;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
#help-panel h1 { font-size: 22px; color: #ffcf6e; margin-bottom: 10px; }
#help-panel h1 small { font-size: 13px; color: #8fa8d5; font-weight: 500; margin-left: 8px; }
#help-panel h2 { font-size: 15px; color: #9fd0ff; margin: 14px 0 5px; }
#help-panel p, #help-panel li { font-size: 13.5px; line-height: 1.75; }
#help-panel ol { padding-left: 20px; }
#help-panel b { color: #ffd9a0; }

#help-actions { display: flex; gap: 10px; margin-top: 20px; }
#help-actions button {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: none;
  font-family: inherit; font-weight: 800; font-size: 14px;
  cursor: pointer;
}
#btn-close-help { background: linear-gradient(160deg, #ffb547, #f08c1e); color: #3a2400; }
#btn-reset { background: rgba(180, 60, 60, .25); color: #ff9d9d; border: 1px solid rgba(255,120,120,.35) !important; }
#help-actions button:active { transform: scale(.97); }

/* ===== レスポンシブ調整 ===== */
@media (max-width: 700px) {
  #status-strip { bottom: calc(84px + env(safe-area-inset-bottom)); font-size: 11px; max-width: calc(100vw - 16px); }
  .cam-btn { width: 42px; height: 42px; font-size: 15px; }
  #camera-pad-mid { gap: 26px; }
  .hud-chip { font-size: 15px; padding: 7px 13px; }
  .hud-btn { width: 38px; height: 38px; font-size: 15px; }
  .tool-btn { min-width: 56px; }
  .tool-icon { font-size: 19px; }
}
@media (max-height: 500px) {
  #camera-pad { transform: translateY(-58%) scale(.85); }
}
