* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  font-family: "Segoe UI", "Hiragino Sans", "Meiryo", sans-serif;
  color: #e8efe4;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0f0a;
  color: #9ab;
  font-size: 1.1rem;
  z-index: 20;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.panel {
  position: absolute;
  top: 52px;
  left: 8px;
  max-width: min(300px, calc(100vw - 200px));
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(120, 180, 100, 0.35);
  border-radius: 6px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.panel.hidden {
  display: none;
}

.panel .hint {
  margin-top: 6px;
  color: #9ab;
  font-size: 0.78rem;
}

#stamina-bar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: min(280px, 60vw);
  height: 10px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(180, 200, 160, 0.4);
  border-radius: 5px;
  overflow: hidden;
}

#stamina-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #5a9, #8d4);
  transition: width 0.08s linear;
}

#stamina-fill.low {
  background: linear-gradient(90deg, #a53, #d84);
}

#status-row {
  position: absolute;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  font-size: 0.9rem;
  text-shadow: 0 1px 3px #000;
}

#key-status.has-key {
  color: #d4af37;
}

#help-status.urgent {
  color: #f96;
  animation: pulse-help 0.8s ease-in-out infinite;
}

@keyframes pulse-help {
  50% { opacity: 0.7; }
}

#hide-hint {
  color: #8cf;
}

#key-near {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, 80px);
  padding: 6px 14px;
  background: rgba(40, 35, 10, 0.75);
  border: 1px solid rgba(255, 215, 0, 0.4);
  border-radius: 5px;
  color: #ffd866;
  font-size: 0.9rem;
  text-shadow: 0 1px 2px #000;
}

.minimap-label {
  position: absolute;
  top: 42px;
  right: 8px;
  left: auto;
  max-width: 170px;
  font-size: 0.62rem;
  color: rgba(180, 200, 170, 0.65);
  text-align: right;
  text-shadow: 0 1px 2px #000;
}

#message {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  font-size: 1.1rem;
}

#message.visible {
  opacity: 1;
}

#enemy-debug {
  display: none;
  position: absolute;
  bottom: 12px;
  left: 12px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 0.75rem;
  font-family: monospace;
}

.debug-mode #enemy-debug {
  display: block;
  max-width: 340px;
  line-height: 1.45;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  pointer-events: auto;
}

.overlay.visible {
  display: flex;
}

.overlay-box {
  max-width: 420px;
  padding: 28px 32px;
  background: #141a14;
  border: 1px solid #3a5a38;
  border-radius: 10px;
  text-align: center;
}

.overlay-box h1 {
  font-size: 1.5rem;
  margin-bottom: 12px;
  color: #b8e0a8;
}

.overlay-box p {
  margin-bottom: 20px;
  line-height: 1.6;
  color: #bdc;
}

#overlay-btn {
  padding: 10px 28px;
  font-size: 1rem;
  background: #2a5a2a;
  color: #efe;
  border: 1px solid #4a8a4a;
  border-radius: 6px;
  cursor: pointer;
}

#overlay-btn:hover {
  background: #3a7a3a;
}

#enemy-map-btn,
#settings-btn {
  /* legacy — toolbar内に移動 */
}

#hud-toolbar {
  display: none;
}

#hud-menu-wrap {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 14;
  pointer-events: auto;
}

.hud-menu-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
  background: rgba(20, 30, 20, 0.9);
  color: #dfe;
  border: 1px solid rgba(120, 180, 100, 0.5);
  border-radius: 8px;
  cursor: pointer;
}

.hud-menu-panel {
  position: absolute;
  top: 44px;
  left: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 118px;
  padding: 6px;
  background: rgba(10, 18, 10, 0.94);
  border: 1px solid rgba(120, 180, 100, 0.4);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

.hud-menu-panel[hidden] {
  display: none !important;
}

.hud-btn-install {
  display: none;
}

body.mobile-device .hud-btn-install {
  display: block;
}

body.mobile-device .hud-btn-pc-fs {
  display: none;
}

.install-toast {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%);
  max-width: min(92vw, 360px);
  padding: 12px 16px;
  z-index: 90;
  background: rgba(20, 35, 20, 0.95);
  border: 1px solid rgba(140, 200, 120, 0.5);
  border-radius: 8px;
  color: #dfe;
  font-size: 0.85rem;
  line-height: 1.45;
  text-align: center;
  pointer-events: none;
}

.install-toast.visible {
  display: block;
}

.install-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 0;
  right: 0;
  z-index: 96;
  padding: 6px 12px;
  background: rgba(25, 45, 25, 0.92);
  border-bottom: 1px solid rgba(140, 200, 120, 0.4);
  font-size: 0.78rem;
  color: #dfe;
}

.install-banner[hidden] {
  display: none !important;
}

.install-banner button {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 0.72rem;
  background: #2a5a2a;
  color: #efe;
  border: 1px solid #4a8a4a;
  border-radius: 5px;
  cursor: pointer;
}

body.mobile-device:not(.standalone-app) #hud-menu-wrap {
  top: calc(34px + env(safe-area-inset-top, 0));
}

body.standalone-app .install-banner {
  display: none !important;
}

.hud-btn {
  padding: 7px 9px;
  font-size: 0.76rem;
  background: rgba(20, 30, 20, 0.88);
  color: #bdc;
  border: 1px solid rgba(120, 180, 100, 0.45);
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}

.hud-btn.on {
  background: rgba(50, 70, 45, 0.92);
  border-color: rgba(160, 220, 140, 0.55);
  color: #dfe;
}

#enemy-map-btn.on,
.hud-btn#enemy-map-btn.on {
  background: rgba(80, 40, 40, 0.88);
  border-color: rgba(255, 120, 100, 0.5);
  color: #fcc;
}

.hud-btn-fs {
  border-color: rgba(140, 160, 200, 0.45);
}

#enemy-map-btn {
  position: static;
  pointer-events: auto;
}

#help-near {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, 120px);
  padding: 6px 14px;
  background: rgba(30, 20, 45, 0.75);
  border: 1px solid rgba(180, 120, 255, 0.4);
  border-radius: 5px;
  color: #d8b8ff;
  font-size: 0.9rem;
  text-shadow: 0 1px 2px #000;
}

#hide-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  background: radial-gradient(ellipse at center, transparent 25%, rgba(0, 0, 0, 0.55) 100%);
  box-shadow: inset 0 0 80px rgba(20, 60, 30, 0.35);
}

#hide-vignette.active {
  opacity: 1;
}


#settings-btn {
  position: static;
  pointer-events: auto;
}

.gamepad-status {
  position: absolute;
  top: 8px;
  right: 8px;
  max-width: 160px;
  font-size: 0.65rem;
  color: rgba(180, 200, 170, 0.7);
  text-align: right;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}

.learn-hint {
  position: absolute;
  top: 24px;
  right: 8px;
  max-width: 160px;
  font-size: 0.62rem;
  color: rgba(160, 190, 220, 0.75);
  text-align: right;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}

.settings-panel {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 30;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  pointer-events: auto;
}

.settings-panel.visible {
  display: flex;
}

.settings-box {
  width: min(420px, 92vw);
  max-height: 80vh;
  overflow: auto;
  padding: 20px;
  background: #141a14;
  border: 1px solid #3a5a38;
  border-radius: 8px;
}

.settings-box h2 {
  margin-bottom: 8px;
  color: #b8e0a8;
  font-size: 1.1rem;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(80, 120, 80, 0.25);
  font-size: 0.85rem;
}

.settings-row button {
  min-width: 72px;
  padding: 4px 10px;
  background: #2a4a2a;
  color: #efe;
  border: 1px solid #4a7a4a;
  border-radius: 4px;
  cursor: pointer;
}

.settings-mouse {
  display: block;
  margin: 14px 0 8px;
  font-size: 0.85rem;
}

.settings-mouse select {
  margin-left: 8px;
  background: #1a221a;
  color: #efe;
  border: 1px solid #4a6a4a;
  padding: 4px 8px;
}

.settings-slider {
  display: block;
  margin: 12px 0 8px;
  font-size: 0.85rem;
}

.settings-slider input[type="range"] {
  width: 55%;
  margin: 0 10px;
  vertical-align: middle;
}

.settings-slider span {
  font-family: monospace;
  color: #9c9;
}

.settings-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.settings-actions button {
  padding: 8px 16px;
  background: #2a5a2a;
  color: #efe;
  border: 1px solid #4a8a4a;
  border-radius: 6px;
  cursor: pointer;
}

/* 第2波: タッチ操作 UI */
.touch-ui {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  display: none;
}

.touch-ui--enabled.touch-ui--active {
  display: block;
}

.touch-ui--active .touch-look-zone,
.touch-ui--active .touch-stick-wrap,
.touch-ui--active .touch-actions {
  pointer-events: auto;
}

.touch-look-zone {
  position: absolute;
  top: 0;
  right: 0;
  width: 55%;
  height: 100%;
  touch-action: none;
}

.touch-stick-wrap {
  position: absolute;
  left: 16px;
  bottom: 72px;
  width: 120px;
  height: 120px;
  touch-action: none;
}

.touch-stick-base {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(20, 35, 20, 0.45);
  border: 2px solid rgba(120, 180, 100, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.touch-stick-knob {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(160, 210, 140, 0.55);
  border: 2px solid rgba(200, 240, 180, 0.5);
  transform: translate(0, 0);
  pointer-events: none;
}

.touch-actions {
  position: absolute;
  right: 16px;
  bottom: 72px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.touch-btn {
  min-width: 52px;
  min-height: 52px;
  padding: 8px 12px;
  border-radius: 50%;
  border: 2px solid rgba(180, 200, 160, 0.5);
  background: rgba(30, 50, 28, 0.65);
  color: #e8efe4;
  font-size: 0.9rem;
  font-weight: bold;
  touch-action: none;
  user-select: none;
}

.touch-btn--held,
.touch-btn:active {
  background: rgba(80, 130, 60, 0.75);
  border-color: rgba(200, 240, 180, 0.8);
}

.touch-btn-run {
  border-color: rgba(220, 180, 100, 0.6);
}

body.touch-mode #game-canvas {
  cursor: default;
}

body.touch-mode #tutorial {
  display: none;
}

body.touch-mode .hud-menu-btn {
  width: 36px;
  height: 36px;
  font-size: 1rem;
}

body.touch-mode .hud-menu-panel .hud-btn {
  min-height: 36px;
  padding: 6px 8px;
  font-size: 0.74rem;
}

body.touch-mode .touch-stick-wrap {
  left: 10px;
  bottom: 12px;
  width: 112px;
  height: 112px;
}

body.touch-mode .touch-actions {
  right: 10px;
  bottom: 12px;
  gap: 8px;
}

body.touch-mode .touch-btn {
  min-width: 52px;
  min-height: 52px;
  font-size: 0.92rem;
  padding: 8px 12px;
}

body.touch-mode #status-row {
  bottom: 38px;
  font-size: 0.72rem;
  gap: 10px;
}

body.touch-mode #stamina-bar {
  bottom: 12px;
  height: 8px;
  width: min(220px, 50vw);
}

body.touch-mode #message {
  font-size: 0.88rem;
  max-width: 88vw;
  padding: 8px 14px;
}

body.touch-mode #key-near,
body.touch-mode #help-near {
  font-size: 0.78rem;
  padding: 4px 10px;
}

body.touch-mode .gamepad-status,
body.touch-mode .learn-hint {
  display: none;
}

body.touch-mode .touch-look-zone {
  width: 62%;
  right: 0;
  left: auto;
}

body.touch-mode .minimap-label {
  display: none;
}

@media (pointer: coarse) and (orientation: landscape) {
  .touch-hint {
    display: block;
  }
}

/* 縦画面時のソフト案内（ゲームはブロックしない） */
.portrait-hint {
  display: none;
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 0;
  right: 0;
  z-index: 95;
  padding: 8px 12px;
  background: rgba(10, 18, 10, 0.88);
  border-bottom: 1px solid rgba(120, 180, 100, 0.35);
  pointer-events: none;
}

.portrait-hint-box {
  max-width: 100%;
  padding: 0;
  text-align: center;
}

.portrait-hint-box h2 {
  font-size: 0.9rem;
  margin-bottom: 2px;
  color: #b8e0a8;
}

.portrait-hint-box p {
  font-size: 0.78rem;
  line-height: 1.35;
  color: #bdc;
}

.portrait-hint-box .hint {
  margin-top: 4px;
  color: #9ab;
  font-size: 0.72rem;
}

body.portrait-mode .portrait-hint {
  display: block;
}

body.portrait-hint-dismissed .portrait-hint {
  display: none !important;
}

body.portrait-mode #hud-menu-wrap {
  top: calc(44px + env(safe-area-inset-top, 0));
}

body.portrait-hint-dismissed.portrait-mode #hud-menu-wrap,
body.portrait-hint-dismissed.mobile-device:not(.standalone-app) #hud-menu-wrap {
  top: calc(6px + env(safe-area-inset-top, 0));
}

/* スマホ横画面 */
body.touch-landscape .touch-stick-wrap {
  left: 24px;
  bottom: 12px;
  width: 112px;
  height: 112px;
}

body.touch-landscape .touch-actions {
  right: 6px;
  bottom: 12px;
  gap: 8px;
}

body.touch-landscape #hud-menu-wrap {
  left: max(18px, calc(env(safe-area-inset-left, 0px) + 14px));
  top: max(6px, env(safe-area-inset-top, 0px));
}

body.touch-landscape #status-row {
  bottom: 54px;
  left: 10px;
  right: auto;
  transform: none;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  font-size: 0.66rem;
  max-width: 42vw;
}

body.touch-landscape #message {
  top: 22%;
  font-size: 0.78rem;
  max-width: 70vw;
  padding: 6px 12px;
}

body.touch-landscape #key-near,
body.touch-landscape #help-near {
  top: auto;
  bottom: 108px;
  left: 10px;
  right: auto;
  transform: none;
  font-size: 0.72rem;
  padding: 4px 10px;
}

body.touch-landscape #stamina-bar {
  bottom: 10px;
  width: min(180px, 38vw);
}
